@tt-a1i/openpi 0.2.0 → 0.3.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/README.md +28 -6
- package/SETUP.md +1 -1
- package/extensions/plan-mode/bash-policy.ts +219 -42
- package/extensions/plan-mode/index.ts +44 -19
- package/extensions/setup/index.ts +3 -3
- package/extensions/shared/editor-layers.ts +150 -0
- package/extensions/shared/setup-config.ts +4 -15
- package/extensions/subagents/index.ts +164 -96
- package/extensions/subagents/src/prompt.ts +6 -6
- package/extensions/subagents/src/ui/takeover.ts +231 -133
- package/extensions/subagents/src/ui/transcript.ts +252 -37
- package/extensions/subagents/src/ui/wait-result.ts +6 -19
- package/extensions/suggestions/index.ts +27 -18
- package/extensions/tasks/index.ts +24 -6
- package/extensions/ui-customization/footer.ts +59 -10
- package/extensions/workflows/index.ts +28 -20
- package/package.json +1 -1
- package/skills/subagents/SKILL.md +1 -1
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CustomEditor,
|
|
3
|
+
type ExtensionAPI,
|
|
4
|
+
type ExtensionContext,
|
|
5
|
+
type KeybindingsManager,
|
|
6
|
+
} from "@earendil-works/pi-coding-agent";
|
|
7
|
+
import type { EditorComponent, EditorTheme, TUI } from "@earendil-works/pi-tui";
|
|
8
|
+
|
|
9
|
+
const CLAIM_CHANNEL = "openpi:editor-layers:claim";
|
|
10
|
+
const REGISTER_CHANNEL = "openpi:editor-layers:register";
|
|
11
|
+
const REMOVE_CHANNEL = "openpi:editor-layers:remove";
|
|
12
|
+
|
|
13
|
+
type EditorFactory = NonNullable<
|
|
14
|
+
ReturnType<ExtensionContext["ui"]["getEditorComponent"]>
|
|
15
|
+
>;
|
|
16
|
+
|
|
17
|
+
export interface EditorLayer {
|
|
18
|
+
readonly id: string;
|
|
19
|
+
readonly order: number;
|
|
20
|
+
readonly wrap: (
|
|
21
|
+
base: EditorComponent,
|
|
22
|
+
tui: TUI,
|
|
23
|
+
theme: EditorTheme,
|
|
24
|
+
keybindings: KeybindingsManager,
|
|
25
|
+
) => EditorComponent;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
interface EditorLayerRegistration {
|
|
29
|
+
readonly ctx: ExtensionContext;
|
|
30
|
+
readonly layer: EditorLayer;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
34
|
+
return typeof value === "object" && value !== null;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function readRegistration(value: unknown) {
|
|
38
|
+
if (!isRecord(value) || !isRecord(value.layer)) return undefined;
|
|
39
|
+
const { ctx, layer } = value;
|
|
40
|
+
if (
|
|
41
|
+
!isRecord(ctx) ||
|
|
42
|
+
typeof layer.id !== "string" ||
|
|
43
|
+
typeof layer.order !== "number" ||
|
|
44
|
+
typeof layer.wrap !== "function"
|
|
45
|
+
) {
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
ctx: ctx as unknown as ExtensionContext,
|
|
50
|
+
layer: layer as unknown as EditorLayer,
|
|
51
|
+
} satisfies EditorLayerRegistration;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function readLayerId(value: unknown) {
|
|
55
|
+
if (!isRecord(value) || typeof value.id !== "string") return undefined;
|
|
56
|
+
return value.id;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function composeEditorFactory(
|
|
60
|
+
previous: EditorFactory | undefined,
|
|
61
|
+
layers: readonly EditorLayer[],
|
|
62
|
+
) {
|
|
63
|
+
return ((tui, theme, keybindings) => {
|
|
64
|
+
let editor =
|
|
65
|
+
previous?.(tui, theme, keybindings) ??
|
|
66
|
+
new CustomEditor(tui, theme, keybindings);
|
|
67
|
+
for (const layer of layers) {
|
|
68
|
+
editor = layer.wrap(editor, tui, theme, keybindings);
|
|
69
|
+
}
|
|
70
|
+
return editor;
|
|
71
|
+
}) satisfies EditorFactory;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Each extension is evaluated in its own jiti module graph, so ordinary module
|
|
76
|
+
* singletons are not shared. The first OpenPI editor contributor claims the
|
|
77
|
+
* runtime EventBus and coordinates the rest through that host-owned boundary.
|
|
78
|
+
*/
|
|
79
|
+
function ensureCoordinator(pi: ExtensionAPI) {
|
|
80
|
+
const claim = { claimed: false };
|
|
81
|
+
pi.events.emit(CLAIM_CHANNEL, claim);
|
|
82
|
+
if (claim.claimed) return;
|
|
83
|
+
|
|
84
|
+
let ctx: ExtensionContext | undefined;
|
|
85
|
+
let installTimer: ReturnType<typeof setTimeout> | undefined;
|
|
86
|
+
const layers = new Map<string, EditorLayer>();
|
|
87
|
+
|
|
88
|
+
const cancelInstall = () => {
|
|
89
|
+
if (installTimer) clearTimeout(installTimer);
|
|
90
|
+
installTimer = undefined;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const install = () => {
|
|
94
|
+
installTimer = undefined;
|
|
95
|
+
const current = ctx;
|
|
96
|
+
if (!current || current.mode !== "tui" || layers.size === 0) return;
|
|
97
|
+
const ordered = [...layers.values()].sort(
|
|
98
|
+
(left, right) =>
|
|
99
|
+
left.order - right.order || left.id.localeCompare(right.id),
|
|
100
|
+
);
|
|
101
|
+
current.ui.setEditorComponent(
|
|
102
|
+
composeEditorFactory(current.ui.getEditorComponent(), ordered),
|
|
103
|
+
);
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const scheduleInstall = () => {
|
|
107
|
+
if (installTimer) return;
|
|
108
|
+
installTimer = setTimeout(install, 0);
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
pi.events.on(CLAIM_CHANNEL, (value) => {
|
|
112
|
+
if (isRecord(value) && value.claimed === false) value.claimed = true;
|
|
113
|
+
});
|
|
114
|
+
pi.events.on(REGISTER_CHANNEL, (value) => {
|
|
115
|
+
const registration = readRegistration(value);
|
|
116
|
+
if (!registration || registration.ctx.mode !== "tui") return;
|
|
117
|
+
if (ctx !== registration.ctx) {
|
|
118
|
+
cancelInstall();
|
|
119
|
+
layers.clear();
|
|
120
|
+
ctx = registration.ctx;
|
|
121
|
+
}
|
|
122
|
+
layers.set(registration.layer.id, registration.layer);
|
|
123
|
+
scheduleInstall();
|
|
124
|
+
});
|
|
125
|
+
pi.events.on(REMOVE_CHANNEL, (value) => {
|
|
126
|
+
const id = readLayerId(value);
|
|
127
|
+
if (!id) return;
|
|
128
|
+
layers.delete(id);
|
|
129
|
+
if (layers.size > 0) return;
|
|
130
|
+
cancelInstall();
|
|
131
|
+
ctx = undefined;
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export function registerEditorLayer(
|
|
136
|
+
pi: ExtensionAPI,
|
|
137
|
+
ctx: ExtensionContext,
|
|
138
|
+
layer: EditorLayer,
|
|
139
|
+
) {
|
|
140
|
+
if (ctx.mode !== "tui") return;
|
|
141
|
+
ensureCoordinator(pi);
|
|
142
|
+
pi.events.emit(REGISTER_CHANNEL, {
|
|
143
|
+
ctx,
|
|
144
|
+
layer,
|
|
145
|
+
} satisfies EditorLayerRegistration);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export function removeEditorLayer(pi: ExtensionAPI, id: string) {
|
|
149
|
+
pi.events.emit(REMOVE_CHANNEL, { id });
|
|
150
|
+
}
|
|
@@ -67,23 +67,12 @@ export const CAPABILITY_DISCOVERY_MODES = ["explicit", "adaptive"] as const;
|
|
|
67
67
|
export type CapabilityDiscoveryMode =
|
|
68
68
|
(typeof CAPABILITY_DISCOVERY_MODES)[number];
|
|
69
69
|
|
|
70
|
-
/** Canonical default layout: one-line
|
|
70
|
+
/** Canonical default layout: one-line plain footer with flex alignment. */
|
|
71
71
|
export const DEFAULT_FOOTER_LINES: FooterLines = [
|
|
72
|
-
[
|
|
73
|
-
"cwd",
|
|
74
|
-
"model",
|
|
75
|
-
"thinking",
|
|
76
|
-
"context",
|
|
77
|
-
"cache",
|
|
78
|
-
"cost",
|
|
79
|
-
"throughput",
|
|
80
|
-
"flex",
|
|
81
|
-
"git",
|
|
82
|
-
"pr",
|
|
83
|
-
],
|
|
72
|
+
["cwd", "git", "pr", "flex", "model", "context", "cost"],
|
|
84
73
|
];
|
|
85
74
|
|
|
86
|
-
export const DEFAULT_FOOTER_STYLE: FooterStyle = "
|
|
75
|
+
export const DEFAULT_FOOTER_STYLE: FooterStyle = "plain";
|
|
87
76
|
|
|
88
77
|
export const DEFAULT_FOOTER_ITEMS: readonly FooterItem[] =
|
|
89
78
|
flattenFooterItems(DEFAULT_FOOTER_LINES);
|
|
@@ -967,7 +956,7 @@ export function formatSetupConfig(
|
|
|
967
956
|
suggestions,
|
|
968
957
|
`Workflows: ${config.workflows.concurrency} concurrent agents · ${config.workflows.maxAgentCalls} total calls`,
|
|
969
958
|
`UI: large header ${config.ui.showHeader ? "on" : "off"} · custom footer ${footer}`,
|
|
970
|
-
`Subagent results: ${config.ui.subagentResultDisplay === "full" ? "full by default" : "compact
|
|
959
|
+
`Subagent results: ${config.ui.subagentResultDisplay === "full" ? "full by default" : "compact status summary (Ctrl+O expands full output)"}`,
|
|
971
960
|
`Bash operations: ${config.ui.bashToolDisplay === "full" ? "expanded by default" : "folded preview (Ctrl+O expands all)"}`,
|
|
972
961
|
`Write/Edit operations: ${config.ui.fileMutationDisplay === "full" ? "expanded by default" : "folded preview (Ctrl+O expands all)"}`,
|
|
973
962
|
`Post-edit command: ${config.postEdit.command ? config.postEdit.command : "off"}`,
|
|
@@ -31,9 +31,9 @@ import type {
|
|
|
31
31
|
ExtensionCommandContext,
|
|
32
32
|
ExtensionContext,
|
|
33
33
|
ExtensionUIContext,
|
|
34
|
+
MessageRenderer,
|
|
34
35
|
} from "@earendil-works/pi-coding-agent";
|
|
35
36
|
import {
|
|
36
|
-
CustomEditor,
|
|
37
37
|
DEFAULT_MAX_BYTES,
|
|
38
38
|
DEFAULT_MAX_LINES,
|
|
39
39
|
defineTool,
|
|
@@ -69,6 +69,10 @@ import {
|
|
|
69
69
|
OPENPI_TOOL_SURFACE,
|
|
70
70
|
patchOwnedTools,
|
|
71
71
|
} from "../shared/tool-surface.ts";
|
|
72
|
+
import {
|
|
73
|
+
registerEditorLayer,
|
|
74
|
+
removeEditorLayer,
|
|
75
|
+
} from "../shared/editor-layers.ts";
|
|
72
76
|
import { formatContextUtilization } from "./src/format.ts";
|
|
73
77
|
import { SubagentManager, type SubagentManagerShape } from "./src/manager.ts";
|
|
74
78
|
import {
|
|
@@ -125,6 +129,7 @@ import {
|
|
|
125
129
|
} from "./navigation.ts";
|
|
126
130
|
import { openSubagentPicker, openSubagentTakeover } from "./src/ui/takeover.ts";
|
|
127
131
|
import {
|
|
132
|
+
buildWaitResultPreview,
|
|
128
133
|
renderWaitResult,
|
|
129
134
|
type WaitResultDetails,
|
|
130
135
|
} from "./src/ui/wait-result.ts";
|
|
@@ -148,6 +153,23 @@ interface SubagentFinishedData {
|
|
|
148
153
|
readonly elapsed: string;
|
|
149
154
|
}
|
|
150
155
|
|
|
156
|
+
interface SubagentResultDetails {
|
|
157
|
+
readonly id?: string;
|
|
158
|
+
readonly title?: string;
|
|
159
|
+
readonly status?: SubagentSnapshot["status"];
|
|
160
|
+
readonly count?: number;
|
|
161
|
+
readonly results?: ReadonlyArray<{
|
|
162
|
+
readonly id: string;
|
|
163
|
+
readonly title: string;
|
|
164
|
+
readonly status: SubagentSnapshot["status"];
|
|
165
|
+
}>;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
interface SubagentResultEntryData {
|
|
169
|
+
readonly content: string;
|
|
170
|
+
readonly details: SubagentResultDetails;
|
|
171
|
+
}
|
|
172
|
+
|
|
151
173
|
interface BtwResultData {
|
|
152
174
|
readonly id: string;
|
|
153
175
|
readonly title: string;
|
|
@@ -184,6 +206,104 @@ function truncatedOutput(
|
|
|
184
206
|
return text;
|
|
185
207
|
}
|
|
186
208
|
|
|
209
|
+
export function createSubagentResultDispatcher(
|
|
210
|
+
pi: ExtensionAPI,
|
|
211
|
+
outputFor: (snap: SubagentSnapshot) => string = truncatedOutput,
|
|
212
|
+
) {
|
|
213
|
+
return (snaps: readonly SubagentSnapshot[], wake: boolean) => {
|
|
214
|
+
if (snaps.length === 0) return;
|
|
215
|
+
const content = snaps
|
|
216
|
+
.map((snap) =>
|
|
217
|
+
buildSubagentResultMessage({
|
|
218
|
+
id: snap.id,
|
|
219
|
+
title: snap.title,
|
|
220
|
+
status: snap.status,
|
|
221
|
+
errorText: snap.errorText,
|
|
222
|
+
output: outputFor(snap),
|
|
223
|
+
}),
|
|
224
|
+
)
|
|
225
|
+
.join("\n\n");
|
|
226
|
+
const details: SubagentResultDetails =
|
|
227
|
+
snaps.length === 1
|
|
228
|
+
? {
|
|
229
|
+
id: snaps[0]!.id,
|
|
230
|
+
title: snaps[0]!.title,
|
|
231
|
+
status: snaps[0]!.status,
|
|
232
|
+
}
|
|
233
|
+
: {
|
|
234
|
+
count: snaps.length,
|
|
235
|
+
results: snaps.map((snap) => ({
|
|
236
|
+
id: snap.id,
|
|
237
|
+
title: snap.title,
|
|
238
|
+
status: snap.status,
|
|
239
|
+
})),
|
|
240
|
+
};
|
|
241
|
+
pi.appendEntry<SubagentResultEntryData>("subagent-result", {
|
|
242
|
+
content,
|
|
243
|
+
details,
|
|
244
|
+
});
|
|
245
|
+
pi.sendMessage(
|
|
246
|
+
{
|
|
247
|
+
customType: "subagent-result",
|
|
248
|
+
content,
|
|
249
|
+
display: false,
|
|
250
|
+
details,
|
|
251
|
+
},
|
|
252
|
+
resultDeliveryOptions(wake),
|
|
253
|
+
);
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
type SubagentResultTheme = Parameters<MessageRenderer>[2];
|
|
258
|
+
|
|
259
|
+
function renderSubagentResult(
|
|
260
|
+
content: string,
|
|
261
|
+
details: SubagentResultDetails,
|
|
262
|
+
expanded: boolean,
|
|
263
|
+
theme: SubagentResultTheme,
|
|
264
|
+
) {
|
|
265
|
+
if (!expanded && loadSetupConfig().ui.subagentResultDisplay === "compact") {
|
|
266
|
+
const results = details.results?.length
|
|
267
|
+
? details.results
|
|
268
|
+
: details.id
|
|
269
|
+
? [
|
|
270
|
+
{
|
|
271
|
+
id: details.id,
|
|
272
|
+
title: details.title,
|
|
273
|
+
status: details.status,
|
|
274
|
+
},
|
|
275
|
+
]
|
|
276
|
+
: [];
|
|
277
|
+
return new Text(buildWaitResultPreview(content, { results }, theme), 0, 0);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
const failed = details.status === "error";
|
|
281
|
+
const icon = failed ? theme.fg("error", "x") : theme.fg("success", "■");
|
|
282
|
+
const header =
|
|
283
|
+
`${icon} ` +
|
|
284
|
+
theme.fg("accent", theme.bold(`subagent ${details.id ?? "?"}`)) +
|
|
285
|
+
theme.fg(
|
|
286
|
+
"muted",
|
|
287
|
+
` · ${details.title ?? ""} · ${failed ? "failed" : "finished"}`,
|
|
288
|
+
);
|
|
289
|
+
|
|
290
|
+
// Remove only the summary line. The following Error line (when present)
|
|
291
|
+
// is part of the actual result and must remain visible.
|
|
292
|
+
const body = content.split("\n").slice(1).join("\n").trim();
|
|
293
|
+
const md = new Markdown(body, 0, 0, getMarkdownTheme());
|
|
294
|
+
const container = new Text(header, 0, 0);
|
|
295
|
+
return {
|
|
296
|
+
render: (width: number) => [
|
|
297
|
+
...container.render(width),
|
|
298
|
+
...md.render(width),
|
|
299
|
+
],
|
|
300
|
+
invalidate: () => {
|
|
301
|
+
container.invalidate();
|
|
302
|
+
md.invalidate();
|
|
303
|
+
},
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
|
|
187
307
|
export default function (pi: ExtensionAPI) {
|
|
188
308
|
let runtime: SubagentRuntime | undefined;
|
|
189
309
|
let managerPromise: Promise<SubagentManagerShape> | undefined;
|
|
@@ -200,8 +320,10 @@ export default function (pi: ExtensionAPI) {
|
|
|
200
320
|
let navigationManager: SubagentManagerShape | undefined;
|
|
201
321
|
let widgetVisible = false;
|
|
202
322
|
let requestWidgetRender: (() => void) | undefined;
|
|
323
|
+
let navigationLayerRegistered = false;
|
|
203
324
|
let dashboardOpen = false;
|
|
204
325
|
const resultDelivery = createDeferredResultDelivery<SubagentSnapshot>();
|
|
326
|
+
const dispatchResults = createSubagentResultDispatcher(pi);
|
|
205
327
|
const hideLifecycleTools = () =>
|
|
206
328
|
patchOwnedTools(pi, "subagents", {
|
|
207
329
|
disable: OPENPI_TOOL_SURFACE.subagents.deferred,
|
|
@@ -292,26 +414,26 @@ export default function (pi: ExtensionAPI) {
|
|
|
292
414
|
|
|
293
415
|
const installSubagentNavigation = (ctx: ExtensionContext) => {
|
|
294
416
|
if (ctx.mode !== "tui") return;
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
new
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
);
|
|
417
|
+
registerEditorLayer(pi, ctx, {
|
|
418
|
+
id: "subagents",
|
|
419
|
+
order: 100,
|
|
420
|
+
wrap: (base, tui, _theme, keybindings) =>
|
|
421
|
+
new BelowEditorNavigationEditor(
|
|
422
|
+
base,
|
|
423
|
+
keybindings,
|
|
424
|
+
stripState,
|
|
425
|
+
() => Boolean(stripEntry()),
|
|
426
|
+
() => {
|
|
427
|
+
const entry = stripEntry();
|
|
428
|
+
if (entry) void openDashboard(ctx, entry.snapshot.id);
|
|
429
|
+
},
|
|
430
|
+
() => {
|
|
431
|
+
requestWidgetRender?.();
|
|
432
|
+
tui.requestRender();
|
|
433
|
+
},
|
|
434
|
+
),
|
|
314
435
|
});
|
|
436
|
+
navigationLayerRegistered = true;
|
|
315
437
|
};
|
|
316
438
|
|
|
317
439
|
/**
|
|
@@ -326,41 +448,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
326
448
|
snaps: readonly SubagentSnapshot[],
|
|
327
449
|
wake: boolean,
|
|
328
450
|
) => {
|
|
329
|
-
|
|
330
|
-
pi.sendMessage(
|
|
331
|
-
{
|
|
332
|
-
customType: "subagent-result",
|
|
333
|
-
// One message per flush, not per subagent.
|
|
334
|
-
content: snaps
|
|
335
|
-
.map((snap) =>
|
|
336
|
-
buildSubagentResultMessage({
|
|
337
|
-
id: snap.id,
|
|
338
|
-
title: snap.title,
|
|
339
|
-
status: snap.status,
|
|
340
|
-
errorText: snap.errorText,
|
|
341
|
-
output: truncatedOutput(snap),
|
|
342
|
-
}),
|
|
343
|
-
)
|
|
344
|
-
.join("\n\n"),
|
|
345
|
-
display: true,
|
|
346
|
-
details:
|
|
347
|
-
snaps.length === 1
|
|
348
|
-
? {
|
|
349
|
-
id: snaps[0]!.id,
|
|
350
|
-
title: snaps[0]!.title,
|
|
351
|
-
status: snaps[0]!.status,
|
|
352
|
-
}
|
|
353
|
-
: {
|
|
354
|
-
count: snaps.length,
|
|
355
|
-
results: snaps.map((snap) => ({
|
|
356
|
-
id: snap.id,
|
|
357
|
-
title: snap.title,
|
|
358
|
-
status: snap.status,
|
|
359
|
-
})),
|
|
360
|
-
},
|
|
361
|
-
},
|
|
362
|
-
resultDeliveryOptions(wake),
|
|
363
|
-
);
|
|
451
|
+
dispatchResults(snaps, wake);
|
|
364
452
|
};
|
|
365
453
|
|
|
366
454
|
const flushResults = (wake: boolean) => {
|
|
@@ -447,6 +535,10 @@ export default function (pi: ExtensionAPI) {
|
|
|
447
535
|
pi.on("agent_settled", () => flushResults(false));
|
|
448
536
|
|
|
449
537
|
pi.on("session_shutdown", async () => {
|
|
538
|
+
if (navigationLayerRegistered) {
|
|
539
|
+
removeEditorLayer(pi, "subagents");
|
|
540
|
+
navigationLayerRegistered = false;
|
|
541
|
+
}
|
|
450
542
|
resultDelivery.clear();
|
|
451
543
|
unsubStatus?.();
|
|
452
544
|
unsubStatus = undefined;
|
|
@@ -1051,52 +1143,28 @@ export default function (pi: ExtensionAPI) {
|
|
|
1051
1143
|
pi.registerMessageRenderer(
|
|
1052
1144
|
"subagent-result",
|
|
1053
1145
|
(message, { expanded }, theme) => {
|
|
1054
|
-
const details = (message.details ?? {}) as {
|
|
1055
|
-
id?: string;
|
|
1056
|
-
title?: string;
|
|
1057
|
-
status?: string;
|
|
1058
|
-
};
|
|
1059
|
-
const failed = details.status === "error";
|
|
1060
|
-
const icon = failed ? theme.fg("error", "x") : theme.fg("success", "■");
|
|
1061
|
-
const header =
|
|
1062
|
-
`${icon} ` +
|
|
1063
|
-
theme.fg("accent", theme.bold(`subagent ${details.id ?? "?"}`)) +
|
|
1064
|
-
theme.fg(
|
|
1065
|
-
"muted",
|
|
1066
|
-
` · ${details.title ?? ""} · ${failed ? "failed" : "finished"}`,
|
|
1067
|
-
);
|
|
1068
|
-
|
|
1069
1146
|
const content =
|
|
1070
1147
|
typeof message.content === "string" ? message.content : "";
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
const container = new Text(header, 0, 0);
|
|
1078
|
-
return {
|
|
1079
|
-
render: (width: number) => [
|
|
1080
|
-
...container.render(width),
|
|
1081
|
-
...md.render(width),
|
|
1082
|
-
],
|
|
1083
|
-
invalidate: () => {
|
|
1084
|
-
container.invalidate();
|
|
1085
|
-
md.invalidate();
|
|
1086
|
-
},
|
|
1087
|
-
};
|
|
1088
|
-
}
|
|
1089
|
-
|
|
1090
|
-
const previewLines = body.split("\n").slice(0, 8);
|
|
1091
|
-
let text = header;
|
|
1092
|
-
for (const line of previewLines)
|
|
1093
|
-
text += `\n${theme.fg("toolOutput", line)}`;
|
|
1094
|
-
if (body.split("\n").length > 8)
|
|
1095
|
-
text += `\n${theme.fg("dim", `... (${keyHint("app.tools.expand", "to expand")})`)}`;
|
|
1096
|
-
return new Text(text, 0, 0);
|
|
1148
|
+
return renderSubagentResult(
|
|
1149
|
+
content,
|
|
1150
|
+
(message.details ?? {}) as SubagentResultDetails,
|
|
1151
|
+
expanded,
|
|
1152
|
+
theme,
|
|
1153
|
+
);
|
|
1097
1154
|
},
|
|
1098
1155
|
);
|
|
1099
1156
|
|
|
1157
|
+
pi.registerEntryRenderer<SubagentResultEntryData>(
|
|
1158
|
+
"subagent-result",
|
|
1159
|
+
(entry, { expanded }, theme) =>
|
|
1160
|
+
renderSubagentResult(
|
|
1161
|
+
entry.data?.content ?? "",
|
|
1162
|
+
entry.data?.details ?? {},
|
|
1163
|
+
expanded,
|
|
1164
|
+
theme,
|
|
1165
|
+
),
|
|
1166
|
+
);
|
|
1167
|
+
|
|
1100
1168
|
pi.registerEntryRenderer<SubagentFinishedData>(
|
|
1101
1169
|
"subagent-finished",
|
|
1102
1170
|
(entry, _options, theme) => {
|
|
@@ -8,7 +8,7 @@ import { MAX_RUNNING } from "./manager.ts";
|
|
|
8
8
|
|
|
9
9
|
/** Describes subagent_spawn, including the fixed concurrency cap. */
|
|
10
10
|
export const SUBAGENT_SPAWN_TOOL_DESCRIPTION =
|
|
11
|
-
"Spawn a background subagent: a fully autonomous, headless pi session with its own context window, this environment's tools and config, and normal host permissions. Fire-and-forget: this returns immediately with an id
|
|
11
|
+
"Spawn a background subagent: a fully autonomous, headless pi session with its own context window, this environment's tools and config, and normal host permissions. Fire-and-forget: this returns immediately with an id, and the subagent's final output is automatically queued back to you as a message when it settles. In an interactive session, keep working or end your turn so the user remains able to interact; do not block merely because a later step depends on the result. Children cannot orchestrate more agents/workflows or ask the user, and cannot see this conversation, so the prompt must be self-contained. Only use trusted working directories. " +
|
|
12
12
|
`Max ${MAX_RUNNING} subagents can be running at once.`;
|
|
13
13
|
|
|
14
14
|
/**
|
|
@@ -62,7 +62,7 @@ export const SUBAGENT_SPAWN_PROMPT_SNIPPET =
|
|
|
62
62
|
/** Guides the parent model to delegate standalone tasks and avoid unnecessary blocking waits. */
|
|
63
63
|
export const SUBAGENT_SPAWN_PROMPT_GUIDELINES = [
|
|
64
64
|
"Reserve subagent_spawn for substantial, self-contained work; give it a complete, standalone prompt. For a single lookup or edit you can do inline, just do it — each subagent spends a fresh context window and cannot see this conversation.",
|
|
65
|
-
"After subagent_spawn, keep working on
|
|
65
|
+
"After subagent_spawn, keep working on independent work. If none remains in an interactive session, briefly tell the user the subagent is running in the background and end your turn; its result arrives automatically and you are re-invoked when it settles. Do not poll with subagent_check. Do not call subagent_wait merely because your next step depends on the result or because you have nothing else to do. Block only when the user explicitly asks you to keep the current response open for these results, or when a non-interactive automation must return them in the same invocation. Never answer from a guessed result before it arrives.",
|
|
66
66
|
];
|
|
67
67
|
|
|
68
68
|
/** Model-facing schema descriptions for subagent_spawn task and execution options. */
|
|
@@ -113,14 +113,14 @@ export function buildSubagentSpawnResult(options: {
|
|
|
113
113
|
: "";
|
|
114
114
|
return (
|
|
115
115
|
`Spawned subagent ${options.id} "${options.title}" (${options.harness}: ${options.modelLabel}, ${options.cwd}).${typeNote}${toolNote}${worktreeNote}\n` +
|
|
116
|
-
`It runs in the background — keep working on
|
|
117
|
-
`
|
|
116
|
+
`It runs in the background — keep working on independent work. If none remains in an interactive session, briefly tell the user it is still running and end your turn; its result is delivered automatically and you are automatically re-invoked when it finishes. Do not poll or call subagent_wait merely because a later step depends on it. ` +
|
|
117
|
+
`Use subagent_wait(ids: ["${options.id}"]) only if the user explicitly asked you to keep the current response open for this result, or a non-interactive automation must return it in the same invocation; subagent_cancel stops it, subagent_check peeks at a running one, subagent_list shows all.`
|
|
118
118
|
);
|
|
119
119
|
}
|
|
120
120
|
|
|
121
121
|
/** Describes explicit blocking collection of one or more subagent results. */
|
|
122
122
|
export const SUBAGENT_WAIT_TOOL_DESCRIPTION =
|
|
123
|
-
"Block until all listed subagents have settled, then return their final outputs. This is
|
|
123
|
+
"Block until all listed subagents have settled, then return their final outputs. This is an explicit synchronous barrier, not the default. In an interactive session, call it only when the user explicitly asks you to keep the current response open for these results. A dependent next step or having nothing else to do is not sufficient: end your turn and let automatic result delivery re-invoke you while the user remains free to interact. In a non-interactive automation, use it only when the same invocation must return the completed results. Never poll for completion and never answer from a guessed result before it arrives.";
|
|
124
124
|
|
|
125
125
|
/** Model-facing schema description for the subagent ids to await. */
|
|
126
126
|
export const SUBAGENT_WAIT_PARAMETER_DESCRIPTIONS = {
|
|
@@ -154,7 +154,7 @@ export function buildSubagentSendResult(options: {
|
|
|
154
154
|
}) {
|
|
155
155
|
return options.wasRunning
|
|
156
156
|
? `Steered ${options.id} "${options.title}". It is queued into the active run; the result is delivered when it settles.`
|
|
157
|
-
: `Restarted ${options.id} "${options.title}" for another turn on its existing transcript. The result is delivered when it settles
|
|
157
|
+
: `Restarted ${options.id} "${options.title}" for another turn on its existing transcript. The result is delivered automatically when it settles.`;
|
|
158
158
|
}
|
|
159
159
|
|
|
160
160
|
/** Describes nonblocking inspection of a subagent without consuming its result. */
|