pi-subagent-manager 0.28.0 → 0.29.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.
@@ -471,3 +471,219 @@ export async function editModelPreferences(
471
471
  DIALOG_OPTIONS,
472
472
  );
473
473
  }
474
+
475
+ export const HOUSEKEEPING_PICKER_CANCEL = Symbol("housekeeping-picker-cancel");
476
+
477
+ interface HousekeepingRow {
478
+ /** `provider/model-id`; empty string clears the selection. */
479
+ value: string;
480
+ label: string;
481
+ description: string;
482
+ group: string;
483
+ }
484
+
485
+ const HOUSEKEEPING_TITLE = "[lab] Housekeeping model";
486
+ const CLEAR_GROUP = "Selection";
487
+ const SCOPED_GROUP = "Scoped models";
488
+ const OTHER_GROUP = "Other available models";
489
+
490
+ /**
491
+ * Single-select picker over available models, scoped models listed first.
492
+ * Typing searches; Enter selects; Esc cancels. "No model" clears the selection.
493
+ */
494
+ export class HousekeepingModelPickerComponent extends Container {
495
+ private readonly tui: { requestRender(force?: boolean): void; terminal?: { rows: number } };
496
+ private readonly theme: Theme;
497
+ private readonly allModels: readonly AvailableModel[];
498
+ private readonly modelSearch: SnapshotKeys<AvailableModel>;
499
+ private readonly scopedIdentities: ReadonlySet<string>;
500
+ private readonly current: string;
501
+ private readonly onDone: (identity: string) => void;
502
+ private readonly onCancel: () => void;
503
+ private readonly searchInput = new Input({ placeholder: "Search models" });
504
+ private rows: HousekeepingRow[] = [];
505
+ private selected = 0;
506
+ private _focused = false;
507
+
508
+ constructor(options: {
509
+ tui: { requestRender(force?: boolean): void; terminal?: { rows: number } };
510
+ theme: Theme;
511
+ availableModels: readonly AvailableModel[];
512
+ scopedModels: readonly ScopedModel[];
513
+ current?: string;
514
+ onDone(identity: string): void;
515
+ onCancel(): void;
516
+ }) {
517
+ super();
518
+ this.tui = options.tui;
519
+ this.theme = options.theme;
520
+ this.allModels = sortModels(options.availableModels);
521
+ this.modelSearch = fuzzysort.snapshot(this.allModels, {
522
+ keys: [
523
+ (model) => modelSearchText(modelIdentity(model)),
524
+ (model) => modelSearchText(model.name),
525
+ ],
526
+ });
527
+ this.scopedIdentities = new Set(options.scopedModels.map((entry) => modelIdentity(entry.model)));
528
+ this.current = options.current ?? "";
529
+ this.onDone = options.onDone;
530
+ this.onCancel = options.onCancel;
531
+ this.refresh();
532
+ }
533
+
534
+ get focused(): boolean {
535
+ return this._focused;
536
+ }
537
+
538
+ set focused(value: boolean) {
539
+ this._focused = value;
540
+ this.searchInput.focused = value;
541
+ }
542
+
543
+ getRows(): readonly HousekeepingRow[] {
544
+ return this.rows;
545
+ }
546
+
547
+ getSelectedValue(): string | undefined {
548
+ return this.rows[this.selected]?.value;
549
+ }
550
+
551
+ render(width: number): string[] {
552
+ const height = dialogHeight(this.tui);
553
+ const inner = Math.max(1, width - 4);
554
+ const hint = this.scopedIdentities.size
555
+ ? "Scoped models first, then every other available model. Type to search."
556
+ : "No scoped models in this session; all available models are listed. Type to search.";
557
+ const header = [truncateToWidth(this.theme.fg("muted", hint), inner, ""), ...this.searchInput.render(inner)];
558
+ const budget = Math.max(1, height - 4 - header.length);
559
+ const display: (HousekeepingRow | string)[] = [];
560
+ let previous: string | undefined;
561
+ for (const row of this.rows) {
562
+ if (row.group !== previous) display.push(row.group);
563
+ previous = row.group;
564
+ display.push(row);
565
+ }
566
+ const selectedRow = this.rows[this.selected];
567
+ const index = Math.max(0, display.findIndex((row) => row === selectedRow));
568
+ const start = Math.max(0, Math.min(index - budget + 1, display.length - budget));
569
+ const lines = display.slice(start, start + budget).map((row) => {
570
+ if (typeof row === "string") return this.theme.fg("muted", row);
571
+ const text = `${row === selectedRow ? "›" : " "} ${row.label} ${this.theme.fg("muted", row.description)}`;
572
+ return row === selectedRow ? this.theme.fg("accent", text) : text;
573
+ });
574
+ return frameDialog(
575
+ this.theme,
576
+ width,
577
+ height,
578
+ this.theme.fg("accent", HOUSEKEEPING_TITLE),
579
+ [...header, ...lines].map((line) => ` ${line}`),
580
+ this.theme.fg("dim", "↑↓ select · Enter choose · Esc cancel"),
581
+ );
582
+ }
583
+
584
+ handleInput(keyData: string): void {
585
+ const kb = getKeybindings();
586
+ if (kb.matches(keyData, "tui.select.cancel")) return this.onCancel();
587
+ if (kb.matches(keyData, "tui.select.confirm")) {
588
+ const row = this.rows[this.selected];
589
+ if (row) this.onDone(row.value);
590
+ return;
591
+ }
592
+ if (kb.matches(keyData, "tui.select.up")) this.selected = Math.max(0, this.selected - 1);
593
+ else if (kb.matches(keyData, "tui.select.down"))
594
+ this.selected = Math.min(this.rows.length - 1, this.selected + 1);
595
+ else if (matchesKey(keyData, Key.pageUp)) this.selected = Math.max(0, this.selected - 10);
596
+ else if (matchesKey(keyData, Key.pageDown))
597
+ this.selected = Math.min(this.rows.length - 1, this.selected + 10);
598
+ else {
599
+ const before = this.searchInput.getValue();
600
+ this.searchInput.handleInput(keyData);
601
+ if (this.searchInput.getValue() !== before) this.refresh(true);
602
+ }
603
+ this.tui.requestRender();
604
+ }
605
+
606
+ private refresh(resetSelection = false): void {
607
+ const query = modelSearchText(this.searchInput.getValue()).trim();
608
+ let matches: AvailableModel[] = [...this.allModels];
609
+ if (query) {
610
+ const scores = new Map<string, number>();
611
+ for (const result of fuzzysort.go(query, this.modelSearch, { limit: 0, threshold: 0 }))
612
+ scores.set(modelIdentity(result.obj), result.score);
613
+ matches = matches
614
+ .filter((model) => scores.has(modelIdentity(model)))
615
+ .sort((a, b) => scores.get(modelIdentity(b))! - scores.get(modelIdentity(a))!);
616
+ }
617
+ const describe = (model: AvailableModel) =>
618
+ [sanitizeModelText(model.name), modelIdentity(model) === this.current ? "current" : ""]
619
+ .filter(Boolean)
620
+ .join(" · ");
621
+ const row = (model: AvailableModel, group: string): HousekeepingRow => ({
622
+ value: modelIdentity(model),
623
+ label: renderModelIdentity(modelIdentity(model)),
624
+ description: describe(model),
625
+ group,
626
+ });
627
+ const known = this.allModels.some((model) => modelIdentity(model) === this.current);
628
+ const rows: HousekeepingRow[] = [
629
+ {
630
+ value: "",
631
+ label: "No model",
632
+ description: "Leave housekeeping without a model (summaries stay inactive)",
633
+ group: CLEAR_GROUP,
634
+ },
635
+ ...(this.current && !known
636
+ ? [
637
+ {
638
+ value: this.current,
639
+ label: renderModelIdentity(this.current),
640
+ description: "current · unavailable in current model registry",
641
+ group: CLEAR_GROUP,
642
+ },
643
+ ]
644
+ : []),
645
+ ...matches.filter((m) => this.scopedIdentities.has(modelIdentity(m))).map((m) => row(m, SCOPED_GROUP)),
646
+ ...matches.filter((m) => !this.scopedIdentities.has(modelIdentity(m))).map((m) => row(m, OTHER_GROUP)),
647
+ ];
648
+ const previous = this.rows[this.selected]?.value;
649
+ this.rows = rows;
650
+ if (resetSelection) {
651
+ // Land on the best matching available model, never the clear row or an unavailable saved one.
652
+ const first = query ? rows.findIndex((r) => r.group !== CLEAR_GROUP) : -1;
653
+ this.selected = Math.max(0, first);
654
+ } else {
655
+ const kept = rows.findIndex((r) => r.value === previous);
656
+ const initial = rows.findIndex((r) => r.value === this.current && this.current !== "");
657
+ this.selected = kept >= 0 ? kept : Math.max(0, initial);
658
+ }
659
+ }
660
+ }
661
+
662
+ export async function pickHousekeepingModel(
663
+ ctx: ExtensionCommandContext,
664
+ current: string,
665
+ ): Promise<string | typeof HOUSEKEEPING_PICKER_CANCEL> {
666
+ if (ctx.mode !== "tui") {
667
+ if (ctx.hasUI)
668
+ ctx.ui.notify("The housekeeping model picker requires interactive TUI mode.", "warning");
669
+ return HOUSEKEEPING_PICKER_CANCEL;
670
+ }
671
+ const availableModels = ctx.modelRegistry.getAvailable().map((model) => ({
672
+ provider: model.provider,
673
+ id: model.id,
674
+ name: model.name,
675
+ }));
676
+ return ctx.ui.custom<string | typeof HOUSEKEEPING_PICKER_CANCEL>(
677
+ (tui, theme, _keys, done) =>
678
+ new HousekeepingModelPickerComponent({
679
+ tui,
680
+ theme,
681
+ availableModels,
682
+ scopedModels: ctx.scopedModels,
683
+ current,
684
+ onDone: (identity) => done(identity),
685
+ onCancel: () => done(HOUSEKEEPING_PICKER_CANCEL),
686
+ }),
687
+ DIALOG_OPTIONS,
688
+ );
689
+ }
@@ -27,6 +27,7 @@ import {
27
27
  type WidgetMode,
28
28
  } from "../prefs/settings.ts";
