@ferris1225/pi-subagents 6.0.1 → 6.0.2

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/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # Changelog
2
2
 
3
+ ## 6.0.2
4
+
5
+ ### Fixes
6
+
7
+ - Simplify `/subagents-setup` into role, setting, and value lists with consistent
8
+ up/down navigation and one-level-back cancellation. Preserve focus and save
9
+ each confirmed change immediately.
10
+ - Prioritize visible model choices over repeated details, show readable model
11
+ names with providers, and distinguish saved settings from keyboard focus.
12
+ Explain following the main model versus choosing a fixed model explicitly.
13
+ - Preserve Unicode search, paste, paging, capability-aware thinking preferences,
14
+ and space for the workflow required-acceptance row on short terminals.
15
+
3
16
  ## 6.0.1
4
17
 
5
18
  ### Fixes
package/README.md CHANGED
@@ -12,15 +12,21 @@ integration tests use the Pi 1.4.0 SDK.
12
12
  pi install npm:@ferris1225/pi-subagents
13
13
  ```
14
14
 
15
- Run `/subagents-setup` for a role selector and focused settings editor. Wide
16
- terminals place them side by side; narrow terminals stack them. ↑/↓ changes the
17
- role, ←/→ selects **Model**, **Thinking**, or **Reset**, and Enter edits it.
18
- The selected role shows its full model reference, effective reasoning level,
19
- requested level when clamped, and default/override source. Each selection saves
20
- immediately; Esc returns without applying a picker selection and keeps focus.
21
- Model pickers support search, paste, and paging. On short terminals, PgUp/PgDn
22
- scrolls the settings while the selected role and field stay pinned. Setup
23
- reserves space for the workflow's required-acceptance row.
15
+ Run `/subagents-setup`, choose a role, then choose **Model**, **Thinking**, or
16
+ **Reset defaults**. Every screen uses ↑/↓ and Enter; Esc goes back one level
17
+ without applying an unconfirmed choice. Selections save immediately and return
18
+ to the same setting; returning to the role list keeps that role selected.
19
+
20
+ Model and thinking choices support search, Unicode paste, and PgUp/PgDn paging.
21
+ Models show their friendly name and provider; search also matches exact model
22
+ references and capabilities. **[saved]** marks the stored selection independently
23
+ of the navigation cursor. **Follow main (dynamic)** tracks the main window's
24
+ model, including future changes; choosing a specific model pins that reference,
25
+ even when it currently matches main. Tab toggles complete details (including
26
+ exact references); ↑/↓ and PgUp/PgDn scroll them. Tab or Esc returns from details
27
+ to the list, keeping the search and cursor.
28
+ The list takes priority over details on short terminals. Setup reserves space
29
+ for the workflow identity and required-acceptance row.
24
30
 
25
31
  All roles follow the main model by default; thinking defaults to `low` for scout
26
32
  and `high` for artisan, sentinel, and skeptic. The panel distinguishes defaults from overrides and
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ferris1225/pi-subagents",
3
- "version": "6.0.1",
3
+ "version": "6.0.2",
4
4
  "description": "A managed sub-agent team for pi: research, implementation, independent review, interactive follow-ups, and Git worktree isolation.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -24,6 +24,7 @@ export interface ModelPickerItem {
24
24
  value: string;
25
25
  label: string;
26
26
  description?: string;
27
+ saved?: boolean;
27
28
  }
28
29
 
29
30
  export type ModelListEntry = Pick<
@@ -199,19 +200,23 @@ export function buildModelPickerItems(options: {
199
200
 
200
201
  const dynamic: ModelPickerItem = {
201
202
  value: CURRENT_MAIN_MODEL,
202
- label: "Current main model (dynamic)",
203
- description: "Clear agent override; use the current main model dynamically",
203
+ label: "Follow main (dynamic)",
204
+ description: "Uses the main window's model, including future changes. Now: " + (mainRef ?? "Pi default") + ". No model is pinned.",
205
+ saved: !configuredRef,
204
206
  };
205
207
  const items: ModelPickerItem[] = [dynamic];
206
208
  for (const ref of refs) {
207
209
  const model = byRef.get(ref)!;
208
210
  const tags = [ref === liveConfiguredRef ? "configured" : "", ref === mainRef ? "current main" : ""]
209
211
  .filter(Boolean);
210
- const name = model.name.trim() && model.name !== model.id ? model.name.trim() : undefined;
212
+ const name = model.name.trim() || model.id;
213
+ const duplicateName = [...byRef.values()].some((other) =>
214
+ other.id !== model.id && other.provider === model.provider && (other.name.trim() || other.id) === name);
211
215
  items.push({
212
216
  value: ref,
213
- label: ref,
214
- description: [name, modelCapabilities(model), ...tags].filter(Boolean).join(" · "),
217
+ label: name + " · " + model.provider + (duplicateName ? " (" + model.id + ")" : ""),
218
+ description: ["Reference: " + ref, "Pins this model; falls back to main if unavailable or it fails.", modelCapabilities(model), ...tags].join(" · "),
219
+ saved: ref === liveConfiguredRef,
215
220
  });
216
221
  }
217
222
  return items;
@@ -24,7 +24,7 @@ import {
24
24
  resolveThinkingLevel,
25
25
  supportedThinkingLevels,
26
26
  } from "./models.ts";
27
- import { promptRoleGrid, promptSelectOne, type RoleGridFocus, type RoleGridRow } from "./ui.ts";
27
+ import { promptMenu, promptSelectOne, type SetupItem } from "./ui.ts";
28
28
 
29
29
  const ROLE_DEFAULT = "__role_default__";
30
30
  const THINKING_LEVEL_HINTS: Record<ThinkingLevel, string> = {
@@ -50,29 +50,38 @@ function roleModel(ctx: ExtensionContext, config: SubagentsConfig, name: string)
50
50
  return findModelByRef(availableModelsInScope(ctx), config.agentModels[name]) ?? ctx.model;
51
51
  }
52
52
 
53
- /** One row per role: every model and thinking choice stays visible together. */
54
- function roleRows(ctx: ExtensionContext, config: SubagentsConfig): RoleGridRow[] {
55
- const mainRef = currentModelRef(ctx) ?? "Pi default";
56
- const models = availableModelsInScope(ctx);
53
+ const ROLE_PURPOSE: Record<string, string> = {
54
+ scout: "Research with citations",
55
+ artisan: "Implement and verify",
56
+ sentinel: "Review implementation",
57
+ skeptic: "Challenge a named claim",
58
+ };
59
+
60
+ function roleSettings(ctx: ExtensionContext, config: SubagentsConfig, name: string): SetupItem[] {
61
+ const selected = config.agentModels[name];
62
+ const model = findModelByRef(availableModelsInScope(ctx), selected);
63
+ const modelLabel = selected
64
+ ? model ? model.name + " · " + model.provider : selected + " (unavailable)"
65
+ : "Follow main (dynamic)";
66
+ const preferred = config.agentThinkingLevels[name] ?? roleThinkingLevel(name);
67
+ const effective = resolveThinkingLevel(model ?? ctx.model, preferred);
68
+ const source = config.agentThinkingLevels[name] ? "override" : "role default";
69
+ const thinking = effective + (effective !== preferred ? " (" + preferred + " requested)" : "") + " · " + source;
70
+ return [
71
+ { value: "model", label: "Model: " + modelLabel, description: selected
72
+ ? "Pinned reference: " + selected + (model ? ". Falls back to main if it fails." : ". Unavailable; using main.")
73
+ : "Follows the main window's model, including future changes. Now: " + (currentModelRef(ctx) ?? "Pi default") + ". Choose a specific model to pin it." },
74
+ { value: "thinking", label: "Thinking: " + thinking,
75
+ description: "Reasoning effort: " + thinking + ". Role default: " + roleThinkingLevel(name) + ". Model capabilities limit the effective level; your saved preference is kept when changing models." },
76
+ { value: "reset", label: "Reset defaults", description: "Restore only " + name + " to Follow main and role-default thinking (" + roleThinkingLevel(name) + "). Saves immediately." },
77
+ ];
78
+ }
79
+
80
+ function roleItems(ctx: ExtensionContext, config: SubagentsConfig): SetupItem[] {
57
81
  return BUILTIN_AGENT_NAMES.map((name) => {
58
- const profile = agentProfile(name)!;
59
- const selected = config.agentModels[name];
60
- const model = findModelByRef(models, selected);
61
- const available = !selected || Boolean(model);
62
- const preferred = config.agentThinkingLevels[name] ?? roleThinkingLevel(name);
63
- const effective = resolveThinkingLevel(model ?? ctx.model, preferred);
64
- const clamped = effective !== preferred ? " (" + preferred + " requested)" : "";
65
- const overridden = Boolean(config.agentThinkingLevels[name]);
66
- return {
67
- role: name,
68
- thinkingOverridden: overridden,
69
- model: selected ? selected + (available ? "" : " (unavailable)") : "Follow main",
70
- thinking: effective + clamped,
71
- description: profile.remark + " Model: " + (selected
72
- ? (available ? "falls back to main if it fails." : "unavailable; using main.")
73
- : "follows main (" + mainRef + ") dynamically.")
74
- + " Thinking: role default " + roleThinkingLevel(name) + ", clamped to the model-supported levels. Reset restores " + name + " to Follow main and that default. * marks an override.",
75
- };
82
+ const settings = roleSettings(ctx, config, name);
83
+ return { value: name, label: name + " · " + ROLE_PURPOSE[name],
84
+ description: settings[0]!.label + "\n" + settings[1]!.label + "\n" + agentProfile(name)!.remark };
76
85
  });
77
86
  }
78
87
  async function editSetting(
@@ -90,7 +99,7 @@ async function editSetting(
90
99
  delete next.agentThinkingLevels[name];
91
100
  } else if (field === "model") {
92
101
  const choice = await promptSelectOne(ctx, name + " · Model",
93
- "Search provider, model, or capability · Esc back without changes",
102
+ "Follow main = dynamic · Others = pinned",
94
103
  buildModelPickerItems({ models: availableModelsInScope(ctx), configuredRef: config.agentModels[name], mainRef: currentModelRef(ctx) }),
95
104
  config.agentModels[name] ?? CURRENT_MAIN_MODEL);
96
105
  if (choice === undefined) return undefined;
@@ -109,9 +118,13 @@ async function editSetting(
109
118
  ...supported.map((level) => ({ value: level, label: level, description: THINKING_LEVEL_HINTS[level] })),
110
119
  ];
111
120
  const current = config.agentThinkingLevels[name];
121
+ if (current && !supported.includes(current)) {
122
+ options.push({ value: current, label: current + " (runs as " + resolveThinkingLevel(model, current) + ")",
123
+ description: "Saved preference; this model clamps it. Keep it for other models, or choose a supported level." });
124
+ }
112
125
  const choice = await promptSelectOne(ctx, name + " · Thinking",
113
- "Choose reasoning effort · Role default follows model capabilities · Esc back",
114
- options, current && supported.includes(current) ? current : ROLE_DEFAULT);
126
+ "Reasoning effort · saved preferences survive model changes",
127
+ options, current ?? ROLE_DEFAULT);
115
128
  if (choice === undefined) return undefined;
116
129
  if (choice === ROLE_DEFAULT) delete next.agentThinkingLevels[name];
117
130
  else next.agentThinkingLevels[name] = choice as ThinkingLevel;
@@ -130,17 +143,23 @@ export async function runSetup(ctx: ExtensionContext, configPath: string = getCo
130
143
  }
131
144
  try {
132
145
  let config = await loadConfig(configPath);
133
- let focus: RoleGridFocus = {};
146
+ let roleFocus: string | undefined;
147
+ const settingFocus: Record<string, string> = {};
134
148
  let status = "Changes save immediately";
135
149
  while (true) {
136
- const choice = await promptRoleGrid(ctx, roleRows(ctx, config), focus, status);
137
- if (choice === undefined) return;
138
- focus = { row: choice.row, column: choice.column };
139
- const next = await editSetting(ctx, config, choice.role, choice.field);
140
- if (!next) continue;
141
- await saveConfig(next, configPath);
142
- config = next;
143
- status = "Saved " + choice.role + (choice.field === "reset" ? " defaults" : " " + choice.field);
150
+ const name = await promptMenu(ctx, "Subagents · Roles", status === "Changes save immediately" ? "Choose a role · " + status : status, roleItems(ctx, config), roleFocus);
151
+ if (name === undefined) return;
152
+ roleFocus = name;
153
+ while (true) {
154
+ const field = await promptMenu(ctx, name + " · Settings", status === "Changes save immediately" ? "Choose a setting · " + status : status, roleSettings(ctx, config, name), settingFocus[name]);
155
+ if (field === undefined) break;
156
+ settingFocus[name] = field;
157
+ const next = await editSetting(ctx, config, name, field);
158
+ if (!next) continue;
159
+ await saveConfig(next, configPath);
160
+ config = next;
161
+ status = "Saved " + name + (field === "reset" ? " defaults" : " " + field);
162
+ }
144
163
  }
145
164
  } catch (error) {
146
165
  ctx.ui.notify("pi-subagents setup failed: " + errorMessage(error), "error");
@@ -1,4 +1,4 @@
1
- /** Searchable pickers and the /subagents-setup role register. */
1
+ /** Linear setup menus and searchable choices within Pi's input dock. */
2
2
 
3
3
  import {
4
4
  Input, fuzzyFilter, matchesKey, truncateToWidth, visibleWidth, wrapTextWithAnsi,
@@ -15,22 +15,29 @@ function setupHeight(tui: TUI): number {
15
15
  return Math.max(3, (tui.terminal?.rows ?? 28) - 14);
16
16
  }
17
17
 
18
+ export interface SetupItem extends SelectItem {
19
+ /** Saved state is independent of the navigation cursor. */
20
+ saved?: boolean;
21
+ }
18
22
  interface PickerOptions {
19
23
  title: string;
20
24
  hint: string;
21
25
  initialValue?: string;
26
+ searchable: boolean;
22
27
  }
23
28
 
24
29
  /** Input owns Unicode editing, paste, horizontal scrolling and the IME cursor.
25
- * Selection and paging use the host's configurable keybindings. */
30
+ * The bounded list takes priority; Tab exposes complete, scrollable details. */
26
31
  class Picker implements Component, Focusable {
27
32
  private _focused = false;
28
33
  private cursor = 0;
29
- private pageRows = PAGE_SIZE;
30
- private filtered: SelectItem[];
31
- private readonly search = new Input({ prompt: "Search: ", placeholder: "type to filter" });
34
+ private pageRows = 1;
35
+ private details = false;
36
+ private detailTop = 0;
37
+ private filtered: SetupItem[];
38
+ private readonly search = new Input({ prompt: "Search: ", placeholder: "name, provider or reference" });
32
39
 
33
- private readonly items: SelectItem[];
40
+ private readonly items: SetupItem[];
34
41
  private readonly options: PickerOptions;
35
42
  private readonly tui: TUI;
36
43
  private readonly theme: Theme;
@@ -38,7 +45,7 @@ class Picker implements Component, Focusable {
38
45
  private readonly done: (value: string | undefined) => void;
39
46
 
40
47
  constructor(
41
- items: SelectItem[], options: PickerOptions, tui: TUI, theme: Theme,
48
+ items: SetupItem[], options: PickerOptions, tui: TUI, theme: Theme,
42
49
  keybindings: KeybindingsManager, done: (value: string | undefined) => void,
43
50
  ) {
44
51
  this.items = items;
@@ -49,53 +56,103 @@ class Picker implements Component, Focusable {
49
56
  this.done = done;
50
57
  this.filtered = items;
51
58
  const initial = items.findIndex((item) => item.value === options.initialValue);
52
- if (initial >= 0) this.cursor = initial;
59
+ const saved = items.findIndex((item) => item.saved);
60
+ this.cursor = Math.max(0, initial >= 0 ? initial : saved);
53
61
  }
54
62
 
55
63
  get focused(): boolean { return this._focused; }
56
- set focused(value: boolean) { this._focused = value; this.search.focused = value; }
64
+ set focused(value: boolean) {
65
+ this._focused = value;
66
+ this.search.focused = value && this.options.searchable && !this.details;
67
+ }
68
+
69
+ private isSaved(item: SetupItem): boolean {
70
+ return item.saved ?? (this.options.searchable && item.value === this.options.initialValue);
71
+ }
72
+
73
+ private detailLines(width: number): string[] {
74
+ const item = this.filtered[this.cursor];
75
+ if (!item) return ["No matches. Clear or change the search."];
76
+ return [item.label + (this.isSaved(item) ? " [saved]" : ""), item.description ?? item.value]
77
+ .flatMap((text) => wrapTextWithAnsi(text, width));
78
+ }
57
79
 
58
80
  render(width: number): string[] {
59
81
  if (width <= 0) return [];
60
82
  const theme = this.theme;
61
- const dim = (text: string) => theme.fg("dim", text);
83
+ const muted = (text: string) => theme.fg("muted", text);
62
84
  const height = setupHeight(this.tui);
63
- if (height < 8) {
64
- this.pageRows = 1;
65
- const item = this.filtered[this.cursor];
66
- return [theme.bold(this.options.title), ...this.search.render(width),
67
- item ? theme.fg("accent", "› ") + theme.underline(item.label) : "No matches. Clear or change the search."]
68
- .map((line) => truncateToWidth(line, width, "…"));
85
+ const compact = height < 6;
86
+ const lines: string[] = [];
87
+ // At three rows, retain search, a choice and controls instead of a title.
88
+ if (!(height === 3 && this.options.searchable && !this.details)) {
89
+ lines.push(theme.bold(this.options.title + (this.details ? " · Details" : "")));
69
90
  }
70
- const lines = [theme.bold("Subagents · " + this.options.title)];
71
- if (this.options.hint && height >= 16) lines.push(...wrapTextWithAnsi(this.options.hint, width).slice(0, 2).map(dim));
72
- lines.push(...this.search.render(width), "");
73
- const footer = [dim("↑/↓ move · PgUp/PgDn page"), dim("Enter select · Esc back")];
74
- const item = this.filtered[this.cursor];
75
- // The complete selected identity lives beside its capabilities, even when
76
- // a long provider/model id was truncated in the list above.
77
- const details = item ? ["", ...wrapTextWithAnsi(item.label, width).slice(0, 2),
78
- ...wrapTextWithAnsi(item.description ?? "", width).slice(0, 3).map(dim)] : [];
79
- const detailBudget = Math.max(0, Math.min(details.length, height - lines.length - footer.length - 2));
80
- const visibleDetails = details.slice(0, detailBudget);
81
- this.pageRows = Math.max(1, Math.min(PAGE_SIZE, height - lines.length - footer.length - visibleDetails.length - 1));
82
- const start = Math.max(0, Math.min(this.cursor - Math.floor(this.pageRows / 2), this.filtered.length - this.pageRows));
83
- const visible = this.filtered.slice(start, start + this.pageRows);
84
- if (!visible.length) lines.push(dim(this.search.getValue() ? "No matches. Clear or change the search." : "No choices available."));
85
- for (const [index, choice] of visible.entries()) {
86
- const selected = start + index === this.cursor;
87
- const label = truncateToWidth(choice.label, Math.max(0, width - 2), "…");
88
- lines.push(selected ? theme.fg("accent", "› ") + theme.underline(theme.bold(label)) : " " + label);
91
+ if (!this.details && this.options.hint && height >= 10) lines.push(muted(this.options.hint));
92
+ if (!this.details && this.options.searchable) lines.push(...this.search.render(width));
93
+ const footer = compact
94
+ ? [muted(this.details ? "↑↓ scroll · Tab list · Esc" : "↑↓ Enter Esc · Tab details")]
95
+ : this.details
96
+ ? [muted("↑/↓ scroll · Tab list · Esc back"), muted("PgUp/Dn page · Enter select")]
97
+ : [muted("↑/↓ move · Enter select · Esc back"), muted(
98
+ (this.filtered.length ? (this.cursor + 1) + "/" + this.filtered.length + " · " : "") + "PgUp/Dn · Tab details")];
99
+ const budget = Math.max(1, height - lines.length - footer.length);
100
+ if (this.details) {
101
+ this.pageRows = budget;
102
+ const details = this.detailLines(width);
103
+ this.detailTop = Math.max(0, Math.min(this.detailTop, details.length - budget));
104
+ lines.push(...details.slice(this.detailTop, this.detailTop + budget));
105
+ } else {
106
+ this.pageRows = Math.min(PAGE_SIZE, budget);
107
+ const start = Math.max(0, Math.min(this.cursor - Math.floor(this.pageRows / 2), this.filtered.length - this.pageRows));
108
+ const visible = this.filtered.slice(start, start + this.pageRows);
109
+ if (!visible.length) lines.push(muted(this.search.getValue() ? "No matches. Clear or change the search." : "No choices available."));
110
+ for (const [index, item] of visible.entries()) {
111
+ const active = start + index === this.cursor;
112
+ const suffix = this.isSaved(item) ? " [saved]" : "";
113
+ const label = truncateToWidth(item.label, Math.max(0, width - 2 - visibleWidth(suffix)), "…") + suffix;
114
+ lines.push(active ? theme.fg("accent", "› ") + theme.underline(theme.bold(label)) : " " + label);
115
+ }
116
+ // Menus show the active role/setting's explanation. Choice lists only
117
+ // use spare rows for context, never displacing another choice.
118
+ const spare = Math.min(3, height - lines.length - footer.length);
119
+ const item = this.filtered[this.cursor];
120
+ if (spare > 0 && item?.description) {
121
+ const wrapped = wrapTextWithAnsi(item.description, width);
122
+ const preview = wrapped.slice(0, spare);
123
+ if (wrapped.length > spare) preview[spare - 1] = truncateToWidth(preview[spare - 1]! + "…", width, "…");
124
+ lines.push(...preview.map(muted));
125
+ }
89
126
  }
90
- if (item) lines.push(dim((this.cursor + 1) + "/" + this.filtered.length + " matches"));
91
- lines.push(...visibleDetails, ...footer);
92
- return lines.map((line) => truncateToWidth(line, width, "…"));
127
+ return [...lines, ...footer].map((line) => truncateToWidth(line, width, "…"));
93
128
  }
94
129
 
95
130
  handleInput(data: string): void {
96
131
  const kb = this.keybindings;
97
132
  const count = this.filtered.length;
98
- if (kb.matches(data, "tui.select.up")) {
133
+ if (kb.matches(data, "tui.select.cancel")) {
134
+ if (this.details) {
135
+ this.details = false;
136
+ this.detailTop = 0;
137
+ this.focused = this._focused;
138
+ } else {
139
+ this.done(undefined);
140
+ return;
141
+ }
142
+ } else if (kb.matches(data, "tui.select.confirm")) {
143
+ const item = this.filtered[this.cursor];
144
+ if (item) this.done(item.value);
145
+ return;
146
+ } else if (matchesKey(data, "tab")) {
147
+ this.details = !this.details;
148
+ this.detailTop = 0;
149
+ this.focused = this._focused;
150
+ } else if (this.details) {
151
+ if (kb.matches(data, "tui.select.up")) this.detailTop--;
152
+ else if (kb.matches(data, "tui.select.down")) this.detailTop++;
153
+ else if (kb.matches(data, "tui.select.pageUp")) this.detailTop -= this.pageRows;
154
+ else if (kb.matches(data, "tui.select.pageDown")) this.detailTop += this.pageRows;
155
+ } else if (kb.matches(data, "tui.select.up")) {
99
156
  if (count) this.cursor = (this.cursor - 1 + count) % count;
100
157
  } else if (kb.matches(data, "tui.select.down")) {
101
158
  if (count) this.cursor = (this.cursor + 1) % count;
@@ -103,14 +160,7 @@ class Picker implements Component, Focusable {
103
160
  this.cursor = Math.max(0, this.cursor - this.pageRows);
104
161
  } else if (kb.matches(data, "tui.select.pageDown")) {
105
162
  this.cursor = Math.max(0, Math.min(count - 1, this.cursor + this.pageRows));
106
- } else if (kb.matches(data, "tui.select.confirm")) {
107
- const item = this.filtered[this.cursor];
108
- if (item) this.done(item.value);
109
- return;
110
- } else if (kb.matches(data, "tui.select.cancel")) {
111
- this.done(undefined);
112
- return;
113
- } else {
163
+ } else if (this.options.searchable) {
114
164
  const before = this.search.getValue();
115
165
  this.search.handleInput(data);
116
166
  if (before !== this.search.getValue()) {
@@ -125,187 +175,25 @@ class Picker implements Component, Focusable {
125
175
  invalidate(): void { this.search.invalidate(); }
126
176
  }
127
177
 
128
- /** Single-select with fuzzy search and paging. Esc returns without a change. */
129
- export function promptSelectOne(
130
- ctx: PickerContext, title: string, hint: string, items: SelectItem[], initialValue?: string,
131
- ): Promise<string | undefined> {
178
+ function prompt(ctx: PickerContext, items: SetupItem[], options: PickerOptions): Promise<string | undefined> {
132
179
  if (ctx.mode !== "tui") {
133
180
  ctx.ui.notify("/subagents-setup requires Pi's interactive TUI.", "error");
134
181
  return Promise.resolve(undefined);
135
182
  }
136
183
  return ctx.ui.custom<string | undefined>((tui, theme, keybindings, done) =>
137
- new Picker(items, { title, hint, initialValue }, tui, theme, keybindings, done));
138
- }
139
-
140
- export interface RoleGridRow {
141
- role: string;
142
- model: string;
143
- /** Effective level, optionally followed by the requested level when clamped. */
144
- thinking: string;
145
- thinkingOverridden?: boolean;
146
- description: string;
184
+ new Picker(items, options, tui, theme, keybindings, done));
147
185
  }
148
- export interface RoleGridFocus { row?: number; column?: number; }
149
- const GRID_COLUMNS = ["model", "thinking", "reset"] as const;
150
- export type RoleGridColumn = (typeof GRID_COLUMNS)[number];
151
- export interface RoleGridChoice { row: number; column: number; role: string; field: RoleGridColumn; }
152
-
153
- /** A role register beside the selected role's settings; narrow terminals stack
154
- * the same regions. Full effective values are never squeezed into grid cells. */
155
- class RoleGrid implements Component {
156
- private row: number;
157
- private column: number;
158
- private scrollTop = 0;
159
- private pageRows = 1;
160
- private viewport = "";
161
- private revealField = true;
162
-
163
- private readonly rows: RoleGridRow[];
164
- private readonly status: string;
165
- private readonly tui: TUI;
166
- private readonly theme: Theme;
167
- private readonly keybindings: KeybindingsManager;
168
- private readonly done: (choice: RoleGridChoice | undefined) => void;
169
186
 
170
- constructor(
171
- rows: RoleGridRow[], status: string, focus: RoleGridFocus, tui: TUI, theme: Theme,
172
- keybindings: KeybindingsManager, done: (choice: RoleGridChoice | undefined) => void,
173
- ) {
174
- this.rows = rows;
175
- this.status = status;
176
- this.tui = tui;
177
- this.theme = theme;
178
- this.keybindings = keybindings;
179
- this.done = done;
180
- this.row = Math.min(Math.max(0, focus.row ?? 0), Math.max(0, rows.length - 1));
181
- this.column = Math.min(Math.max(0, focus.column ?? 0), GRID_COLUMNS.length - 1);
182
- }
183
-
184
- private settings(width: number): { lines: string[]; start: number; end: number } {
185
- const focused = this.rows[this.row];
186
- if (!focused) return { lines: [this.theme.fg("dim", "No roles configured.")], start: 0, end: 1 };
187
- const theme = this.theme;
188
- const dim = (text: string) => theme.fg("dim", text);
189
- const field = GRID_COLUMNS[this.column]!;
190
- const label = field === "thinking" ? "Thinking (reasoning effort)" : field === "reset" ? "Reset" : "Model";
191
- const lines = [theme.bold(focused.role + " · " + label), ""];
192
- const starts: number[] = [];
193
- const setting = (column: number, name: string, hint: string): void => {
194
- starts.push(lines.length);
195
- const active = this.column === column;
196
- lines.push((active ? theme.fg("accent", "› ") : " ") + (active ? theme.underline(theme.bold(name)) : name) + dim(" · " + hint));
197
- };
198
- const value = (text: string): void => {
199
- lines.push(...wrapTextWithAnsi(text, Math.max(1, width - 2)).map((line) => " " + line));
200
- };
201
- setting(0, "Model", "Enter edit");
202
- value(focused.model);
203
- setting(1, "Thinking", "effective");
204
- value(focused.thinking);
205
- lines.push(dim(" Source: " + (focused.thinkingOverridden ? "override *" : "role default")));
206
- setting(2, "Reset", "Enter restore defaults");
207
- const end = lines.length;
208
- lines.push("", ...wrapTextWithAnsi(focused.description, width).map(dim));
209
- return { lines, start: starts[this.column]!, end: starts[this.column + 1] ?? end };
210
- }
211
-
212
- render(width: number): string[] {
213
- if (width <= 0) return [];
214
- const theme = this.theme;
215
- const dim = (text: string) => theme.fg("dim", text);
216
- const lines = [theme.bold("Subagents · Roles"), dim(this.status), ""];
217
- const height = setupHeight(this.tui);
218
- const wide = width >= 88;
219
- // The two panes close exactly: roleWidth + 3-column gutter + detailWidth = width.
220
- const roleWidth = wide ? Math.min(24, Math.floor(width * 0.24)) : width;
221
- const roles: string[] = [];
222
- for (const [index, role] of this.rows.entries()) {
223
- const selected = index === this.row;
224
- const name = selected ? theme.bold(role.role) : role.role;
225
- roles.push((selected ? "› " : " ") + name);
226
- if (wide) roles.push(dim(" " + truncateToWidth(role.model, roleWidth - 2, "…")));
227
- }
228
- const details = this.settings(wide ? width - roleWidth - 3 : width);
229
- const detailOffset = wide ? 0 : roles.length + 1;
230
- const body: string[] = [];
231
- if (wide) {
232
- for (let i = 0; i < Math.max(roles.length, details.lines.length); i++) {
233
- const left = truncateToWidth(roles[i] ?? "", roleWidth, "…");
234
- body.push(left + " ".repeat(roleWidth - visibleWidth(left) + 3) + (details.lines[i] ?? ""));
235
- }
236
- } else {
237
- body.push(...roles, "", ...details.lines);
238
- }
239
- const footer = [dim("↑/↓ role · ←/→ field"), dim("Enter edit · Esc close")];
240
- if (lines.length + body.length + footer.length + 1 <= height) {
241
- this.scrollTop = 0;
242
- this.revealField = true;
243
- return [...lines, ...body, "", ...footer].map((line) => truncateToWidth(line, width, "…"));
244
- }
245
- // Pin the selected identity while scrolling the existing pane content.
246
- // The field's complete value and provenance remain reachable by paging.
247
- const compact = height < 8;
248
- const header = compact ? [details.lines[0]!] : [...lines.slice(0, 2), details.lines[0]!];
249
- const controls = compact ? [dim("PgUp/Dn scroll · Enter edit · Esc")]
250
- : [footer[0]!, dim("PgUp/Dn scroll · Enter edit · Esc")];
251
- this.pageRows = Math.max(1, height - header.length - controls.length);
252
- const viewport = width + ":" + this.pageRows;
253
- if (this.revealField || this.viewport !== viewport) {
254
- const start = detailOffset + details.start;
255
- const end = detailOffset + details.end;
256
- // One-line viewports show the value rather than repeating its label.
257
- this.scrollTop = end - start > this.pageRows ? start + Number(this.pageRows === 1 && end > start + 1)
258
- : Math.max(0, end - this.pageRows);
259
- }
260
- this.viewport = viewport;
261
- this.revealField = false;
262
- this.scrollTop = Math.max(0, Math.min(this.scrollTop, body.length - this.pageRows));
263
- return [...header, ...body.slice(this.scrollTop, this.scrollTop + this.pageRows), ...controls]
264
- .map((line) => truncateToWidth(line, width, "…"));
265
- }
266
-
267
- handleInput(data: string): void {
268
- const kb = this.keybindings;
269
- const rows = this.rows.length;
270
- const previousRow = this.row;
271
- const previousColumn = this.column;
272
- if (kb.matches(data, "tui.select.pageUp")) {
273
- this.scrollTop -= this.pageRows;
274
- } else if (kb.matches(data, "tui.select.pageDown")) {
275
- this.scrollTop += this.pageRows;
276
- } else if (kb.matches(data, "tui.select.up")) {
277
- if (rows) this.row = (this.row - 1 + rows) % rows;
278
- } else if (kb.matches(data, "tui.select.down")) {
279
- if (rows) this.row = (this.row + 1) % rows;
280
- } else if (matchesKey(data, "left") || kb.matches(data, "tui.editor.cursorLeft")) {
281
- this.column = (this.column - 1 + GRID_COLUMNS.length) % GRID_COLUMNS.length;
282
- } else if (matchesKey(data, "right") || kb.matches(data, "tui.editor.cursorRight")) {
283
- this.column = (this.column + 1) % GRID_COLUMNS.length;
284
- } else if (kb.matches(data, "tui.select.confirm")) {
285
- const focused = this.rows[this.row];
286
- if (focused) {
287
- this.done({ row: this.row, column: this.column, role: focused.role, field: GRID_COLUMNS[this.column]! });
288
- return;
289
- }
290
- } else if (kb.matches(data, "tui.select.cancel")) {
291
- this.done(undefined);
292
- return;
293
- } else return;
294
- if (this.row !== previousRow || this.column !== previousColumn) this.revealField = true;
295
- this.tui.requestRender();
296
- }
297
-
298
- invalidate(): void {}
187
+ /** Searchable choices. Esc returns one level without saving the cursor. */
188
+ export function promptSelectOne(
189
+ ctx: PickerContext, title: string, hint: string, items: SetupItem[], initialValue?: string,
190
+ ): Promise<string | undefined> {
191
+ return prompt(ctx, items, { title, hint, initialValue, searchable: true });
299
192
  }
300
193
 
301
- /** Role × setting navigation. Esc closes without a change. */
302
- export function promptRoleGrid(
303
- ctx: PickerContext, rows: RoleGridRow[], focus: RoleGridFocus = {}, status = "Changes save immediately",
304
- ): Promise<RoleGridChoice | undefined> {
305
- if (ctx.mode !== "tui") {
306
- ctx.ui.notify("/subagents-setup requires Pi's interactive TUI.", "error");
307
- return Promise.resolve(undefined);
308
- }
309
- return ctx.ui.custom<RoleGridChoice | undefined>((tui, theme, keybindings, done) =>
310
- new RoleGrid(rows, status, focus, tui, theme, keybindings, done));
194
+ /** A familiar vertical menu. initialValue restores navigation, not saved state. */
195
+ export function promptMenu(
196
+ ctx: PickerContext, title: string, hint: string, items: SetupItem[], initialValue?: string,
197
+ ): Promise<string | undefined> {
198
+ return prompt(ctx, items, { title, hint, initialValue, searchable: false });
311
199
  }