@ferris1225/pi-subagents 6.0.5 → 7.0.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.
@@ -1,189 +1,93 @@
1
- /** Role-based settings. Each field saves independently; Esc always goes back. */
1
+ /** One worker, two settings. Main keeps Pi's model; workers share their own selection. */
2
2
 
3
- import { stat } from "node:fs/promises";
4
3
  import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
5
4
  import {
6
- BUILTIN_AGENT_NAMES,
7
- DEFAULT_CONFIG,
8
- agentProfile,
9
- errorMessage,
10
- getConfigPath,
11
- loadConfig,
12
- roleThinkingLevel,
13
- saveConfig,
14
- type SubagentsConfig,
15
- type ThinkingLevel,
5
+ DEFAULT_CONFIG, DEFAULT_THINKING_LEVEL, errorMessage, getConfigPath,
6
+ initializeConfig, loadConfig, saveConfig, type ThinkingLevel,
16
7
  } from "./config.ts";
17
8
  import {
18
- CURRENT_MAIN_MODEL,
19
- applyAgentModelChoice,
20
- availableModelsInScope,
21
- buildModelPickerItems,
22
- currentModelRef,
23
- findModelByRef,
24
- resolveThinkingLevel,
25
- supportedThinkingLevels,
9
+ CURRENT_MAIN_MODEL, availableModelsInScope, buildModelPickerItems, currentModelRef,
10
+ findModelByRef, resolveThinkingLevel, supportedThinkingLevels,
26
11
  } from "./models.ts";
27
- import { promptRoleGrid, promptSelectOne, type RoleGridFocus, type RoleGridRow, type SetupItem } from "./ui.ts";
12
+ import { promptSelectOne, promptSettings, type SetupItem } from "./ui.ts";
28
13
 
