pi-subagent-manager 1.2.0 → 1.2.1

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.
@@ -29,7 +29,14 @@ export type CostValue = (typeof COST_VALUES)[number];
29
29
  export const COST_ICONS = ["money", "coins", "wallet"] as const;
30
30
  export type CostIcon = (typeof COST_ICONS)[number];
31
31
 
32
- export const LOADER_STYLES = ["circle", "braille", "hourglass", "ascii", "ascii-star", "ascii-pulse"] as const;
32
+ export const LOADER_STYLES = [
33
+ "circle",
34
+ "braille",
35
+ "hourglass",
36
+ "ascii",
37
+ "ascii-star",
38
+ "ascii-pulse",
39
+ ] as const;
33
40
  export type LoaderStyle = (typeof LOADER_STYLES)[number];
34
41
 
35
42
  export const TOOL_FILTERING_MODES = ["allowed", "all-except-blocked", "all"] as const;
@@ -97,7 +104,23 @@ export const isHousekeepingModel = (value: unknown): value is string =>
97
104
  typeof value === "string" && (value === "" || HOUSEKEEPING_MODEL.test(value));
98
105
 
99
106
  const KEYS = [
100
- "maxLevels", "maxConcurrent", "maxThreads", "modelSelection", "subagentMode", "toolFiltering", "widgetMode", "costDisplay", "costValue", "costIcon", "nerdFontIcons", "loaderStyle", "finalRecap", "subagentExtensions", "checklistIntegration", "housekeepingEnabled", "housekeepingModel",
107
+ "maxLevels",
108
+ "maxConcurrent",
109
+ "maxThreads",
110
+ "modelSelection",
111
+ "subagentMode",
112
+ "toolFiltering",
113
+ "widgetMode",
114
+ "costDisplay",
115
+ "costValue",
116
+ "costIcon",
117
+ "nerdFontIcons",
118
+ "loaderStyle",
119
+ "finalRecap",
120
+ "subagentExtensions",
121
+ "checklistIntegration",
122
+ "housekeepingEnabled",
123
+ "housekeepingModel",
101
124
  ] as const;
102
125
  const MAX_LEVELS = 32;
103
126
 
@@ -107,9 +130,7 @@ function errorCode(error: unknown): string | undefined {
107
130
  : undefined;
108
131
  }
109
132
 
