pi-bro 0.39.0 → 0.40.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.
package/src/config-ui.ts CHANGED
@@ -15,8 +15,10 @@ import {
15
15
  type BackendName,
16
16
  type BroSettings,
17
17
  type Capability,
18
+ type CodexModelChoice,
18
19
  type ExternalBackend,
19
20
  type PiModelChoice,
21
+ AGY_EFFORTS,
20
22
  CAPABILITIES,
21
23
  CAPABILITY_LABELS,
22
24
  EXTERNAL_BACKENDS,
@@ -45,9 +47,7 @@ const SHOW_TURNS_PRESETS = [1, 2, 3, 5, 8];
45
47
  const BACKEND_CHOICES: readonly { value: BackendName; label: string }[] = [
46
48
  { value: "agy", label: "Agy" },
47
49
  { value: "claude", label: "Claude" },
48
- { value: "grok", label: "Grok" },
49
50
  { value: "codex", label: "Codex" },
50
- { value: "muse", label: "Muse" },
51
51
  { value: "pi", label: "Pi" },
52
52
  ] as const;
53
53
 
@@ -67,6 +67,7 @@ export function createConfigModal(
67
67
  persistSettings: (settings: BroSettings) => Promise<void>,
68
68
  piModels: PiModelChoice[] = [],
69
69
  page: ConfigSettingsPage | "all" = "all",
70
+ codexModels: CodexModelChoice[] = [],
70
71
  ): (tui: TuiLike, theme: Theme, keybindings: unknown, done: (value?: void) => void) => Component & { dispose?(): void } {
71
72
  return (tui, theme, _keybindings, done) => {
72
73
  // Size the host list once, then stop interaction if a later resize cannot show the whole
@@ -118,13 +119,20 @@ export function createConfigModal(
118
119
 
119
120
  const buildModelOptions = (backend: BackendName): SelectItem[] => {
120
121
  if (backend === "agy") {
121
- return families.map((family) => ({
122
- value: family.id,
123
- label: `${family.label}${family.efforts.length ? "" : " · fixed effort"}`,
124
- }));
122
+ return [
123
+ ...families.map((family) => ({
124
+ value: family.id,
125
+ label: `${family.label}${family.efforts.length ? "" : " · fixed effort"}`,
126
+ })),
127
+ { value: "__agy_custom__", label: "Agy · custom model ID…" },
128
+ ];
125
129
  }
126
130
  const meta = EXTERNAL_BACKENDS[backend];
127
- const models = backend === "pi" ? piModels.map((choice) => ({ id: choice.value, label: choice.label })) : meta.models;
131
+ const models = backend === "pi"
132
+ ? piModels.map((choice) => ({ id: choice.value, label: choice.label }))
133
+ : backend === "codex"
134
+ ? codexModels.map((choice) => ({ id: choice.value, label: choice.label }))
135
+ : meta.models;
128
136
  return [
129
137
  ...models.map((model) => ({ value: `${meta.prefix}${model.id}`, label: model.label })),
130
138
  { value: `__${backend}_custom__`, label: `${meta.label} · custom model ID…` },
@@ -141,7 +149,7 @@ export function createConfigModal(
141
149
  const prefix = chosenBackend && chosenBackend !== "agy" ? EXTERNAL_BACKENDS[chosenBackend].prefix : "";
142
150
  modelSelectList.setSelectedIndex(Math.max(0, items.findIndex((option) => option.value === current || option.value === `${prefix}${current}`)));
143
151
  modelSelectList.onSelect = (item) => {
144
- if (chosenBackend && chosenBackend !== "agy" && item.value === `__${chosenBackend}_custom__`) {
152
+ if (chosenBackend && item.value === `__${chosenBackend}_custom__`) {
145
153
  step = "custom";
146
154
  customError = undefined;
147
155
  tui.requestRender();
@@ -178,12 +186,18 @@ export function createConfigModal(
178
186
  picker.onCancel = () => pickerDone();
179
187
 
180
188
  input.onSubmit = (value) => {
181
- if (!value.trim() || !chosenBackend || chosenBackend === "agy") return;
189
+ const trimmed = value.trim();
190
+ if (!trimmed || !chosenBackend) return;
191
+ if (chosenBackend === "agy") {
192
+ customError = undefined;
193
+ pickerDone(trimmed);
194
+ return;
195
+ }
182
196
  // Validate before leaving the step so a malformed ID (Pi needs "<provider>/<id>") shows an
183
197
  // inline hint and leaves the field open, instead of throwing out of the input handler.
184
- const choice = `${EXTERNAL_BACKENDS[chosenBackend].prefix}${value.trim()}`;
198
+ const choice = `${EXTERNAL_BACKENDS[chosenBackend].prefix}${trimmed}`;
185
199
  try {
186
- EXTERNAL_BACKENDS[chosenBackend].resolveModel(value.trim());
200
+ EXTERNAL_BACKENDS[chosenBackend].resolveModel(trimmed);
187
201
  } catch (error) {
188
202
  customError = errorMessage(error);
189
203
  tui.requestRender();
@@ -196,9 +210,10 @@ export function createConfigModal(
196
210
  return {
197
211
  // SettingsList draws an open submenu instead of its own list and hints, so the picker brings its own.
198
212
  render: (width: number) => {
199
- if (step === "custom" && chosenBackend && chosenBackend !== "agy") {
213
+ if (step === "custom" && chosenBackend) {
214
+ const label = chosenBackend === "agy" ? "Agy" : EXTERNAL_BACKENDS[chosenBackend].label;
200
215
  return [
201
- `${EXTERNAL_BACKENDS[chosenBackend].label} model ID:${chosenBackend === "pi" ? " <provider>/<id>" : ""}`,
216
+ `${label} model ID:${chosenBackend === "pi" ? " <provider>/<id>" : ""}`,
202
217
  ...input.render(width),
203
218
  ...(customError ? [truncateToWidth(theme.fg("warning", ` ${customError}`), width)] : []),
204
219
  "",
@@ -269,9 +284,9 @@ export function createConfigModal(
269
284
  effortItem.currentValue = effortDisplay(def, defaultBackend);
270
285
  effortItem.values = isExternalBackend(defaultBackend)
271
286
  ? ["default", ...EXTERNAL_BACKENDS[defaultBackend].efforts]
272
- : def.family?.efforts.length
273
- ? [...def.family.efforts]
274
- : undefined;
287
+ : def.family
288
+ ? (def.family.efforts.length ? [...def.family.efforts] : undefined)
289
+ : ["default", ...AGY_EFFORTS];
275
290
  modeItem.currentValue = settings.mode;
276
291
  showTurnsItem.currentValue = String(settings.showTurns);
277
292
  showTurnsItem.values = showTurnsValues(settings.showTurns);
@@ -290,9 +305,9 @@ export function createConfigModal(
290
305
  rows.effort.values =
291
306
  backend in EXTERNAL_BACKENDS
292
307
  ? ["default", ...EXTERNAL_BACKENDS[backend as ExternalBackend].efforts]
293
- : resolved.family?.efforts.length
294
- ? [...resolved.family.efforts]
295
- : undefined;
308
+ : resolved.family
309
+ ? (resolved.family.efforts.length ? [...resolved.family.efforts] : undefined)
310
+ : ["default", ...AGY_EFFORTS];
296
311
  }
297
312
  }
298
313
  refresh();
package/src/doctor.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { mkdtemp, rm } from "node:fs/promises";
2
- import { tmpdir } from "node:os";
1
+ import { mkdtemp, readFile, rm } from "node:fs/promises";
2
+ import { homedir, tmpdir } from "node:os";
3
3
  import { join } from "node:path";
4
4
  import {
5
5
  getAgentDir,
@@ -29,7 +29,9 @@ import {
29
29
  type AgyModelFamily,
30
30
  type BackendName,
31
31
  type BroSettings,
32
+ type CodexModelChoice,
32
33
  type PiModelChoice,
34
+ AGY_EFFORTS,
33
35
  CAPABILITIES,
34
36
  CAPABILITY_LABELS,
35
37
  EFFORTS,
@@ -40,6 +42,7 @@ import {
40
42
  capabilityPair,
41
43
  readPreferences,
42
44
  readSettings,
45
+ readSettingsForConfig,
43
46
  resolveCapabilitySettings,
44
47
  resolveModelEffort,
45
48
  toPiModelChoices,
@@ -70,20 +73,22 @@ export function formatAgyUsage(value: unknown): string {
70
73
  }
71
74
 
72
75
  export function parseAgyModels(output: string): AgyModelFamily[] {
73
- // ponytail: Agy 1.1.13 exposes a tab-separated variant list; use structured catalog data when available here.
76
+ // ponytail: Agy exposes a tab-separated variant list; group dynamically by effort suffix without hard-coding model names.
74
77
  const families = new Map<string, AgyModelFamily>();
75
78
  for (const line of output.split(/\r?\n/)) {
76
79
  const [rawId, ...rawLabel] = line.split("\t");
77
80
  if (!rawId?.trim() || !rawLabel.length) continue;
78
81
  const id = rawId.trim();
79
82
  const label = rawLabel.join(" ").trim();
80
- const effort = (["low", "medium", "high"] as const).find(
81
- (value) => id.endsWith(`-${value}`) && label.endsWith(`(${value[0].toUpperCase()}${value.slice(1)})`),
82
- );
83
+ const effortMatch = /\s+\((Low|Medium|High|XHigh|Max)\)$/i.exec(label);
84
+ const matchedEffort = effortMatch?.[1]?.toLowerCase() as AgyEffort | undefined;
85
+ const effort = matchedEffort && AGY_EFFORTS.includes(matchedEffort) && id.endsWith(`-${matchedEffort}`)
86
+ ? matchedEffort
87
+ : undefined;
83
88
  const familyId = effort ? id.slice(0, -effort.length - 1) : id;
84
89
  const family = families.get(familyId) ?? {
85
90
  id: familyId,
86
- label: effort ? label.replace(/\s+\((Low|Medium|High)\)$/, "") : label,
91
+ label: effort ? label.replace(/\s+\((Low|Medium|High|XHigh|Max)\)$/i, "") : label,
87
92
  efforts: [],
88
93
  variants: [],
89
94
  };
@@ -108,6 +113,43 @@ export async function listAgyModels(pi: ExtensionAPI, signal?: AbortSignal): Pro
108
113
  }
109
114
  }
110
115
 
116
+ export function parseCodexModelsCache(raw: string): CodexModelChoice[] {
117
+ const data = JSON.parse(raw) as unknown;
118
+ if (!data || typeof data !== "object" || !Array.isArray((data as { models?: unknown }).models)) {
119
+ throw new Error("Unexpected Codex models_cache.json format.");
120
+ }
121
+ const seen = new Set<string>();
122
+ const models: CodexModelChoice[] = [];
123
+ for (const item of (data as { models: unknown[] }).models) {
124
+ if (!item || typeof item !== "object") continue;
125
+ const record = item as { slug?: unknown; display_name?: unknown; visibility?: unknown };
126
+ if (record.visibility === "hide") continue;
127
+ if (typeof record.slug !== "string" || !record.slug.trim()) continue;
128
+ const value = record.slug.trim();
129
+ if (seen.has(value)) continue;
130
+ seen.add(value);
131
+ const label = typeof record.display_name === "string" && record.display_name.trim()
132
+ ? record.display_name.trim()
133
+ : value;
134
+ models.push({ value, label });
135
+ }
136
+ return models;
137
+ }
138
+
139
+ /** Reads Codex's local models_cache.json (respecting CODEX_HOME). Returns [] when absent so custom model IDs still work. */
140
+ export async function listCodexModels(codexHome?: string): Promise<CodexModelChoice[]> {
141
+ const base = codexHome ?? process.env.CODEX_HOME ?? join(homedir(), ".codex");
142
+ const file = join(base, "models_cache.json");
143
+ let raw: string;
144
+ try {
145
+ raw = await readFile(file, "utf8");
146
+ } catch (error) {
147
+ if ((error as NodeJS.ErrnoException).code === "ENOENT") return [];
148
+ throw error;
149
+ }
150
+ return parseCodexModelsCache(raw);
151
+ }
152
+
111
153
  // The Pi backend's selectable models: the configured scoped models (enabledModels) when present,
112
154
  // else every model with configured auth. Physical models only -- a virtual model routes elsewhere
113
155
  // and cannot be driven as a standalone in-process session. This never makes a model request.
@@ -304,7 +346,7 @@ export async function doctorReport(pi: ExtensionAPI, ctx: ExtensionCommandContex
304
346
  fail("Preferences", error);
305
347
  }
306
348
 
307
- // Probe only the backends some feature actually selects: a Claude/Grok/Codex/Muse-only setup never
349
+ // Probe only the backends some feature actually selects: a Claude/Codex-only setup never
308
350
  // requires Agy to be installed, and vice versa.
309
351
  const backendInUse = (backend: BackendName) => settings
310
352
  ? CAPABILITIES.some(capability => capabilityBackend(settings, capability) === backend)
@@ -344,9 +386,8 @@ export async function doctorReport(pi: ExtensionAPI, ctx: ExtensionCommandContex
344
386
  pass("Agy", "not probed — no feature selects the Agy backend");
345
387
  }
346
388
 
347
- // These CLIs share a version probe; only Claude and Codex have a supported auth probe.
348
- // Grok and Muse must still say "unverified" rather than implying login or connectivity.
349
- for (const backend of ["claude", "grok", "codex", "muse"] as const) {
389
+ // Claude and Codex share a version probe and each has a supported auth probe.
390
+ for (const backend of ["claude", "codex"] as const) {
350
391
  const label = EXTERNAL_BACKENDS[backend].label;
351
392
  if (!backendInUse(backend)) {
352
393
  pass(label, `not probed — no feature selects the ${label} backend`);
@@ -358,15 +399,11 @@ export async function doctorReport(pi: ExtensionAPI, ctx: ExtensionCommandContex
358
399
  if (signal.aborted) throw error;
359
400
  fail(label, error);
360
401
  }
361
- if (backend === "claude" || backend === "codex") {
362
- try {
363
- pass(`${label} auth`, await (backend === "claude" ? checkClaudeAuth(pi, signal) : checkCodexAuth(pi, signal, ctx.cwd)));
364
- } catch (error) {
365
- if (signal.aborted) throw error;
366
- fail(`${label} auth`, error);
367
- }
368
- } else {
369
- pass(`${label} auth`, "unverified — no auth probe exists (version does not imply auth or connectivity)");
402
+ try {
403
+ pass(`${label} auth`, await (backend === "claude" ? checkClaudeAuth(pi, signal) : checkCodexAuth(pi, signal, ctx.cwd)));
404
+ } catch (error) {
405
+ if (signal.aborted) throw error;
406
+ fail(`${label} auth`, error);
370
407
  }
371
408
  }
372
409
 
@@ -515,12 +552,8 @@ export async function doctorReport(pi: ExtensionAPI, ctx: ExtensionCommandContex
515
552
  }
516
553
  if (settings && capabilityBackend(settings, "advisor") === "claude") {
517
554
  pass("Advisor compatibility", "Claude backend — no Agy version floor applies");
518
- } else if (settings && capabilityBackend(settings, "advisor") === "grok") {
519
- pass("Advisor compatibility", "Grok backend — no Agy version floor applies; auth/connectivity unverified (no probe)");
520
555
  } else if (settings && capabilityBackend(settings, "advisor") === "codex") {
521
556
  pass("Advisor compatibility", "Codex backend — no Agy version floor applies");
522
- } else if (settings && capabilityBackend(settings, "advisor") === "muse") {
523
- pass("Advisor compatibility", "Muse backend — no Agy version floor applies; auth/connectivity unverified (no probe)");
524
557
  } else if (settings && capabilityBackend(settings, "advisor") === "pi") {
525
558
  pass("Advisor compatibility", "Pi backend — runs in-process; no Agy version floor or CLI probe applies");
526
559
  } else if (agyVersion && advisorAgyCompatible(agyVersion)) pass("Advisor compatibility", ADVISOR_COMPATIBILITY);
@@ -529,7 +562,7 @@ export async function doctorReport(pi: ExtensionAPI, ctx: ExtensionCommandContex
529
562
  return `# Bro doctor\n\n${lines.join("\n")}\n\n**${failed ? "Bro needs attention." : "Bro is ready."}**\n\n${
530
563
  failed
531
564
  ? "Fix the failed items, then press **R** to check again."
532
- : "No assistant response was sent and no model turn was run. Version/auth checks do not imply connectivity (Grok and Muse auth are unverified — no probe exists)."
565
+ : "No assistant response was sent and no model turn was run. Version/auth checks do not imply connectivity."
533
566
  }`;
534
567
  }
535
568
 
@@ -544,7 +577,7 @@ export async function showBroConfigModal(ctx: ExtensionCommandContext, pi: Exten
544
577
  // Even invalid settings must not prevent access to Doctor. The placeholder is navigation-only:
545
578
  // every editable page re-reads the actual settings and refuses to edit on failure.
546
579
  let current: BroSettings;
547
- try { current = await readSettings(); }
580
+ try { current = (await readSettingsForConfig()).settings; }
548
581
  catch (error) {
549
582
  ctx.ui.notify("Settings unavailable: "+errorMessage(error)+". Global > Doctor can diagnose.", "warning");
550
583
  current = { backend:"agy",model:"(unavailable)",effort:"default",mode:"balanced",showTurns:1,overrides:{} };
@@ -585,7 +618,11 @@ export async function showBroConfigModal(ctx: ExtensionCommandContext, pi: Exten
585
618
  // Catalog discovery is needed only when an editable settings page is opened, not on
586
619
  // every navigation or diagnostic visit. Keep independent Agy/Pi failure handling.
587
620
  let settings:BroSettings;
588
- try { settings = await readSettings(); }
621
+ try {
622
+ const loaded = await readSettingsForConfig();
623
+ settings = loaded.settings;
624
+ if (loaded.notice) ctx.ui.notify(loaded.notice, "warning");
625
+ }
589
626
  catch (error) { ctx.ui.notify(withDoctor(error),"error"); continue; }
590
627
  let families:AgyModelFamily[]=[];
591
628
  try { families=await listAgyModels(pi); }
@@ -596,8 +633,11 @@ export async function showBroConfigModal(ctx: ExtensionCommandContext, pi: Exten
596
633
  piModels=catalog.models;
597
634
  for(const diagnostic of catalog.diagnostics) ctx.ui.notify("Pi scoped models: "+diagnostic,"warning");
598
635
  } catch(error) { ctx.ui.notify("Pi catalog unavailable: "+errorMessage(error),"warning"); }
636
+ let codexModels:CodexModelChoice[]=[];
637
+ try { codexModels=await listCodexModels(); }
638
+ catch(error) { ctx.ui.notify("Codex catalog unavailable: "+errorMessage(error),"warning"); }
599
639
  await openBroOverlay<void>(
600
- ctx,createConfigModal(settings,families,writeSettings,piModels,selected.page),{mouse:true}
640
+ ctx,createConfigModal(settings,families,writeSettings,piModels,selected.page,codexModels),{mouse:true}
601
641
  );
602
642
  }
603
643
  }
@@ -395,7 +395,7 @@ These are needs, not modes. Copied text does not enter Pi until you paste and su
395
395
  - \`/bro guided-review <PR number or URL>\` — assess captured PR code in local interactive Pi (requires Git and authenticated gh).
396
396
  - Reviews save automatically. Reopen without a model call; bare \`/bro guided-review\` lists saved reviews.\n- \`/bro guided-review delete [PR number or URL]\` — delete one local saved review with confirmation; Overview also offers Delete review.
397
397
  - Enter opens items or activates focused actions. Tab changes focus; Esc goes back, then closes from Contents. Close saves; Stop and close cancels active work first.
398
- - Copy finding goes to the clipboard, not GitHub. Regenerate reuses captured source. For untrusted PRs, choose file-only Claude/Muse/Pi; Codex/Grok offer sandboxed shell, while Agy may write captured files. Bro warns when shell is allowed. See docs/features/guided-review.md.
398
+ - Copy finding goes to the clipboard, not GitHub. Regenerate reuses captured source. For untrusted PRs, choose file-only Claude/Pi; Codex offers sandboxed shell, while Agy may write captured files. Bro warns when shell is allowed. See docs/features/guided-review.md.
399
399
 
400
400
  ## Elevate
401
401
 
package/src/grill.ts CHANGED
@@ -45,7 +45,7 @@ export async function openGrillModal(
45
45
  return [conversation, ending].filter(Boolean).join("\n\n---\n\n")
46
46
  || "Tell Bro what you want to be grilled on. It can be a proposal or an open question.";
47
47
  };
48
- const refreshHeader = () => modal.setCustomMode(`${thread.depth} · ${thread.fullAccess ? "FULL (prompt-only no-edits)" : activeBackend === "agy" ? "Agy (writes possible)" : ["claude", "muse", "pi"].includes(activeBackend) ? "File-only tools" : "Read-only sandbox"}`);
48
+ const refreshHeader = () => modal.setCustomMode(`${thread.depth} · ${thread.fullAccess ? "FULL (prompt-only no-edits)" : activeBackend === "agy" ? "Agy (writes possible)" : ["claude", "pi"].includes(activeBackend) ? "File-only tools" : "Read-only sandbox"}`);
49
49
  const saveDraft = () => {
50
50
  const draft = modal.getComposerText();
51
51
  if (draft.trim()) thread.draft = draft;
@@ -131,10 +131,6 @@ export function rememberBackendNotice(backend: string): string {
131
131
  return "Claude uses the restricted explain path: disabled tools, strict empty MCP config, no session persistence and a temporary working directory.";
132
132
  case "pi":
133
133
  return "Pi uses a fresh isolated SDK session with no tools, extensions, skills or project context files. It runs the configured physical Pi model.";
134
- case "muse":
135
- return "Muse runs with write and shell actions disabled and approval disabled, from a temporary working directory. Other available capabilities may differ by Muse version.";
136
- case "grok":
137
- return "Grok's restricted explain path uses an advisory instruction, but its CLI runs with the sandbox off and permissions bypassed. This is not a technical tool or write restriction.";
138
134
  default:
139
135
  return "Uses this backend's existing restricted explain execution path; see /bro doctor and backend-specific permissions. No stronger guarantee is implied.";
140
136
  }