29
- const ROLE_DEFAULT = "__role_default__";
30
- const THINKING_LEVEL_HINTS: Record<ThinkingLevel, string> = {
31
- off: "no reasoning tokens",
32
- minimal: "minimal reasoning",
33
- low: "light reasoning",
34
- medium: "balanced reasoning",
35
- high: "deep reasoning",
36
- xhigh: "extra-deep reasoning",
37
- max: "strongest reasoning",
14
+ const THINKING_HINTS: Record<ThinkingLevel, string> = {
15
+ off: "No reasoning tokens", minimal: "Minimal reasoning", low: "Light reasoning",
16
+ medium: "Balanced reasoning", high: "Deep reasoning", xhigh: "Extra-deep reasoning", max: "Strongest reasoning",
38
17
  };
39
18
 
40
- const ROLE_PURPOSE: Record<string, string> = {
41
- scout: "Research with citations",
42
- artisan: "Implement and verify",
43
- sentinel: "Review and challenge claims",
44
- };
45
-
46
- async function configExists(configPath: string): Promise<boolean> {
47
- try {
48
- await stat(configPath);
49
- return true;
50
- } catch {
51
- return false;
52
- }
53
- }
54
-
55
- function roleModel(ctx: ExtensionContext, config: SubagentsConfig, name: string) {
56
- return findModelByRef(availableModelsInScope(ctx), config.agentModels[name]) ?? ctx.model;
57
- }
58
-
59
- /** One row per role: every model and thinking choice stays visible together in the standalone modal panel. */
60
- function roleRows(ctx: ExtensionContext, config: SubagentsConfig): RoleGridRow[] {
61
- const mainRef = currentModelRef(ctx) ?? "Pi default";
62
- const models = availableModelsInScope(ctx);
63
- return BUILTIN_AGENT_NAMES.map((name) => {
64
- const profile = agentProfile(name)!;
65
- const selected = config.agentModels[name];
66
- const model = findModelByRef(models, selected);
67
- const available = !selected || Boolean(model);
68
- const modelLabel = selected
69
- ? (model ? model.name + " · " + model.provider + (model.name !== selected ? " (" + selected + ")" : "") : selected + " (unavailable)")
70
- : "Follow main (dynamic)";
71
- const preferred = config.agentThinkingLevels[name] ?? roleThinkingLevel(name);
72
- const effective = resolveThinkingLevel(model ?? ctx.model, preferred);
73
- const clamped = effective !== preferred ? " (" + preferred + " requested)" : "";
74
- const overridden = Boolean(config.agentThinkingLevels[name]);
75
- return {
76
- role: name,
77
- purpose: ROLE_PURPOSE[name],
78
- thinkingOverridden: overridden,
79
- model: modelLabel,
80
- thinking: effective + clamped,
81
- description: profile.remark + " Model: " + (selected
82
- ? "pinned reference " + selected + (available ? "; falls back to main if it fails." : "; unavailable, using main.")
83
- : "follows main (" + mainRef + ") dynamically.")
84
- + " Thinking: role default " + roleThinkingLevel(name) + ", clamped to the model-supported levels. Reset restores " + name + " to Follow main and that default. * marks an override.",
85
- };
86
- });
87
- }
88
-
89
- async function editSetting(
90
- ctx: ExtensionContext,
91
- config: SubagentsConfig,
92
- name: string,
93
- field: string,
94
- ): Promise<SubagentsConfig | undefined> {
95
- const next: SubagentsConfig = {
96
- agentModels: { ...config.agentModels },
97
- agentThinkingLevels: { ...config.agentThinkingLevels },
98
- };
99
- if (field === "reset") {
100
- delete next.agentModels[name];
101
- delete next.agentThinkingLevels[name];
102
- } else if (field === "model") {
103
- const choice = await promptSelectOne(ctx, name + " · Model",
104
- "Follow main = dynamic · Others = pinned · Esc back without changes",
105
- buildModelPickerItems({ models: availableModelsInScope(ctx), configuredRef: config.agentModels[name], mainRef: currentModelRef(ctx) }),
106
- config.agentModels[name] ?? CURRENT_MAIN_MODEL);
107
- if (choice === undefined) return undefined;
108
- next.agentModels = applyAgentModelChoice(next.agentModels, name, choice);
109
- } else if (field === "thinking") {
110
- const model = roleModel(ctx, config, name);
111
- const preferredDefault = roleThinkingLevel(name);
112
- const effectiveDefault = resolveThinkingLevel(model, preferredDefault);
113
- const supported = supportedThinkingLevels(model);
114
- if (!supported.length) {
115
- ctx.ui.notify("Choose a model before changing thinking; its supported levels are not available yet.", "info");
116
- return undefined;
117
- }
118
- const current = config.agentThinkingLevels[name];
119
- const options: SetupItem[] = [
120
- {
121
- value: ROLE_DEFAULT,
122
- label: "Role default",
123
- description: preferredDefault + (effectiveDefault !== preferredDefault ? " → " + effectiveDefault + " on this model" : ""),
124
- saved: !current,
125
- },
126
- ...supported.map((level) => ({
127
- value: level,
128
- label: level,
129
- description: THINKING_LEVEL_HINTS[level],
130
- saved: current === level,
131
- })),
132
- ];
133
- if (current && !supported.includes(current)) {
134
- options.push({
135
- value: current,
136
- label: current + " (runs as " + resolveThinkingLevel(model, current) + ")",
137
- description: "Saved preference; this model clamps it. Keep it for other models, or choose a supported level.",
138
- saved: true,
139
- });
140
- }
141
- const choice = await promptSelectOne(ctx, name + " · Thinking",
142
- "Reasoning effort · saved preferences survive model changes · Esc back",
143
- options, current ?? ROLE_DEFAULT);
144
- if (choice === undefined) return undefined;
145
- if (choice === ROLE_DEFAULT) delete next.agentThinkingLevels[name];
146
- else next.agentThinkingLevels[name] = choice as ThinkingLevel;
147
- } else {
148
- return undefined;
149
- }
150
- return next;
151
- }
152
-
153
- /** Standalone modal panel for first install and later edits. */
154
19
  export async function runSetup(ctx: ExtensionContext, configPath: string = getConfigPath()): Promise<void> {
155
20
  if (ctx.mode !== "tui") {
156
21
  ctx.ui.notify("/subagents-setup requires Pi's interactive TUI.", "error");
157
22
  return;
158
23
  }
159
24
  try {
160
- let config = await loadConfig(configPath);
161
- let focus: RoleGridFocus = {};
25
+ await ensureDefaultConfig(ctx, configPath);
26
+ let focus = "model";
162
27
  let status = "Changes save immediately";
163
28
  while (true) {
164
- const choice = await promptRoleGrid(ctx, roleRows(ctx, config), focus, status);
165
- if (choice === undefined) return;
166
- focus = { row: choice.row, column: choice.column };
167
- const next = await editSetting(ctx, config, choice.role, choice.field);
168
- if (!next) continue;
169
- await saveConfig(next, configPath);
170
- config = next;
171
- status = "Saved " + choice.role + (choice.field === "reset" ? " defaults" : " " + choice.field);
29
+ const config = await loadConfig(configPath);
30
+ const models = availableModelsInScope(ctx);
31
+ const selected = findModelByRef(models, config.model);
32
+ const model = selected ?? ctx.model;
33
+ const effective = resolveThinkingLevel(model, config.thinking);
34
+ const choice = await promptSettings(ctx, {
35
+ main: currentModelRef(ctx) ?? "Pi default",
36
+ model: config.model ?? "Follow main",
37
+ thinking: config.model && !selected ? config.thinking : effective + (effective !== config.thinking ? " (" + config.thinking + " requested)" : ""),
38
+ note: config.model && !selected ? "Worker unavailable; dispatch paused. Select an available model." : !config.model ? "Choose a cheaper worker to reduce main-model spending." : "",
39
+ status, focus,
40
+ });
41
+ if (!choice) return;
42
+ focus = choice;
43
+ if (choice === "model") {
44
+ const picked = await promptSelectOne(ctx, "Worker model", "Choose a cost-effective model · Esc back",
45
+ buildModelPickerItems({ models, configuredRef: config.model, mainRef: currentModelRef(ctx) }),
46
+ config.model ?? CURRENT_MAIN_MODEL);
47
+ if (picked === undefined) continue;
48
+ const next = await loadConfig(configPath);
49
+ if (picked === CURRENT_MAIN_MODEL) delete next.model;
50
+ else next.model = picked;
51
+ await saveConfig(next, configPath);
52
+ status = "Model saved";
53
+ } else if (choice === "thinking") {
54
+ const levels = supportedThinkingLevels(config.model && !selected ? undefined : model);
55
+ if (!levels.length) {
56
+ ctx.ui.notify("Choose a model before changing thinking; its supported levels are not available yet.", "info");
57
+ continue;
58
+ }
59
+ const items: SetupItem[] = levels.map((level) => ({
60
+ value: level, label: level + (level === DEFAULT_THINKING_LEVEL ? " (default)" : ""),
61
+ description: THINKING_HINTS[level], saved: level === config.thinking,
62
+ }));
63
+ if (!levels.includes(config.thinking)) items.push({
64
+ value: config.thinking, label: config.thinking + " (runs as " + effective + ")",
65
+ description: "Saved preference; the current model clamps it.", saved: true,
66
+ });
67
+ const picked = await promptSelectOne(ctx, "Worker thinking", "Reasoning effort · Esc back", items, config.thinking);
68
+ if (picked === undefined) continue;
69
+ await saveConfig({ ...await loadConfig(configPath), thinking: picked as ThinkingLevel }, configPath);
70
+ status = "Thinking saved";
71
+ } else if (choice === "reset") {
72
+ await saveConfig({ ...DEFAULT_CONFIG }, configPath);
73
+ status = "Defaults restored";
74
+ }
172
75
  }
173
76
  } catch (error) {
174
77
  ctx.ui.notify("pi-subagents setup failed: " + errorMessage(error), "error");
175
78
  }
176
79
  }
177
80
 
178
- /** Write shipped defaults once so every role works immediately. */
179
- export async function ensureDefaultConfig(
180
- ctx: ExtensionContext,
181
- configPath: string = getConfigPath(),
182
- ): Promise<void> {
183
- if (await configExists(configPath)) return;
184
- await saveConfig(DEFAULT_CONFIG, configPath);
185
- ctx.ui.notify(
186
- "pi-subagents: wrote " + configPath + " with all roles enabled; each follows the main model. Run /subagents-setup to pick a model and thinking level per role.",
187
- "info",
188
- );
81
+ export async function ensureDefaultConfig(ctx: ExtensionContext, configPath: string = getConfigPath()): Promise<void> {
82
+ try {
83
+ const result = await initializeConfig(configPath);
84
+ if (!result) return;
85
+ ctx.ui.notify(
86
+ "pi-subagents: " + (result === "reset" ? "deleted the old config and initialized new worker settings at " : "initialized worker settings at ")
87
+ + configPath + ". Main plans and reviews; workers execute. Run /subagents-setup to choose a cost-effective worker model and thinking level. Defaults follow main with medium thinking.",
88
+ "info",
89
+ );
90
+ } catch (error) {
91
+ ctx.ui.notify("pi-subagents could not initialize settings: " + errorMessage(error) + ". Fix the config path and run /subagents-setup.", "warning");
92
+ }
189
93
  }
@@ -1,4 +1,4 @@
1
- /** Standalone modal panels for /subagents-setup role settings and model selection. */
1
+ /** Compact worker settings and a searchable model picker in standalone modal panels. */
2
2
 
3
3
  import {
4
4
  Input, fuzzyFilter, matchesKey, truncateToWidth, visibleWidth, wrapTextWithAnsi,
@@ -285,205 +285,92 @@ export function promptSelectOne(
285
285
  }
286
286
  return ctx.ui.custom<string | undefined>(
287
287
  (tui, theme, keybindings, done) => new Picker(items, { title, hint, initialValue }, tui, theme, keybindings, done),
288
- { overlay: true, overlayOptions: SETUP_OVERLAY_OPTIONS },
288
+ { overlay: true, overlayOptions: SETUP_OVERLAY_OPTIONS, blocked: { kind: "question", message: title } },
289
289
  );
290
290
  }
291
291
 
292
- export interface RoleGridRow {
293
- role: string;
294
- purpose?: string;
292
+ export interface WorkerSettingsView {
293
+ main: string;
295
294
  model: string;
296
- /** Effective level, optionally followed by the requested level when clamped. */
297
295
  thinking: string;
298
- thinkingOverridden?: boolean;
299
- description: string;
296
+ note: string;
297
+ status: string;
298
+ focus: string;
300
299
  }
301
- export interface RoleGridFocus { row?: number; column?: number; }
302
- const GRID_COLUMNS = ["model", "thinking", "reset"] as const;
303
- export type RoleGridColumn = (typeof GRID_COLUMNS)[number];
304
- export interface RoleGridChoice { row: number; column: number; role: string; field: RoleGridColumn; }
305
-
306
- /** Standalone modal panel with a role register beside the selected role's settings;
307
- * narrow terminals stack the same regions. Full effective values are never squeezed into grid cells. */
308
- class RoleGrid implements Component {
309
- private row: number;
310
- private column: number;
311
- private scrollTop = 0;
312
- private pageRows = 1;
313
- private viewport = "";
314
- private revealField = true;
315
-
316
- private readonly rows: RoleGridRow[];
317
- private readonly status: string;
300
+
301
+ const SETTING_KEYS = ["model", "thinking", "reset"] as const;
302
+
303
+ class WorkerSettings implements Component {
304
+ private cursor: number;
305
+ private detailTop = 0;
306
+ private detailPage = 1;
307
+ private readonly view: WorkerSettingsView;
318
308
  private readonly tui: TUI;
319
309
  private readonly theme: Theme;
320
- private readonly keybindings: KeybindingsManager;
321
- private readonly done: (choice: RoleGridChoice | undefined) => void;
322
-
310
+ private readonly keys: KeybindingsManager;
311
+ private readonly done: (value: string | undefined) => void;
323
312
  constructor(
324
- rows: RoleGridRow[], status: string, focus: RoleGridFocus, tui: TUI, theme: Theme,
325
- keybindings: KeybindingsManager, done: (choice: RoleGridChoice | undefined) => void,
313
+ view: WorkerSettingsView, tui: TUI, theme: Theme,
314
+ keys: KeybindingsManager, done: (value: string | undefined) => void,
326
315
  ) {
327
- this.rows = rows;
328
- this.status = status;
316
+ this.view = view;
329
317
  this.tui = tui;
330
318
  this.theme = theme;
331
- this.keybindings = keybindings;
319
+ this.keys = keys;
332
320
  this.done = done;
333
- this.row = Math.min(Math.max(0, focus.row ?? 0), Math.max(0, rows.length - 1));
334
- this.column = Math.min(Math.max(0, focus.column ?? 0), GRID_COLUMNS.length - 1);
335
- }
336
-
337
- private settings(width: number): { lines: string[]; start: number; end: number } {
338
- const focused = this.rows[this.row];
339
- if (!focused) return { lines: [this.theme.fg("dim", "No roles configured.")], start: 0, end: 1 };
340
- const theme = this.theme;
341
- const dim = (text: string) => theme.fg("dim", text);
342
- const field = GRID_COLUMNS[this.column]!;
343
- const label = field === "thinking" ? "Thinking (reasoning effort)" : field === "reset" ? "Reset" : "Model";
344
- const lines = [theme.bold(focused.role + " · " + label), ""];
345
- const starts: number[] = [];
346
- const setting = (column: number, name: string, hint: string): void => {
347
- starts.push(lines.length);
348
- const active = this.column === column;
349
- lines.push((active ? theme.fg("accent", "› ") : " ") + (active ? theme.underline(theme.bold(name)) : name) + dim(" · " + hint));
350
- };
351
- const value = (text: string): void => {
352
- lines.push(...wrapTextWithAnsi(text, Math.max(1, width - 2)).map((line) => " " + line));
353
- };
354
- setting(0, "Model", "Enter edit");
355
- value(focused.model);
356
- setting(1, "Thinking", "effective");
357
- value(focused.thinking);
358
- lines.push(dim(" Source: " + (focused.thinkingOverridden ? "override *" : "role default")));
359
- setting(2, "Reset", "Enter restore defaults");
360
- const end = lines.length;
361
- lines.push("", ...wrapTextWithAnsi(focused.description, width).map(dim));
362
- return { lines, start: starts[this.column]!, end: starts[this.column + 1] ?? end };
321
+ this.cursor = Math.max(0, SETTING_KEYS.findIndex((key) => key === view.focus));
363
322
  }
364
323
 
365
324
  render(width: number): string[] {
366
325
  if (width <= 0) return [];
367
- const theme = this.theme;
368
- const dim = (text: string) => theme.fg("dim", text);
369
326
  const height = setupHeight(this.tui);
370
- const framed = width >= 20 && height >= 10;
371
- const innerWidth = framed ? Math.max(1, width - 4) : width;
372
- const wide = innerWidth >= 72;
373
- // The two panes close exactly: roleWidth + 3-column gutter + detailWidth = innerWidth.
374
- const roleWidth = wide ? Math.min(28, Math.max(20, Math.floor(innerWidth * 0.28))) : innerWidth;
375
- const roles: string[] = [];
376
- for (const [index, role] of this.rows.entries()) {
377
- const selected = index === this.row;
378
- const title = role.purpose && wide ? role.role + " · " + role.purpose : role.role;
379
- const clippedTitle = truncateToWidth(title, Math.max(1, roleWidth - 2), "…");
380
- const name = selected ? theme.bold(clippedTitle) : clippedTitle;
381
- roles.push((selected ? theme.fg("accent", "› ") : " ") + name);
382
- if (wide) {
383
- const summary = role.model + " · " + role.thinking + (role.thinkingOverridden ? " *" : "");
384
- roles.push(dim(" " + truncateToWidth(summary, roleWidth - 2, "…")));
385
- }
386
- }
387
- const details = this.settings(wide ? innerWidth - roleWidth - 3 : innerWidth);
388
- const detailOffset = wide ? 0 : roles.length + 1;
389
- const body: string[] = [];
390
- const divider = dim(" │ ");
391
- if (wide) {
392
- for (let i = 0; i < Math.max(roles.length, details.lines.length); i++) {
393
- const left = truncateToWidth(roles[i] ?? "", roleWidth, "…");
394
- body.push(left + " ".repeat(Math.max(0, roleWidth - visibleWidth(left))) + divider + (details.lines[i] ?? ""));
395
- }
396
- } else {
397
- body.push(...roles, "", ...details.lines);
398
- }
399
- const footer = innerWidth >= 52
400
- ? [dim("↑/↓ role · ←/→ field · Enter edit · Esc close")]
401
- : [dim("↑/↓ role · ←/→ field"), dim("Enter edit · Esc close")];
402
-
403
- const chromeRows = framed ? 4 + footer.length + 1 : 3 + footer.length + 1;
404
- if (body.length + chromeRows <= height) {
405
- this.scrollTop = 0;
406
- this.revealField = true;
407
- if (!framed) {
408
- return [theme.bold("Subagents · Roles"), dim(this.status), "", ...body, "", ...footer]
409
- .map((line) => truncateToWidth(line, width, "…"));
410
- }
411
- return framePanel(theme, width, "Subagents · Roles", this.status, body, footer);
412
- }
413
-
414
- // Pin the selected identity while scrolling the existing pane content.
415
- // The field's complete value and provenance remain reachable by paging.
416
- const compact = height < 10;
417
- const header = [details.lines[0]!];
418
- const controls = innerWidth >= 58
419
- ? [dim("↑/↓ role · ←/→ field · PgUp/Dn scroll · Enter edit · Esc close")]
420
- : compact
421
- ? [dim("PgUp/Dn scroll · Enter edit · Esc")]
422
- : [dim("↑/↓ role · ←/→ field"), dim("PgUp/Dn scroll · Enter edit · Esc")];
423
- const scrollChrome = framed ? 4 + header.length + controls.length + 1 : header.length + controls.length;
424
- this.pageRows = Math.max(1, height - scrollChrome);
425
- const viewport = innerWidth + ":" + this.pageRows;
426
- if (this.revealField || this.viewport !== viewport) {
427
- const start = detailOffset + details.start;
428
- const end = detailOffset + details.end;
429
- // One-line viewports show the value rather than repeating its label.
430
- this.scrollTop = end - start > this.pageRows ? start + Number(this.pageRows === 1 && end > start + 1)
431
- : Math.max(0, end - this.pageRows);
432
- }
433
- this.viewport = viewport;
434
- this.revealField = false;
435
- this.scrollTop = Math.max(0, Math.min(this.scrollTop, body.length - this.pageRows));
436
- const visibleBody = [...header, ...body.slice(this.scrollTop, this.scrollTop + this.pageRows)];
437
- if (!framed) {
438
- return [...visibleBody, ...controls].map((line) => truncateToWidth(line, width, "…"));
327
+ const framed = width >= 20 && height >= 13;
328
+ const inner = Math.max(1, width - (framed ? 4 : 0));
329
+ const values = [this.view.model, this.view.thinking, "Follow main · medium"];
330
+ const labels = ["Model", "Thinking", "Reset"];
331
+ const rows = labels.map((label, index) => {
332
+ const line = truncateToWidth(label + " " + values[index], Math.max(1, inner - 2), "…");
333
+ return index === this.cursor ? this.theme.fg("accent", "› " + this.theme.bold(line)) : " " + line;
334
+ });
335
+ const hints = ["Worker model: " + this.view.model, "Worker thinking: " + this.view.thinking, "Restore Follow main and medium thinking."];
336
+ const details = [...wrapTextWithAnsi(hints[this.cursor]!, inner), ...(this.view.note ? wrapTextWithAnsi(this.view.note, inner) : [])];
337
+ const key = (action: Keybinding) => {
338
+ const name = this.keys.getKeys(action)[0] ?? "unbound";
339
+ return ({ escape: "Esc", enter: "Enter", up: "↑", down: "↓" } as Record<string, string>)[name] ?? name;
340
+ };
341
+ const footer = key("tui.select.cancel") + " close · " + key("tui.select.confirm") + " edit · " + key("tui.select.up") + key("tui.select.down") + " move";
342
+ if (height < 12) {
343
+ return [this.theme.bold("Subagents"), ...rows, this.view.status, footer]
344
+ .slice(0, height).map((line) => truncateToWidth(line, width, "…"));
439
345
  }
440
- return framePanel(theme, width, "Subagents · Roles", this.status, visibleBody, controls);
346
+ this.detailPage = Math.max(1, height - (framed ? 12 : 9));
347
+ this.detailTop = Math.max(0, Math.min(this.detailTop, details.length - this.detailPage));
348
+ const body = [
349
+ this.theme.fg("muted", truncateToWidth("Main · " + this.view.main, inner, "…")),
350
+ "", ...rows, "",
351
+ ...details.slice(this.detailTop, this.detailTop + this.detailPage).map((line) => this.theme.fg("muted", line)),
352
+ ];
353
+ const status = (details.length > this.detailPage ? "PgUp/PgDn details · " : "") + this.view.status;
354
+ if (framed) return framePanel(this.theme, width, "Subagents", undefined, body, [status, footer]);
355
+ return [this.theme.bold("Subagents"), ...body, status, footer].map((line) => truncateToWidth(line, width, "…"));
441
356
  }
442
357
 
443
358
  handleInput(data: string): void {
444
- const kb = this.keybindings;
445
- const rows = this.rows.length;
446
- const previousRow = this.row;
447
- const previousColumn = this.column;
448
- if (kb.matches(data, "tui.select.pageUp")) {
449
- this.scrollTop -= this.pageRows;
450
- } else if (kb.matches(data, "tui.select.pageDown")) {
451
- this.scrollTop += this.pageRows;
452
- } else if (kb.matches(data, "tui.select.up")) {
453
- if (rows) this.row = (this.row - 1 + rows) % rows;
454
- } else if (kb.matches(data, "tui.select.down")) {
455
- if (rows) this.row = (this.row + 1) % rows;
456
- } else if (matchesKey(data, "left") || kb.matches(data, "tui.editor.cursorLeft")) {
457
- this.column = (this.column - 1 + GRID_COLUMNS.length) % GRID_COLUMNS.length;
458
- } else if (matchesKey(data, "right") || kb.matches(data, "tui.editor.cursorRight")) {
459
- this.column = (this.column + 1) % GRID_COLUMNS.length;
460
- } else if (kb.matches(data, "tui.select.confirm")) {
461
- const focused = this.rows[this.row];
462
- if (focused) {
463
- this.done({ row: this.row, column: this.column, role: focused.role, field: GRID_COLUMNS[this.column]! });
464
- return;
465
- }
466
- } else if (kb.matches(data, "tui.select.cancel")) {
467
- this.done(undefined);
468
- return;
469
- } else return;
470
- if (this.row !== previousRow || this.column !== previousColumn) this.revealField = true;
359
+ if (this.keys.matches(data, "tui.select.cancel")) { this.done(undefined); return; }
360
+ if (this.keys.matches(data, "tui.select.confirm")) { this.done(SETTING_KEYS[this.cursor]); return; }
361
+ if (this.keys.matches(data, "tui.select.up")) { this.cursor = (this.cursor + 2) % 3; this.detailTop = 0; }
362
+ else if (this.keys.matches(data, "tui.select.down")) { this.cursor = (this.cursor + 1) % 3; this.detailTop = 0; }
363
+ else if (this.keys.matches(data, "tui.select.pageUp")) this.detailTop -= this.detailPage;
364
+ else if (this.keys.matches(data, "tui.select.pageDown")) this.detailTop += this.detailPage;
471
365
  this.tui.requestRender();
472
366
  }
473
367
 
474
368
  invalidate(): void {}
475
369
  }
476
370
 
477
- /** Role × setting modal panel. Esc closes without a change. */
478
- export function promptRoleGrid(
479
- ctx: PickerContext, rows: RoleGridRow[], focus: RoleGridFocus = {}, status = "Changes save immediately",
480
- ): Promise<RoleGridChoice | undefined> {
481
- if (ctx.mode !== "tui") {
482
- ctx.ui.notify("/subagents-setup requires Pi's interactive TUI.", "error");
483
- return Promise.resolve(undefined);
484
- }
485
- return ctx.ui.custom<RoleGridChoice | undefined>(
486
- (tui, theme, keybindings, done) => new RoleGrid(rows, status, focus, tui, theme, keybindings, done),
487
- { overlay: true, overlayOptions: SETUP_OVERLAY_OPTIONS },
371
+ export function promptSettings(ctx: PickerContext, view: WorkerSettingsView): Promise<string | undefined> {
372
+ return ctx.ui.custom<string | undefined>(
373
+ (tui, theme, keys, done) => new WorkerSettings(view, tui, theme, keys, done),
374
+ { overlay: true, overlayOptions: SETUP_OVERLAY_OPTIONS, blocked: { kind: "question", message: "Configure subagent worker" } },
488
375
  );
489
376
  }
@@ -4,8 +4,8 @@
4
4
  * The built-in roles ship as code and are the whole catalog: all are
5
5
  * always enabled and there are no user or project role files.
6
6
  *
7
- * Role prompts stay tool-agnostic: the host decides whether a writer or
8
- * reviewer reaches its tools directly or through a script tool such as
7
+ * Worker prompts stay tool-agnostic: the host decides whether a writer
8
+ * reaches its tools directly or through a script tool such as
9
9
  * codemode. Scout receives only direct read-only tools.
10
10
  */
11
11
 
@@ -30,34 +30,20 @@ const SCOUT_SYSTEM_PROMPT = `Answer the brief's bounded research question. Follo
30
30
  Lead with the answer. Return only findings needed for the brief, with decisive citations rather than raw search logs or whole files. Cite repository facts as \`path:line-range\` and external facts as source URLs. Distinguish inference from verified facts, and name unresolved gaps.
31
31
  `;
32
32
 
33
- const ARTISAN_SYSTEM_PROMPT = `Complete the brief's bounded engineering task: implementation, fix, tests, or docs. Follow the brief within loaded project instructions; this role supplies the working method. The leaf boundary below still wins. You have no interactive clarification; resolve routine details, state material assumptions, and finish the authorized outcome.
33
+ const ARTISAN_SYSTEM_PROMPT = `Execute the lead's bounded plan: implementation, fix, tests, or docs. Main owns architecture, ambiguity, review, and acceptance. Follow the brief within loaded project instructions; this role supplies the working method. The leaf boundary below still wins. You have no interactive clarification; resolve routine details, state material assumptions, and finish the authorized outcome.
34
34
 
35
35
  ## Rules
36
36
 
37
37
  - Read what the task needs, then complete the change. Reach the tools this session declares the way it declares them — directly, or through its script tool when that is the only interface. Continue through affected tests, docs, comments, local cleanup, and verification. Do not stop at a plan or a first draft.
38
38
  - For a reported defect, confirm current behavior and fix the root cause. If the premise is disproved, or finishing requires a wider scope or an approval boundary, report the blocker with evidence.
39
+ - If an interface or assumption invalidates the plan, or the same verification failure survives two attempted fixes, stop that approach and return the evidence, partial changes, and proposed next step to main. Do not retry indefinitely or silently redesign the task.
39
40
  - Own only the brief's scope and done condition, including the change and its regression tests. Reuse completed main or upstream work; implement only the remaining delta. Make the smallest coherent change. Preserve unrelated work, other agents' changes, and project conventions. Report a required change outside your write boundary instead of expanding it silently.
40
41
  - Run the checks and gates the brief or project requires. Reuse supplied passing checks when they cover the current files; name the evidence and any gap. Tests should catch the relevant failure. Skip a test that only mirrors a reversible, low-impact edit. Fix failures caused by your change. Repeat or broaden checks only for new edits, failures, or unresolved concerns. Main owns the final integrated gate.
41
42
  - You are a leaf: do not dispatch agents, bump versions, commit, push, publish, tag, or release.
42
43
 
43
44
  ## Output
44
45
 
45
- Lead with the outcome and whether the done condition was met. Keep the handoff compact: changed paths, checks as \`command → result\`, and material blockers or follow-ups. Summarize evidence instead of dumping logs or whole files. State unrun checks and pre-existing failures accurately.
46
- `;
47
-
48
- const SENTINEL_SYSTEM_PROMPT = `Verify the brief's existing implementation, diff, or named claim against its requirements and callers. Follow the brief within loaded project instructions; this role supplies the working method. The leaf boundary below still wins. You have no interactive clarification; state material assumptions and finish the bounded review.
49
-
50
- ## Rules
51
-
52
- - Inspect the scoped implementation and relevant callers for correctness defects, regressions, and broken assumptions. For a diff, report defects introduced by the change. When the brief names a specific claim, design assumption, or finding, seek a decisive counterexample or failing precondition to test it. Review the wider codebase only when the brief explicitly requests an audit.
53
- - Reuse main or upstream findings, research, and passing checks when they still cover the current code. Fill evidence gaps and resolve conflicts; repeat or broaden checks only for changed code or a concrete uncertainty.
54
- - Reach tools the way this session declares them — directly, or through its script tool when that is the only interface. Verify suspected defects or claims with safe focused checks or a concrete counterexample. Do not edit files or change Git state; your tools can write, so respect this instruction. Main applies confirmed fixes.
55
- - Findings are confirmed, actionable defects with exact location, trigger, consequence, evidence, and smallest fix. List material unverified concerns separately from findings. Skip style preferences and speculative hardening.
56
- - You are a leaf: do not dispatch agents, bump versions, commit, push, publish, tag, or release.
57
-
58
- ## Output
59
-
60
- Lead with confirmed findings ordered by severity (or the verdict on a named claim), then checks as \`command → result\` and material gaps. State clearly when no findings were found and what was verified.
46
+ Lead with the outcome and whether the done condition was met. Keep the handoff compact: changed paths, checks as \`command → result\`, and material blockers or follow-ups. Summarize evidence instead of dumping logs or whole files. State unrun checks and pre-existing failures accurately. Return evidence for main to review; do not declare the overall task approved.
61
47
  `;
62
48
 
63
49
  export const BUILTIN_AGENTS: readonly BuiltinAgentDefinition[] = [
@@ -72,9 +58,4 @@ export const BUILTIN_AGENTS: readonly BuiltinAgentDefinition[] = [
72
58
  description: "Implement a bounded change through its tests, docs, and verification.",
73
59
  systemPrompt: ARTISAN_SYSTEM_PROMPT,
74
60
  },
75
- {
76
- name: "sentinel",
77
- description: "Inspect an existing implementation or diff and challenge claims or assumptions for defects and regressions; no edits.",
78
- systemPrompt: SENTINEL_SYSTEM_PROMPT,
79
- },
80
61
  ];