29
29
  import { editAgentTypes } from "./ui.ts";
30
+ import { HOUSEKEEPING_PICKER_CANCEL, pickHousekeepingModel } from "./model-picker.ts";
30
31
  import type { ToolEditorOptions } from "./tool-picker.ts";
31
32
  import { AGENT_LOADERS, availableLoaderStyles, effectiveLoaderStyle } from "./agent-loader.ts";
32
33
  import { costIconGlyph } from "./cost-footer.ts";
@@ -224,6 +225,47 @@ async function configureFooterDisplay(ctx: ExtensionCommandContext, draft: Manag
224
225
  }
225
226
  }
226
227
 
228
+ function housekeepingValue(draft: ManagerSettings): string {
229
+ if (!draft.housekeepingEnabled) return "Off";
230
+ return draft.housekeepingModel ? `On · ${draft.housekeepingModel}` : "On · no model selected";
231
+ }
232
+
233
+ const HOUSEKEEPING_HELP =
234
+ "Experimental: a model you choose writes a one-line summary of each running agent's current work, shown in the tree and widget instead of raw tool-call status.\nSends the agent's task and recent tool names/arguments/text to the selected model, uses extra tokens, and is not included in subagent cost totals.\nOff by default. Any failure keeps the original status. Choose from available and scoped models.";
235
+
236
+ /** Edits the shared draft; only the outer settings screen saves or applies it. */
237
+ async function configureHousekeeping(ctx: ExtensionCommandContext, draft: ManagerSettings, layers: SettingsLayers): Promise<void> {
238
+ let selectedId: string | undefined;
239
+ while (true) {
240
+ const action = await dialogMenu(ctx, "[lab] Housekeeping model", ([
241
+ {
242
+ id: "enabled",
243
+ label: "Summaries",
244
+ value: draft.housekeepingEnabled ? "On" : "Off",
245
+ help: "Name each running agent's work in one line using the housekeeping model, replacing raw tool-call status in the tree and widget.\nInactive until a model is selected. Off by default.",
246
+ },
247
+ {
248
+ id: "model",
249
+ label: "Model",
250
+ value: draft.housekeepingModel || "Not selected",
251
+ valueColor: draft.housekeepingModel ? undefined : "muted" as const,
252
+ help: "Pick any available model; scoped models are listed first. A small, fast, inexpensive model is usually enough.\nIf the model later becomes unavailable (no credentials, removed), summaries stay inactive and normal status shows.",
253
+ },
254
+ { id: "back", label: "Back", help: "Return to settings. Save and apply there to commit these changes." },
255
+ ] as DialogRow[]).map((row) => {
256
+ const key = ({ enabled: "housekeepingEnabled", model: "housekeepingModel" } as Record<string, keyof ManagerSettings>)[row.id];
257
+ return key ? withProvenance(row, [key], layers) : row;
258
+ }), { selectedId, renderLegend: provenanceLegend, footer: "↑↓/Tab navigate · Enter edit · Esc back" });
259
+ if (!action || action === "back") return;
260
+ selectedId = action;
261
+ if (action === "enabled") draft.housekeepingEnabled = !draft.housekeepingEnabled;
262
+ else if (action === "model") {
263
+ const picked = await pickHousekeepingModel(ctx, draft.housekeepingModel);
264
+ if (picked !== HOUSEKEEPING_PICKER_CANCEL) draft.housekeepingModel = picked;
265
+ }
266
+ }
267
+ }
268
+
227
269
  const MODEL_SELECTION_OPTIONS = [
228
270
  {
229
271
  id: "pick-first-available",
@@ -358,6 +400,13 @@ async function configureAgentsDialog(
358
400
  value: COST_DISPLAY_OPTIONS.find((mode) => mode.id === draft.costDisplay)!.label,
359
401
  help: "Configure footer location, displayed cost, and money icon in a submenu. Save and apply to update immediately.",
360
402
  },
403
+ {
404
+ id: "housekeeping",
405
+ label: "[lab] Housekeeping model",
406
+ value: housekeepingValue(draft),
407
+ valueColor: draft.housekeepingEnabled && !draft.housekeepingModel ? "warning" as const : undefined,
408
+ help: HOUSEKEEPING_HELP,
409
+ },
361
410
  {
362
411
  id: "nerdFontIcons",
363
412
  label: "[lab] Nerd Font icons",
@@ -415,6 +464,8 @@ async function configureAgentsDialog(
415
464
  ] as DialogRow[]).map((row) => {
416
465
  const keys = row.id === "costDisplay"
417
466
  ? ["costDisplay", "costValue", "costIcon"] as (keyof ManagerSettings)[]
467
+ : row.id === "housekeeping"
468
+ ? ["housekeepingEnabled", "housekeepingModel"] as (keyof ManagerSettings)[]
418
469
  : row.id in DEFAULT_MANAGER_SETTINGS ? [row.id as keyof ManagerSettings] : [];
419
470
  return keys.length ? withProvenance(row, keys, layers) : row;
420
471
  }),
@@ -472,6 +523,8 @@ async function configureAgentsDialog(
472
523
  draft.widgetMode = mode as WidgetMode;
473
524
  } else if (action === "costDisplay") {
474
525
  await configureFooterDisplay(ctx, draft, layers);
526
+ } else if (action === "housekeeping") {
527
+ await configureHousekeeping(ctx, draft, layers);
475
528
  } else if (action === "nerdFontIcons") {
476
529
  draft.nerdFontIcons = !draft.nerdFontIcons;
477
530
  } else if (action === "loaderStyle") {
@@ -26,7 +26,7 @@ import {
26
26
  } from "./dialog.ts";
27
27
  import type { ThreadService } from "../types.ts";
28
28
  import type { LoaderStyle } from "../prefs/settings.ts";
29
- import { buildStatusTree, type StatusRow } from "./thread-tree.ts";
29
+ import { buildStatusTree, threadActivity, type StatusRow } from "./thread-tree.ts";
30
30
  import {
31
31
  AGENT_PROGRESS_INTERVAL,
32
32
  agentProgressIcon,
@@ -309,7 +309,7 @@ export class StatusDialog {
309
309
  ].join("");
310
310
  // Continue the tree's vertical guides without repeating the branch or selection marker.
311
311
  const stem = row.prefix.replace("├ ", "│ ").replace("└ ", " ");
312
- const activity = ` ${stem} ${dialogText(thread.status || thread.task)}`;
312
+ const activity = ` ${stem} ${dialogText(threadActivity(thread))}`;
313
313
  const metrics = this.theme.fg(base, threadMetrics(thread));
314
314
  const metricWidth = visibleWidth(metrics);
315
315
  const first =
@@ -2,6 +2,16 @@ import type { ThreadView } from "../types.ts";
2
2
 
3
3
  const ROOT = "/root";
4
4
 
5
+ /**
6
+ * Activity line for tree rows and the widget. A [labs] housekeeping summary replaces raw
7
+ * tool-call status only while the agent is active; otherwise the original status/task shows.
8
+ */
9
+ export function threadActivity(thread: ThreadView): string {
10
+ const active = thread.state === "starting" || thread.state === "running";
11
+ const summary = typeof thread.summary === "string" ? thread.summary.trim() : "";
12
+ return (active && summary) || thread.status || thread.task;
13
+ }
14
+
5
15
  export interface StatusRow {
6
16
  path: string;
7
17
  prefix: string;
package/src/ui/ui.ts CHANGED
@@ -1037,6 +1037,44 @@ export async function editAgentTypes(
1037
1037
  );
1038
1038
  }
1039
1039
 
1040
+ function agentSourceHelp(store: ConfigStore, name: string): string {
1041
+ const layers = store.getLayers(name);
1042
+ const paths = layers.map((layer) =>
1043
+ `${layer.source ?? "user"} · ${layer.filePath ?? ""}`,
1044
+ ).join("\n");
1045
+ return layers.length > 1
1046
+ ? `${layers.map((layer) => layer.source).join(" → ")}\n${paths}`
1047
+ : paths;
1048
+ }
1049
+
1050
+ function agentSettingsIndicators(
1051
+ store: ConfigStore,
1052
+ name: string,
1053
+ action: EditMenuAction,
1054
+ ): (theme: Theme) => string {
1055
+ const hasKey = (scope: "user" | "project") => {
1056
+ const settings = store.getSettingsOverride(name, scope);
1057
+ if (!settings) return false;
1058
+ if (action === "tools.allow" || action === "tools.block") {
1059
+ return Object.hasOwn(settings, "tools") &&
1060
+ (settings.tools === null || Object.hasOwn(settings.tools ?? {}, action.split(".")[1]!));
1061
+ }
1062
+ return Object.hasOwn(settings, action);
1063
+ };
1064
+ const global = hasKey("user");
1065
+ const project = hasKey("project");
1066
+ return (theme) =>
1067
+ (global ? theme.fg("accent", "●") : " ") + " " +
1068
+ (project ? theme.fg("warning", "●") : " ");
1069
+ }
1070
+
1071
+ function agentSettingsLegend(theme: Theme): string {
1072
+ const global = theme.fg("accent", "●");
1073
+ const project = theme.fg("warning", "●");
1074
+ return theme.fg("muted", "Saved: ") +
1075
+ `${global} Global · ${project} Current Project · ${global} ${project} Both`;
1076
+ }
1077
+
1040
1078
  async function editAgentTypesDialog(
1041
1079
  ctx: ExtensionCommandContext,
1042
1080
  store: ConfigStore,
@@ -1058,7 +1096,7 @@ async function editAgentTypesDialog(
1058
1096
  renderLabel: (label: string, theme: Theme) =>
1059
1097
  agentTypeBadge(label, type.color, theme, type.icon, nerdFontIcons),
1060
1098
  value: type.description,
1061
- help: `${type.source ?? "user"} · ${type.filePath ?? ""}`,
1099
+ help: agentSourceHelp(store, type.name),
1062
1100
  })),
1063
1101
  ]);
1064
1102
  if (selection === undefined) return;
@@ -1095,6 +1133,9 @@ async function editAgentTypesDialog(
1095
1133
  return {
1096
1134
  id: action,
1097
1135
  label: EDIT_FIELD_LABELS[action],
1136
+ renderIndicators: editMode === "override" && original
1137
+ ? agentSettingsIndicators(store, original.name, action)
1138
+ : undefined,
1098
1139
  valueColor: action === "Save" && dirty ? ("warning" as const) : undefined,
1099
1140
  value:
1100
1141
  action === "Customization"
@@ -1102,9 +1143,9 @@ async function editAgentTypesDialog(
1102
1143
  : action === "Save" && dirty
1103
1144
  ? "(changes)"
1104
1145
  : action === "Source"
1105
- ? original?.customization
1106
- ? `${original.customization.scope} ${original.customization.kind} over ${original.baseSource ?? "bundled"}`
1107
- : (original?.source ?? "New draft")
1146
+ ? original
1147
+ ? store.getLayers(original.name).map((layer) => layer.source).join(" → ")
1148
+ : "New draft"
1108
1149
  : action === "Save scope"
1109
1150
  ? saveScope === "user"
1110
1151
  ? "Global"
@@ -1116,10 +1157,9 @@ async function editAgentTypesDialog(
1116
1157
  : "",
1117
1158
  help:
1118
1159
  action === "Source"
1119
- ? original?.customization
1120
- ? `Settings file: ${original.customization.filePath}. Base prompt: ${original.baseFilePath ?? "(bundled)"}.`
1121
- : (original?.filePath ??
1122
- "Not saved yet. Bundled definitions are copied, never overwritten.")
1160
+ ? original
1161
+ ? agentSourceHelp(store, original.name)
1162
+ : "Not saved yet. Bundled definitions are copied, never overwritten."
1123
1163
  : EDIT_FIELD_HELP[action],
1124
1164
  };
1125
1165
  }),
@@ -1127,6 +1167,7 @@ async function editAgentTypesDialog(
1127
1167
  selectedId,
1128
1168
  saveId: "Save",
1129
1169
  footer: "↑↓/Tab fields · Enter edit · Ctrl+S save · Esc cancel",
1170
+ renderLegend: editMode === "override" ? agentSettingsLegend : undefined,
1130
1171
  },
1131
1172
  );
1132
1173
  selectedId = field;