pi-subagent-manager 0.21.1 → 0.23.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.
@@ -5,6 +5,7 @@ import {
5
5
  dialogInput,
6
6
  dialogMenu,
7
7
  withDialogSession,
8
+ type DialogRow,
8
9
  } from "./dialog.ts";
9
10
  import {
10
11
  DEFAULT_MANAGER_SETTINGS,
@@ -14,9 +15,9 @@ import {
14
15
  type CostValue,
15
16
  LOADER_STYLES,
16
17
  type LoaderStyle,
17
- loadManagerSaveScope,
18
- saveManagerSaveScope,
19
- saveManagerSettings,
18
+ loadManagerSettingsLayers,
19
+ saveManagerOverrides,
20
+ setManagerProjectSettings,
20
21
  type ManagerSettings,
21
22
  type ModelSelectionMode,
22
23
  type SubagentMode,
@@ -25,7 +26,7 @@ import {
25
26
  } from "../prefs/settings.ts";
26
27
  import { editAgentTypes } from "./ui.ts";
27
28
  import type { ToolEditorOptions } from "./tool-picker.ts";
28
- import { AGENT_LOADERS } from "./agent-loader.ts";
29
+ import { AGENT_LOADERS, availableLoaderStyles, effectiveLoaderStyle } from "./agent-loader.ts";
29
30
  import { costIconGlyph } from "./cost-footer.ts";
30
31
 
31
32
  const LOADER_OPTIONS = LOADER_STYLES.map((id) => {
@@ -34,7 +35,7 @@ const LOADER_OPTIONS = LOADER_STYLES.map((id) => {
34
35
  id,
35
36
  label: loader.label,
36
37
  value: `${loader.frames.join(" ")} · ${Object.values(loader.states).join(" ")}`,
37
- help: `Each row: all starting/running frames · completed, paused, failed, stopped.\nStarting/running: ${loader.frames.join(" ")}\nCompleted: ${loader.states.completed} · Paused: ${loader.states.paused}\nFailed: ${loader.states.failed} · Stopped: ${loader.states.stopped}\nRequires [labs] Nerd Font icons On. The loader appears before the unchanged role icon.`,
38
+ help: `Each row: all starting/running frames · completed, paused, failed, stopped.\nStarting/running: ${loader.frames.join(" ")}\nCompleted: ${loader.states.completed} · Paused: ${loader.states.paused}\nFailed: ${loader.states.failed} · Stopped: ${loader.states.stopped}\n${loader.requiresNerdFont ? "Requires [labs] Nerd Font icons On." : id === "braille" ? "Standard Unicode Braille; no Nerd Font needed." : "ASCII only; no special font needed."} The loader appears before the role icon when enabled.`,
38
39
  };
39
40
  });
40
41
 
@@ -149,11 +150,28 @@ const COST_VALUE_OPTIONS = [
149
150
 
150
151
  const COST_ICON_LABELS = { money: "Money", coins: "Coins", wallet: "Wallet" } as const;
151
152
 
153
+ type SettingsLayers = ReturnType<typeof loadManagerSettingsLayers>;
154
+
155
+ /** Persisted changes, not unsaved draft values; theme styling is computed on render. */
156
+ function withProvenance(row: DialogRow, keys: (keyof ManagerSettings)[], layers: SettingsLayers): DialogRow {
157
+ const globalChanged = keys.some((key) => layers.global[key] !== undefined &&
158
+ layers.global[key] !== DEFAULT_MANAGER_SETTINGS[key]);
159
+ const projectChanged = keys.some((key) => layers.project[key] !== undefined &&
160
+ layers.project[key] !== (layers.global[key] ?? DEFAULT_MANAGER_SETTINGS[key]));
161
+ return {
162
+ ...row,
163
+ renderLabel: (label, theme) =>
164
+ (globalChanged ? theme.fg("accent", "●") + " " : "") +
165
+ (projectChanged ? theme.fg("warning", "●") + " " : "") + label.replace(/^\[labs\] /, ""),
166
+ help: `${row.label}\n${row.help ?? ""}\nDots (saved): accent ● Global; warning ● Current Project; both ● ● changed in both.`,
167
+ };
168
+ }
169
+
152
170
  /** Edits the shared draft; only the outer settings screen saves or applies it. */
153
- async function configureFooterDisplay(ctx: ExtensionCommandContext, draft: ManagerSettings): Promise<void> {
171
+ async function configureFooterDisplay(ctx: ExtensionCommandContext, draft: ManagerSettings, layers: SettingsLayers): Promise<void> {
154
172
  let selectedId: string | undefined;
155
173
  while (true) {
156
- const action = await dialogMenu(ctx, "[labs] Footer display", [
174
+ const action = await dialogMenu(ctx, "[labs] Footer display", ([
157
175
  {
158
176
  id: "location",
159
177
  label: "Location",
@@ -173,7 +191,10 @@ async function configureFooterDisplay(ctx: ExtensionCommandContext, draft: Manag
173
191
  help: `Choose a money-related ${draft.nerdFontIcons ? "Nerd Font" : "emoji"} icon. The family follows [labs] Nerd Font icons.`,
174
192
  },
175
193
  { id: "back", label: "Back", help: "Return to settings. Save and apply there to commit these changes." },
176
- ], { selectedId, footer: "↑↓/Tab navigate · Enter edit · Esc back" });
194
+ ] as DialogRow[]).map((row) => {
195
+ const key = ({ location: "costDisplay", value: "costValue", icon: "costIcon" } as Record<string, keyof ManagerSettings>)[row.id];
196
+ return key ? withProvenance(row, [key], layers) : row;
197
+ }), { selectedId, footer: "↑↓/Tab navigate · Enter edit · Esc back" });
177
198
  if (!action || action === "back") return;
178
199
  selectedId = action;
179
200
  if (action === "location") {
@@ -244,18 +265,26 @@ async function configureAgentsDialog(
244
265
  apply(): void;
245
266
  },
246
267
  ): Promise<void> {
247
- let draft = { ...options.settings };
248
- let scope = loadManagerSaveScope({
268
+ const readLayers = () => loadManagerSettingsLayers({
269
+ cwd: ctx.cwd,
249
270
  agentDir: options.agentDir,
250
271
  includeProject: ctx.isProjectTrusted(),
251
272
  });
273
+ let layers = readLayers();
274
+ const reportDiagnostics = () => {
275
+ for (const diagnostic of layers.diagnostics) ctx.ui.notify(diagnostic, "warning");
276
+ };
277
+ reportDiagnostics();
278
+ let baseline = { ...layers.settings };
279
+ let draft = { ...baseline };
280
+ let scope = layers.scope;
252
281
  let selectedId: string | undefined;
253
282
  while (true) {
254
- const dirty = JSON.stringify(draft) !== JSON.stringify(options.settings);
283
+ const dirty = JSON.stringify(draft) !== JSON.stringify(baseline);
255
284
  const action = await dialogMenu(
256
285
  ctx,
257
286
  `Agents settings${dirty ? " · unsaved" : ""}`,
258
- [
287
+ ([
259
288
  {
260
289
  id: "subagentMode",
261
290
  label: "Subagent Mode",
@@ -294,13 +323,19 @@ async function configureAgentsDialog(
294
323
  id: "nerdFontIcons",
295
324
  label: "[labs] Nerd Font icons",
296
325
  value: draft.nerdFontIcons ? "On" : "Off",
297
- help: "Experimental: display each agent type’s optional icon, preceded by its loader/state indicator.\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.",
326
+ help: "Experimental: display each agent type’s optional Nerd Font icon and unlock Nerd Font loader palettes.\nRequires a Nerd Font configured in your terminal; otherwise glyphs may appear as boxes.\nOff by default. Braille and ASCII loaders work with this Off. Save and apply to update immediately.",
298
327
  },
299
328
  {
300
329
  id: "loaderStyle",
301
330
  label: "[labs] Loader style",
302
- value: AGENT_LOADERS[draft.loaderStyle].label,
303
- help: "Choose Circle, Braille or Hourglass. Preview every animation frame and settled state for all families.\nRequires [labs] Nerd Font icons On. Circle is the default.\nSave and apply to update the widget immediately.",
331
+ value: AGENT_LOADERS[effectiveLoaderStyle(draft.loaderStyle, draft.nerdFontIcons)].label,
332
+ help: "Preview every animation frame and settled state.\nNerd Fonts Off: Braille (standard Unicode), ASCII, ASCII Star and ASCII Pulse. On: all palettes, including Circle and Hourglass.\nNerd-only saved styles fall back to ASCII while Nerd Fonts are off. Save and apply to update immediately.",
333
+ },
334
+ {
335
+ id: "subagentExtensions",
336
+ label: "[labs] Enable subagent extensions",
337
+ value: draft.subagentExtensions ? "On" : "Off",
338
+ help: "Experimental: reload configured user/trusted-project extension hooks in separate subagent sessions (not CLI-only or inline extensions). Bugs and unintended consequences may occur if hooks assume main-session state.\nRead limitations: https://github.com/championswimmer/pi-subagent-manager/blob/main/docs/subagent-extension-limitations.md\nOff by default. Save and apply affects newly opened sessions, not already-open agents.",
304
339
  },
305
340
  {
306
341
  id: "finalRecap",
@@ -312,7 +347,7 @@ async function configureAgentsDialog(
312
347
  id: "scope",
313
348
  label: "Save scope",
314
349
  value: scope === "user" ? "Global" : "Current Project",
315
- help: "Global: save all values shown as your defaults for every project. Existing project settings still override them, including here.\nCurrent Project: save all values shown for this project only, overriding your global defaults here. Other projects are unchanged. Requires a trusted project.\nSwitching scope only changes where you save, not the values shown. Your choice is remembered across projects and restarts, even if you cancel.",
350
+ help: "Global: save overrides of built-in defaults for all projects.\nCurrent Project: save overrides of global settings for this trusted project.\nSwitching requires confirmation: enabling Project creates its settings file; switching to Global deletes it and discards unsaved edits. Confirmed scope changes happen immediately, even if you later cancel.",
316
351
  },
317
352
  {
318
353
  id: "types",
@@ -330,14 +365,19 @@ async function configureAgentsDialog(
330
365
  label: "Save and apply",
331
366
  value: dirty ? "(changes)" : undefined,
332
367
  valueColor: dirty ? "warning" as const : undefined,
333
- help: "Save all values to the selected scope and reload settings now.\nProject overrides still take precedence.\nRunning agents and retained sessions are kept.",
368
+ help: "Save only overrides to the selected scope and reload settings now.\nUnchanged values inherit from the lower layer.\nRunning agents and retained sessions are kept.",
334
369
  },
335
370
  {
336
371
  id: "cancel",
337
372
  label: "Cancel",
338
373
  help: "Close without saving manager settings.",
339
374
  },
340
- ],
375
+ ] as DialogRow[]).map((row) => {
376
+ const keys = row.id === "costDisplay"
377
+ ? ["costDisplay", "costValue", "costIcon"] as (keyof ManagerSettings)[]
378
+ : row.id in DEFAULT_MANAGER_SETTINGS ? [row.id as keyof ManagerSettings] : [];
379
+ return keys.length ? withProvenance(row, keys, layers) : row;
380
+ }),
341
381
  {
342
382
  selectedId,
343
383
  saveId: "save",
@@ -390,14 +430,20 @@ async function configureAgentsDialog(
390
430
  if (WIDGET_MODE_OPTIONS.some((option) => option.id === mode))
391
431
  draft.widgetMode = mode as WidgetMode;
392
432
  } else if (action === "costDisplay") {
393
- await configureFooterDisplay(ctx, draft);
433
+ await configureFooterDisplay(ctx, draft, layers);
394
434
  } else if (action === "nerdFontIcons") {
395
435
  draft.nerdFontIcons = !draft.nerdFontIcons;
396
436
  } else if (action === "loaderStyle") {
397
- const style = await dialogMenu(ctx, "[labs] Loader style", LOADER_OPTIONS, {
398
- selectedId: draft.loaderStyle,
399
- });
400
- if (LOADER_STYLES.includes(style as LoaderStyle)) draft.loaderStyle = style as LoaderStyle;
437
+ const styles = availableLoaderStyles(draft.nerdFontIcons);
438
+ const style = await dialogMenu(
439
+ ctx,
440
+ "[labs] Loader style",
441
+ LOADER_OPTIONS.filter((option) => styles.includes(option.id)),
442
+ { selectedId: effectiveLoaderStyle(draft.loaderStyle, draft.nerdFontIcons) },
443
+ );
444
+ if (styles.includes(style as LoaderStyle)) draft.loaderStyle = style as LoaderStyle;
445
+ } else if (action === "subagentExtensions") {
446
+ draft.subagentExtensions = !draft.subagentExtensions;
401
447
  } else if (action === "finalRecap") {
402
448
  draft.finalRecap = !draft.finalRecap;
403
449
  } else if (action === "scope") {
@@ -408,8 +454,33 @@ async function configureAgentsDialog(
408
454
  );
409
455
  else {
410
456
  const nextScope = scope === "user" ? "project" : "user";
411
- saveManagerSaveScope(options.agentDir, nextScope);
457
+ const message = nextScope === "project"
458
+ ? "Create project file now; outer Cancel cannot undo.\nThis will create this project's settings.json. Further changes will be saved there. Unsaved edits are kept until Save and apply."
459
+ : "Delete project file now. Discard edits. No undo.\nUnsaved edits will be discarded. Outer Cancel cannot undo. We reload global settings; further changes are saved globally.";
460
+ const confirmation = await dialogMenu(ctx,
461
+ nextScope === "project" ? "Enable project settings?" : "Clear project settings and use Global?",
462
+ [
463
+ { id: "confirm", label: "Confirm", help: message },
464
+ { id: "cancel", label: "Cancel", help: message + "\nCancel leaves files, scope and unsaved edits unchanged." },
465
+ ],
466
+ { selectedId: "cancel", footer: "↑↓/Tab choose · Enter select · Esc cancel" },
467
+ );
468
+ if (confirmation !== "confirm") continue;
469
+ setManagerProjectSettings({
470
+ cwd: ctx.cwd,
471
+ agentDir: options.agentDir,
472
+ includeProject: ctx.isProjectTrusted(),
473
+ enabled: nextScope === "project",
474
+ expectedLayers: layers,
475
+ });
476
+ layers = readLayers();
477
+ reportDiagnostics();
412
478
  scope = nextScope;
479
+ if (scope === "user") {
480
+ baseline = { ...layers.settings };
481
+ draft = { ...baseline };
482
+ options.apply();
483
+ }
413
484
  }
414
485
  } else if (action === "defaults") draft = { ...DEFAULT_MANAGER_SETTINGS };
415
486
  else if (action === "types") {
@@ -419,16 +490,17 @@ async function configureAgentsDialog(
419
490
  });
420
491
  options.store.reload();
421
492
  } else if (action === "save") {
422
- const file = saveManagerSettings({
493
+ const file = saveManagerOverrides({
423
494
  cwd: ctx.cwd,
424
495
  agentDir: options.agentDir,
425
496
  includeProject: ctx.isProjectTrusted(),
426
497
  scope,
427
498
  settings: draft,
499
+ expectedLayers: layers,
428
500
  });
429
501
  options.apply();
430
502
  ctx.ui.notify(
431
- `Saved ${file}. Settings reloaded; project overrides take precedence.`,
503
+ `Saved ${file}. Settings reloaded; unchanged values inherit from the lower layer.`,
432
504
  "info",
433
505
  );
434
506
  return;
@@ -139,7 +139,6 @@ export class StatusDialog {
139
139
  private syncRefresh(): void {
140
140
  if (!this.refreshing) return;
141
141
  const delay =
142
- this.nerdFontIcons &&
143
142
  this.service
144
143
  .list()
145
144
  .some(
package/src/ui/ui.ts CHANGED
@@ -92,7 +92,7 @@ export function agentTypeLabel(
92
92
  const role =
93
93
  nerdFontIcons && typeof icon === "string" && /^\p{Co}$/u.test(icon) ? `${icon} ` : "";
94
94
  const progress =
95
- nerdFontIcons && loaderIcon && isAgentLoaderGlyph(loaderIcon) ? `${loaderIcon} ` : "";
95
+ loaderIcon && isAgentLoaderGlyph(loaderIcon, nerdFontIcons) ? `${loaderIcon} ` : "";
96
96
  return `${progress}${role}${sanitizeText(type)}`;
97
97
  }
98
98
 
@@ -460,11 +460,8 @@ export function updateWidget(
460
460
  "pi-subagent",
461
461
  (tui) => {
462
462
  let timer: ReturnType<typeof setInterval> | undefined;
463
- if (snapshot.some(isLive) && (mode === "full" || nerdFontIcons)) {
464
- timer = setInterval(
465
- () => tui.requestRender(),
466
- nerdFontIcons ? AGENT_PROGRESS_INTERVAL : 1000,
467
- );
463
+ if (snapshot.some(isLive)) {
464
+ timer = setInterval(() => tui.requestRender(), AGENT_PROGRESS_INTERVAL);
468
465
  timer.unref();
469
466
  }
470
467
  return {