pi-bro 0.36.1 → 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 +16 -0
- package/docs/elevate.md +2 -0
- package/docs/features/btw.md +6 -0
- package/docs/grill-me.md +2 -0
- package/docs/remember-me.md +2 -0
- package/package.json +1 -1
- package/src/backend.ts +58 -19
- package/src/btw.ts +71 -17
- package/src/elevate.ts +42 -9
- package/src/explain-modal.ts +33 -5
- package/src/grill.ts +21 -3
- package/src/modal-kit.ts +34 -0
- package/src/remember.ts +15 -4
- package/src/simplify-ui.ts +18 -5
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,22 @@
|
|
|
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
|
+
|
|
13
|
+
## [0.36.2] - 2026-11-10
|
|
14
|
+
|
|
15
|
+
### Improved
|
|
16
|
+
|
|
17
|
+
- `/bro btw` shows a live phase and elapsed time in its modal while a side question is running, including before the backend begins streaming text.
|
|
18
|
+
- When a backend reports tool use, BTW shows the last tool name/type without exposing commands, tool output or hidden reasoning. A quiet backend still updates the elapsed time every second.
|
|
19
|
+
- Progress hints stay out of saved threads and copies and clear on completion, errors and cancellation. Added offline UI/protocol checks.
|
|
20
|
+
|
|
5
21
|
## [0.36.1] - 2026-11-09
|
|
6
22
|
|
|
7
23
|
### Fixed
|
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/features/btw.md
CHANGED
|
@@ -43,6 +43,12 @@ asked in.
|
|
|
43
43
|
are at the bottom; scroll up to read earlier turns. The header shows the model and reasoning effort the latest
|
|
44
44
|
turn used (`default` when the model's own effort applies) and the current
|
|
45
45
|
mode.
|
|
46
|
+
- While a turn runs, the bottom hint shows its current phase and elapsed time, even
|
|
47
|
+
when a backend has not started streaming the answer. When a backend reports tool
|
|
48
|
+
activity, the hint shows the latest tool name/type, not commands or private
|
|
49
|
+
output. Elapsed time means the request is still active, not that a specific
|
|
50
|
+
step is complete. These status hints are temporary: they are not copied or
|
|
51
|
+
stored with the conversation and disappear on completion or cancellation.
|
|
46
52
|
- A turn is capped at 2 minutes in conversation-only mode and 10 minutes in
|
|
47
53
|
full permission mode.
|
|
48
54
|
- Bro saves its completed thread, mode and draft as private Pi session entries.
|
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.
|
package/docs/remember-me.md
CHANGED
|
@@ -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.
|
|
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 =
|
|
@@ -221,7 +235,7 @@ export function beginAttempt(child: ChildProcess, signal: AbortSignal, deadlineM
|
|
|
221
235
|
type AgyEvent = {
|
|
222
236
|
event?: string;
|
|
223
237
|
conversation_id?: string;
|
|
224
|
-
step_update?: { step_type?: string; text_delta?: unknown };
|
|
238
|
+
step_update?: { step_type?: string; text_delta?: unknown; tool_name?: unknown };
|
|
225
239
|
result?: { status?: string; response?: unknown; error?: unknown; conversation_id?: string };
|
|
226
240
|
};
|
|
227
241
|
|
|
@@ -244,7 +258,7 @@ function parseExplainLine(line: string): { delta?: string; result?: string } {
|
|
|
244
258
|
return {};
|
|
245
259
|
}
|
|
246
260
|
|
|
247
|
-
export function parseBtwAgyLine(line: string): { delta?: string; result?: string; conversationId?: string; error?: string } {
|
|
261
|
+
export function parseBtwAgyLine(line: string): { delta?: string; result?: string; conversationId?: string; error?: string; activity?: string } {
|
|
248
262
|
let event: AgyEvent;
|
|
249
263
|
try {
|
|
250
264
|
event = JSON.parse(line) as AgyEvent;
|
|
@@ -252,6 +266,11 @@ 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;
|
|
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 };
|
|
273
|
+
}
|
|
255
274
|
if (event.event === "step_update" && event.step_update?.step_type === "agent_response" && typeof event.step_update.text_delta === "string") {
|
|
256
275
|
return { delta: event.step_update.text_delta, conversationId };
|
|
257
276
|
}
|
|
@@ -390,6 +409,7 @@ async function executeArgvPrint(
|
|
|
390
409
|
if (isBtw) {
|
|
391
410
|
const parsed = parseBtwAgyLine(line);
|
|
392
411
|
if (parsed.conversationId) conversationId = parsed.conversationId;
|
|
412
|
+
if (parsed.activity) onProgress?.({ kind: "activity", label: parsed.activity, timestamp: Date.now(), tool: parsed.activity });
|
|
393
413
|
if (parsed.error) throw new Error(parsed.error);
|
|
394
414
|
if (parsed.delta) {
|
|
395
415
|
partial += parsed.delta;
|
|
@@ -397,6 +417,11 @@ async function executeArgvPrint(
|
|
|
397
417
|
}
|
|
398
418
|
if (parsed.result !== undefined) final = parsed.result;
|
|
399
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
|
+
}
|
|
400
425
|
const parsed = parseExplainLine(line);
|
|
401
426
|
if (parsed.delta) {
|
|
402
427
|
partial += parsed.delta;
|
|
@@ -563,7 +588,12 @@ async function executeAdvisorStdin(
|
|
|
563
588
|
throw new Error("Agy emitted invalid stream-json output.");
|
|
564
589
|
}
|
|
565
590
|
const activity = advisorActivityFromEvent(event);
|
|
566
|
-
if (activity)
|
|
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
|
+
}
|
|
567
597
|
if (event.event !== "result") return;
|
|
568
598
|
sawTerminal = true;
|
|
569
599
|
const result = event.result;
|
|
@@ -869,16 +899,18 @@ async function executeClaude(
|
|
|
869
899
|
onProgress?.({ kind: "text", text: partial });
|
|
870
900
|
}
|
|
871
901
|
}
|
|
872
|
-
if (isAdvisor && 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)) {
|
|
873
903
|
for (const block of event.message.content as Array<{ type?: unknown; name?: unknown; text?: unknown }>) {
|
|
874
904
|
if (attempt.causeOf()) break;
|
|
905
|
+
if ((isBtw || (inspect && request.reportReviewTools)) && block?.type !== "tool_use") continue;
|
|
906
|
+
const tool = block?.type === "tool_use" ? btwToolName(block.name) : undefined;
|
|
875
907
|
const label =
|
|
876
908
|
block?.type === "tool_use" && typeof block.name === "string"
|
|
877
|
-
? block.name.trim()
|
|
909
|
+
? ((isBtw || (inspect && request.reportReviewTools)) ? tool : block.name.trim())
|
|
878
910
|
: block?.type === "text" && typeof block.text === "string"
|
|
879
911
|
? block.text.split("\n").find((text) => text.trim())?.trim()
|
|
880
912
|
: undefined;
|
|
881
|
-
if (label) onProgress?.({ kind: "activity", label, timestamp: Date.now() });
|
|
913
|
+
if (label) onProgress?.({ kind: "activity", label, timestamp: Date.now(), ...(tool ? { tool } : {}) });
|
|
882
914
|
}
|
|
883
915
|
}
|
|
884
916
|
if (event.type !== "result" || !topLevel) return;
|
|
@@ -1059,16 +1091,18 @@ async function executeGrok(
|
|
|
1059
1091
|
}
|
|
1060
1092
|
streamedSinceAssistant = false;
|
|
1061
1093
|
}
|
|
1062
|
-
if (isAdvisor && event.type === "assistant" && Array.isArray(message?.content)) {
|
|
1094
|
+
if ((isAdvisor || isBtw || (inspect && request.reportReviewTools)) && event.type === "assistant" && Array.isArray(message?.content)) {
|
|
1063
1095
|
for (const block of message.content as Array<{ type?: unknown; name?: unknown; text?: unknown }>) {
|
|
1064
1096
|
if (attempt.causeOf()) break;
|
|
1097
|
+
if ((isBtw || (inspect && request.reportReviewTools)) && block?.type !== "tool_use") continue;
|
|
1098
|
+
const tool = block?.type === "tool_use" ? btwToolName(block.name) : undefined;
|
|
1065
1099
|
const label =
|
|
1066
1100
|
block?.type === "tool_use" && typeof block.name === "string"
|
|
1067
|
-
? block.name.trim()
|
|
1101
|
+
? ((isBtw || (inspect && request.reportReviewTools)) ? tool : block.name.trim())
|
|
1068
1102
|
: block?.type === "text" && typeof block.text === "string"
|
|
1069
1103
|
? block.text.split("\n").find((text) => text.trim())?.trim()
|
|
1070
1104
|
: undefined;
|
|
1071
|
-
if (label) onProgress?.({ kind: "activity", label, timestamp: Date.now() });
|
|
1105
|
+
if (label) onProgress?.({ kind: "activity", label, timestamp: Date.now(), ...(tool ? { tool } : {}) });
|
|
1072
1106
|
}
|
|
1073
1107
|
}
|
|
1074
1108
|
if (event.type !== "result") return;
|
|
@@ -1257,9 +1291,10 @@ async function executeCodex(
|
|
|
1257
1291
|
return;
|
|
1258
1292
|
}
|
|
1259
1293
|
const item = event.item;
|
|
1260
|
-
if (isAdvisor && (event.type === "item.started" || event.type === "item.completed")) {
|
|
1261
|
-
const
|
|
1262
|
-
|
|
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 } : {}) });
|
|
1263
1298
|
}
|
|
1264
1299
|
if (event.type === "item.completed" && item?.type === "agent_message") {
|
|
1265
1300
|
const text = extractCodexItemText(item);
|
|
@@ -1402,22 +1437,24 @@ async function executeMuse(
|
|
|
1402
1437
|
const runStream = payload?.run_stream;
|
|
1403
1438
|
const isRoot = rootRunId !== undefined && runStream?.kind === "run" && runStream.id === rootRunId;
|
|
1404
1439
|
|
|
1405
|
-
if (isAdvisor) {
|
|
1440
|
+
if (isAdvisor || isBtw || (inspect && request.reportReviewTools)) {
|
|
1406
1441
|
if (envelope.payload_type === "tool.result") {
|
|
1407
1442
|
const facts = payload?.correlation_facts as { tool_name?: unknown } | undefined;
|
|
1408
1443
|
const toolName = typeof facts?.tool_name === "string" && facts.tool_name ? facts.tool_name : "tool";
|
|
1409
1444
|
const candidate = [payload?.text, payload?.command, payload?.path, payload?.file_path, payload?.query]
|
|
1410
1445
|
.find((v) => typeof v === "string" && v.trim());
|
|
1411
1446
|
const preview = typeof candidate === "string" ? candidate.replace(/\s+/g, " ").trim() : "";
|
|
1412
|
-
const
|
|
1413
|
-
|
|
1414
|
-
|
|
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 } : {}) });
|
|
1450
|
+
} else if (isAdvisor && envelope.payload_type === "task.lifecycle.status") {
|
|
1415
1451
|
const event = payload?.event as { message?: unknown } | undefined;
|
|
1416
1452
|
if (typeof event?.message === "string" && event.message.trim()) {
|
|
1417
1453
|
onProgress?.({ kind: "activity", label: event.message.trim(), timestamp: Date.now() });
|
|
1418
1454
|
}
|
|
1419
1455
|
}
|
|
1420
|
-
}
|
|
1456
|
+
}
|
|
1457
|
+
if (!isAdvisor && isRoot && envelope.payload_type === "run.output.delta") {
|
|
1421
1458
|
if (typeof payload?.text === "string" && payload.text) {
|
|
1422
1459
|
partial += payload.text;
|
|
1423
1460
|
onProgress?.({ kind: "text", text: partial });
|
|
@@ -1868,7 +1905,9 @@ async function executePi(
|
|
|
1868
1905
|
onProgress?.({ kind: "text", text });
|
|
1869
1906
|
}
|
|
1870
1907
|
} else if (event.type === "tool_execution_start" && onProgress) {
|
|
1871
|
-
|
|
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 } : {}) });
|
|
1872
1911
|
}
|
|
1873
1912
|
});
|
|
1874
1913
|
|
package/src/btw.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
|
|
2
2
|
import { copyToClipboard, getMarkdownTheme } from "@earendil-works/pi-coding-agent";
|
|
3
3
|
import { Input, Markdown, matchesKey, wrapTextWithAnsi, type Focusable } from "@earendil-works/pi-tui";
|
|
4
|
-
import { execute as executeBackend, textProgressThrottle, type BackendSelection } from "./backend.ts";
|
|
4
|
+
import { execute as executeBackend, textProgressThrottle, type BackendProgress, type BackendSelection } from "./backend.ts";
|
|
5
5
|
import { buildBtwPrompt } from "./prompt.ts";
|
|
6
6
|
import {
|
|
7
7
|
type BackendName,
|
|
@@ -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
|
|
|
@@ -138,9 +138,17 @@ export async function runBtwTurn(
|
|
|
138
138
|
selection: BackendSelection,
|
|
139
139
|
options: { full: boolean; cwd: string; conversationId?: string },
|
|
140
140
|
signal: AbortSignal,
|
|
141
|
-
onProgress?: (
|
|
141
|
+
onProgress?: (event: BackendProgress) => void,
|
|
142
|
+
onRenderedText?: (text: string) => void,
|
|
142
143
|
): Promise<{ text: string; conversationId?: string; expiredContinuation?: true }> {
|
|
143
|
-
|
|
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);
|
|
147
|
+
const receive = (event: BackendProgress) => {
|
|
148
|
+
if (signal.aborted) return;
|
|
149
|
+
onProgress?.(event);
|
|
150
|
+
if (event.kind === "text") textProgress.receive?.(event);
|
|
151
|
+
};
|
|
144
152
|
|
|
145
153
|
try {
|
|
146
154
|
const outcome = await executeBackend(
|
|
@@ -153,13 +161,13 @@ export async function runBtwTurn(
|
|
|
153
161
|
},
|
|
154
162
|
selection,
|
|
155
163
|
signal,
|
|
156
|
-
|
|
164
|
+
receive,
|
|
157
165
|
);
|
|
158
166
|
if (outcome.status === "success") return { text: outcome.text, conversationId: outcome.continuation?.id };
|
|
159
167
|
if (outcome.continuationExpired) return { text: "", expiredContinuation: true };
|
|
160
168
|
throw new Error(outcome.message);
|
|
161
169
|
} finally {
|
|
162
|
-
|
|
170
|
+
textProgress.dispose();
|
|
163
171
|
}
|
|
164
172
|
}
|
|
165
173
|
|
|
@@ -179,6 +187,7 @@ export class BtwModal implements Focusable {
|
|
|
179
187
|
{ followEnd: true },
|
|
180
188
|
);
|
|
181
189
|
private running = false;
|
|
190
|
+
private progressText = "";
|
|
182
191
|
private full = false;
|
|
183
192
|
private model = "";
|
|
184
193
|
private customMode = "";
|
|
@@ -243,6 +252,14 @@ export class BtwModal implements Focusable {
|
|
|
243
252
|
|
|
244
253
|
setRunning(running: boolean): void {
|
|
245
254
|
this.running = running;
|
|
255
|
+
if (!running) this.progressText = "";
|
|
256
|
+
this.tui.requestRender();
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/** Ephemeral in-flight status; never enters the thread or clipboard. */
|
|
260
|
+
setProgress(text: string): void {
|
|
261
|
+
if (this.disposed || !this.running) return;
|
|
262
|
+
this.progressText = text;
|
|
246
263
|
this.tui.requestRender();
|
|
247
264
|
}
|
|
248
265
|
|
|
@@ -323,7 +340,13 @@ export class BtwModal implements Focusable {
|
|
|
323
340
|
this.input.render(inner)[0] ?? "",
|
|
324
341
|
],
|
|
325
342
|
notice: this.noticeText ? formatNotice(this.theme, this.noticeText, this.noticeTone) : undefined,
|
|
326
|
-
|
|
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"),
|
|
327
350
|
});
|
|
328
351
|
}
|
|
329
352
|
|
|
@@ -345,6 +368,7 @@ export async function openBtwModal(
|
|
|
345
368
|
(tui, theme, _keybindings, done) => {
|
|
346
369
|
let closed = false;
|
|
347
370
|
let controller: AbortController | undefined;
|
|
371
|
+
let stopActiveProgress: (() => void) | undefined;
|
|
348
372
|
let activeTurn: { pending?: BtwTurn; original?: BtwTurn } | undefined;
|
|
349
373
|
// Discard an unfinished reply immediately on close, before another modal can
|
|
350
374
|
// reuse the same thread. A cancelled retry restores the completed old turn.
|
|
@@ -381,6 +405,7 @@ export async function openBtwModal(
|
|
|
381
405
|
if (closed) return;
|
|
382
406
|
closed = true;
|
|
383
407
|
saveDraft();
|
|
408
|
+
stopActiveProgress?.();
|
|
384
409
|
controller?.abort();
|
|
385
410
|
discardUnfinished();
|
|
386
411
|
options.onChange?.();
|
|
@@ -391,6 +416,7 @@ export async function openBtwModal(
|
|
|
391
416
|
if (closed) return; // Close already saved and cleaned this thread.
|
|
392
417
|
closed = true;
|
|
393
418
|
saveDraft();
|
|
419
|
+
stopActiveProgress?.();
|
|
394
420
|
controller?.abort();
|
|
395
421
|
discardUnfinished();
|
|
396
422
|
options.onChange?.();
|
|
@@ -407,7 +433,22 @@ export async function openBtwModal(
|
|
|
407
433
|
const work: { pending?: BtwTurn; original?: BtwTurn } = { original: replaced };
|
|
408
434
|
activeTurn = work;
|
|
409
435
|
controller = turnController;
|
|
436
|
+
let elapsedSeconds = 0;
|
|
437
|
+
let stage = "Preparing request";
|
|
438
|
+
const updateProgress = () => {
|
|
439
|
+
if (!closed && controller === turnController && !turnController.signal.aborted)
|
|
440
|
+
modal.setProgress(`${stage} · ${elapsedSeconds}s`);
|
|
441
|
+
};
|
|
410
442
|
modal.setRunning(true);
|
|
443
|
+
const stopClock = startProgressClock(turnController.signal, seconds => {
|
|
444
|
+
elapsedSeconds = seconds;
|
|
445
|
+
updateProgress();
|
|
446
|
+
});
|
|
447
|
+
const stopProgress = () => {
|
|
448
|
+
stopClock();
|
|
449
|
+
if (stopActiveProgress === stopProgress) stopActiveProgress = undefined;
|
|
450
|
+
};
|
|
451
|
+
stopActiveProgress = stopProgress;
|
|
411
452
|
|
|
412
453
|
let settings: BroSettings;
|
|
413
454
|
let preferences: string;
|
|
@@ -415,6 +456,7 @@ export async function openBtwModal(
|
|
|
415
456
|
settings = await readSettings();
|
|
416
457
|
preferences = await readPreferences();
|
|
417
458
|
} catch (error) {
|
|
459
|
+
stopProgress();
|
|
418
460
|
if (activeTurn === work) discardUnfinished();
|
|
419
461
|
if (!closed && !replaced && !options.initialQuestion) modal.setComposerText(question);
|
|
420
462
|
if (controller === turnController) controller = undefined;
|
|
@@ -423,6 +465,7 @@ export async function openBtwModal(
|
|
|
423
465
|
}
|
|
424
466
|
// Do not restore a cancelled retry twice after close/dispose.
|
|
425
467
|
if (closed || turnController.signal.aborted) {
|
|
468
|
+
stopProgress();
|
|
426
469
|
if (activeTurn === work) discardUnfinished();
|
|
427
470
|
if (controller === turnController) controller = undefined;
|
|
428
471
|
return;
|
|
@@ -454,16 +497,27 @@ export async function openBtwModal(
|
|
|
454
497
|
thread.model = selectionLabel(selection);
|
|
455
498
|
thread.preferences = Boolean(preferences);
|
|
456
499
|
modal.setModel(btwHeaderLabel(thread));
|
|
500
|
+
stage = "Waiting for backend";
|
|
501
|
+
updateProgress();
|
|
502
|
+
const showBackendProgress = (event: BackendProgress) => {
|
|
503
|
+
if (closed || turnController.signal.aborted) return;
|
|
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());
|
|
513
|
+
};
|
|
457
514
|
let result = await runBtwTurn(
|
|
458
515
|
buildBtwPrompt(context, question, { full, history, preferences }),
|
|
459
516
|
selection,
|
|
460
517
|
{ full, cwd: ctx.cwd, conversationId },
|
|
461
518
|
turnController.signal,
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
pending.answer = partial;
|
|
465
|
-
modal.setText(transcript());
|
|
466
|
-
},
|
|
519
|
+
showBackendProgress,
|
|
520
|
+
showRenderedText,
|
|
467
521
|
);
|
|
468
522
|
if (closed || turnController.signal.aborted) return;
|
|
469
523
|
if (result.expiredContinuation) {
|
|
@@ -471,17 +525,16 @@ export async function openBtwModal(
|
|
|
471
525
|
// transcript AND its captured main-session context (the local `context` is undefined
|
|
472
526
|
// whenever a continuation existed), and run once more so nothing is silently lost.
|
|
473
527
|
thread.conversationId = undefined;
|
|
528
|
+
stage = "Restoring side thread";
|
|
529
|
+
updateProgress();
|
|
474
530
|
modal.setNotice("Side thread expired — reseeded from the transcript and session context.", "warning");
|
|
475
531
|
const reseeded = await runBtwTurn(
|
|
476
532
|
buildBtwPrompt(thread.context, question, { full, history: formatBtwTranscript(thread.turns.slice(0, -1)), preferences }),
|
|
477
533
|
selection,
|
|
478
534
|
{ full, cwd: ctx.cwd },
|
|
479
535
|
turnController.signal,
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
pending.answer = partial;
|
|
483
|
-
modal.setText(transcript());
|
|
484
|
-
},
|
|
536
|
+
showBackendProgress,
|
|
537
|
+
showRenderedText,
|
|
485
538
|
);
|
|
486
539
|
result = reseeded;
|
|
487
540
|
}
|
|
@@ -496,6 +549,7 @@ export async function openBtwModal(
|
|
|
496
549
|
pending.answer = `_${errorMessage(error)}_`;
|
|
497
550
|
modal.setNotice(errorMessage(error), "error");
|
|
498
551
|
} finally {
|
|
552
|
+
stopProgress();
|
|
499
553
|
if (controller === turnController) controller = undefined;
|
|
500
554
|
if (activeTurn === work) {
|
|
501
555
|
if (closed || turnController.signal.aborted) discardUnfinished();
|
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
|
-
|
|
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 {
|
|
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
|
-
|
|
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 {
|
|
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. */
|
package/src/explain-modal.ts
CHANGED
|
@@ -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"
|
|
589
|
-
|
|
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
|
|
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
|
}
|
package/src/simplify-ui.ts
CHANGED
|
@@ -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("
|
|
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)
|
|
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);
|