pi-bro 0.36.2 → 0.36.3

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
@@ -2,6 +2,14 @@
2
2
 
3
3
  All notable changes to pi-bro are documented here.
4
4
 
5
+ ## [0.36.3] - 2026-11-10
6
+
7
+ ### Improved
8
+
9
+ - Add simple, live elapsed-time hints for Grill Me interviews and decision briefs, Remember Me proposal drafting, Elevate discovery and rewrites, and Simplify/Show. The shared result modal also shows time for other long-running tasks.
10
+ - Status distinguishes preparation, waiting and receiving output when known. It never guesses completion or displays hidden reasoning or raw tool output.
11
+ - Stop status timers on completion and cancellation; do not store progress with replies, saved memories, or clipboard output. Add quiet-backend, cleanup and constrained-terminal regression coverage.
12
+
5
13
  ## [0.36.2] - 2026-11-10
6
14
 
7
15
  ### Improved
package/docs/elevate.md CHANGED
@@ -41,6 +41,8 @@ The **Context: Messages** button toggles to **Context: Full**. Use Tab to focus
41
41
  1. **Discover:** “Given my objective, what would a skilled expert know, question, investigate, or test that I haven't accounted for?” Bro looks across **altitude** (right problem), **depth** (evidence, methods, tests), and **range** (useful ideas from other fields). It offers up to **five** non-overlapping suggestions, with a reason and an expert action for each. It can also report **zero** suggestions.
42
42
  2. **Upgrade:** “Rewrite my request using only the insights I approve. Keep my outcome, constraints, and scope. Improve the quality of the work, not the amount of work.” Bro returns the improved assignment for **you to review**.
43
43
 
44
+ Discovery and rewrite show a live elapsed-time status in the modal footer, even when the selected backend has not begun replying. The footer is not part of the proposed assignment and clears on completion or cancellation.
45
+
44
46
  The flow is **Discover → Select → Upgrade → Copy**. It typically makes **two model calls** (discovery and rewrite); if Bro finds no useful changes, it makes only the discovery call and keeps the original request.
45
47
 
46
48
  ## Example: before and after
package/docs/grill-me.md CHANGED
@@ -47,6 +47,8 @@ The old `/finish`, `/copy-all`, `/insert`, `/insert-all`, `/insert-last-message`
47
47
 
48
48
  Grill Me uses the **BTW model/backend/effort** selection from `/bro config`, but has its own independent thread. The header shows depth and effective access; `/help` keeps the footer short. Full access and Agy write risks remain visible in the header even when another notice is shown.
49
49
 
50
+ While Bro works, the footer shows the current stage and elapsed seconds. When the backend reports tools, it shows only the tool name/type. The timer confirms the request is still pending, not that the backend is making progress. Progress disappears on completion or cancellation and never enters saved replies or copies.
51
+
50
52
  ## Access, privacy and limits
51
53
 
52
54
  - Inspection uses the Guided Review backend path in your current workspace. Claude, Muse and Pi have file-only tools. Codex and Grok have read-only sandboxes with shell access. **Agy inspection can still write project files.** No-edit prompts are not security controls.
@@ -37,6 +37,8 @@ Before the first model call, Bro identifies the selected model/backend, the capt
37
37
 
38
38
  Browsing and failed saves preserve the proposal. If the store changed after the proposal was reviewed, `/save` compares the original and current target (and related entries) and **does not save**. An explicit `/confirm-revision` approves against that exact new revision; if it changes again, another review is required. Durable drafts across restarts are not implemented.
39
39
 
40
+ During a draft or revision, the footer shows the current stage and elapsed seconds even if the model is quiet. It does not show the raw draft JSON, and progress is not saved as a memory. Elapsed time means the call remains pending, not that the model has made progress.
41
+
40
42
  Esc closes the modal and cancels an active model call. The draft conversation is not durable; **approved saved memories are durable**. Saved entries survive Pi restarts and project changes.
41
43
 
42
44
  ## Agent access
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-bro",
3
- "version": "0.36.2",
3
+ "version": "0.36.3",
4
4
  "description": "A sidekick for you and your Pi agent: plain-language explanations, side questions, diagrams, PR review and second opinions, without cluttering the agent's context.",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/src/backend.ts CHANGED
@@ -2,6 +2,7 @@ import { type ChildProcess, type SpawnOptions, spawn } from "node:child_process"
2
2
  import { mkdtemp, rm, writeFile } from "node:fs/promises";
3
3
  import { tmpdir } from "node:os";
4
4
  import { join } from "node:path";
5
+ import { stripVTControlCharacters } from "node:util";
5
6
  import { codexSubscriptionRouteProblem, isSubscriptionStatus, resolveCliChildAuth, type CliAuthBackend } from "./cli-auth.ts";
