pi-subagent-manager 0.11.2 → 0.12.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 +2 -0
- package/docs/settings.md +9 -0
- package/docs/tools-and-ui.md +3 -1
- package/package.json +1 -1
- package/src/index.ts +85 -7
- package/src/prefs/settings.ts +6 -4
- package/src/ui/live-agent-view.ts +134 -27
- package/src/ui/settings-ui.ts +8 -0
package/README.md
CHANGED
|
@@ -76,6 +76,8 @@ A live **Agents** widget sits above the input box. Choose **Full** (the existing
|
|
|
76
76
|
|
|
77
77
|
Experimental features are marked **[labs]** in settings. Enable **[labs] Nerd Font icons** in `/agents` to show role-specific icons beside agent names (off by default; requires a Nerd Font in your terminal). Custom agent types can set an optional `icon` or use **[labs] Icon** in `/agents types`. See [icon setup](docs/settings.md#labs-nerd-font-icons-nerdfonticons).
|
|
78
78
|
|
|
79
|
+
Enable **[labs] Final Recap** in `/agents` to automatically ask the idle main agent to summarize detached-agent results, keeping the final response in the main thread. It is off by default and suppressed by Subagent Mode Off. **Enabling it may cause extra model turns and uses more tokens and context.** See [Final Recap](docs/settings.md#labs-final-recap-finalrecap).
|
|
80
|
+
|
|
79
81
|
## Docs
|
|
80
82
|
|
|
81
83
|
- [Your own agent](docs/custom-agents.md) — walkthrough for writing an agent type
|
package/docs/settings.md
CHANGED
|
@@ -16,6 +16,7 @@ All keys are optional. Defaults:
|
|
|
16
16
|
"subagentMode": "opportunistic",
|
|
17
17
|
"widgetMode": "full",
|
|
18
18
|
"nerdFontIcons": false,
|
|
19
|
+
"finalRecap": false,
|
|
19
20
|
"modelSelection": "pick-first-scoped",
|
|
20
21
|
"toolFiltering": "allowed",
|
|
21
22
|
"maxLevels": 3,
|
|
@@ -62,6 +63,14 @@ When enabled, an agent type’s optional `icon` appears before its readable name
|
|
|
62
63
|
|
|
63
64
|
All six bundled agents have [role-specific icons](default-agents.md#nerd-font-icons). Add or change an icon with **[labs] Icon** in `/agents types`, or the optional `icon` frontmatter field in [your own agent](custom-agents.md#icons-labs). Retained threads keep the icon from their saved agent definition.
|
|
64
65
|
|
|
66
|
+
## [labs] Final Recap (`finalRecap`)
|
|
67
|
+
|
|
68
|
+
**[labs] Final Recap** is an experimental on/off toggle, **off by default**. Enable it in `/agents` and save with **Ctrl+S**, or set `"finalRecap": true` in your settings file.
|
|
69
|
+
|
|
70
|
+
When detached agents finish or fail and the main agent is idle, their results are sent back to the main agent for an automatic summary. The summary is a main-thread response, so child notifications do not become the final visible message. Progress updates do not trigger summaries, and active main-agent work is not interrupted. **Subagent Mode Off** suppresses automatic summaries even if this setting is enabled.
|
|
71
|
+
|
|
72
|
+
**Enabling Final Recap may cause extra model turns and uses more tokens and context.** Leave it off if you prefer to inspect results manually in `/agents tree` or request a summary yourself.
|
|
73
|
+
|
|
65
74
|
## Model Picking (`modelSelection`)
|
|
66
75
|
|
|
67
76
|
Which model an agent gets when its session starts.
|
package/docs/tools-and-ui.md
CHANGED
|
@@ -25,6 +25,8 @@
|
|
|
25
25
|
|
|
26
26
|
Then `agent_wait` or `agent_status` on `/root/controller-security-research`.
|
|
27
27
|
|
|
28
|
+
Child progress and completion notifications are retained in the main agent's context without adding visible chat messages. By default they do not start another turn, keeping the main agent's final response last in the conversation even when detached children finish later. The opt-in **[labs] Final Recap** setting asks an idle main agent to summarize newly completed or failed asynchronous agents; results arriving during a summary are handled after that summary finishes. Progress updates and foreground results do not trigger summaries. Enabling it uses more tokens and context. Use the Agents widget, `/agents tree`, or `agent_output` to inspect child status and answers.
|
|
29
|
+
|
|
28
30
|
## Parallel and nested work
|
|
29
31
|
|
|
30
32
|
- Launch **all independent siblings with `wait: false`, then wait**. Spawning one foreground child and waiting before the next is sequential.
|
|
@@ -58,7 +60,7 @@ Refreshes every second and keeps your selection, collapse state and scroll posit
|
|
|
58
60
|
|
|
59
61
|
### Live agent navigation
|
|
60
62
|
|
|
61
|
-
The fullscreen watcher
|
|
63
|
+
The fullscreen watcher renders steer and agent messages (including thinking) as Markdown, same as pi's main transcript. Tool calls use pi's built-in call formats (`$ command`, `read path:range`, `grep /pattern/ in path`, …) rather than bare JSON; unknown tools fall back to pretty-printed JSON. Tool results and other metadata show their name/status and only the first three wrapped lines of each output preview, followed by `...` when more is hidden. Use **i → Transcript** from the tree for retained tool details. **t** cycles three detail levels with transcript controls focused: **preview** (default: three rows per call, first three rendered thinking lines), **compact** (one line per call, thinking hidden), **full** (complete calls and thinking). Inherited context is initially collapsed (**c** toggles it with transcript controls focused). Watching alone never starts a turn, switches sessions, or changes model/tool/resource ownership. Unsupported/custom content and images use safe text placeholders rather than native rich rendering. Legacy sessions without reliable inherited-prefix metadata show their whole transcript.
|
|
62
64
|
|
|
63
65
|
- The bottom **Steer** input is focused initially. Type and press **Enter** to send to the inspected agent, including nested descendants, through the same service as `agent_steer`: running agents receive queued input; paused/completed/stopped agents resume their retained session. Empty input is ignored. Sending leaves the viewer open; failures are shown and preserve the draft for retry.
|
|
64
66
|
- **Tab** switches between steering input and transcript controls. While typing, **c/t/l/r** are ordinary text and **Home/End** move the input cursor. Pasting never submits by itself.
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -18,9 +18,11 @@ import type { SavedThread, ThreadEvent } from "./types.ts";
|
|
|
18
18
|
|
|
19
19
|
const REGISTRY_ENTRY = "pi-subagent:registry:v1";
|
|
20
20
|
const ROOT_MAILBOX_ENTRY = "pi-subagent:root-mailbox:v1";
|
|
21
|
+
const ROOT_SUMMARY_MESSAGE = "pi-subagent:final-recap";
|
|
21
22
|
type RootNotification = {
|
|
22
23
|
rootSessionId: string;
|
|
23
24
|
content: string;
|
|
25
|
+
finalRecap?: boolean;
|
|
24
26
|
details: { mailboxId: string; path: string; state: string };
|
|
25
27
|
};
|
|
26
28
|
|
|
@@ -49,6 +51,14 @@ export default function piSubagent(pi: ExtensionAPI): void {
|
|
|
49
51
|
};
|
|
50
52
|
let generation = 0;
|
|
51
53
|
let rootTurnEnded = false;
|
|
54
|
+
let summaryRunning = false;
|
|
55
|
+
let suspendingSummaries = false;
|
|
56
|
+
let summaryTimer: ReturnType<typeof setTimeout> | undefined;
|
|
57
|
+
const cancelSummary = () => {
|
|
58
|
+
if (summaryTimer !== undefined) clearTimeout(summaryTimer);
|
|
59
|
+
summaryTimer = undefined;
|
|
60
|
+
summaryRunning = false;
|
|
61
|
+
};
|
|
52
62
|
let navigation = new AgentNavigationController();
|
|
53
63
|
let navigationEditor: AgentNavigationEditor | undefined;
|
|
54
64
|
let navigationEditorFactory: Parameters<ExtensionContext["ui"]["setEditorComponent"]>[0];
|
|
@@ -149,12 +159,62 @@ export default function piSubagent(pi: ExtensionAPI): void {
|
|
|
149
159
|
{
|
|
150
160
|
customType: "pi-subagent:update",
|
|
151
161
|
content: notification.content,
|
|
152
|
-
|
|
162
|
+
// Keep asynchronous child updates in model context, not the main chat.
|
|
163
|
+
// Idle/settlement delivery can follow the root's final answer; rendering it
|
|
164
|
+
// would leave a child's output as the last visible message. The widget and
|
|
165
|
+
// agent browser provide status/output without displacing the root response.
|
|
166
|
+
display: false,
|
|
153
167
|
details: notification.details,
|
|
154
168
|
},
|
|
155
169
|
{ triggerTurn: false },
|
|
156
170
|
);
|
|
157
171
|
};
|
|
172
|
+
const pendingSummaries = (ctx: ExtensionContext) => {
|
|
173
|
+
const entries = ctx.sessionManager.getBranch();
|
|
174
|
+
const summarized = new Set(entries.flatMap((entry) => {
|
|
175
|
+
if (entry.type !== "custom_message" || entry.customType !== ROOT_SUMMARY_MESSAGE) return [];
|
|
176
|
+
const ids = (entry.details as { mailboxIds?: unknown } | undefined)?.mailboxIds;
|
|
177
|
+
return Array.isArray(ids) ? ids.filter((id): id is string => typeof id === "string") : [];
|
|
178
|
+
}));
|
|
179
|
+
return entries.flatMap((entry) => {
|
|
180
|
+
if (entry.type !== "custom" || entry.customType !== ROOT_MAILBOX_ENTRY) return [];
|
|
181
|
+
const notification = entry.data as RootNotification | undefined;
|
|
182
|
+
return notification?.rootSessionId === ctx.sessionManager.getSessionId() &&
|
|
183
|
+
notification.finalRecap === true && typeof notification.content === "string" &&
|
|
184
|
+
typeof notification.details?.mailboxId === "string" &&
|
|
185
|
+
!summarized.has(notification.details.mailboxId) ? [notification] : [];
|
|
186
|
+
});
|
|
187
|
+
};
|
|
188
|
+
const scheduleSummary = (ctx: ExtensionContext) => {
|
|
189
|
+
if (!limits.finalRecap || limits.subagentMode === "off" || summaryRunning || suspendingSummaries ||
|
|
190
|
+
summaryTimer !== undefined || ctx.isIdle() === false || !pendingSummaries(ctx).length) return;
|
|
191
|
+
const currentGeneration = generation;
|
|
192
|
+
// Coalesce siblings finishing together and leave the settlement boundary before
|
|
193
|
+
// starting a new turn. Recheck settings/session/idle state after the deferral.
|
|
194
|
+
summaryTimer = setTimeout(() => {
|
|
195
|
+
summaryTimer = undefined;
|
|
196
|
+
if (currentGeneration !== generation || context?.sessionManager !== ctx.sessionManager ||
|
|
197
|
+
!limits.finalRecap || limits.subagentMode === "off" || suspendingSummaries || ctx.isIdle() === false) return;
|
|
198
|
+
const notifications = pendingSummaries(ctx);
|
|
199
|
+
if (!notifications.length) return;
|
|
200
|
+
summaryRunning = true;
|
|
201
|
+
try {
|
|
202
|
+
pi.sendMessage({
|
|
203
|
+
customType: ROOT_SUMMARY_MESSAGE,
|
|
204
|
+
content: "Summarize the newly finished asynchronous subagent results for the user. " +
|
|
205
|
+
"Their results are in the preceding subagent notifications; use agent_output if more detail is needed. " +
|
|
206
|
+
"Give a concise main-thread answer covering results and any failures. " +
|
|
207
|
+
"Do not spawn or resume agents solely to summarize.\nAgents: " +
|
|
208
|
+
[...new Set(notifications.map((notification) => notification.details.path))].join(", "),
|
|
209
|
+
display: false,
|
|
210
|
+
details: { mailboxIds: notifications.map((notification) => notification.details.mailboxId) },
|
|
211
|
+
}, { triggerTurn: true });
|
|
212
|
+
} catch (error) {
|
|
213
|
+
summaryRunning = false;
|
|
214
|
+
warnDelivery(error);
|
|
215
|
+
}
|
|
216
|
+
}, 0);
|
|
217
|
+
};
|
|
158
218
|
const restoreRootMailbox = (ctx: ExtensionContext) => {
|
|
159
219
|
if (limits.subagentMode === "off" || ctx.isIdle?.() === false) return;
|
|
160
220
|
const entries = ctx.sessionManager.getBranch();
|
|
@@ -178,9 +238,13 @@ export default function piSubagent(pi: ExtensionAPI): void {
|
|
|
178
238
|
delivered.add(notification.details.mailboxId);
|
|
179
239
|
}
|
|
180
240
|
}
|
|
241
|
+
scheduleSummary(ctx);
|
|
181
242
|
};
|
|
182
243
|
pi.on("agent_settled", async (_event, ctx) => {
|
|
183
|
-
if (context?.sessionManager === ctx.sessionManager)
|
|
244
|
+
if (context?.sessionManager === ctx.sessionManager) {
|
|
245
|
+
summaryRunning = false;
|
|
246
|
+
restoreRootMailbox(ctx);
|
|
247
|
+
}
|
|
184
248
|
});
|
|
185
249
|
const delivery = (event: ThreadEvent) => {
|
|
186
250
|
if (event.kind === "change" || event.kind === "metrics") return;
|
|
@@ -196,6 +260,11 @@ export default function piSubagent(pi: ExtensionAPI): void {
|
|
|
196
260
|
const notification: RootNotification = {
|
|
197
261
|
rootSessionId: requireContext().sessionManager.getSessionId(),
|
|
198
262
|
content: message,
|
|
263
|
+
// Foreground results already handled by a busy main thread do not need
|
|
264
|
+
// another turn. Completions during a summary do need a follow-up summary.
|
|
265
|
+
finalRecap: limits.finalRecap && !suspendingSummaries && event.kind === "settled" &&
|
|
266
|
+
(thread.state === "completed" || thread.state === "failed") &&
|
|
267
|
+
(requireContext().isIdle() || summaryRunning),
|
|
199
268
|
details: {
|
|
200
269
|
mailboxId: randomUUID(),
|
|
201
270
|
path: thread.path,
|
|
@@ -205,7 +274,7 @@ export default function piSubagent(pi: ExtensionAPI): void {
|
|
|
205
274
|
// Persist first; defer delivery until the root is idle and the plugin is enabled.
|
|
206
275
|
// The eventual transcript message carries its ID for branch-local recovery.
|
|
207
276
|
pi.appendEntry(ROOT_MAILBOX_ENTRY, notification);
|
|
208
|
-
|
|
277
|
+
restoreRootMailbox(requireContext());
|
|
209
278
|
} else void requireManager().deliver(event.recipient, message).catch(warnDelivery);
|
|
210
279
|
} catch (error) {
|
|
211
280
|
warnDelivery(error);
|
|
@@ -266,6 +335,7 @@ export default function piSubagent(pi: ExtensionAPI): void {
|
|
|
266
335
|
});
|
|
267
336
|
|
|
268
337
|
const attachSession = async (ctx: ExtensionContext, installEditor = false, seedHistory = true) => {
|
|
338
|
+
cancelSummary();
|
|
269
339
|
const token = ++generation;
|
|
270
340
|
closeNavigation(installEditor);
|
|
271
341
|
navigation = new AgentNavigationController();
|
|
@@ -336,11 +406,18 @@ export default function piSubagent(pi: ExtensionAPI): void {
|
|
|
336
406
|
});
|
|
337
407
|
pi.on("session_tree", async (_event, ctx) => attachSession(ctx));
|
|
338
408
|
const stopWorkingThreads = async () => {
|
|
409
|
+
cancelSummary();
|
|
339
410
|
closeNavigation();
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
411
|
+
suspendingSummaries = true;
|
|
412
|
+
try {
|
|
413
|
+
if (!manager) return;
|
|
414
|
+
for (const thread of manager.list()) {
|
|
415
|
+
const state = manager.get(thread.path).state;
|
|
416
|
+
if (state === "starting" || state === "running") await manager.stop("/root", thread.path);
|
|
417
|
+
}
|
|
418
|
+
} finally {
|
|
419
|
+
cancelSummary();
|
|
420
|
+
suspendingSummaries = false;
|
|
344
421
|
}
|
|
345
422
|
};
|
|
346
423
|
// Finish old-thread cancellation while appendEntry still points to the old branch/session.
|
|
@@ -348,6 +425,7 @@ export default function piSubagent(pi: ExtensionAPI): void {
|
|
|
348
425
|
pi.on("session_before_switch", stopWorkingThreads);
|
|
349
426
|
pi.on("session_before_fork", stopWorkingThreads);
|
|
350
427
|
pi.on("session_shutdown", async () => {
|
|
428
|
+
cancelSummary();
|
|
351
429
|
generation++;
|
|
352
430
|
closeNavigation(true);
|
|
353
431
|
await manager?.shutdown();
|
package/src/prefs/settings.ts
CHANGED
|
@@ -34,6 +34,7 @@ export interface ManagerSettings {
|
|
|
34
34
|
toolFiltering: ToolFilteringMode;
|
|
35
35
|
widgetMode: WidgetMode;
|
|
36
36
|
nerdFontIcons: boolean;
|
|
37
|
+
finalRecap: boolean;
|
|
37
38
|
maxLevels: number;
|
|
38
39
|
maxConcurrent: number;
|
|
39
40
|
maxThreads: number;
|
|
@@ -49,10 +50,11 @@ export const DEFAULT_MANAGER_SETTINGS: ManagerSettings = {
|
|
|
49
50
|
toolFiltering: "allowed",
|
|
50
51
|
widgetMode: "full",
|
|
51
52
|
nerdFontIcons: false,
|
|
53
|
+
finalRecap: false,
|
|
52
54
|
};
|
|
53
55
|
|
|
54
56
|
const KEYS = [
|
|
55
|
-
"maxLevels", "maxConcurrent", "maxThreads", "modelSelection", "subagentMode", "toolFiltering", "widgetMode", "nerdFontIcons",
|
|
57
|
+
"maxLevels", "maxConcurrent", "maxThreads", "modelSelection", "subagentMode", "toolFiltering", "widgetMode", "nerdFontIcons", "finalRecap",
|
|
56
58
|
] as const;
|
|
57
59
|
const MAX_LEVELS = 32;
|
|
58
60
|
|
|
@@ -90,7 +92,7 @@ function positiveSafeInteger(value: unknown): value is number {
|
|
|
90
92
|
}
|
|
91
93
|
|
|
92
94
|
function requirement(key: (typeof KEYS)[number]): string {
|
|
93
|
-
if (key === "nerdFontIcons") return
|
|
95
|
+
if (key === "nerdFontIcons" || key === "finalRecap") return `${key} must be a boolean`;
|
|
94
96
|
if (key === "subagentMode") return "subagentMode must be off, opportunistic or orchestration";
|
|
95
97
|
if (key === "widgetMode") return "widgetMode must be full or minimal";
|
|
96
98
|
if (key === "toolFiltering") return "toolFiltering must be allowed, all-except-blocked or all";
|
|
@@ -125,9 +127,9 @@ function parseSettings(content: string): Partial<ManagerSettings> {
|
|
|
125
127
|
for (const key of KEYS) {
|
|
126
128
|
if (!Object.hasOwn(record, key)) continue;
|
|
127
129
|
const value = record[key];
|
|
128
|
-
if (key === "nerdFontIcons") {
|
|
130
|
+
if (key === "nerdFontIcons" || key === "finalRecap") {
|
|
129
131
|
if (typeof value !== "boolean") throw new Error(requirement(key));
|
|
130
|
-
layer
|
|
132
|
+
layer[key] = value;
|
|
131
133
|
continue;
|
|
132
134
|
}
|
|
133
135
|
if (key === "subagentMode") {
|
|
@@ -15,11 +15,15 @@ import type { ThreadService, TranscriptSnapshot } from "../types.ts";
|
|
|
15
15
|
import { dialogText, type DialogHost } from "./dialog.ts";
|
|
16
16
|
import { agentTypeLabel } from "./ui.ts";
|
|
17
17
|
|
|
18
|
+
/** Transcript detail level cycled by the t key: full → preview → compact. */
|
|
19
|
+
export type TranscriptDetail = "full" | "preview" | "compact";
|
|
20
|
+
const DETAIL_CYCLE: TranscriptDetail[] = ["full", "preview", "compact"];
|
|
21
|
+
|
|
18
22
|
export interface AgentViewportState {
|
|
19
23
|
scrollTop: number;
|
|
20
24
|
follow: boolean;
|
|
21
25
|
showInherited?: boolean;
|
|
22
|
-
|
|
26
|
+
detail?: TranscriptDetail;
|
|
23
27
|
}
|
|
24
28
|
|
|
25
29
|
/** Fully cover main, including at very small sizes; only trusted renderers emit terminal sequences. */
|
|
@@ -60,7 +64,7 @@ export class LiveAgentView {
|
|
|
60
64
|
private attachment = 0;
|
|
61
65
|
private unsubscribe: (() => void) | undefined;
|
|
62
66
|
private renderTimer: ReturnType<typeof setTimeout> | undefined;
|
|
63
|
-
private cache = new WeakMap<object, { width: number;
|
|
67
|
+
private cache = new WeakMap<object, { width: number; detail: TranscriptDetail; lines: string[] }>();
|
|
64
68
|
private scroll: ScrollView;
|
|
65
69
|
private content: string[] = [];
|
|
66
70
|
private restoreViewport = true;
|
|
@@ -235,7 +239,8 @@ export class LiveAgentView {
|
|
|
235
239
|
this.viewport.showInherited = !this.viewport.showInherited;
|
|
236
240
|
this.invalidate();
|
|
237
241
|
} else if (data === "t") {
|
|
238
|
-
this.viewport.
|
|
242
|
+
this.viewport.detail =
|
|
243
|
+
DETAIL_CYCLE[(DETAIL_CYCLE.indexOf(this.detail) + 1) % DETAIL_CYCLE.length];
|
|
239
244
|
this.invalidate();
|
|
240
245
|
} else if (matchesKey(data, Key.home)) this.scroll.scrollTo(0, { disableFollow: true });
|
|
241
246
|
else if (matchesKey(data, Key.end) || data === "l") this.scroll.scrollToEnd();
|
|
@@ -249,6 +254,10 @@ export class LiveAgentView {
|
|
|
249
254
|
this.viewport.follow = this.scroll.isFollowingEnd;
|
|
250
255
|
}
|
|
251
256
|
|
|
257
|
+
private get detail(): TranscriptDetail {
|
|
258
|
+
return this.viewport.detail ?? "preview";
|
|
259
|
+
}
|
|
260
|
+
|
|
252
261
|
private wrap(value: string, width: number): string[] {
|
|
253
262
|
return text(value)
|
|
254
263
|
.split("\n")
|
|
@@ -302,26 +311,23 @@ export class LiveAgentView {
|
|
|
302
311
|
if (!block) return this.wrap(json(value), width);
|
|
303
312
|
if (block.type === "text") return this.markdown(String(block.text ?? ""), width);
|
|
304
313
|
if (block.type === "image") return ["[Image — text-only observer]"];
|
|
305
|
-
if (block.type === "thinking")
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
314
|
+
if (block.type === "thinking") {
|
|
315
|
+
if (this.detail === "compact")
|
|
316
|
+
return [this.theme.fg("dim", "[Thinking hidden · t cycles view]")];
|
|
317
|
+
// Thinking is model-authored Markdown; preview truncates the rendered lines, not the source.
|
|
318
|
+
const rendered = this.markdown(String(block.thinking ?? "[redacted thinking]"), width, true);
|
|
319
|
+
if (this.detail === "full" || rendered.length <= 3) return rendered;
|
|
320
|
+
return [...rendered.slice(0, 3), this.theme.fg("dim", "...")];
|
|
321
|
+
}
|
|
309
322
|
if (block.type === "toolCall")
|
|
310
|
-
return
|
|
311
|
-
this.theme.fg(
|
|
312
|
-
"accent",
|
|
313
|
-
dialogText(`Tool call: ${String(block.name)} (${String(block.id)})`),
|
|
314
|
-
),
|
|
315
|
-
...this.preview(json(block.arguments), width),
|
|
316
|
-
];
|
|
323
|
+
return this.toolCall(String(block.name), block.arguments, width);
|
|
317
324
|
return this.preview(json(block), width);
|
|
318
325
|
});
|
|
319
326
|
}
|
|
320
327
|
|
|
321
328
|
private message(message: AgentMessage, width: number): string[] {
|
|
322
329
|
const cached = this.cache.get(message);
|
|
323
|
-
if (cached && cached.width === width && cached.
|
|
324
|
-
return cached.lines;
|
|
330
|
+
if (cached && cached.width === width && cached.detail === this.detail) return cached.lines;
|
|
325
331
|
const data = message as unknown as Record<string, unknown>;
|
|
326
332
|
const label =
|
|
327
333
|
message.role === "toolResult"
|
|
@@ -340,10 +346,112 @@ export class LiveAgentView {
|
|
|
340
346
|
: []),
|
|
341
347
|
"",
|
|
342
348
|
];
|
|
343
|
-
this.cache.set(message, { width,
|
|
349
|
+
this.cache.set(message, { width, detail: this.detail, lines });
|
|
344
350
|
return lines;
|
|
345
351
|
}
|
|
346
352
|
|
|
353
|
+
/**
|
|
354
|
+
* Pi-style tool call lines, mirroring the main session's built-in renderers (`$ command`,
|
|
355
|
+
* `read path:range`, `grep /pattern/ in path`, …) instead of bare JSON. All interpolated values
|
|
356
|
+
* are sanitized; unknown tools fall back to pretty-printed JSON. Shaped by the detail mode:
|
|
357
|
+
* compact keeps one truncated line, preview keeps three wrapped rows, full keeps everything
|
|
358
|
+
* (bounded by the preview byte cap for pathological payloads).
|
|
359
|
+
*/
|
|
360
|
+
private toolCall(name: string, args: unknown, width: number): string[] {
|
|
361
|
+
const data = object(args);
|
|
362
|
+
const str = (key: string): string | undefined => {
|
|
363
|
+
const value = data?.[key];
|
|
364
|
+
return typeof value === "string" ? text(value) : undefined;
|
|
365
|
+
};
|
|
366
|
+
const num = (key: string): number | undefined => {
|
|
367
|
+
const value = data?.[key];
|
|
368
|
+
return typeof value === "number" && Number.isFinite(value) ? value : undefined;
|
|
369
|
+
};
|
|
370
|
+
const title = (value: string) => this.theme.fg("accent", value);
|
|
371
|
+
const detail = (value: string) => this.theme.fg("muted", value);
|
|
372
|
+
const path = str("file_path") ?? str("path");
|
|
373
|
+
let lines: string[];
|
|
374
|
+
switch (name) {
|
|
375
|
+
case "bash":
|
|
376
|
+
case "powershell": {
|
|
377
|
+
const prompt = name === "bash" ? "$" : ">";
|
|
378
|
+
const command = (str("command") ?? "...").split("\n");
|
|
379
|
+
const timeout = num("timeout");
|
|
380
|
+
lines = [
|
|
381
|
+
`${title(`${prompt} ${command[0]}`)}${timeout ? detail(` (timeout ${timeout}s)`) : ""}`,
|
|
382
|
+
...command.slice(1),
|
|
383
|
+
];
|
|
384
|
+
break;
|
|
385
|
+
}
|
|
386
|
+
case "read": {
|
|
387
|
+
const offset = num("offset");
|
|
388
|
+
const limit = num("limit");
|
|
389
|
+
const range =
|
|
390
|
+
offset == null && limit == null
|
|
391
|
+
? ""
|
|
392
|
+
: this.theme.fg(
|
|
393
|
+
"warning",
|
|
394
|
+
`:${offset ?? 1}${limit != null ? `-${(offset ?? 1) + limit - 1}` : ""}`,
|
|
395
|
+
);
|
|
396
|
+
lines = [`${title("read")} ${path ?? "?"}${range}`];
|
|
397
|
+
break;
|
|
398
|
+
}
|
|
399
|
+
case "edit":
|
|
400
|
+
lines = [`${title("edit")} ${path ?? "?"}`];
|
|
401
|
+
break;
|
|
402
|
+
case "write": {
|
|
403
|
+
lines = [`${title("write")} ${path ?? "?"}`];
|
|
404
|
+
const content = str("content");
|
|
405
|
+
if (content) {
|
|
406
|
+
const contentLines = content.split("\n");
|
|
407
|
+
while (contentLines.length && contentLines.at(-1) === "") contentLines.pop();
|
|
408
|
+
lines.push(...contentLines);
|
|
409
|
+
}
|
|
410
|
+
break;
|
|
411
|
+
}
|
|
412
|
+
case "grep": {
|
|
413
|
+
const pattern = str("pattern");
|
|
414
|
+
const glob = str("glob");
|
|
415
|
+
const limit = num("limit");
|
|
416
|
+
lines = [
|
|
417
|
+
`${title("grep")} ${this.theme.fg("accent", `/${pattern ?? ""}/`)}` +
|
|
418
|
+
`${path ? detail(` in ${path}`) : ""}${glob ? detail(` (${glob})`) : ""}` +
|
|
419
|
+
`${limit != null ? detail(` limit ${limit}`) : ""}`,
|
|
420
|
+
];
|
|
421
|
+
break;
|
|
422
|
+
}
|
|
423
|
+
case "find": {
|
|
424
|
+
const pattern = str("pattern");
|
|
425
|
+
const limit = num("limit");
|
|
426
|
+
lines = [
|
|
427
|
+
`${title("find")} ${this.theme.fg("accent", pattern ?? "")}` +
|
|
428
|
+
`${path ? detail(` in ${path}`) : ""}${limit != null ? detail(` (limit ${limit})`) : ""}`,
|
|
429
|
+
];
|
|
430
|
+
break;
|
|
431
|
+
}
|
|
432
|
+
case "ls": {
|
|
433
|
+
const limit = num("limit");
|
|
434
|
+
lines = [`${title("ls")} ${path ?? "."}${limit != null ? detail(` (limit ${limit})`) : ""}`];
|
|
435
|
+
break;
|
|
436
|
+
}
|
|
437
|
+
default:
|
|
438
|
+
lines = [title(dialogText(name)), ...json(args).split("\n")];
|
|
439
|
+
}
|
|
440
|
+
if (this.detail === "compact")
|
|
441
|
+
return [truncateToWidth(lines[0] ?? "", Math.max(1, width), "…", true)];
|
|
442
|
+
const wrapped = lines.flatMap((line) => wrapTextWithAnsi(line, Math.max(1, width)));
|
|
443
|
+
if (this.detail === "preview" && wrapped.length > 3)
|
|
444
|
+
return [...wrapped.slice(0, 3), this.theme.fg("dim", "...")];
|
|
445
|
+
const bounded: string[] = [];
|
|
446
|
+
let chars = 0;
|
|
447
|
+
for (const line of wrapped) {
|
|
448
|
+
if (chars > 32768) return [...bounded, this.theme.fg("dim", "...")];
|
|
449
|
+
bounded.push(line);
|
|
450
|
+
chars += line.length;
|
|
451
|
+
}
|
|
452
|
+
return bounded;
|
|
453
|
+
}
|
|
454
|
+
|
|
347
455
|
render(width: number): string[] {
|
|
348
456
|
const height = Math.max(1, this.host.terminal?.rows ?? 24);
|
|
349
457
|
const columns = Math.max(1, width);
|
|
@@ -386,16 +494,15 @@ export class LiveAgentView {
|
|
|
386
494
|
);
|
|
387
495
|
for (const tool of snapshot.tools) {
|
|
388
496
|
if (committedResults.has(tool.toolCallId)) continue;
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
),
|
|
497
|
+
const call = this.toolCall(tool.toolName, tool.args, columns);
|
|
498
|
+
call[0] = `${call[0]} ${this.theme.fg(
|
|
499
|
+
tool.isError ? "error" : "warning",
|
|
500
|
+
dialogText(
|
|
501
|
+
`— ${tool.state}${tool.isError ? " (error)" : ""}${tool.parentToolCallId ? " (nested)" : ""}`,
|
|
395
502
|
),
|
|
396
|
-
|
|
397
|
-
);
|
|
398
|
-
if (tool.result !== undefined)
|
|
503
|
+
)}`;
|
|
504
|
+
body.push(...call);
|
|
505
|
+
if (tool.result !== undefined && this.detail !== "compact")
|
|
399
506
|
body.push(...this.preview(object(tool.result)?.content ?? tool.result, columns));
|
|
400
507
|
body.push("");
|
|
401
508
|
}
|
|
@@ -421,7 +528,7 @@ export class LiveAgentView {
|
|
|
421
528
|
this.saveViewport();
|
|
422
529
|
const footer = this.error
|
|
423
530
|
? "Ctrl+R Retry · Tab input/transcript · Esc tree · Ctrl+Q main"
|
|
424
|
-
: `${this.editing ? "Enter steer · Tab browse" :
|
|
531
|
+
: `${this.editing ? "Enter steer · Tab browse" : `Tab steer · Home/End scroll · c context · t view:${this.detail}`} · Esc tree · Ctrl+Q main · ↑↓/PgUp/PgDn scroll · ${this.viewport.follow ? "following" : "scrolled"}`;
|
|
425
532
|
const input = this.input.render(columns)[0]!;
|
|
426
533
|
const status = this.theme.fg(
|
|
427
534
|
this.steerStatus ? (this.steerFailed ? "error" : "muted") : this.error ? "error" : "muted",
|
package/src/ui/settings-ui.ts
CHANGED
|
@@ -197,6 +197,12 @@ async function configureAgentsDialog(
|
|
|
197
197
|
value: draft.nerdFontIcons ? "On" : "Off",
|
|
198
198
|
help: "Experimental: display each agent type’s optional icon.\nRequires a Nerd Font configured in your terminal; otherwise glyphs may appear as boxes.\nOff by default. Save and apply to update the widget immediately.",
|
|
199
199
|
},
|
|
200
|
+
{
|
|
201
|
+
id: "finalRecap",
|
|
202
|
+
label: "[labs] Final Recap",
|
|
203
|
+
value: draft.finalRecap ? "On" : "Off",
|
|
204
|
+
help: "Experimental: when detached agents finish or fail and the main agent is idle, automatically ask the main agent to summarize their results.\nEnabling this may cause extra model turns and uses more tokens and context.\nOff by default. Subagent Mode Off suppresses automatic summaries.",
|
|
205
|
+
},
|
|
200
206
|
{
|
|
201
207
|
id: "scope",
|
|
202
208
|
label: "Save scope",
|
|
@@ -280,6 +286,8 @@ async function configureAgentsDialog(
|
|
|
280
286
|
draft.widgetMode = mode as WidgetMode;
|
|
281
287
|
} else if (action === "nerdFontIcons") {
|
|
282
288
|
draft.nerdFontIcons = !draft.nerdFontIcons;
|
|
289
|
+
} else if (action === "finalRecap") {
|
|
290
|
+
draft.finalRecap = !draft.finalRecap;
|
|
283
291
|
} else if (action === "scope") {
|
|
284
292
|
if (!ctx.isProjectTrusted())
|
|
285
293
|
ctx.ui.notify(
|