110
- function lstatIfPresent(
111
- path: string,
112
- ): ReturnType<typeof lstatSync> | undefined {
133
+ function lstatIfPresent(path: string): ReturnType<typeof lstatSync> | undefined {
113
134
  try {
114
135
  return lstatSync(path);
115
136
  } catch (error) {
@@ -118,9 +139,7 @@ function lstatIfPresent(
118
139
  }
119
140
  }
120
141
 
121
- function assertNotSymlinkPath(
122
- path: string,
123
- ): ReturnType<typeof lstatSync> | undefined {
142
+ function assertNotSymlinkPath(path: string): ReturnType<typeof lstatSync> | undefined {
124
143
  const stat = lstatIfPresent(path);
125
144
  if (stat?.isSymbolicLink()) throw new Error(`Unsafe symlink path: ${path}`);
126
145
  return stat;
@@ -135,12 +154,20 @@ function positiveSafeInteger(value: unknown): value is number {
135
154
  }
136
155
 
137
156
  function requirement(key: (typeof KEYS)[number]): string {
138
- if (key === "subagentExtensions") return "subagentExtensions must be a boolean or an array of absolute file paths";
139
- if (key === "nerdFontIcons" || key === "finalRecap" || key === "checklistIntegration" || key === "housekeepingEnabled") return `${key} must be a boolean`;
157
+ if (key === "subagentExtensions")
158
+ return "subagentExtensions must be a boolean or an array of absolute file paths";
159
+ if (
160
+ key === "nerdFontIcons" ||
161
+ key === "finalRecap" ||
162
+ key === "checklistIntegration" ||
163
+ key === "housekeepingEnabled"
164
+ )
165
+ return `${key} must be a boolean`;
140
166
  if (key === "housekeepingModel") return "housekeepingModel must be empty or provider/model-id";
141
167
  if (key === "subagentMode") return "subagentMode must be off, opportunistic or orchestration";
142
168
  if (key === "widgetMode") return "widgetMode must be full or minimal";
143
- if (key === "costDisplay") return "costDisplay must be pi-footer-event, pi-footer-status or pi-status";
169
+ if (key === "costDisplay")
170
+ return "costDisplay must be pi-footer-event, pi-footer-status or pi-status";
144
171
  if (key === "costValue") return "costValue must be subagents or total";
145
172
  if (key === "costIcon") return "costIcon must be money, coins or wallet";
146
173
  if (key === "loaderStyle") return `loaderStyle must be one of: ${LOADER_STYLES.join(", ")}`;
@@ -171,21 +198,40 @@ function parseSettings(content: string): Partial<ManagerSettings> {
171
198
  if (typeof record.scopedModelFiltering !== "boolean")
172
199
  throw new Error("scopedModelFiltering must be a boolean");
173
200
  if (!Object.hasOwn(record, "modelSelection"))
174
- layer.modelSelection = record.scopedModelFiltering ? "pick-first-scoped" : "pick-first-available";
201
+ layer.modelSelection = record.scopedModelFiltering
202
+ ? "pick-first-scoped"
203
+ : "pick-first-available";
175
204
  }
176
205
  for (const key of KEYS) {
177
206
  if (!Object.hasOwn(record, key)) continue;
178
207
  const value = record[key];
179
- if (key === "nerdFontIcons" || key === "finalRecap" || key === "checklistIntegration" || key === "housekeepingEnabled") {
208
+ if (
209
+ key === "nerdFontIcons" ||
210
+ key === "finalRecap" ||
211
+ key === "checklistIntegration" ||
212
+ key === "housekeepingEnabled"
213
+ ) {
180
214
  if (typeof value !== "boolean") throw new Error(requirement(key));
181
215
  layer[key] = value;
182
216
  continue;
183
217
  }
184
218
  if (key === "subagentExtensions") {
185
- if (typeof value !== "boolean" && !(Array.isArray(value) && value.every(
186
- (entry) => typeof entry === "string" && entry.length > 0 && resolve(entry) === entry && !entry.includes("\0"),
187
- ))) throw new Error(requirement(key));
188
- layer.subagentExtensions = typeof value === "boolean" ? value : [...new Set(value as string[])].sort();
219
+ if (
220
+ typeof value !== "boolean" &&
221
+ !(
222
+ Array.isArray(value) &&
223
+ value.every(
224
+ (entry) =>
225
+ typeof entry === "string" &&
226
+ entry.length > 0 &&
227
+ resolve(entry) === entry &&
228
+ !entry.includes("\0"),
229
+ )
230
+ )
231
+ )
232
+ throw new Error(requirement(key));
233
+ layer.subagentExtensions =
234
+ typeof value === "boolean" ? value : [...new Set(value as string[])].sort();
189
235
  continue;
190
236
  }
191
237
  if (key === "housekeepingModel") {
@@ -266,8 +312,7 @@ function settingsFileExists(entry: SettingsLayer): boolean {
266
312
  }
267
313
  const stat = assertNotSymlinkPath(entry.filePath);
268
314
  if (!stat) return false;
269
- if (!stat.isFile())
270
- throw new Error(`Settings must be a regular file: ${entry.filePath}`);
315
+ if (!stat.isFile()) throw new Error(`Settings must be a regular file: ${entry.filePath}`);
271
316
  return true;
272
317
  }
273
318
 
@@ -329,11 +374,7 @@ export function loadManagerSettings(options: ManagerSettingsOptions): {
329
374
  }
330
375
 
331
376
  function serializedSettings(settings: ManagerSettings): string {
332
- if (
333
- settings === null ||
334
- typeof settings !== "object" ||
335
- Array.isArray(settings)
336
- ) {
377
+ if (settings === null || typeof settings !== "object" || Array.isArray(settings)) {
337
378
  throw new Error("Settings must be a JSON object");
338
379
  }
339
380
  for (const key of Object.keys(settings)) {
@@ -379,8 +420,7 @@ function ensureScopeDirectories(directories: string[]): void {
379
420
 
380
421
  function assertRegularFileOrAbsent(filePath: string): void {
381
422
  const stat = assertNotSymlinkPath(filePath);
382
- if (stat && !stat.isFile())
383
- throw new Error(`Settings must be a regular file: ${filePath}`);
423
+ if (stat && !stat.isFile()) throw new Error(`Settings must be a regular file: ${filePath}`);
384
424
  }
385
425
 
386
426
  function exclusiveCreateFlags(): number {
@@ -405,8 +445,7 @@ function writeAtomically(entry: SettingsLayer, content: string, overwrite = true
405
445
  for (const directory of entry.directories) assertExistingDirectory(directory);
406
446
  assertRegularFileOrAbsent(filePath);
407
447
  const tempStat = assertNotSymlinkPath(temporary);
408
- if (!tempStat?.isFile())
409
- throw new Error(`Settings must be a regular file: ${temporary}`);
448
+ if (!tempStat?.isFile()) throw new Error(`Settings must be a regular file: ${temporary}`);
410
449
  if (overwrite) renameSync(temporary, filePath);
411
450
  else {
412
451
  try {
@@ -452,24 +491,34 @@ export function saveManagerSettings(options: {
452
491
  return entry.filePath;
453
492
  }
454
493
 
455
- function assertExpectedLayers(current: ManagerSettingsLayers, expected: ManagerSettingsLayers): void {
494
+ function assertExpectedLayers(
495
+ current: ManagerSettingsLayers,
496
+ expected: ManagerSettingsLayers,
497
+ ): void {
456
498
  if (
457
499
  current.scope !== expected.scope ||
458
- KEYS.some((key) => !settingsValueEqual(current.global[key], expected.global[key]) ||
459
- !settingsValueEqual(current.project[key], expected.project[key])) ||
500
+ KEYS.some(
501
+ (key) =>
502
+ !settingsValueEqual(current.global[key], expected.global[key]) ||
503
+ !settingsValueEqual(current.project[key], expected.project[key]),
504
+ ) ||
460
505
  current.diagnostics.length !== expected.diagnostics.length ||
461
506
  current.diagnostics.some((diagnostic, index) => diagnostic !== expected.diagnostics[index])
462
507
  ) {
463
- throw new Error("Settings changed on disk. Reopen settings before saving or switching scope to avoid stale inherited values.");
508
+ throw new Error(
509
+ "Settings changed on disk. Reopen settings before saving or switching scope to avoid stale inherited values.",
510
+ );
464
511
  }
465
512
  }
466
513
 
467
514
  /** Persist only values that change the selected scope's inherited settings. */
468
- export function saveManagerOverrides(options: ManagerSettingsOptions & {
469
- scope: ManagerSaveScope;
470
- settings: ManagerSettings;
471
- expectedLayers?: ManagerSettingsLayers;
472
- }): string {
515
+ export function saveManagerOverrides(
516
+ options: ManagerSettingsOptions & {
517
+ scope: ManagerSaveScope;
518
+ settings: ManagerSettings;
519
+ expectedLayers?: ManagerSettingsLayers;
520
+ },
521
+ ): string {
473
522
  if (options.scope !== "user" && options.scope !== "project")
474
523
  throw new Error("Invalid settings scope");
475
524
  if (options.scope === "project" && !options.includeProject)
@@ -480,29 +529,40 @@ export function saveManagerOverrides(options: ManagerSettingsOptions & {
480
529
  if (options.expectedLayers) assertExpectedLayers(current, options.expectedLayers);
481
530
  if (options.scope === "project") {
482
531
  const globalPath = layer(options.agentDir, ["subagent-manager"]).filePath;
483
- const globalDiagnostics = current.diagnostics.filter((diagnostic) => diagnostic.startsWith(`${globalPath}:`));
532
+ const globalDiagnostics = current.diagnostics.filter((diagnostic) =>
533
+ diagnostic.startsWith(`${globalPath}:`),
534
+ );
484
535
  if (globalDiagnostics.length > 0)
485
- throw new Error(`Cannot save project overrides while global settings are invalid. Fix global settings and reopen settings. ${globalDiagnostics.join("; ")}`);
536
+ throw new Error(
537
+ `Cannot save project overrides while global settings are invalid. Fix global settings and reopen settings. ${globalDiagnostics.join("; ")}`,
538
+ );
486
539
  }
487
- const inherited = options.scope === "user"
488
- ? DEFAULT_MANAGER_SETTINGS
489
- : { ...DEFAULT_MANAGER_SETTINGS, ...current.global };
540
+ const inherited =
541
+ options.scope === "user"
542
+ ? DEFAULT_MANAGER_SETTINGS
543
+ : { ...DEFAULT_MANAGER_SETTINGS, ...current.global };
490
544
  const overrides = Object.fromEntries(
491
- KEYS.filter((key) => !settingsValueEqual(parsed[key], inherited[key])).map((key) => [key, parsed[key]]),
545
+ KEYS.filter((key) => !settingsValueEqual(parsed[key], inherited[key])).map((key) => [
546
+ key,
547
+ parsed[key],
548
+ ]),
492
549
  );
493
- const entry = options.scope === "user"
494
- ? layer(options.agentDir, ["subagent-manager"])
495
- : layer(options.cwd, [".pi", "agent", "subagent-manager"]);
550
+ const entry =
551
+ options.scope === "user"
552
+ ? layer(options.agentDir, ["subagent-manager"])
553
+ : layer(options.cwd, [".pi", "agent", "subagent-manager"]);
496
554
  ensureScopeDirectories(entry.directories);
497
555
  writeAtomically(entry, `${JSON.stringify(overrides, null, 2)}\n`);
498
556
  return entry.filePath;
499
557
  }
500
558
 
501
559
  /** Confirmed scope transition: create an empty project layer or remove only its file. */
502
- export function setManagerProjectSettings(options: ManagerSettingsOptions & {
503
- enabled: boolean;
504
- expectedLayers?: ManagerSettingsLayers;
505
- }): string {
560
+ export function setManagerProjectSettings(
561
+ options: ManagerSettingsOptions & {
562
+ enabled: boolean;
563
+ expectedLayers?: ManagerSettingsLayers;
564
+ },
565
+ ): string {
506
566
  if (!options.includeProject) throw new Error("Project settings are not enabled/trusted");
507
567
  if (typeof options.enabled !== "boolean") throw new Error("Invalid project settings state");
508
568
  if (options.expectedLayers)
@@ -522,7 +582,10 @@ export function setManagerProjectSettings(options: ManagerSettingsOptions & {
522
582
  }
523
583
 
524
584
  /** Resolved settings.json path for a scope; the file may not exist. */
525
- export function managerSettingsPath(options: ManagerSettingsOptions, scope: ManagerSaveScope): string {
585
+ export function managerSettingsPath(
586
+ options: ManagerSettingsOptions,
587
+ scope: ManagerSaveScope,
588
+ ): string {
526
589
  if (scope === "project") {
527
590
  if (!options.includeProject) throw new Error("Project settings are not enabled/trusted");
528
591
  return layer(options.cwd, [".pi", "agent", "subagent-manager"]).filePath;
@@ -531,16 +594,19 @@ export function managerSettingsPath(options: ManagerSettingsOptions, scope: Mana
531
594
  }
532
595
 
533
596
  /** Restore a scope's defaults by deleting its settings file (nothing is written). A missing file is not an error. */
534
- export function deleteManagerSettings(options: ManagerSettingsOptions & { scope: ManagerSaveScope }): {
597
+ export function deleteManagerSettings(
598
+ options: ManagerSettingsOptions & { scope: ManagerSaveScope },
599
+ ): {
535
600
  filePath: string;
536
601
  deleted: boolean;
537
602
  } {
538
603
  if (options.scope !== "user" && options.scope !== "project")
539
604
  throw new Error("Invalid settings scope");
540
605
  const filePath = managerSettingsPath(options, options.scope);
541
- const entry = options.scope === "project"
542
- ? layer(options.cwd, [".pi", "agent", "subagent-manager"])
543
- : layer(options.agentDir, ["subagent-manager"]);
606
+ const entry =
607
+ options.scope === "project"
608
+ ? layer(options.cwd, [".pi", "agent", "subagent-manager"])
609
+ : layer(options.agentDir, ["subagent-manager"]);
544
610
  // Malformed JSON is removable; symlinks and non-files are refused by settingsFileExists.
545
611
  if (!settingsFileExists(entry)) return { filePath, deleted: false };
546
612
  unlinkSync(entry.filePath);
@@ -92,8 +92,11 @@ export class AgentNavigationEditor extends CustomEditor {
92
92
 
93
93
  override handleInput(data: string): void {
94
94
  const outer = this.dispatchDepth === 0;
95
- const direction = this.ordinaryArrow(data, "left") ? "left"
96
- : this.ordinaryArrow(data, "right") ? "right" : undefined;
95
+ const direction = this.ordinaryArrow(data, "left")
96
+ ? "left"
97
+ : this.ordinaryArrow(data, "right")
98
+ ? "right"
99
+ : undefined;
97
100
  if (outer && (!direction || (this.pending && this.pending !== direction))) this.inputEpoch++;
98
101
  const previousPaste = this.pastePending;
99
102
  const wasPaste = previousPaste || data.includes("\x1b[200~");
@@ -105,10 +108,12 @@ export class AgentNavigationEditor extends CustomEditor {
105
108
  const cursor = this.getCursor();
106
109
  const text = this.getText();
107
110
  const lines = text.split("\n");
108
- const atBoundary = direction === "left"
109
- ? cursor.line === 0 && cursor.col === 0
110
- : direction === "right" && cursor.line === lines.length - 1 &&
111
- cursor.col === lines.at(-1)!.length;
111
+ const atBoundary =
112
+ direction === "left"
113
+ ? cursor.line === 0 && cursor.col === 0
114
+ : direction === "right" &&
115
+ cursor.line === lines.length - 1 &&
116
+ cursor.col === lines.at(-1)!.length;
112
117
  const eligible =
113
118
  outer &&
114
119
  direction !== undefined &&
@@ -180,7 +185,8 @@ export class AgentNavigationEditor extends CustomEditor {
180
185
  const action = (): "expand" | "tree" | "collapse" | undefined => {
181
186
  if (direction === "right")
182
187
  return this.navigation.collapseWidget && (this.navigation.canCollapse?.() ?? false)
183
- ? "collapse" : undefined;
188
+ ? "collapse"
189
+ : undefined;
184
190
  if (this.navigation.expandWidget && (this.navigation.canExpand?.() ?? false)) return "expand";
185
191
  return this.navigation.canOpen() ? "tree" : undefined;
186
192
  };
@@ -207,9 +213,13 @@ export class AgentNavigationEditor extends CustomEditor {
207
213
  try {
208
214
  // Call within the checked microtask: an extra Promise.then would leave
209
215
  // a gap in which root ownership could change after validation.
210
- void Promise.resolve(chosen === "tree" ? this.navigation.openTree()
211
- : chosen === "expand" ? this.navigation.expandWidget!()
212
- : this.navigation.collapseWidget!())
216
+ void Promise.resolve(
217
+ chosen === "tree"
218
+ ? this.navigation.openTree()
219
+ : chosen === "expand"
220
+ ? this.navigation.expandWidget!()
221
+ : this.navigation.collapseWidget!(),
222
+ )
213
223
  .catch((error: unknown) => this.navigation.onError?.(error))
214
224
  .finally(() => {
215
225
  this.pending = undefined;
@@ -103,7 +103,9 @@ export class CostFooterController {
103
103
  return;
104
104
  }
105
105
  if (this.subagentCost() <= 0 || !ctx.hasUI || ctx.mode !== "tui") return;
106
- this.requestRender = installCostFooter(ctx, this.subagentCost, (mainCost) => this.formatCost(mainCost));
106
+ this.requestRender = installCostFooter(ctx, this.subagentCost, (mainCost) =>
107
+ this.formatCost(mainCost),
108
+ );
107
109
  this.installed = true;
108
110
  }
109
111
 
@@ -176,7 +178,8 @@ export function installCostFooter(
176
178
  const subscription =
177
179
  ctx.model &&
178
180
  (ctx.model.provider === "kimi-coding" || ctx.modelRegistry?.isUsingOAuth(ctx.model));
179
- const costText = displayCost?.(totals.cost) ?? `$${(totals.cost + subagentCost()).toFixed(3)}`;
181
+ const costText =
182
+ displayCost?.(totals.cost) ?? `$${(totals.cost + subagentCost()).toFixed(3)}`;
180
183
  parts.push(`${costText}${subscription ? " (sub)" : ""}`);
181
184
  const context = ctx.getContextUsage();
182
185
  if (context) {
package/src/ui/dialog.ts CHANGED
@@ -74,18 +74,14 @@ export function frameDialog(
74
74
  const clipped = truncateToWidth(text, Math.max(0, columns), "", true);
75
75
  return clipped + " ".repeat(Math.max(0, columns - visibleWidth(clipped)));
76
76
  };
77
- if (width < 4 || height < 4)
78
- return [fit(theme.fg("muted", dialogText(title)), width)];
77
+ if (width < 4 || height < 4) return [fit(theme.fg("muted", dialogText(title)), width)];
79
78
  const inner = width - 2;
80
79
  const line = (text: string) =>
81
80
  theme.fg("border", "│") + fit(text, inner) + theme.fg("border", "│");
82
81
  const heading = truncateToWidth(` ${dialogText(title)} `, inner, "");
83
82
  const top = theme.fg(
84
83
  "border",
85
- "╭" +
86
- heading +
87
- "─".repeat(Math.max(0, inner - visibleWidth(heading))) +
88
- "╮",
84
+ "╭" + heading + "─".repeat(Math.max(0, inner - visibleWidth(heading))) + "╮",
89
85
  );
90
86
  // Pad to the full frame so centered overlays keep the same bounds between views.
91
87
  const budget = height - 4;
@@ -178,8 +174,7 @@ export function dialogEditor(
178
174
  prefill: string,
179
175
  ): Promise<string | undefined> {
180
176
  return ctx.ui.custom(
181
- (host, theme, _keys, done) =>
182
- new DialogEditor(host, theme, title, prefill, done),
177
+ (host, theme, _keys, done) => new DialogEditor(host, theme, title, prefill, done),
183
178
  DIALOG_OPTIONS,
184
179
  );
185
180
  }
@@ -209,23 +204,20 @@ export class DialogMenu {
209
204
  handleInput(data: string): void {
210
205
  const keys = getKeybindings();
211
206
  if (keys.matches(data, "tui.select.cancel")) return this.done(undefined);
212
- if (keys.matches(data, "tui.select.confirm") || (this.spaceSelect && matchesKey(data, Key.space)))
207
+ if (
208
+ keys.matches(data, "tui.select.confirm") ||
209
+ (this.spaceSelect && matchesKey(data, Key.space))
210
+ )
213
211
  return this.done(this.getSelectedId());
214
- if (this.saveId && matchesKey(data, Key.ctrl("s")))
215
- return this.done(this.saveId);
212
+ if (this.saveId && matchesKey(data, Key.ctrl("s"))) return this.done(this.saveId);
216
213
  let offset = 0;
217
214
  if (keys.matches(data, "tui.select.up")) offset = -1;
218
- else if (keys.matches(data, "tui.select.down") || matchesKey(data, Key.tab))
219
- offset = 1;
215
+ else if (keys.matches(data, "tui.select.down") || matchesKey(data, Key.tab)) offset = 1;
220
216
  else if (matchesKey(data, Key.pageUp)) offset = -this.viewport;
221
217
  else if (matchesKey(data, Key.pageDown)) offset = this.viewport;
222
218
  else if (matchesKey(data, Key.home)) this.selected = 0;
223
- else if (matchesKey(data, Key.end))
224
- this.selected = Math.max(0, this.rows.length - 1);
225
- this.selected = Math.max(
226
- 0,
227
- Math.min(this.rows.length - 1, this.selected + offset),
228
- );
219
+ else if (matchesKey(data, Key.end)) this.selected = Math.max(0, this.rows.length - 1);
220
+ this.selected = Math.max(0, Math.min(this.rows.length - 1, this.selected + offset));
229
221
  this.host.requestRender();
230
222
  }
231
223
  invalidate(): void {}
@@ -245,10 +237,7 @@ export class DialogMenu {
245
237
  this.viewport = Math.max(1, Math.floor((height - 6 - help.length - legend.length) / rowHeight));
246
238
  const start = Math.max(
247
239
  0,
248
- Math.min(
249
- this.selected - this.viewport + 1,
250
- this.rows.length - this.viewport,
251
- ),
240
+ Math.min(this.selected - this.viewport + 1, this.rows.length - this.viewport),
252
241
  );
253
242
  const hasIndicators = this.rows.some((row) => row.renderIndicators);
254
243
  const indicatorWidth = 3;
@@ -265,7 +254,7 @@ export class DialogMenu {
265
254
  ),
266
255
  ...this.rows.slice(start, start + this.viewport).flatMap((row, i) => {
267
256
  const selected = start + i === this.selected;
268
- const color = (text: string) => selected ? this.theme.fg("accent", text) : text;
257
+ const color = (text: string) => (selected ? this.theme.fg("accent", text) : text);
269
258
  const plainLabel = dialogText(row.label);
270
259
  const label = truncateToWidth(
271
260
  row.renderLabel ? row.renderLabel(plainLabel, this.theme) : plainLabel,
@@ -274,17 +263,26 @@ export class DialogMenu {
274
263
  true,
275
264
  );
276
265
  const padding = " ".repeat(Math.max(0, labelWidth - visibleWidth(label)));
277
- const indicators = truncateToWidth(row.renderIndicators?.(this.theme) ?? "", indicatorWidth, "", true);
266
+ const indicators = truncateToWidth(
267
+ row.renderIndicators?.(this.theme) ?? "",
268
+ indicatorWidth,
269
+ "",
270
+ true,
271
+ );
278
272
  const indicatorPadding = " ".repeat(Math.max(0, indicatorWidth - visibleWidth(indicators)));
279
273
  const value = dialogText(row.value ?? "");
280
- const primary = color(`${selected ? "›" : " "} `)
281
- + (row.renderLabel ? label : color(label))
282
- + color(`${padding} │ `)
283
- + (hasIndicators ? indicators + color(`${indicatorPadding} │ `) : "")
284
- + (row.valueColor ? this.theme.fg(row.valueColor, value) : color(value));
274
+ const primary =
275
+ color(`${selected ? "›" : " "} `) +
276
+ (row.renderLabel ? label : color(label)) +
277
+ color(`${padding} │ `) +
278
+ (hasIndicators ? indicators + color(`${indicatorPadding} │ `) : "") +
279
+ (row.valueColor ? this.theme.fg(row.valueColor, value) : color(value));
285
280
  if (rowHeight === 1) return [primary];
286
281
  const valueStart = 2 + labelWidth + 3 + (hasIndicators ? indicatorWidth + 3 : 0);
287
- const detail = truncateToWidth(dialogText(row.valueDetail ?? ""), Math.max(0, inner - valueStart));
282
+ const detail = truncateToWidth(
283
+ dialogText(row.valueDetail ?? ""),
284
+ Math.max(0, inner - valueStart),
285
+ );
288
286
  return [primary, " ".repeat(valueStart) + this.theme.fg("muted", detail)];
289
287
  }),
290
288
  "",
@@ -296,14 +294,7 @@ export class DialogMenu {
296
294
  while (body.length < budget) body.push("");
297
295
  body.push(...legend);
298
296
  }
299
- return frameDialog(
300
- this.theme,
301
- width,
302
- height,
303
- this.title,
304
- body,
305
- this.footer,
306
- );
297
+ return frameDialog(this.theme, width, height, this.title, body, this.footer);
307
298
  }
308
299
  }
309
300
 
@@ -320,7 +311,13 @@ export async function dialogMenu(
320
311
  ctx: ExtensionContext,
321
312
  title: string,
322
313
  rows: DialogRow[],
323
- options: { selectedId?: string; footer?: string; saveId?: string; renderLegend?: (theme: Theme) => string; spaceSelect?: boolean } = {},
314
+ options: {
315
+ selectedId?: string;
316
+ footer?: string;
317
+ saveId?: string;
318
+ renderLegend?: (theme: Theme) => string;
319
+ spaceSelect?: boolean;
320
+ } = {},
324
321
  ): Promise<string | undefined> {
325
322
  return ctx.ui.custom(
326
323
  (host, theme, _keys, done) =>
@@ -406,9 +403,7 @@ const dialogScopes = new WeakSet<ExtensionContext>();
406
403
 
407
404
  function isPromise<T>(value: T | Promise<T>): value is Promise<T> {
408
405
  return (
409
- typeof value === "object" &&
410
- value !== null &&
411
- typeof (value as Promise<T>).then === "function"
406
+ typeof value === "object" && value !== null && typeof (value as Promise<T>).then === "function"
412
407
  );
413
408
  }
414
409
 
@@ -477,16 +472,14 @@ export class DialogSession {
477
472
  const resolveOnce = (value: T) => {
478
473
  if (settled) return;
479
474
  settled = true;
480
- if (this.pending?.generation === generation)
481
- this.pending.settled = true;
475
+ if (this.pending?.generation === generation) this.pending.settled = true;
482
476
  resolve(value);
483
477
  };
484
478
  const rejectOnce = (error: unknown) => {
485
479
  if (settled) return;
486
480
  settled = true;
487
481
  this.inputLocked = true;
488
- if (this.pending?.generation === generation)
489
- this.pending.settled = true;
482
+ if (this.pending?.generation === generation) this.pending.settled = true;
490
483
  reject(error);
491
484
  };
492
485
  this.pending = {
@@ -515,8 +508,7 @@ export class DialogSession {
515
508
  void produced.then(
516
509
  (component) => adopt(component),
517
510
  (error: unknown) => {
518
- if (settled || this.closed || generation !== this.generation)
519
- return;
511
+ if (settled || this.closed || generation !== this.generation) return;
520
512
  rejectOnce(error);
521
513
  },
522
514
  );
@@ -581,8 +573,7 @@ export class DialogSession {
581
573
  return;
582
574
  }
583
575
  this.replaceChild(component);
584
- this.inputLocked =
585
- this.pending?.generation === generation ? this.pending.settled : true;
576
+ this.inputLocked = this.pending?.generation === generation ? this.pending.settled : true;
586
577
  this.host.requestRender();
587
578
  }
588
579
 
@@ -610,18 +601,13 @@ export class DialogSession {
610
601
  }
611
602
  }
612
603
 
613
- export function scopeDialogContext<T extends ExtensionContext>(
614
- ctx: T,
615
- session: DialogSession,
616
- ): T {
604
+ export function scopeDialogContext<T extends ExtensionContext>(ctx: T, session: DialogSession): T {
617
605
  const source = ctx.ui;
618
606
  const originalCustom = source.custom.bind(source);
619
607
  const ui = Object.create(source) as ExtensionUIContext;
620
608
  ui.custom = ((factory, options) => {
621
609
  if (options?.overlay) return session.mount(factory);
622
- return originalCustom(factory, options).finally(() =>
623
- session.restoreFocus(),
624
- );
610
+ return originalCustom(factory, options).finally(() => session.restoreFocus());
625
611
  }) as ExtensionUIContext["custom"];
626
612
  // Pi exposes ctx.ui as a getter; assignment cannot shadow an inherited accessor.
627
613
  // Define an own property while keeping the remaining context getters live.
@@ -524,7 +524,9 @@ export class HousekeepingModelPickerComponent extends Container {
524
524
  (model) => modelSearchText(model.name),
525
525
  ],
526
526
  });
527
- this.scopedIdentities = new Set(options.scopedModels.map((entry) => modelIdentity(entry.model)));
527
+ this.scopedIdentities = new Set(
528
+ options.scopedModels.map((entry) => modelIdentity(entry.model)),
529
+ );
528
530
  this.current = options.current ?? "";
529
531
  this.onDone = options.onDone;
530
532
  this.onCancel = options.onCancel;
@@ -554,7 +556,10 @@ export class HousekeepingModelPickerComponent extends Container {
554
556
  const hint = this.scopedIdentities.size
555
557
  ? "Scoped models first, then every other available model. Type to search."
556
558
  : "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)];
559
+ const header = [
560
+ truncateToWidth(this.theme.fg("muted", hint), inner, ""),
561
+ ...this.searchInput.render(inner),
562
+ ];
558
563
  const budget = Math.max(1, height - 4 - header.length);
559
564
  const display: (HousekeepingRow | string)[] = [];
560
565
  let previous: string | undefined;
@@ -564,7 +569,10 @@ export class HousekeepingModelPickerComponent extends Container {
564
569
  display.push(row);
565
570
  }
566
571
  const selectedRow = this.rows[this.selected];
567
- const index = Math.max(0, display.findIndex((row) => row === selectedRow));
572
+ const index = Math.max(
573
+ 0,
574
+ display.findIndex((row) => row === selectedRow),
575
+ );
568
576
  const start = Math.max(0, Math.min(index - budget + 1, display.length - budget));
569
577
  const lines = display.slice(start, start + budget).map((row) => {
570
578
  if (typeof row === "string") return this.theme.fg("muted", row);
@@ -642,8 +650,12 @@ export class HousekeepingModelPickerComponent extends Container {
642
650
  },
643
651
  ]
644
652
  : []),
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)),
653
+ ...matches
654
+ .filter((m) => this.scopedIdentities.has(modelIdentity(m)))
655
+ .map((m) => row(m, SCOPED_GROUP)),
656
+ ...matches
657
+ .filter((m) => !this.scopedIdentities.has(modelIdentity(m)))
658
+ .map((m) => row(m, OTHER_GROUP)),
647
659
  ];
648
660
  const previous = this.rows[this.selected]?.value;
649
661
  this.rows = rows;