6
7
  import {
7
8
  createAgentSession,
@@ -60,15 +61,28 @@ export type BackendSelection =
60
61
  | { backend: "muse"; model: string; effort?: (typeof MUSE_EFFORTS)[number] }
61
62
  | { backend: "pi"; model: string; effort?: (typeof PI_EFFORTS)[number] };
62
63
  export type BackendContinuation = { id: string };
63
- export type BackendProgress = { kind: "text"; text: string } | { kind: "activity"; label: string; timestamp: number };
64
+ export type BackendProgress = { kind: "text"; text: string } | { kind: "activity"; label: string; timestamp: number; tool?: string };
64
65
  export type BackendOnProgress = (progress: BackendProgress) => void;
65
66
 
67
+ /** BTW reports a tool name/type, not a command, argument, or assistant message.
68
+ * All six adapters use this extraction before events cross into the UI. */
69
+ export function btwToolName(value: unknown): string | undefined {
70
+ if (typeof value !== "string") return undefined;
71
+ // Restrict to the initial identifier. Agy may supply "Read /path" (or
72
+ // "Read(/path)"); neither should expose the path in a status hint.
73
+ return /^[A-Za-z_][A-Za-z0-9_.-]*/.exec(
74
+ stripVTControlCharacters(value).replace(/[\u0000-\u001f\u007f-\u009f]/g, " ").trim(),
75
+ )?.[0];
76
+ }
77
+
66
78
  export type BackendRequest = {
67
79
  feature: BackendFeature;
68
80
  prompt: string;
69
81
  access: BackendAccess;
70
82
  cwd?: string; // required for workspace-full
71
83
  continuation?: BackendContinuation;
84
+ /** Opt-in tool-only activity for Grill on the review path; Guided Review stays unchanged. */
85
+ reportReviewTools?: boolean;
72
86
  };
73
87
 
74
88
  export type BackendOutcome =
@@ -252,8 +266,10 @@ export function parseBtwAgyLine(line: string): { delta?: string; result?: string
252
266
  throw new Error("Agy returned invalid streaming data.");
253
267
  }
254
268
  const conversationId = event.conversation_id ?? event.result?.conversation_id;
255
- if (event.event === "step_update" && typeof event.step_update?.tool_name === "string" && event.step_update.tool_name.trim()) {
256
- return { activity: event.step_update.tool_name.trim(), conversationId };
269
+ const stepType = event.step_update?.step_type;
270
+ const tool = stepType === "agent_response" || stepType === "assistant" ? undefined : btwToolName(event.step_update?.tool_name);
271
+ if (event.event === "step_update" && tool) {
272
+ return { activity: tool, conversationId };
257
273
  }
258
274
  if (event.event === "step_update" && event.step_update?.step_type === "agent_response" && typeof event.step_update.text_delta === "string") {
259
275
  return { delta: event.step_update.text_delta, conversationId };
@@ -393,7 +409,7 @@ async function executeArgvPrint(
393
409
  if (isBtw) {
394
410
  const parsed = parseBtwAgyLine(line);
395
411
  if (parsed.conversationId) conversationId = parsed.conversationId;
396
- if (parsed.activity) onProgress?.({ kind: "activity", label: parsed.activity, timestamp: Date.now() });
412
+ if (parsed.activity) onProgress?.({ kind: "activity", label: parsed.activity, timestamp: Date.now(), tool: parsed.activity });
397
413
  if (parsed.error) throw new Error(parsed.error);
398
414
  if (parsed.delta) {
399
415
  partial += parsed.delta;
@@ -401,6 +417,11 @@ async function executeArgvPrint(
401
417
  }
402
418
  if (parsed.result !== undefined) final = parsed.result;
403
419
  } else {
420
+ // Review-backed Grill receives tool events without changing review access.
421
+ if (inspect && request.reportReviewTools) {
422
+ const tool = parseBtwAgyLine(line).activity;
423
+ if (tool) onProgress?.({ kind: "activity", label: tool, timestamp: Date.now(), tool });
424
+ }
404
425
  const parsed = parseExplainLine(line);
405
426
  if (parsed.delta) {
406
427
  partial += parsed.delta;
@@ -567,7 +588,12 @@ async function executeAdvisorStdin(
567
588
  throw new Error("Agy emitted invalid stream-json output.");
568
589
  }
569
590
  const activity = advisorActivityFromEvent(event);
570
- if (activity) onProgress?.({ kind: "activity", label: activity, timestamp: Date.now() });
591
+ if (activity) {
592
+ const step = event.step_update;
593
+ const tool = step?.step_type === "agent_response" || step?.step_type === "assistant"
594
+ ? undefined : btwToolName(step?.tool_name);
595
+ onProgress?.({ kind: "activity", label: activity, timestamp: Date.now(), ...(tool ? { tool } : {}) });
596
+ }
571
597
  if (event.event !== "result") return;
572
598
  sawTerminal = true;
573
599
  const result = event.result;
@@ -873,17 +899,18 @@ async function executeClaude(
873
899
  onProgress?.({ kind: "text", text: partial });
874
900
  }
875
901
  }
876
- if ((isAdvisor || isBtw) && topLevel && event.type === "assistant" && Array.isArray(event.message?.content)) {
902
+ if ((isAdvisor || isBtw || (inspect && request.reportReviewTools)) && topLevel && event.type === "assistant" && Array.isArray(event.message?.content)) {
877
903
  for (const block of event.message.content as Array<{ type?: unknown; name?: unknown; text?: unknown }>) {
878
904
  if (attempt.causeOf()) break;
879
- if (isBtw && block?.type !== "tool_use") continue;
905
+ if ((isBtw || (inspect && request.reportReviewTools)) && block?.type !== "tool_use") continue;
906
+ const tool = block?.type === "tool_use" ? btwToolName(block.name) : undefined;
880
907
  const label =
881
908
  block?.type === "tool_use" && typeof block.name === "string"
882
- ? block.name.trim()
909
+ ? ((isBtw || (inspect && request.reportReviewTools)) ? tool : block.name.trim())
883
910
  : block?.type === "text" && typeof block.text === "string"
884
911
  ? block.text.split("\n").find((text) => text.trim())?.trim()
885
912
  : undefined;
886
- if (label) onProgress?.({ kind: "activity", label, timestamp: Date.now() });
913
+ if (label) onProgress?.({ kind: "activity", label, timestamp: Date.now(), ...(tool ? { tool } : {}) });
887
914
  }
888
915
  }
889
916
  if (event.type !== "result" || !topLevel) return;
@@ -1064,17 +1091,18 @@ async function executeGrok(
1064
1091
  }
1065
1092
  streamedSinceAssistant = false;
1066
1093
  }
1067
- if ((isAdvisor || isBtw) && event.type === "assistant" && Array.isArray(message?.content)) {
1094
+ if ((isAdvisor || isBtw || (inspect && request.reportReviewTools)) && event.type === "assistant" && Array.isArray(message?.content)) {
1068
1095
  for (const block of message.content as Array<{ type?: unknown; name?: unknown; text?: unknown }>) {
1069
1096
  if (attempt.causeOf()) break;
1070
- if (isBtw && block?.type !== "tool_use") continue;
1097
+ if ((isBtw || (inspect && request.reportReviewTools)) && block?.type !== "tool_use") continue;
1098
+ const tool = block?.type === "tool_use" ? btwToolName(block.name) : undefined;
1071
1099
  const label =
1072
1100
  block?.type === "tool_use" && typeof block.name === "string"
1073
- ? block.name.trim()
1101
+ ? ((isBtw || (inspect && request.reportReviewTools)) ? tool : block.name.trim())
1074
1102
  : block?.type === "text" && typeof block.text === "string"
1075
1103
  ? block.text.split("\n").find((text) => text.trim())?.trim()
1076
1104
  : undefined;
1077
- if (label) onProgress?.({ kind: "activity", label, timestamp: Date.now() });
1105
+ if (label) onProgress?.({ kind: "activity", label, timestamp: Date.now(), ...(tool ? { tool } : {}) });
1078
1106
  }
1079
1107
  }
1080
1108
  if (event.type !== "result") return;
@@ -1263,11 +1291,10 @@ async function executeCodex(
1263
1291
  return;
1264
1292
  }
1265
1293
  const item = event.item;
1266
- if ((isAdvisor || isBtw) && (event.type === "item.started" || event.type === "item.completed")) {
1267
- const activity = isBtw
1268
- ? (typeof item?.type === "string" && item.type !== "agent_message" && item.type !== "reasoning" ? item.type : undefined)
1269
- : codexActivityFromEvent(event);
1270
- if (activity) onProgress?.({ kind: "activity", label: activity, timestamp: Date.now() });
1294
+ if ((isAdvisor || isBtw || (inspect && request.reportReviewTools)) && (event.type === "item.started" || event.type === "item.completed")) {
1295
+ const tool = item?.type !== "agent_message" && item?.type !== "reasoning" ? btwToolName(item?.type) : undefined;
1296
+ const activity = (isBtw || (inspect && request.reportReviewTools)) ? tool : codexActivityFromEvent(event);
1297
+ if (activity) onProgress?.({ kind: "activity", label: activity, timestamp: Date.now(), ...(tool ? { tool } : {}) });
1271
1298
  }
1272
1299
  if (event.type === "item.completed" && item?.type === "agent_message") {
1273
1300
  const text = extractCodexItemText(item);
@@ -1410,15 +1437,16 @@ async function executeMuse(
1410
1437
  const runStream = payload?.run_stream;
1411
1438
  const isRoot = rootRunId !== undefined && runStream?.kind === "run" && runStream.id === rootRunId;
1412
1439
 
1413
- if (isAdvisor || isBtw) {
1440
+ if (isAdvisor || isBtw || (inspect && request.reportReviewTools)) {
1414
1441
  if (envelope.payload_type === "tool.result") {
1415
1442
  const facts = payload?.correlation_facts as { tool_name?: unknown } | undefined;
1416
1443
  const toolName = typeof facts?.tool_name === "string" && facts.tool_name ? facts.tool_name : "tool";
1417
1444
  const candidate = [payload?.text, payload?.command, payload?.path, payload?.file_path, payload?.query]
1418
1445
  .find((v) => typeof v === "string" && v.trim());
1419
1446
  const preview = typeof candidate === "string" ? candidate.replace(/\s+/g, " ").trim() : "";
1420
- const label = isBtw ? toolName : `${toolName}${preview ? ` ${preview}` : ""}`;
1421
- onProgress?.({ kind: "activity", label, timestamp: Date.now() });
1447
+ const tool = btwToolName(toolName);
1448
+ const label = (isBtw || (inspect && request.reportReviewTools)) ? tool : `${toolName}${preview ? ` ${preview}` : ""}`;
1449
+ if (label) onProgress?.({ kind: "activity", label, timestamp: Date.now(), ...(tool ? { tool } : {}) });
1422
1450
  } else if (isAdvisor && envelope.payload_type === "task.lifecycle.status") {
1423
1451
  const event = payload?.event as { message?: unknown } | undefined;
1424
1452
  if (typeof event?.message === "string" && event.message.trim()) {
@@ -1877,7 +1905,9 @@ async function executePi(
1877
1905
  onProgress?.({ kind: "text", text });
1878
1906
  }
1879
1907
  } else if (event.type === "tool_execution_start" && onProgress) {
1880
- onProgress({ kind: "activity", label: event.toolName, timestamp: Date.now() });
1908
+ const tool = btwToolName(event.toolName);
1909
+ const label = request.feature === "btw" || (request.feature === "review" && request.reportReviewTools) ? tool : event.toolName;
1910
+ if (label) onProgress({ kind: "activity", label, timestamp: Date.now(), ...(tool ? { tool } : {}) });
1881
1911
  }
1882
1912
  });
1883
1913
 
package/src/btw.ts CHANGED
@@ -13,7 +13,7 @@ import {
13
13
  selectionLabel,
14
14
  } from "./settings.ts";
15
15
  import { captureShowTranscript } from "./show.ts";
16
- import { BRO_OVERLAY, broOverlayArea, formatNotice, modalHeight, openBroOverlay, renderFrame, Scroller, type Area, type NoticeTone, type Theme, type TuiLike } from "./modal-kit.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
17
  import { type BroMouseEvent, type BroMouseResult } from "./ui-capabilities.ts";
18
18
  import { errorMessage } from "./util.ts";
19
19
 
@@ -139,12 +139,15 @@ export async function runBtwTurn(
139
139
  options: { full: boolean; cwd: string; conversationId?: string },
140
140
  signal: AbortSignal,
141
141
  onProgress?: (event: BackendProgress) => void,
142
+ onRenderedText?: (text: string) => void,
142
143
  ): Promise<{ text: string; conversationId?: string; expiredContinuation?: true }> {
143
- const textProgress = textProgressThrottle(signal, (text) => onProgress?.({ kind: "text", text }));
144
+ // Phases use backend event order. Only expensive transcript rendering is delayed.
145
+ // Otherwise an old throttled text update can replace a newer tool status.
146
+ const textProgress = textProgressThrottle(signal, onRenderedText);
144
147
  const receive = (event: BackendProgress) => {
145
148
  if (signal.aborted) return;
146
- if (event.kind === "activity") onProgress?.(event);
147
- else textProgress.receive?.(event);
149
+ onProgress?.(event);
150
+ if (event.kind === "text") textProgress.receive?.(event);
148
151
  };
149
152
 
150
153
  try {
@@ -337,7 +340,13 @@ export class BtwModal implements Focusable {
337
340
  this.input.render(inner)[0] ?? "",
338
341
  ],
339
342
  notice: this.noticeText ? formatNotice(this.theme, this.noticeText, this.noticeTone) : undefined,
340
- hints: this.running ? `${this.progressText || "Bro is thinking…"} · Esc close (stops reply)` : (this.appearance.idleHint ?? "Enter send · Esc close"),
343
+ // A tool label may be long. Preserve the elapsed seconds and Esc
344
+ // on one line; shorten only the stage so transcript height stays put.
345
+ hints: this.running
346
+ ? runningHint(this.progressText || "Bro is thinking…", inner, [
347
+ " · Esc close (stops reply)", " · Esc close",
348
+ ])
349
+ : (this.appearance.idleHint ?? "Enter send · Esc close"),
341
350
  });
342
351
  }
343
352
 
@@ -424,21 +433,22 @@ export async function openBtwModal(
424
433
  const work: { pending?: BtwTurn; original?: BtwTurn } = { original: replaced };
425
434
  activeTurn = work;
426
435
  controller = turnController;
427
- const startedAt = Date.now();
436
+ let elapsedSeconds = 0;
428
437
  let stage = "Preparing request";
429
438
  const updateProgress = () => {
430
439
  if (!closed && controller === turnController && !turnController.signal.aborted)
431
- modal.setProgress(`${stage} · ${Math.floor((Date.now() - startedAt) / 1000)}s`);
440
+ modal.setProgress(`${stage} · ${elapsedSeconds}s`);
432
441
  };
433
- const timer = setInterval(updateProgress, 1000);
434
- timer.unref?.();
442
+ modal.setRunning(true);
443
+ const stopClock = startProgressClock(turnController.signal, seconds => {
444
+ elapsedSeconds = seconds;
445
+ updateProgress();
446
+ });
435
447
  const stopProgress = () => {
436
- clearInterval(timer);
448
+ stopClock();
437
449
  if (stopActiveProgress === stopProgress) stopActiveProgress = undefined;
438
450
  };
439
451
  stopActiveProgress = stopProgress;
440
- modal.setRunning(true);
441
- updateProgress();
442
452
 
443
453
  let settings: BroSettings;
444
454
  let preferences: string;
@@ -491,16 +501,15 @@ export async function openBtwModal(
491
501
  updateProgress();
492
502
  const showBackendProgress = (event: BackendProgress) => {
493
503
  if (closed || turnController.signal.aborted) return;
494
- if (event.kind === "activity") {
495
- // Tool names/types only, never commands, tool results, or hidden reasoning.
496
- const label = event.label.trim().split(/\s+/)[0]?.slice(0, 30);
497
- if (label) stage = `Last tool: ${label}`;
498
- } else {
499
- stage = "Receiving answer";
500
- pending.answer = event.text;
501
- modal.setText(transcript());
502
- }
503
- updateProgress();
504
+ // Activity labels are name/type-only at the backend boundary.
505
+ // Process every phase here, before the 75 ms text render throttle.
506
+ const next = event.kind === "activity" ? `Last tool: ${event.label}` : "Receiving answer";
507
+ if (next !== stage) { stage = next; updateProgress(); }
508
+ };
509
+ const showRenderedText = (partial: string) => {
510
+ if (closed || turnController.signal.aborted) return;
511
+ pending.answer = partial;
512
+ modal.setText(transcript());
504
513
  };
505
514
  let result = await runBtwTurn(
506
515
  buildBtwPrompt(context, question, { full, history, preferences }),
@@ -508,6 +517,7 @@ export async function openBtwModal(
508
517
  { full, cwd: ctx.cwd, conversationId },
509
518
  turnController.signal,
510
519
  showBackendProgress,
520
+ showRenderedText,
511
521
  );
512
522
  if (closed || turnController.signal.aborted) return;
513
523
  if (result.expiredContinuation) {
@@ -524,6 +534,7 @@ export async function openBtwModal(
524
534
  { full, cwd: ctx.cwd },
525
535
  turnController.signal,
526
536
  showBackendProgress,
537
+ showRenderedText,
527
538
  );
528
539
  result = reseeded;
529
540
  }
package/src/elevate.ts CHANGED
@@ -7,7 +7,7 @@ import {
7
7
  selectedFindings, stripElevateFence, captureElevateContext, isElevateContextOverflow,
8
8
  reduceElevateContext, elevateDisplayText, type ElevateContextMode, type ElevateDiscovery, type ElevateInput,
9
9
  } from "./elevate-engine.ts";
10
- import { BRO_OVERLAY, broOverlayArea, buttonLabels, delegateMouse, formatNotice, modalHeight, openBroOverlay, renderFrame, Scroller, wrapButtons, type Area, type Theme, type TuiLike } from "./modal-kit.ts";
10
+ import { BRO_OVERLAY, broOverlayArea, buttonLabels, delegateMouse, formatNotice, modalHeight, openBroOverlay, renderFrame, Scroller, startProgressClock, wrapButtons, type Area, type Theme, type TuiLike } from "./modal-kit.ts";
11
11
  import { readPreferences, readSettings, selectionForCapability, selectionLabel } from "./settings.ts";
12
12
  import { type BroMouseEvent, type BroMouseResult } from "./ui-capabilities.ts";
13
13
  import { errorMessage } from "./util.ts";
@@ -32,6 +32,7 @@ export class ElevateModal implements Focusable {
32
32
  private rawArea: Area | undefined;
33
33
  private editorArea: Area = { top: 0, left: 0, width: 0, height: 0 };
34
34
  private stage: Stage = "compose";
35
+ private progressText = "";
35
36
  private zone: Zone = "editor";
36
37
  private notice = "";
37
38
  private model = "";
@@ -97,6 +98,11 @@ export class ElevateModal implements Focusable {
97
98
  get currentSelection(): ReadonlySet<number> { return this.accepted; }
98
99
  setModel(value: string): void { this.model = value; if (!this.disposed) this.tui.requestRender(); }
99
100
  setNotice(value: string): void { if (!this.disposed) { this.notice = value; this.tui.requestRender(); } }
101
+ setProgress(value: string): void {
102
+ if (this.disposed || (this.stage !== "discovering" && this.stage !== "upgrading")) return;
103
+ this.progressText = value;
104
+ this.tui.requestRender();
105
+ }
100
106
 
101
107
  // Every state setter is inert after disposal: a late backend result must never touch an
102
108
  // unmounted component.
@@ -107,6 +113,7 @@ export class ElevateModal implements Focusable {
107
113
  this.discovery = undefined;
108
114
  this.accepted.clear();
109
115
  this.stage = "discovering";
116
+ this.progressText = "";
110
117
  // Waiting stages have no zones; focusing actions keeps Page/wheel scrolling reachable.
111
118
  this.zone = "actions";
112
119
  this.notice = "";
@@ -131,9 +138,9 @@ export class ElevateModal implements Focusable {
131
138
  this.syncEditorFocus();
132
139
  this.drawFromTop();
133
140
  }
134
- setUpgrading(): void { if (this.disposed) return; this.stage = "upgrading"; this.zone = "actions"; this.notice = ""; this.syncEditorFocus(); this.drawFromTop(); }
135
- setReady(value: string): void { if (this.disposed) return; this.stage = "ready"; this.revised = value.trim(); this.notice = ""; this.zone = "actions"; this.action = 0; this.syncEditorFocus(); this.drawFromTop(); }
136
- setFailed(message: string): void { if (this.disposed) return; this.stage = "failed"; this.notice = message; this.zone = "actions"; this.action = 0; this.syncEditorFocus(); this.drawFromTop(); }
141
+ setUpgrading(): void { if (this.disposed) return; this.stage = "upgrading"; this.progressText = ""; this.zone = "actions"; this.notice = ""; this.syncEditorFocus(); this.drawFromTop(); }
142
+ setReady(value: string): void { if (this.disposed) return; this.stage = "ready"; this.progressText = ""; this.revised = value.trim(); this.notice = ""; this.zone = "actions"; this.action = 0; this.syncEditorFocus(); this.drawFromTop(); }
143
+ setFailed(message: string): void { if (this.disposed) return; this.stage = "failed"; this.progressText = ""; this.notice = message; this.zone = "actions"; this.action = 0; this.syncEditorFocus(); this.drawFromTop(); }
137
144
  /** Back to the objective for editing, keeping what the user already wrote. */
138
145
  setCompose(objective?: string): void {
139
146
  if (this.disposed) return;
@@ -387,7 +394,7 @@ export class ElevateModal implements Focusable {
387
394
  : this.stage === "review" ? "↑↓ move · Space/Enter toggle · Tab actions · Ctrl+C copy · Esc cancel"
388
395
  : this.stage === "ready" ? "↑↓ scroll · Ctrl+C copy · Esc close"
389
396
  : this.stage === "failed" ? "Ctrl+C copy · Esc close"
390
- : "Thinking… · Esc cancel";
397
+ : `${this.progressText || "Thinking…"} · Esc cancel`;
391
398
  return renderFrame(this.theme, width, height, {
392
399
  header: () => this.theme.fg("accent", this.theme.bold("Bro · elevate"))
393
400
  + this.theme.fg("dim", ` · ${this.contextMode === "messages" ? "Messages" : "Full"}${this.contextReduced ? " (reduced)" : ""}`)
@@ -457,6 +464,7 @@ export async function openElevateModal(ctx: ExtensionCommandContext, request = "
457
464
  await openBroOverlay<void>(ctx, (tui, theme, _keybindings, done) => {
458
465
  let closed = false;
459
466
  let controller: AbortController | undefined;
467
+ let stopProgress: (() => void) | undefined;
460
468
  let original = initialObjective;
461
469
  let contextMessages = captureElevateContext(branch, "messages");
462
470
  let reduced = false;
@@ -468,6 +476,7 @@ export async function openElevateModal(ctx: ExtensionCommandContext, request = "
468
476
  const close = () => {
469
477
  if (closed) return;
470
478
  closed = true;
479
+ stopProgress?.();
471
480
  controller?.abort();
472
481
  done(undefined);
473
482
  };
@@ -496,18 +505,30 @@ export async function openElevateModal(ctx: ExtensionCommandContext, request = "
496
505
  controller = run;
497
506
  pending = { kind: "discover" };
498
507
  modal.setDiscovering(original);
508
+ let phase = "Preparing discovery";
509
+ const stop = startProgressClock(run.signal, seconds => {
510
+ if (!closed && controller === run) modal.setProgress(`${phase} · ${seconds}s`);
511
+ });
512
+ stopProgress = stop;
499
513
  try {
500
514
  const [settings, preferences] = await Promise.all([readSettings(), readPreferences()]);
501
515
  if (closed || run.signal.aborted) return;
502
516
  input.preferences = preferences;
503
517
  const selection = selectionForCapability(settings, "btw");
504
518
  modal.setModel(selectionLabel(selection));
505
- const raw = await runBackendText(buildElevateDiscoveryPrompt(input), selection, run.signal);
519
+ phase = "Discovering improvements";
520
+ const raw = await runBackendText(buildElevateDiscoveryPrompt(input), selection, run.signal, () => {
521
+ phase = "Receiving findings";
522
+ });
506
523
  if (closed || run.signal.aborted) return;
507
524
  modal.setDiscovery(parseElevateDiscovery(raw));
508
525
  } catch (error) {
509
526
  if (!closed && !run.signal.aborted) fail(error);
510
- } finally { if (controller === run) controller = undefined; }
527
+ } finally {
528
+ stop();
529
+ if (stopProgress === stop) stopProgress = undefined;
530
+ if (controller === run) controller = undefined;
531
+ }
511
532
  }
512
533
 
513
534
  async function upgrade(indexes: ReadonlySet<number>): Promise<void> {
@@ -519,6 +540,11 @@ export async function openElevateModal(ctx: ExtensionCommandContext, request = "
519
540
  input.context = contextText();
520
541
  reduceOnRetry = false;
521
542
  modal.setUpgrading();
543
+ let phase = "Preparing rewrite";
544
+ const stop = startProgressClock(run.signal, seconds => {
545
+ if (!closed && controller === run) modal.setProgress(`${phase} · ${seconds}s`);
546
+ });
547
+ stopProgress = stop;
522
548
  try {
523
549
  const settings = await readSettings();
524
550
  if (closed || run.signal.aborted) return;
@@ -531,7 +557,10 @@ export async function openElevateModal(ctx: ExtensionCommandContext, request = "
531
557
  const approved = selectedFindings(discovery, indexes);
532
558
  const selection = selectionForCapability(settings, "btw");
533
559
  modal.setModel(selectionLabel(selection));
534
- const revised = await runBackendText(buildElevateUpgradePrompt(input, approved), selection, run.signal);
560
+ phase = "Rewriting request";
561
+ const revised = await runBackendText(buildElevateUpgradePrompt(input, approved), selection, run.signal, () => {
562
+ phase = "Receiving revision";
563
+ });
535
564
  if (closed || run.signal.aborted) return;
536
565
  if (!revised.trim()) throw new Error("Bro returned an empty request. Retry.");
537
566
  // Validate after stripping: a fence containing only whitespace is still empty output, and
@@ -541,7 +570,11 @@ export async function openElevateModal(ctx: ExtensionCommandContext, request = "
541
570
  modal.setReady(cleaned);
542
571
  } catch (error) {
543
572
  if (!closed && !run.signal.aborted) fail(error);
544
- } finally { if (controller === run) controller = undefined; }
573
+ } finally {
574
+ stop();
575
+ if (stopProgress === stop) stopProgress = undefined;
576
+ if (controller === run) controller = undefined;
577
+ }
545
578
  }
546
579
 
547
580
  /** Retry whichever call failed, with the objective and approvals the user already chose. */
@@ -36,7 +36,7 @@ import {
36
36
  } from "./settings.ts";
37
37
  import { openShowHtml, stripShowDiagramFence } from "./show.ts";
38
38
  import type { BroSource } from "./sources.ts";
39
- import { BRO_OVERLAY, broOverlayArea, delegateMouse, formatNotice, modalHeight, openBroOverlay, renderFrame, Scroller, type Area, type NoticeTone, type Theme, type TuiLike } from "./modal-kit.ts";
39
+ import { BRO_OVERLAY, broOverlayArea, delegateMouse, formatNotice, modalHeight, openBroOverlay, renderFrame, runningHint, Scroller, startProgressClock, type Area, type NoticeTone, type Theme, type TuiLike } from "./modal-kit.ts";
40
40
  import { hasBroCustomUi, type BroMouseEvent, type BroMouseResult } from "./ui-capabilities.ts";
41
41
  import { errorMessage } from "./util.ts";
42
42
  import { latestCompletedAssistantText } from "./last-assistant.ts";
@@ -477,6 +477,7 @@ export class BroModal implements Focusable {
477
477
  private modelLabel = "";
478
478
  private noticeText = "";
479
479
  private noticeTone: NoticeTone = "info";
480
+ private progressText = "";
480
481
  private rawArea: Area | undefined;
481
482
  private readonly scroller = new Scroller(() => {
482
483
  this.noticeText = "";
@@ -528,6 +529,12 @@ export class BroModal implements Focusable {
528
529
  this.tui.requestRender();
529
530
  }
530
531
 
532
+ setProgress(value: string): void {
533
+ if (this.disposed || (this.kind !== "loading" && this.kind !== "streaming")) return;
534
+ this.progressText = value;
535
+ this.tui.requestRender();
536
+ }
537
+
531
538
  setHtmlPath(path: string): void {
532
539
  this.htmlPath = path;
533
540
  this.tui.requestRender();
@@ -563,6 +570,7 @@ export class BroModal implements Focusable {
563
570
  noticeTone: NoticeTone = "info",
564
571
  ): void {
565
572
  this.kind = kind;
573
+ if (kind !== "streaming") this.progressText = "";
566
574
  if (kind !== "result") this.htmlPath = "";
567
575
  this.rawText = rawText;
568
576
  this.copyable = copyable;
@@ -583,10 +591,17 @@ export class BroModal implements Focusable {
583
591
  return Boolean(this.modeLabel) && (this.kind === "loading" || this.kind === "streaming" || this.kind === "result");
584
592
  }
585
593
 
586
- private controls(): string {
594
+ private controls(innerWidth: number): string {
587
595
  const mode = this.canSwitchMode() ? " · M mode" : "";
588
- if (this.kind === "loading") return mode ? "M mode · Esc cancel" : "Esc cancel";
589
- if (this.kind === "streaming") return `Simplifying… · ↑/↓ scroll${mode} · Esc cancel`;
596
+ if (this.kind === "loading" || this.kind === "streaming") {
597
+ // The elapsed seconds and Esc matter more than a long stage name.
598
+ // Keep one hint row so the body never jumps as that stage changes.
599
+ const scroll = this.kind === "streaming" ? " · ↑/↓ scroll" : "";
600
+ const phase = this.progressText || (this.kind === "loading" ? "Working…" : "Receiving output…");
601
+ return runningHint(phase, innerWidth, [
602
+ `${scroll}${mode} · Esc cancel`, `${mode} · Esc cancel`, " · Esc cancel",
603
+ ], 12);
604
+ }
590
605
  if (this.kind === "result") {
591
606
  return `↑/↓ scroll · C copy${this.htmlPath ? " · O open diagram" : ""}${mode}${this.retryable ? ` · R ${this.retryLabel}` : ""} · Esc close`;
592
607
  }
@@ -608,7 +623,7 @@ export class BroModal implements Focusable {
608
623
  },
609
624
  body: (rows, innerWidth) => this.scroller.view(this.markdown.render(innerWidth), rows),
610
625
  notice: this.noticeText ? formatNotice(this.theme, this.noticeText, this.noticeTone) : undefined,
611
- hints: this.controls(),
626
+ hints: this.controls(Math.max(1, width - 2)),
612
627
  });
613
628
  }
614
629
 
@@ -700,6 +715,7 @@ export async function showBroModal(ctx: ExtensionCommandContext, options: BroMod
700
715
  (tui, theme, _keybindings, done) => {
701
716
  let closed = false;
702
717
  let controller: AbortController | undefined;
718
+ let stopProgress: (() => void) | undefined;
703
719
  let current = options.result;
704
720
  let inFlightMode: BroMode | undefined;
705
721
  let execute: (source?: BroSource, mode?: BroMode, notice?: string, noticeTone?: NoticeTone) => void = () => {};
@@ -707,6 +723,7 @@ export async function showBroModal(ctx: ExtensionCommandContext, options: BroMod
707
723
  const close = () => {
708
724
  if (closed) return;
709
725
  closed = true;
726
+ stopProgress?.();
710
727
  controller?.abort();
711
728
  done(undefined);
712
729
  };
@@ -718,6 +735,7 @@ export async function showBroModal(ctx: ExtensionCommandContext, options: BroMod
718
735
  () => execute(current?.source, current?.mode),
719
736
  () => {
720
737
  closed = true;
738
+ stopProgress?.();
721
739
  controller?.abort();
722
740
  },
723
741
  options.retryLabel ?? "simplify again",
@@ -726,6 +744,7 @@ export async function showBroModal(ctx: ExtensionCommandContext, options: BroMod
726
744
  const from = inFlightMode ?? current?.mode;
727
745
  if (!from || !current?.source || closed) return;
728
746
  const next = nextBroMode(from);
747
+ stopProgress?.();
729
748
  controller?.abort();
730
749
  controller = undefined;
731
750
  execute(current.source, next, `Mode: ${next} (not saved)`);
@@ -749,10 +768,17 @@ export async function showBroModal(ctx: ExtensionCommandContext, options: BroMod
749
768
  modal.setLoading(options.loadingText);
750
769
  modal.setMode(mode);
751
770
  modal.setPreferences(false);
771
+ const phase = options.loadingText ?? "Working";
772
+ const stop = startProgressClock(nextController.signal, seconds => {
773
+ if (!closed && controller === nextController) modal.setProgress(`${phase} · ${seconds}s`);
774
+ });
775
+ stopProgress = stop;
752
776
 
753
777
  void options
754
778
  .run(nextController.signal, source, (text) => {
755
779
  if (closed || nextController.signal.aborted || controller !== nextController) return;
780
+ // This callback may be a workflow stage (Architecture), not
781
+ // a streaming answer. The body owns the stage; keep the hint neutral.
756
782
  modal.setStreaming(text);
757
783
  }, mode)
758
784
  .then((result) => {
@@ -773,6 +799,8 @@ export async function showBroModal(ctx: ExtensionCommandContext, options: BroMod
773
799
  }
774
800
  })
775
801
  .finally(() => {
802
+ stop();
803
+ if (stopProgress === stop) stopProgress = undefined;
776
804
  if (controller === nextController) {
777
805
  controller = undefined;
778
806
  inFlightMode = undefined;
package/src/grill.ts CHANGED
@@ -8,7 +8,7 @@ import {
8
8
  } from "./grill-engine.ts";
9
9
  import { readPreferences, readSettings, selectionForCapability, selectionLabel, capabilityBackend } from "./settings.ts";
10
10
  import { captureShowTranscript } from "./show.ts";
11
- import { openBroOverlay } from "./modal-kit.ts";
11
+ import { openBroOverlay, startProgressClock } from "./modal-kit.ts";
12
12
  import { errorMessage } from "./util.ts";
13
13
 
14
14
  /**
@@ -27,6 +27,7 @@ export async function openGrillModal(
27
27
  (tui, theme, _keys, done) => {
28
28
  let closed = false;
29
29
  let controller: AbortController | undefined;
30
+ let stopProgress: (() => void) | undefined;
30
31
  let composerTouched = false;
31
32
  let pendingTurn: GrillTurn | undefined;
32
33
  let pendingSummary: string | undefined;
@@ -54,6 +55,7 @@ export async function openGrillModal(
54
55
  if (closed) return;
55
56
  closed = true;
56
57
  saveDraft();
58
+ stopProgress?.();
57
59
  if (!controller) options.onChange?.();
58
60
  controller?.abort();
59
61
  done(undefined);
@@ -61,6 +63,7 @@ export async function openGrillModal(
61
63
  const modal = new BtwModal(tui, theme, close, submit, () => {
62
64
  closed = true;
63
65
  saveDraft();
66
+ stopProgress?.();
64
67
  if (!controller) options.onChange?.();
65
68
  controller?.abort();
66
69
  }, {
@@ -132,6 +135,11 @@ export async function openGrillModal(
132
135
  const attempt = new AbortController();
133
136
  controller = attempt;
134
137
  modal.setRunning(true);
138
+ let phase = turn ? "Preparing next question" : "Preparing decision brief";
139
+ const stop = startProgressClock(attempt.signal, seconds => {
140
+ if (!closed && controller === attempt) modal.setProgress(`${phase} · ${seconds}s`);
141
+ });
142
+ stopProgress = stop;
135
143
  if (turn) pendingReply = operation.reply;
136
144
  try {
137
145
  const prepared = await prepareRun(attempt.signal);
@@ -151,10 +159,18 @@ export async function openGrillModal(
151
159
  modal.setText(transcript());
152
160
  modal.scrollToEnd();
153
161
  }
162
+ phase = turn ? "Waiting for next question" : "Waiting for decision brief";
154
163
  const outcome = await executeBackend(
155
- { ...grillExecution(thread.fullAccess), cwd: ctx.cwd, prompt },
164
+ { ...grillExecution(thread.fullAccess), ...(thread.fullAccess ? {} : { reportReviewTools: true }), cwd: ctx.cwd, prompt },
156
165
  selection, attempt.signal, (event) => {
157
- if (closed || attempt.signal.aborted || event.kind !== "text") return;
166
+ if (closed || attempt.signal.aborted) return;
167
+ if (event.kind === "activity") {
168
+ // Advisor activity may be prose; only structured tool events
169
+ // qualify as a tool status. The adapter owns name filtering.
170
+ if (event.tool) phase = `Last tool: ${event.tool}`;
171
+ return;
172
+ }
173
+ phase = turn ? "Receiving next question" : "Receiving decision brief";
158
174
  if (turn) pendingTurn!.answer = event.text;
159
175
  else pendingSummary = event.text;
160
176
  modal.setText(transcript());
@@ -178,6 +194,8 @@ export async function openGrillModal(
178
194
  if (turn && !modal.getComposerText().trim()) modal.setComposerText(operation.reply);
179
195
  }
180
196
  } finally {
197
+ stop();
198
+ if (stopProgress === stop) stopProgress = undefined;
181
199
  pendingTurn = undefined;
182
200
  pendingSummary = undefined;
183
201
  pendingReply = undefined;
package/src/modal-kit.ts CHANGED
@@ -16,6 +16,40 @@ export type TuiLike = {
16
16
 
17
17
  export type NoticeTone = "info" | "success" | "warning" | "error";
18
18
 
19
+ /** One-second UI heartbeat. It reports elapsed time, not proof of backend activity. */
20
+ export function startProgressClock(signal: AbortSignal, onTick: (seconds: number) => void): () => void {
21
+ const startedAt = Date.now();
22
+ let stopped = false;
23
+ const tick = () => {
24
+ if (!stopped && !signal.aborted) onTick(Math.floor((Date.now() - startedAt) / 1000));
25
+ };
26
+ const timer = setInterval(tick, 1000);
27
+ timer.unref?.();
28
+ const stop = () => {
29
+ if (stopped) return;
30
+ stopped = true;
31
+ clearInterval(timer);
32
+ signal.removeEventListener("abort", stop);
33
+ };
34
+ signal.addEventListener("abort", stop, { once: true });
35
+ if (signal.aborted) stop();
36
+ else tick();
37
+ return stop;
38
+ }
39
+
40
+ /** Keep elapsed time and cancellation visible while trimming only the phase.
41
+ * Each action variant must end with the same short cancel control, longest first. */
42
+ export function runningHint(progress: string, innerWidth: number, actions: readonly string[], minStageWidth = 11): string {
43
+ const match = /^(.*?)( · [0-9]+s)$/.exec(progress);
44
+ const stage = match ? match[1] : progress;
45
+ const elapsed = match ? match[2] : "";
46
+ const action = actions.find((value) =>
47
+ visibleWidth(value) + visibleWidth(elapsed) + minStageWidth <= innerWidth
48
+ ) ?? actions.at(-1) ?? "";
49
+ const stageWidth = Math.max(0, innerWidth - visibleWidth(elapsed) - visibleWidth(action));
50
+ return truncateToWidth(stage, stageWidth, "…") + elapsed + action;
51
+ }
52
+
19
53
  /**
20
54
  * Format a notice text with the semantic tone.
21
55
  * Strips raw terminal control characters from the message to prevent escape sequence injection.
package/src/remember.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  import type { ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
3
3
  import { execute as executeBackend } from "./backend.ts";
4
4
  import { BtwModal, formatBtwTranscript } from "./btw.ts";
5
- import { openBroOverlay } from "./modal-kit.ts";
5
+ import { openBroOverlay, startProgressClock } from "./modal-kit.ts";
6
6
  import { captureShowTranscript } from "./show.ts";
7
7
  import { readPreferences, readSettings, selectionForCapability, selectionLabel } from "./settings.ts";
8
8
  import {
@@ -43,6 +43,7 @@ export async function openRememberModal(ctx: ExtensionCommandContext, initial =
43
43
  await openBroOverlay<void>(ctx, (tui, theme, _keys, done) => {
44
44
  let closed = false;
45
45
  let controller: AbortController | undefined;
46
+ let stopProgress: (() => void) | undefined;
46
47
  let busy = false;
47
48
  let proposal: RememberProposal | undefined;
48
49
  let transcript: RememberTurn[] = [];
@@ -54,8 +55,8 @@ export async function openRememberModal(ctx: ExtensionCommandContext, initial =
54
55
  let browserText = "";
55
56
  let selectedBackend = openingSelection.backend ?? "agy";
56
57
  let selectedModel = selectionLabel(openingSelection);
57
- const close = () => { if (closed) return; closed = true; controller?.abort(); done(undefined); };
58
- const modal = new BtwModal(tui, theme, close, submit, () => { closed = true; controller?.abort(); }, {
58
+ const close = () => { if (closed) return; closed = true; stopProgress?.(); controller?.abort(); done(undefined); };
59
+ const modal = new BtwModal(tui, theme, close, submit, () => { closed = true; stopProgress?.(); controller?.abort(); }, {
59
60
  title:"Bro · remember-me", commands:"", inputLabel:"Your memory or correction",
60
61
  idleHint:"Enter discuss · /save approve · /context show · /help",
61
62
  });
@@ -165,6 +166,11 @@ export async function openRememberModal(ctx: ExtensionCommandContext, initial =
165
166
  busy=true;
166
167
  const attempt=new AbortController();
167
168
  controller=attempt; modal.setRunning(true);
169
+ let phase = "Reading saved memories";
170
+ const stop = startProgressClock(attempt.signal, seconds => {
171
+ if (!closed && controller === attempt) modal.setProgress(`${phase} · ${seconds}s`);
172
+ });
173
+ stopProgress = stop;
168
174
  try {
169
175
  store=await readMemoryStore();
170
176
  const [settings,preferences]=await Promise.all([readSettings(),readPreferences()]);
@@ -177,9 +183,12 @@ export async function openRememberModal(ctx: ExtensionCommandContext, initial =
177
183
  });
178
184
  const pending:RememberTurn={user:input,bro:"Drafting…"};
179
185
  transcript.push(pending); show();
186
+ phase = "Waiting for proposal";
180
187
  const result=await executeBackend({
181
188
  feature:"explain",access:"restricted",cwd:ctx.cwd,prompt
182
- },selection,attempt.signal);
189
+ },selection,attempt.signal,event=>{
190
+ if (!closed && !attempt.signal.aborted && event.kind === "text") phase = "Receiving proposal";
191
+ });
183
192
  if(closed||attempt.signal.aborted)return;
184
193
  if(result.status!=="success")throw new Error(result.message);
185
194
  const parsed=parseRememberResult(result.text);
@@ -206,6 +215,8 @@ export async function openRememberModal(ctx: ExtensionCommandContext, initial =
206
215
  show();
207
216
  }
208
217
  } finally {
218
+ stop();
219
+ if (stopProgress === stop) stopProgress = undefined;
209
220
  if(controller===attempt)controller=undefined;
210
221
  busy=false; if(!closed)modal.setRunning(false);
211
222
  }
@@ -5,7 +5,7 @@ import { copyToClipboard } from "@earendil-works/pi-coding-agent";
5
5
  import { matchesKey } from "@earendil-works/pi-tui";
6
6
  import { BtwModal } from "./btw.ts";
7
7
  import { latestAssistant, simplify, type BroResult } from "./explain-modal.ts";
8
- import { openBroOverlay } from "./modal-kit.ts";
8
+ import { openBroOverlay, startProgressClock } from "./modal-kit.ts";
9
9
  import { nextBroMode, type BroMode } from "./prompt.ts";
10
10
  import { readSettings } from "./settings.ts";
11
11
  import { extractDocumentText, extractWebPage, type BroSource } from "./sources.ts";
@@ -61,10 +61,11 @@ export async function openSimplifyWorkflow(
61
61
  await openBroOverlay<void>(ctx,(tui,theme,_keys,done)=>{
62
62
  let closed=false;
63
63
  let controller:AbortController|undefined;
64
+ let stopProgress:(()=>void)|undefined;
64
65
  let running=false;
65
- const close=()=>{if(closed)return; closed=true;state.draft=modal.getComposerText();controller?.abort();done(undefined);};
66
+ const close=()=>{if(closed)return; closed=true;state.draft=modal.getComposerText();stopProgress?.();controller?.abort();done(undefined);};
66
67
  const modal=new BtwModal(tui,theme,close,submit,()=>{
67
- closed=true;state.draft=modal.getComposerText();controller?.abort();
68
+ closed=true;state.draft=modal.getComposerText();stopProgress?.();controller?.abort();
68
69
  },{
69
70
  title:"Bro · simplify",
70
71
  commands:"",
@@ -85,14 +86,24 @@ export async function openSimplifyWorkflow(
85
86
  if(running||closed)return;
86
87
  const attempt=new AbortController();
87
88
  controller=attempt; running=true;
88
- modal.setRunning(true);modal.setNotice("Simplifying…");
89
+ modal.setRunning(true);modal.setNotice("");
90
+ let phase=request.kind==="url" ? "Fetching page" : request.kind==="file" ? "Reading file"
91
+ : request.kind==="latest" ? "Getting latest reply" : "Preparing source";
92
+ const stop=startProgressClock(attempt.signal,seconds=>{
93
+ if(!closed&&controller===attempt)modal.setProgress(`${phase} · ${seconds}s`);
94
+ });
95
+ stopProgress=stop;
89
96
  const previous=state.result,previousView=state.view;
90
97
  try {
91
98
  const source=await resolveSource(ctx,request,attempt.signal,retained);
92
99
  if(closed||attempt.signal.aborted)return;
93
100
  const currentSettings=await readSettings();
101
+ phase="Waiting for explanation";
94
102
  const result=await simplify(source.text,attempt.signal,currentSettings,text=>{
95
- if(!closed&&!attempt.signal.aborted)modal.setText(text);
103
+ if(!closed&&!attempt.signal.aborted){
104
+ phase="Receiving explanation";
105
+ modal.setText(text);
106
+ }
96
107
  },mode);
97
108
  if(closed||attempt.signal.aborted)return;
98
109
  state.result={source,...result};
@@ -111,6 +122,8 @@ export async function openSimplifyWorkflow(
111
122
  state.draft=submitted;
112
123
  }
113
124
  } finally {
125
+ stop();
126
+ if(stopProgress===stop)stopProgress=undefined;
114
127
  if(controller===attempt)controller=undefined;
115
128
  running=false;
116
129
  if(!closed)modal.setRunning(false);