pi-subagent-manager 0.17.0 → 0.18.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.
@@ -11,6 +11,7 @@ import {
11
11
  matchesKey,
12
12
  type Keybinding,
13
13
  } from "@earendil-works/pi-tui";
14
+ import { truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
14
15
  import {
15
16
  canOpenDialog,
16
17
  DIALOG_OPTIONS,
@@ -27,7 +28,12 @@ import type { ThreadService } from "../types.ts";
27
28
  import type { LoaderStyle } from "../prefs/settings.ts";
28
29
  import { buildStatusTree, type StatusRow } from "./thread-tree.ts";
29
30
  import {
30
- AGENT_PROGRESS_INTERVAL, agentProgressIcon, agentTypeBadge, agentTypeLabel, showThreads, threadMetrics,
31
+ AGENT_PROGRESS_INTERVAL,
32
+ agentProgressIcon,
33
+ agentTypeBadge,
34
+ agentTypeLabel,
35
+ showThreads,
36
+ threadMetrics,
31
37
  } from "./ui.ts";
32
38
  import { LiveAgentView, fillViewport, type AgentViewportState } from "./live-agent-view.ts";
33
39
 
@@ -132,9 +138,16 @@ export class StatusDialog {
132
138
 
133
139
  private syncRefresh(): void {
134
140
  if (!this.refreshing) return;
135
- const delay = this.nerdFontIcons && this.service.list().some((thread) =>
136
- thread.path !== ROOT && (thread.state === "starting" || thread.state === "running"))
137
- ? AGENT_PROGRESS_INTERVAL : 1000;
141
+ const delay =
142
+ this.nerdFontIcons &&
143
+ this.service
144
+ .list()
145
+ .some(
146
+ (thread) =>
147
+ thread.path !== ROOT && (thread.state === "starting" || thread.state === "running"),
148
+ )
149
+ ? AGENT_PROGRESS_INTERVAL
150
+ : 1000;
138
151
  if (this.timer !== undefined && this.refreshDelay === delay) return;
139
152
  this.stopRefresh();
140
153
  this.refreshDelay = delay;
@@ -156,7 +169,10 @@ export class StatusDialog {
156
169
  private stopAll(): void {
157
170
  const live = this.service
158
171
  .list()
159
- .filter((thread) => thread.path !== ROOT && (thread.state === "starting" || thread.state === "running"))
172
+ .filter(
173
+ (thread) =>
174
+ thread.path !== ROOT && (thread.state === "starting" || thread.state === "running"),
175
+ )
160
176
  .map((thread) => thread.path);
161
177
  const tops = live.filter((path) => !live.some((other) => path.startsWith(`${other}/`)));
162
178
  for (const path of tops) {
@@ -243,38 +259,65 @@ export class StatusDialog {
243
259
  this.host.requestRender();
244
260
  }
245
261
 
246
- private line(row: StatusRow, selected: boolean): string {
262
+ private line(row: StatusRow, selected: boolean, width: number): string[] {
247
263
  const marker = row.hasChildren ? (this.collapsed.has(row.path) ? "▸ " : "▾ ") : "";
248
264
  const head = ` ${row.prefix}${selected ? "›" : " "} ${marker}`;
249
265
  const thread = row.thread;
250
266
  if (!thread) {
251
267
  const text = `${head}${label(row)}`;
252
- return selected ? this.theme.fg("accent", text) : text;
268
+ return [selected ? this.theme.fg("accent", text) : text, ""];
253
269
  }
254
270
  const inactive = INACTIVE_STATES.has(thread.state);
255
- if (inactive) {
256
- // Completed fades furthest (dim); the state word keeps a theme hint for done/failed.
257
- const base = thread.state === "completed" ? "dim" : "muted";
258
- const hint =
259
- thread.state === "completed" ? "success" : thread.state === "failed" ? "error" : base;
260
- const state = dialogText(thread.state);
261
- const path = dialogText(thread.path);
262
- const status = dialogText(thread.status);
263
- return [
264
- this.theme.fg(selected ? "accent" : base, head),
265
- this.theme.fg(base, `${agentTypeLabel(thread.type, thread.icon, this.nerdFontIcons, agentProgressIcon(thread, this.nerdFontIcons, Date.now(), true, this.loaderStyle))} ${path} `),
266
- this.theme.fg(hint, state),
267
- this.theme.fg(base, ` ${status}`),
268
- ].join("");
269
- }
270
- const rest = [thread.path, thread.state, thread.status]
271
+ const base = thread.state === "completed" ? "dim" : "muted";
272
+ const hint =
273
+ thread.state === "completed" ? "success" : thread.state === "failed" ? "error" : base;
274
+ const progress = agentProgressIcon(
275
+ thread,
276
+ this.nerdFontIcons,
277
+ Date.now(),
278
+ true,
279
+ this.loaderStyle,
280
+ );
281
+ const badge = inactive
282
+ ? this.theme.fg(base, agentTypeLabel(thread.type, thread.icon, this.nerdFontIcons, progress))
283
+ : agentTypeBadge(
284
+ thread.type,
285
+ thread.color,
286
+ this.theme,
287
+ thread.icon,
288
+ this.nerdFontIcons,
289
+ progress,
290
+ );
291
+ const identity = [
292
+ thread.path,
293
+ `${thread.model ?? "model pending"}${thread.thinkingLevel ? `:${thread.thinkingLevel}` : ""}`,
294
+ ]
271
295
  .map((part) => dialogText(part))
272
296
  .join(" ");
273
- const badge = agentTypeBadge(thread.type, thread.color, this.theme, thread.icon, this.nerdFontIcons,
274
- agentProgressIcon(thread, this.nerdFontIcons, Date.now(), true, this.loaderStyle));
275
- if (selected)
276
- return `${this.theme.fg("accent", head)}${badge} ${this.theme.fg("accent", rest)}`;
277
- return `${head}${badge} ${rest}`;
297
+ const first = [
298
+ selected ? this.theme.fg("accent", head) : head,
299
+ badge,
300
+ this.theme.fg(inactive ? base : selected ? "accent" : "text", ` ${identity} `),
301
+ this.theme.fg(inactive ? hint : "muted", dialogText(thread.state)),
302
+ ].join("");
303
+ // Continue the tree's vertical guides without repeating the branch or selection marker.
304
+ const stem = row.prefix.replace("├─ ", "│ ").replace("└─ ", " ");
305
+ const activity = ` ${stem} ${dialogText(thread.status || thread.task)}`;
306
+ const metrics = this.theme.fg(base, threadMetrics(thread));
307
+ const metricWidth = visibleWidth(metrics);
308
+ const second =
309
+ metricWidth >= width
310
+ ? truncateToWidth(metrics, width, "")
311
+ : (() => {
312
+ const left = truncateToWidth(
313
+ this.theme.fg(inactive ? base : selected ? "accent" : "muted", activity),
314
+ width - metricWidth - 1,
315
+ );
316
+ return (
317
+ left + " ".repeat(Math.max(1, width - visibleWidth(left) - metricWidth)) + metrics
318
+ );
319
+ })();
320
+ return [first, second];
278
321
  }
279
322
 
280
323
  private detail(row: StatusRow | undefined): string[] {
@@ -297,7 +340,7 @@ export class StatusDialog {
297
340
  if (rows[index]) this.selectedPath = rows[index].path;
298
341
  const budget = Math.max(0, height - 4);
299
342
  const detail = budget > 2 ? this.detail(rows[index]) : [];
300
- const treeCount = Math.max(0, budget - detail.length);
343
+ const treeCount = Math.max(0, Math.floor((budget - detail.length) / 2));
301
344
  this.viewport = Math.max(1, treeCount);
302
345
  const start = treeCount
303
346
  ? Math.max(0, Math.min(index - treeCount + 1, Math.max(0, rows.length - treeCount)))
@@ -305,7 +348,7 @@ export class StatusDialog {
305
348
  const body = [
306
349
  ...rows
307
350
  .slice(start, start + treeCount)
308
- .map((row) => this.line(row, row.path === this.selectedPath)),
351
+ .flatMap((row) => this.line(row, row.path === this.selectedPath, Math.max(0, width - 2))),
309
352
  ...detail,
310
353
  ];
311
354
  return frameDialog(
@@ -314,9 +357,7 @@ export class StatusDialog {
314
357
  height,
315
358
  this.heading(rows, start, treeCount),
316
359
  body,
317
- this.navigation
318
- ? "Esc main · ↑↓ select · ←→ fold · i Actions · Ctrl+C stop all"
319
- : FOOTER,
360
+ this.navigation ? "Esc main · ↑↓ select · ←→ fold · i Actions · Ctrl+C stop all" : FOOTER,
320
361
  );
321
362
  }
322
363
 
@@ -350,7 +391,17 @@ async function showAgentDialog(
350
391
  let dialog: StatusDialog | undefined;
351
392
  try {
352
393
  const chosen = await ctx.ui.custom<string | undefined>((host, theme, _keys, done) => {
353
- dialog = new StatusDialog(host, theme, service, done, selected, options.title, undefined, options.nerdFontIcons, options.loaderStyle);
394
+ dialog = new StatusDialog(
395
+ host,
396
+ theme,
397
+ service,
398
+ done,
399
+ selected,
400
+ options.title,
401
+ undefined,
402
+ options.nerdFontIcons,
403
+ options.loaderStyle,
404
+ );
354
405
  dialog.startRefresh();
355
406
  return dialog;
356
407
  }, DIALOG_OPTIONS);
@@ -394,7 +445,13 @@ export class AgentNavigationController {
394
445
  this.session = undefined;
395
446
  }
396
447
 
397
- open(ctx: ExtensionContext, service: ThreadService, selectedPath?: string, nerdFontIcons = false, loaderStyle: LoaderStyle = "circle"): Promise<void> {
448
+ open(
449
+ ctx: ExtensionContext,
450
+ service: ThreadService,
451
+ selectedPath?: string,
452
+ nerdFontIcons = false,
453
+ loaderStyle: LoaderStyle = "circle",
454
+ ): Promise<void> {
398
455
  if (this.opening) return this.opening;
399
456
  if (!canOpenDialog(ctx)) return Promise.resolve();
400
457
  if (selectedPath) this.tree.selectedPath = selectedPath;
@@ -493,7 +550,16 @@ export class AgentNavigationController {
493
550
  }
494
551
  const result = await session.mount<"back" | "main">(
495
552
  (tui, activeTheme, _keys, finish) =>
496
- new LiveAgentView(tui, activeTheme, service, chosen.path, viewport!, finish, nerdFontIcons, loaderStyle),
553
+ new LiveAgentView(
554
+ tui,
555
+ activeTheme,
556
+ service,
557
+ chosen.path,
558
+ viewport!,
559
+ finish,
560
+ nerdFontIcons,
561
+ loaderStyle,
562
+ ),
497
563
  );
498
564
  if (result !== "back") break;
499
565
  }