pi-bro 0.37.1 → 0.38.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/bro.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { existsSync } from "node:fs";
1
2
  import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
2
3
  import { ADVISOR_STEERING_FILE, ADVISOR_TOOL_NAME, registerAdvisorTool } from "./advisor.ts";
3
4
  import {
@@ -16,19 +17,16 @@ import { openCopyModal } from "./copy.ts";
16
17
  import { registerOverthink } from "./overthink.ts";
17
18
  import { openRememberModal } from "./remember.ts";
18
19
  import { openSimplifyWorkflow, type SimplifyState } from "./simplify-ui.ts";
20
+ import { parseSimplifyRequest, SIMPLIFY_INPUTS } from "./simplify-engine.ts";
19
21
  import { registerAboutUserTool } from "./remember-tool.ts";
20
22
  import { parseGrillArguments, type GrillThread } from "./grill-engine.ts";
21
23
  import {
22
- type BroResult,
23
- type ModalResult,
24
24
  helpText,
25
- latestAssistant,
26
25
  showAdvisorSteerModal,
27
26
  showBroModal,
28
27
  showPreferencesModal,
29
- simplify,
30
28
  } from "./explain-modal.ts";
31
- import { BRO_MODES, type BroMode, parseBroMode } from "./prompt.ts";
29
+ import { BRO_MODES, parseBroMode } from "./prompt.ts";
32
30
  import { openGuidedReview, stopGuidedReviews } from "./review-ui.ts";
33
31
  import {
34
32
  type BroSettings,
@@ -37,20 +35,9 @@ import {
37
35
  readSettings,
38
36
  writeSettings,
39
37
  } from "./settings.ts";
40
- import {
41
- captureShowTranscript,
42
- parseShowArguments,
43
- runShowExplanation,
44
- showDiagramPath,
45
- } from "./show.ts";
46
- import {
47
- type BroSource,
48
- isDocumentFile,
49
- looksLikeWebUrl,
50
- } from "./sources.ts";
51
38
  import { hasBroCustomUi } from "./ui-capabilities.ts";
52
- import { errorMessage, unquote, withDoctor } from "./util.ts";
53
- import { BTW_SESSION_ENTRY, GRILL_SESSION_ENTRY, SIMPLIFY_SESSION_ENTRY, LAST_RESULT_SESSION_ENTRY, restorePrivateBroState, privateSessionEntrySnapshots } from "./session-state.ts";
39
+ import { errorMessage, withDoctor } from "./util.ts";
40
+ import { BTW_SESSION_ENTRY, GRILL_SESSION_ENTRY, SIMPLIFY_SESSION_ENTRY, restorePrivateBroState } from "./session-state.ts";
54
41
 
55
42
  export * from "./util.ts";
56
43
  export * from "./ui-capabilities.ts";
@@ -77,14 +64,9 @@ export * from "./copy.ts";
77
64
 
78
65
  const COMMANDS = [
79
66
  { value: "architecture", label: "architecture", description: "Document this repository in docs/architecture/ with diagrams and an offline map" },
80
- { value: "simplify", label: "simplify", description: "Reopen the last Simplify screen without a new model call" },
67
+ { value: "simplify", label: "simplify", description: "Understand one source in plain words or as a diagram" },
81
68
  { value: "copy", label: "copy", description: "Edit, preview and copy the last assistant reply as Markdown — no model call" },
82
- { value: "text", label: "text", description: "Explain pasted text, or the latest reply when text is omitted" },
83
- { value: "file", label: "file", description: "Explain a local document" },
84
- { value: "url", label: "url", description: "Explain a public webpage" },
85
- { value: "open", label: "open", description: "Reopen the last explanation" },
86
69
  { value: "doctor", label: "doctor", description: "Check whether Bro is ready" },
87
- { value: "show", label: "show", description: "Need to see how recent turns fit together? Get a visual outline or diagram" },
88
70
  { value: "mode", label: "mode", description: "View or choose explanation mode (brief, balanced, faithful)" },
89
71
  { value: "preferences", label: "preferences", description: "Want Bro to follow your style? Edit saved response preferences" },
90
72
  { value: "guided-review", label: "guided-review", description: "Need to assess a PR? Get source-backed findings and saved private questions" },
@@ -99,16 +81,14 @@ const COMMANDS = [
99
81
  { value: "help", label: "help", description: "Learn what Bro does and what it can access" },
100
82
  ];
101
83
  const KNOWN_ACTIONS = new Set(COMMANDS.map((command) => command.value));
102
- /** Only capability-level commands appear by default; all existing commands remain discoverable by prefix. */
84
+ /** Top-level discovery lists Simplify once, not each source command. */
103
85
  export const FEATURED_BRO_COMMANDS = [
104
- "simplify","show","btw","guided-review","architecture","elevate","grill-me","remember-me","overthink","config",
86
+ "simplify", "btw", "guided-review", "architecture", "elevate", "grill-me", "remember-me", "overthink", "config",
105
87
  ] as const;
106
88
  const FEATURED_COMMANDS = new Set<string>(FEATURED_BRO_COMMANDS);
107
89
 
108
90
  export default async function bro(pi: ExtensionAPI) {
109
- let lastResult: ModalResult | undefined;
110
91
  let simplifyState: SimplifyState = {};
111
- let lastShowSteering: string | undefined;
112
92
  let btwThread: BtwThread | undefined;
113
93
  let grillThread: GrillThread | undefined;
114
94
  let savedSnapshots = new Map<string, string>();
@@ -121,17 +101,6 @@ export default async function bro(pi: ExtensionAPI) {
121
101
  pi.appendEntry(type, data);
122
102
  savedSnapshots.set(type, serialized);
123
103
  };
124
- const remember = (result: ModalResult, showSteering?: string) => {
125
- if (result.source) {
126
- lastResult = result;
127
- lastShowSteering = showSteering;
128
- appendChanged(LAST_RESULT_SESSION_ENTRY, { result, steering: showSteering });
129
- }
130
- };
131
- const saveSimplify = () => {
132
- if (!savedSnapshots.has(SIMPLIFY_SESSION_ENTRY) && !simplifyState.result && !simplifyState.draft) return;
133
- appendChanged(SIMPLIFY_SESSION_ENTRY, { state: simplifyState });
134
- };
135
104
  const saveBtw = () => {
136
105
  if (!btwThread) return;
137
106
  // Visiting an empty BTW modal does not need a disk entry.
@@ -146,11 +115,8 @@ export default async function bro(pi: ExtensionAPI) {
146
115
  appendChanged(GRILL_SESSION_ENTRY, { thread: grillThread });
147
116
  };
148
117
  const restore = (ctx: ExtensionContext) => {
149
- const branch = ctx.sessionManager.getBranch();
150
- const restored = restorePrivateBroState(branch);
151
- savedSnapshots = privateSessionEntrySnapshots(branch);
152
- lastResult = restored.lastResult;
153
- lastShowSteering = restored.lastShowSteering;
118
+ savedSnapshots = new Map();
119
+ const restored = restorePrivateBroState(ctx.sessionManager.getBranch(), savedSnapshots);
154
120
  simplifyState = restored.simplify;
155
121
  btwThread = restored.btw;
156
122
  grillThread = restored.grill;
@@ -174,9 +140,14 @@ export default async function bro(pi: ExtensionAPI) {
174
140
  pi.registerCommand("bro", {
175
141
  description: "Explain text, documents, and webpages; draw session turns; open a side conversation; configure Bro and the executor's advisor tool",
176
142
  getArgumentCompletions: (prefix) => {
177
- const normalized = prefix.trim().toLowerCase();
178
- const matches = COMMANDS.filter((command) =>
179
- normalized ? command.value.startsWith(normalized) : FEATURED_COMMANDS.has(command.value));
143
+ const normalized = prefix.trimStart().toLowerCase();
144
+ const nested = /^simplify\s+(\S*)$/.exec(normalized);
145
+ if (nested) {
146
+ const matches = SIMPLIFY_INPUTS.filter(input => input.startsWith(nested[1]!));
147
+ return matches.length ? matches.map(input => ({ value: `simplify ${input}`, label: input })) : null;
148
+ }
149
+ const matches = COMMANDS.filter(command =>
150
+ normalized.trim() ? command.value.startsWith(normalized.trim()) : FEATURED_COMMANDS.has(command.value));
180
151
  return matches.length ? matches : null;
181
152
  },
182
153
  handler: async (args, ctx) => {
@@ -185,49 +156,43 @@ export default async function bro(pi: ExtensionAPI) {
185
156
  const raw = args.trim();
186
157
  const normalized = raw.toLowerCase();
187
158
  const parts = normalized ? normalized.split(/\s+/) : [];
188
- let action = parts[0] ?? "";
189
- let value = raw.slice(raw.split(/\s+/, 1)[0]?.length ?? 0).trim();
159
+ const action = parts[0] ?? "";
160
+ const value = raw.slice(action.length).trim();
190
161
 
191
- // Removed commands must never fall through to a paid text explanation.
192
162
  if (action === "model" || action === "effort") {
193
- ctx.ui.notify(`/bro ${action} was removed. Use /bro config to choose the shared default and per-capability ${action}; use /bro text <text> to explain text.`, "warning");
163
+ ctx.ui.notify(`/bro ${action} was removed. Use /bro config to choose the shared default and per-capability ${action}.`, "warning");
194
164
  return;
195
165
  }
196
-
197
- // An unknown first word means the whole input is the source: route it by shape.
198
166
  if (action && !KNOWN_ACTIONS.has(action)) {
199
- const candidate = unquote(raw);
200
- const quoted = candidate !== raw;
201
- action = quoted || !/\s/.test(candidate)
202
- ? looksLikeWebUrl(candidate)
203
- ? "url"
204
- : (await isDocumentFile(candidate, ctx.cwd))
205
- ? "file"
206
- : "text"
207
- : "text";
208
- value = raw;
167
+ const replacement = action === "open" ? "/bro simplify"
168
+ : action === "text" && !value ? "/bro simplify latest"
169
+ : action === "text" ? "/bro simplify text <text>"
170
+ : action === "file" ? "/bro simplify file <path>"
171
+ : action === "url" ? "/bro simplify url <url>"
172
+ : action === "show" ? "/bro simplify show [n-turns] [query]" : undefined;
173
+ ctx.ui.notify(replacement ? `/bro ${action} moved. Use ${replacement}.`
174
+ : "Unknown Bro command. Use /bro help, or /bro simplify text <text> to explain pasted text.", "warning");
175
+ return;
209
176
  }
210
177
 
211
- // Source operations open the same single-purpose Simplify modal, not separate
212
- // top-level workflows. Old /bro text|file|url commands remain valid aliases.
213
- if (!action || action === "simplify" || action === "text" || action === "file" || action === "url") {
214
- if (action === "simplify" && value) {
215
- ctx.ui.notify("Use /bro simplify to reopen the last Simplify view; use /text, /file or /url inside it.", "warning");
216
- return;
217
- }
218
- if ((action === "file" || action === "url") && !value) {
219
- ctx.ui.notify(`Use /bro ${action} <${action === "file" ? "path" : "url"}>.`, "warning");
220
- return;
221
- }
222
- const initial = !action || action === "simplify"
223
- ? {kind:"resume" as const}
224
- : action === "text" && !value
225
- ? {kind:"latest" as const}
226
- : {kind:action as "text" | "file" | "url", input:value};
178
+ if (!action || action === "simplify") {
179
+ const input = value.split(/\s+/, 1)[0] ?? "";
180
+ const initial = input ? parseSimplifyRequest(input.toLowerCase(), value.slice(input.length).trim()) : undefined;
181
+ if (initial?.kind === "invalid") { ctx.ui.notify(initial.message, "warning"); return; }
182
+ const state = simplifyState;
183
+ const hadResult = Boolean(state.result);
184
+ const headlessRun = initial && !hasBroCustomUi(ctx);
227
185
  try {
228
- await openSimplifyWorkflow(ctx, simplifyState, initial);
229
- saveSimplify();
230
- if (simplifyState.result) remember(simplifyState.result);
186
+ await openSimplifyWorkflow(ctx, state, initial, initial ? (initial.kind === "latest" ? "/simplify" : `/${value}`) : undefined);
187
+ if (simplifyState === state && (savedSnapshots.has(SIMPLIFY_SESSION_ENTRY) || hadResult || state.result || state.draft)) {
188
+ appendChanged(SIMPLIFY_SESSION_ENTRY, { state });
189
+ if (headlessRun) {
190
+ const file = ctx.sessionManager.getSessionFile?.();
191
+ if (!file || !existsSync(file)) {
192
+ ctx.ui.notify("Simplify finished, but Pi has no saved session file. The result is only in memory. To keep headless results, reopen a saved Pi session before running Simplify.", "warning");
193
+ }
194
+ }
195
+ }
231
196
  } catch (error) { ctx.ui.notify(withDoctor(error), "error"); }
232
197
  return;
233
198
  }
@@ -239,44 +204,6 @@ export default async function bro(pi: ExtensionAPI) {
239
204
  return;
240
205
  }
241
206
 
242
- if (action === "show") {
243
- const { requested, steering, invalid } = parseShowArguments(value);
244
- if (invalid) {
245
- ctx.ui.notify("Use /bro show [n-turns] [query].", "warning");
246
- return;
247
- }
248
- const runShow = async (
249
- signal: AbortSignal,
250
- source?: BroSource,
251
- onProgress?: (text: string) => void,
252
- ): Promise<ModalResult> => {
253
- const captured =
254
- source ?? captureShowTranscript(ctx, requested ? Number(requested) : (await readSettings()).showTurns);
255
- if (!captured) {
256
- return { text: "**Nothing to show yet**\n\nThis session has no conversation turns to draw. Run something first, then press **R**." };
257
- }
258
- let result: Awaited<ReturnType<typeof runShowExplanation>>;
259
- try {
260
- result = await runShowExplanation(captured.text, steering, signal, await readSettings(), onProgress);
261
- } catch (error) {
262
- throw new Error(withDoctor(error));
263
- }
264
- const htmlPath = await showDiagramPath(result.text, (message) => ctx.ui.notify(message, "warning"));
265
- return { source: captured, ...result, ...(htmlPath ? { htmlPath } : {}) };
266
- };
267
- try {
268
- await showBroModal(ctx, {
269
- loadingText: "Drawing what happened…",
270
- retryLabel: "show again",
271
- run: runShow,
272
- onResult: (result) => remember(result, steering),
273
- });
274
- } catch (error) {
275
- ctx.ui.notify(withDoctor(error), "error");
276
- }
277
- return;
278
- }
279
-
280
207
  if (action === "doctor") {
281
208
  if (parts.length !== 1) {
282
209
  ctx.ui.notify("Use /bro doctor.", "warning");
@@ -468,71 +395,6 @@ export default async function bro(pi: ExtensionAPI) {
468
395
  await showBroModal(ctx, { text: helpText(settings, settingsError, preferences), kind: "help", copyable: true });
469
396
  return;
470
397
  }
471
-
472
- const run = async (
473
- signal: AbortSignal,
474
- source?: BroSource,
475
- onProgress?: (text: string) => void,
476
- mode?: BroMode,
477
- ): Promise<BroResult> => {
478
- let target = source ?? (action === "text" && value ? { text: value } : undefined);
479
- if (!target) {
480
- await ctx.waitForIdle();
481
- target = latestAssistant(ctx);
482
- }
483
- if (!target) throw new Error("No completed assistant response found.");
484
- try {
485
- const settings = await readSettings();
486
- return {
487
- source: target,
488
- ...(await simplify(target.text, signal, settings, onProgress, mode)),
489
- };
490
- } catch (error) {
491
- throw new Error(withDoctor(error));
492
- }
493
- };
494
-
495
- if (action === "open") {
496
- if (parts.length !== 1) {
497
- ctx.ui.notify("Use /bro open.", "warning");
498
- return;
499
- }
500
- if (!lastResult) {
501
- await showBroModal(ctx, {
502
- text: "# Nothing to open yet\n\nUse `/bro text <text>`, run `/bro text` (or `/simplify` inside `/bro`) after an assistant response, use `/bro file <path>`, use `/bro url <url>`, or run `/bro show` to draw recent turns.",
503
- kind: "empty",
504
- });
505
- return;
506
- }
507
-
508
- const steering = lastShowSteering;
509
- if (steering !== undefined) {
510
- // Temp files may have been cleaned by the OS or another Bro session.
511
- if (ctx.mode === "tui") lastResult.htmlPath = await showDiagramPath(lastResult.text, (message) => ctx.ui.notify(message, "warning"));
512
- }
513
- await showBroModal(ctx, {
514
- result: lastResult,
515
- loadingText: steering !== undefined ? "Drawing what happened…" : undefined,
516
- retryLabel: steering !== undefined ? "show again" : undefined,
517
- run: steering === undefined ? run : async (signal, source, onProgress) => {
518
- if (!source) throw new Error("No captured Show source.");
519
- const result = await runShowExplanation(source.text, steering, signal, await readSettings(), onProgress);
520
- const htmlPath = await showDiagramPath(result.text, (message) => ctx.ui.notify(message, "warning"));
521
- return { source, ...result, ...(htmlPath ? { htmlPath } : {}) };
522
- },
523
- onResult: (result) => remember(result, steering),
524
- });
525
- return;
526
- }
527
-
528
- try {
529
- await showBroModal(ctx, {
530
- run,
531
- onResult: remember,
532
- });
533
- } catch (error) {
534
- ctx.ui.notify(error instanceof Error ? error.message : String(error), "error");
535
- }
536
398
  },
537
399
  });
538
400
 
package/src/btw.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import type { ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
2
- import { copyToClipboard, getMarkdownTheme } from "@earendil-works/pi-coding-agent";
3
- import { Input, Markdown, matchesKey, wrapTextWithAnsi, type Focusable } from "@earendil-works/pi-tui";
2
+ import { copyToClipboard } from "@earendil-works/pi-coding-agent";
4
3
  import { execute as executeBackend, textProgressThrottle, type BackendProgress, type BackendSelection } from "./backend.ts";
5
4
  import { buildBtwPrompt } from "./prompt.ts";
6
5
  import {
@@ -13,8 +12,8 @@ import {
13
12
  selectionLabel,
14
13
  } from "./settings.ts";
15
14
  import { captureShowTranscript } from "./show.ts";
16
- import { BRO_OVERLAY, broOverlayArea, formatNotice, modalHeight, openBroOverlay, renderFrame, runningHint, Scroller, startProgressClock, type Area, type NoticeTone, type Theme, type TuiLike } from "./modal-kit.ts";
17
- import { type BroMouseEvent, type BroMouseResult } from "./ui-capabilities.ts";
15
+ import { openBroOverlay, startProgressClock } from "./modal-kit.ts";
16
+ import { ComposerModal } from "./composer-modal.ts";
18
17
  import { errorMessage } from "./util.ts";
19
18
 
20
19
  export const BTW_CONTEXT_TURNS = 8;
@@ -171,198 +170,6 @@ export async function runBtwTurn(
171
170
  }
172
171
  }
173
172
 
174
- export class BtwModal implements Focusable {
175
- private _focused = false;
176
- private readonly markdown = new Markdown("", 0, 0, getMarkdownTheme());
177
- private readonly input = new Input();
178
- private noticeText = "";
179
- private noticeTone: NoticeTone = "info";
180
- private rawArea: Area | undefined;
181
- // Follows the newest text until the reader scrolls up; scrolling back to the end follows again.
182
- private readonly scroller = new Scroller(
183
- () => {
184
- this.noticeText = "";
185
- this.tui.requestRender();
186
- },
187
- { followEnd: true },
188
- );
189
- private running = false;
190
- private progressText = "";
191
- private full = false;
192
- private model = "";
193
- private customMode = "";
194
- private disposed = false;
195
- onInput?: () => void;
196
- onKey?: (data: string) => boolean;
197
- private suggestions = "";
198
-
199
- setSuggestions(text: string): void {
200
- this.suggestions = text;
201
- this.tui.requestRender();
202
- }
203
-
204
- get focused(): boolean {
205
- return this._focused;
206
- }
207
-
208
- set focused(value: boolean) {
209
- this._focused = value;
210
- this.input.focused = value;
211
- }
212
-
213
- constructor(
214
- private readonly tui: TuiLike,
215
- private readonly theme: Theme,
216
- private readonly onClose: () => void,
217
- private readonly onSubmit: (value: string) => void,
218
- private readonly onDispose: () => void,
219
- private readonly appearance: { title?: string; commands?: string; inputLabel?: string; idleHint?: string } = {},
220
- ) {
221
- this.input.onSubmit = (value) => {
222
- if (!this.running) this.onSubmit(value);
223
- };
224
- }
225
-
226
- // Keeps the reader's place; the scroller clamps when the text shrinks (e.g. /clear).
227
- setText(text: string): void {
228
- this.markdown.setText(text);
229
- this.tui.requestRender();
230
- }
231
-
232
- /** Start at the top of a static or single-document view. */
233
- scrollToStart(): void {
234
- this.scroller.toStart();
235
- this.tui.requestRender();
236
- }
237
-
238
- /** Show the newest text and keep following it while a reply streams. */
239
- scrollToEnd(): void {
240
- this.scroller.toEnd();
241
- this.tui.requestRender();
242
- }
243
-
244
- get notice(): string {
245
- return this.noticeText;
246
- }
247
-
248
- set notice(notice: string) {
249
- this.setNotice(notice);
250
- }
251
-
252
- setNotice(notice: string, tone: NoticeTone = "info"): void {
253
- if (this.disposed) return;
254
- this.noticeText = notice;
255
- this.noticeTone = tone;
256
- this.tui.requestRender();
257
- }
258
-
259
- setRunning(running: boolean): void {
260
- this.running = running;
261
- if (!running) this.progressText = "";
262
- this.tui.requestRender();
263
- }
264
-
265
- /** Ephemeral in-flight status; never enters the thread or clipboard. */
266
- setProgress(text: string): void {
267
- if (this.disposed || !this.running) return;
268
- this.progressText = text;
269
- this.tui.requestRender();
270
- }
271
-
272
- setModel(model: string): void {
273
- this.model = model;
274
- this.tui.requestRender();
275
- }
276
-
277
- setFull(full: boolean): void {
278
- this.full = full;
279
- this.tui.requestRender();
280
- }
281
-
282
- /** Reuse the BTW modal for independent interview flows without sharing BTW state. */
283
- setCustomMode(label: string): void {
284
- this.customMode = label;
285
- this.tui.requestRender();
286
- }
287
-
288
- clearComposer(): void {
289
- this.input.setValue("");
290
- this.tui.requestRender();
291
- }
292
-
293
- getComposerText(): string {
294
- return this.input.getValue();
295
- }
296
-
297
- setComposerText(text: string): void {
298
- this.input.setValue(text);
299
- (this.input as unknown as { cursor: number }).cursor = text.length;
300
- this.tui.requestRender();
301
- }
302
-
303
- invalidate(): void {
304
- this.markdown.invalidate();
305
- this.input.invalidate();
306
- }
307
-
308
- handleMouse(event: BroMouseEvent): BroMouseResult {
309
- return this.scroller.handleMouse(event);
310
- }
311
-
312
- handleInput(data: string): void {
313
- if (this.onKey?.(data)) return;
314
- if (matchesKey(data, "escape")) {
315
- this.onClose();
316
- return;
317
- }
318
- if (this.scroller.handleKey(data, this.rawArea)) return;
319
- this.input.handleInput(data);
320
- this.onInput?.();
321
- this.tui.requestRender();
322
- }
323
-
324
- render(width: number): string[] {
325
- const inner = Math.max(1, width - 2);
326
- const height = modalHeight(this.tui, BRO_OVERLAY, 34);
327
- this.rawArea = broOverlayArea(this.tui, width, height);
328
- return renderFrame(this.theme, width, height, {
329
- header: () => {
330
- const scroll = this.scroller.indicator();
331
- const model = this.model ? this.theme.fg("dim", ` · ${this.model}`) : "";
332
- const mode = this.customMode
333
- ? this.theme.fg("dim", this.customMode)
334
- : this.theme.fg("dim", " · ") + (this.full ? this.theme.fg("accent", this.theme.bold(btwModeLabel(true))) : this.theme.fg("dim", btwModeLabel(false)));
335
- const title = this.theme.fg("accent", this.theme.bold(this.appearance.title ?? "Bro · btw"));
336
- // Keep Grill's access warning ahead of text the frame may truncate.
337
- const header = this.customMode ? `${mode} · ${title}${model}` : title + model + mode;
338
- return header + this.theme.fg("dim", scroll ? ` · ${scroll}` : "");
339
- },
340
- body: (rows, innerWidth) => this.scroller.view(this.markdown.render(innerWidth), rows),
341
- // The frame drops lines from the top when space runs out, so the composer goes last.
342
- footer: [
343
- ...(this.appearance.commands === "" ? [] : wrapTextWithAnsi(this.appearance.commands ?? "Commands: /mode · /copy · /copy-all · /clear · /retry · /help", inner)),
344
- ...(this.suggestions ? wrapTextWithAnsi(this.theme.fg("accent", this.suggestions), inner) : []),
345
- this.theme.fg("accent", this.theme.bold(this.appearance.inputLabel ?? "Your message to Bro")),
346
- this.input.render(inner)[0] ?? "",
347
- ],
348
- notice: this.noticeText ? formatNotice(this.theme, this.noticeText, this.noticeTone) : undefined,
349
- // A tool label may be long. Preserve the elapsed seconds and Esc
350
- // on one line; shorten only the stage so transcript height stays put.
351
- hints: this.running
352
- ? runningHint(this.progressText || "Bro is thinking…", inner, [
353
- " · Esc close (stops reply)", " · Esc close",
354
- ])
355
- : (this.appearance.idleHint ?? "Enter send · Esc close"),
356
- });
357
- }
358
-
359
- dispose(): void {
360
- if (this.disposed) return;
361
- this.disposed = true;
362
- this.onDispose();
363
- }
364
- }
365
-
366
173
  export async function openBtwModal(
367
174
  ctx: ExtensionCommandContext,
368
175
  options: { thread: BtwThread; initialQuestion?: string; onChange?: () => void },
@@ -418,7 +225,7 @@ export async function openBtwModal(
418
225
  done(undefined);
419
226
  };
420
227
 
421
- const modal = new BtwModal(tui, theme, close, submit, () => {
228
+ const modal = new ComposerModal(tui, theme, close, submit, () => {
422
229
  if (closed) return; // Close already saved and cleaned this thread.
423
230
  closed = true;
424
231
  saveDraft();
@@ -426,6 +233,10 @@ export async function openBtwModal(
426
233
  controller?.abort();
427
234
  discardUnfinished();
428
235
  options.onChange?.();
236
+ }, {
237
+ title: "Bro · btw",
238
+ commands: "Commands: /mode · /copy · /copy-all · /clear · /retry · /help",
239
+ inputLabel: "Your message to Bro",
429
240
  });
430
241
  modal.onInput = () => {
431
242
  composerTouched = true;
@@ -571,7 +382,7 @@ export async function openBtwModal(
571
382
 
572
383
  const toggleMode = () => {
573
384
  toggleBtwMode(thread);
574
- modal.setFull(thread.full);
385
+ modal.setTrailingMode(btwModeLabel(thread.full), thread.full);
575
386
  modal.setNotice(`Mode: ${btwModeLabel(thread.full)}`, "info");
576
387
  options.onChange?.();
577
388
  };
@@ -653,7 +464,7 @@ export async function openBtwModal(
653
464
  void runTurn(action.text);
654
465
  }
655
466
 
656
- modal.setFull(thread.full);
467
+ modal.setTrailingMode(btwModeLabel(thread.full), thread.full);
657
468
  modal.setModel(btwHeaderLabel(thread));
658
469
  modal.setText(transcript());
659
470
  modal.scrollToEnd();