pi-bro 0.36.1 → 0.36.2
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 +8 -0
- package/docs/features/btw.md +6 -0
- package/package.json +1 -1
- package/src/backend.ts +19 -10
- package/src/btw.ts +59 -16
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.2] - 2026-11-10
|
|
6
|
+
|
|
7
|
+
### Improved
|
|
8
|
+
|
|
9
|
+
- `/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.
|
|
10
|
+
- 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.
|
|
11
|
+
- Progress hints stay out of saved threads and copies and clear on completion, errors and cancellation. Added offline UI/protocol checks.
|
|
12
|
+
|
|
5
13
|
## [0.36.1] - 2026-11-09
|
|
6
14
|
|
|
7
15
|
### Fixed
|
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-bro",
|
|
3
|
-
"version": "0.36.
|
|
3
|
+
"version": "0.36.2",
|
|
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
|
@@ -221,7 +221,7 @@ export function beginAttempt(child: ChildProcess, signal: AbortSignal, deadlineM
|
|
|
221
221
|
type AgyEvent = {
|
|
222
222
|
event?: string;
|
|
223
223
|
conversation_id?: string;
|
|
224
|
-
step_update?: { step_type?: string; text_delta?: unknown };
|
|
224
|
+
step_update?: { step_type?: string; text_delta?: unknown; tool_name?: unknown };
|
|
225
225
|
result?: { status?: string; response?: unknown; error?: unknown; conversation_id?: string };
|
|
226
226
|
};
|
|
227
227
|
|
|
@@ -244,7 +244,7 @@ function parseExplainLine(line: string): { delta?: string; result?: string } {
|
|
|
244
244
|
return {};
|
|
245
245
|
}
|
|
246
246
|
|
|
247
|
-
export function parseBtwAgyLine(line: string): { delta?: string; result?: string; conversationId?: string; error?: string } {
|
|
247
|
+
export function parseBtwAgyLine(line: string): { delta?: string; result?: string; conversationId?: string; error?: string; activity?: string } {
|
|
248
248
|
let event: AgyEvent;
|
|
249
249
|
try {
|
|
250
250
|
event = JSON.parse(line) as AgyEvent;
|
|
@@ -252,6 +252,9 @@ export function parseBtwAgyLine(line: string): { delta?: string; result?: string
|
|
|
252
252
|
throw new Error("Agy returned invalid streaming data.");
|
|
253
253
|
}
|
|
254
254
|
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 };
|
|
257
|
+
}
|
|
255
258
|
if (event.event === "step_update" && event.step_update?.step_type === "agent_response" && typeof event.step_update.text_delta === "string") {
|
|
256
259
|
return { delta: event.step_update.text_delta, conversationId };
|
|
257
260
|
}
|
|
@@ -390,6 +393,7 @@ async function executeArgvPrint(
|
|
|
390
393
|
if (isBtw) {
|
|
391
394
|
const parsed = parseBtwAgyLine(line);
|
|
392
395
|
if (parsed.conversationId) conversationId = parsed.conversationId;
|
|
396
|
+
if (parsed.activity) onProgress?.({ kind: "activity", label: parsed.activity, timestamp: Date.now() });
|
|
393
397
|
if (parsed.error) throw new Error(parsed.error);
|
|
394
398
|
if (parsed.delta) {
|
|
395
399
|
partial += parsed.delta;
|
|
@@ -869,9 +873,10 @@ async function executeClaude(
|
|
|
869
873
|
onProgress?.({ kind: "text", text: partial });
|
|
870
874
|
}
|
|
871
875
|
}
|
|
872
|
-
if (isAdvisor && topLevel && event.type === "assistant" && Array.isArray(event.message?.content)) {
|
|
876
|
+
if ((isAdvisor || isBtw) && topLevel && event.type === "assistant" && Array.isArray(event.message?.content)) {
|
|
873
877
|
for (const block of event.message.content as Array<{ type?: unknown; name?: unknown; text?: unknown }>) {
|
|
874
878
|
if (attempt.causeOf()) break;
|
|
879
|
+
if (isBtw && block?.type !== "tool_use") continue;
|
|
875
880
|
const label =
|
|
876
881
|
block?.type === "tool_use" && typeof block.name === "string"
|
|
877
882
|
? block.name.trim()
|
|
@@ -1059,9 +1064,10 @@ async function executeGrok(
|
|
|
1059
1064
|
}
|
|
1060
1065
|
streamedSinceAssistant = false;
|
|
1061
1066
|
}
|
|
1062
|
-
if (isAdvisor && event.type === "assistant" && Array.isArray(message?.content)) {
|
|
1067
|
+
if ((isAdvisor || isBtw) && event.type === "assistant" && Array.isArray(message?.content)) {
|
|
1063
1068
|
for (const block of message.content as Array<{ type?: unknown; name?: unknown; text?: unknown }>) {
|
|
1064
1069
|
if (attempt.causeOf()) break;
|
|
1070
|
+
if (isBtw && block?.type !== "tool_use") continue;
|
|
1065
1071
|
const label =
|
|
1066
1072
|
block?.type === "tool_use" && typeof block.name === "string"
|
|
1067
1073
|
? block.name.trim()
|
|
@@ -1257,8 +1263,10 @@ async function executeCodex(
|
|
|
1257
1263
|
return;
|
|
1258
1264
|
}
|
|
1259
1265
|
const item = event.item;
|
|
1260
|
-
if (isAdvisor && (event.type === "item.started" || event.type === "item.completed")) {
|
|
1261
|
-
const activity =
|
|
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);
|
|
1262
1270
|
if (activity) onProgress?.({ kind: "activity", label: activity, timestamp: Date.now() });
|
|
1263
1271
|
}
|
|
1264
1272
|
if (event.type === "item.completed" && item?.type === "agent_message") {
|
|
@@ -1402,22 +1410,23 @@ async function executeMuse(
|
|
|
1402
1410
|
const runStream = payload?.run_stream;
|
|
1403
1411
|
const isRoot = rootRunId !== undefined && runStream?.kind === "run" && runStream.id === rootRunId;
|
|
1404
1412
|
|
|
1405
|
-
if (isAdvisor) {
|
|
1413
|
+
if (isAdvisor || isBtw) {
|
|
1406
1414
|
if (envelope.payload_type === "tool.result") {
|
|
1407
1415
|
const facts = payload?.correlation_facts as { tool_name?: unknown } | undefined;
|
|
1408
1416
|
const toolName = typeof facts?.tool_name === "string" && facts.tool_name ? facts.tool_name : "tool";
|
|
1409
1417
|
const candidate = [payload?.text, payload?.command, payload?.path, payload?.file_path, payload?.query]
|
|
1410
1418
|
.find((v) => typeof v === "string" && v.trim());
|
|
1411
1419
|
const preview = typeof candidate === "string" ? candidate.replace(/\s+/g, " ").trim() : "";
|
|
1412
|
-
const label = `${toolName}${preview ? ` ${preview}` : ""}`;
|
|
1420
|
+
const label = isBtw ? toolName : `${toolName}${preview ? ` ${preview}` : ""}`;
|
|
1413
1421
|
onProgress?.({ kind: "activity", label, timestamp: Date.now() });
|
|
1414
|
-
} else if (envelope.payload_type === "task.lifecycle.status") {
|
|
1422
|
+
} else if (isAdvisor && envelope.payload_type === "task.lifecycle.status") {
|
|
1415
1423
|
const event = payload?.event as { message?: unknown } | undefined;
|
|
1416
1424
|
if (typeof event?.message === "string" && event.message.trim()) {
|
|
1417
1425
|
onProgress?.({ kind: "activity", label: event.message.trim(), timestamp: Date.now() });
|
|
1418
1426
|
}
|
|
1419
1427
|
}
|
|
1420
|
-
}
|
|
1428
|
+
}
|
|
1429
|
+
if (!isAdvisor && isRoot && envelope.payload_type === "run.output.delta") {
|
|
1421
1430
|
if (typeof payload?.text === "string" && payload.text) {
|
|
1422
1431
|
partial += payload.text;
|
|
1423
1432
|
onProgress?.({ kind: "text", text: partial });
|
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,
|
|
@@ -138,9 +138,14 @@ 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
142
|
): Promise<{ text: string; conversationId?: string; expiredContinuation?: true }> {
|
|
143
|
-
const
|
|
143
|
+
const textProgress = textProgressThrottle(signal, (text) => onProgress?.({ kind: "text", text }));
|
|
144
|
+
const receive = (event: BackendProgress) => {
|
|
145
|
+
if (signal.aborted) return;
|
|
146
|
+
if (event.kind === "activity") onProgress?.(event);
|
|
147
|
+
else textProgress.receive?.(event);
|
|
148
|
+
};
|
|
144
149
|
|
|
145
150
|
try {
|
|
146
151
|
const outcome = await executeBackend(
|
|
@@ -153,13 +158,13 @@ export async function runBtwTurn(
|
|
|
153
158
|
},
|
|
154
159
|
selection,
|
|
155
160
|
signal,
|
|
156
|
-
|
|
161
|
+
receive,
|
|
157
162
|
);
|
|
158
163
|
if (outcome.status === "success") return { text: outcome.text, conversationId: outcome.continuation?.id };
|
|
159
164
|
if (outcome.continuationExpired) return { text: "", expiredContinuation: true };
|
|
160
165
|
throw new Error(outcome.message);
|
|
161
166
|
} finally {
|
|
162
|
-
|
|
167
|
+
textProgress.dispose();
|
|
163
168
|
}
|
|
164
169
|
}
|
|
165
170
|
|
|
@@ -179,6 +184,7 @@ export class BtwModal implements Focusable {
|
|
|
179
184
|
{ followEnd: true },
|
|
180
185
|
);
|
|
181
186
|
private running = false;
|
|
187
|
+
private progressText = "";
|
|
182
188
|
private full = false;
|
|
183
189
|
private model = "";
|
|
184
190
|
private customMode = "";
|
|
@@ -243,6 +249,14 @@ export class BtwModal implements Focusable {
|
|
|
243
249
|
|
|
244
250
|
setRunning(running: boolean): void {
|
|
245
251
|
this.running = running;
|
|
252
|
+
if (!running) this.progressText = "";
|
|
253
|
+
this.tui.requestRender();
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/** Ephemeral in-flight status; never enters the thread or clipboard. */
|
|
257
|
+
setProgress(text: string): void {
|
|
258
|
+
if (this.disposed || !this.running) return;
|
|
259
|
+
this.progressText = text;
|
|
246
260
|
this.tui.requestRender();
|
|
247
261
|
}
|
|
248
262
|
|
|
@@ -323,7 +337,7 @@ export class BtwModal implements Focusable {
|
|
|
323
337
|
this.input.render(inner)[0] ?? "",
|
|
324
338
|
],
|
|
325
339
|
notice: this.noticeText ? formatNotice(this.theme, this.noticeText, this.noticeTone) : undefined,
|
|
326
|
-
hints: this.running ? "Bro is thinking… · Esc close (stops reply)
|
|
340
|
+
hints: this.running ? `${this.progressText || "Bro is thinking…"} · Esc close (stops reply)` : (this.appearance.idleHint ?? "Enter send · Esc close"),
|
|
327
341
|
});
|
|
328
342
|
}
|
|
329
343
|
|
|
@@ -345,6 +359,7 @@ export async function openBtwModal(
|
|
|
345
359
|
(tui, theme, _keybindings, done) => {
|
|
346
360
|
let closed = false;
|
|
347
361
|
let controller: AbortController | undefined;
|
|
362
|
+
let stopActiveProgress: (() => void) | undefined;
|
|
348
363
|
let activeTurn: { pending?: BtwTurn; original?: BtwTurn } | undefined;
|
|
349
364
|
// Discard an unfinished reply immediately on close, before another modal can
|
|
350
365
|
// reuse the same thread. A cancelled retry restores the completed old turn.
|
|
@@ -381,6 +396,7 @@ export async function openBtwModal(
|
|
|
381
396
|
if (closed) return;
|
|
382
397
|
closed = true;
|
|
383
398
|
saveDraft();
|
|
399
|
+
stopActiveProgress?.();
|
|
384
400
|
controller?.abort();
|
|
385
401
|
discardUnfinished();
|
|
386
402
|
options.onChange?.();
|
|
@@ -391,6 +407,7 @@ export async function openBtwModal(
|
|
|
391
407
|
if (closed) return; // Close already saved and cleaned this thread.
|
|
392
408
|
closed = true;
|
|
393
409
|
saveDraft();
|
|
410
|
+
stopActiveProgress?.();
|
|
394
411
|
controller?.abort();
|
|
395
412
|
discardUnfinished();
|
|
396
413
|
options.onChange?.();
|
|
@@ -407,7 +424,21 @@ export async function openBtwModal(
|
|
|
407
424
|
const work: { pending?: BtwTurn; original?: BtwTurn } = { original: replaced };
|
|
408
425
|
activeTurn = work;
|
|
409
426
|
controller = turnController;
|
|
427
|
+
const startedAt = Date.now();
|
|
428
|
+
let stage = "Preparing request";
|
|
429
|
+
const updateProgress = () => {
|
|
430
|
+
if (!closed && controller === turnController && !turnController.signal.aborted)
|
|
431
|
+
modal.setProgress(`${stage} · ${Math.floor((Date.now() - startedAt) / 1000)}s`);
|
|
432
|
+
};
|
|
433
|
+
const timer = setInterval(updateProgress, 1000);
|
|
434
|
+
timer.unref?.();
|
|
435
|
+
const stopProgress = () => {
|
|
436
|
+
clearInterval(timer);
|
|
437
|
+
if (stopActiveProgress === stopProgress) stopActiveProgress = undefined;
|
|
438
|
+
};
|
|
439
|
+
stopActiveProgress = stopProgress;
|
|
410
440
|
modal.setRunning(true);
|
|
441
|
+
updateProgress();
|
|
411
442
|
|
|
412
443
|
let settings: BroSettings;
|
|
413
444
|
let preferences: string;
|
|
@@ -415,6 +446,7 @@ export async function openBtwModal(
|
|
|
415
446
|
settings = await readSettings();
|
|
416
447
|
preferences = await readPreferences();
|
|
417
448
|
} catch (error) {
|
|
449
|
+
stopProgress();
|
|
418
450
|
if (activeTurn === work) discardUnfinished();
|
|
419
451
|
if (!closed && !replaced && !options.initialQuestion) modal.setComposerText(question);
|
|
420
452
|
if (controller === turnController) controller = undefined;
|
|
@@ -423,6 +455,7 @@ export async function openBtwModal(
|
|
|
423
455
|
}
|
|
424
456
|
// Do not restore a cancelled retry twice after close/dispose.
|
|
425
457
|
if (closed || turnController.signal.aborted) {
|
|
458
|
+
stopProgress();
|
|
426
459
|
if (activeTurn === work) discardUnfinished();
|
|
427
460
|
if (controller === turnController) controller = undefined;
|
|
428
461
|
return;
|
|
@@ -454,16 +487,27 @@ export async function openBtwModal(
|
|
|
454
487
|
thread.model = selectionLabel(selection);
|
|
455
488
|
thread.preferences = Boolean(preferences);
|
|
456
489
|
modal.setModel(btwHeaderLabel(thread));
|
|
490
|
+
stage = "Waiting for backend";
|
|
491
|
+
updateProgress();
|
|
492
|
+
const showBackendProgress = (event: BackendProgress) => {
|
|
493
|
+
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
|
+
};
|
|
457
505
|
let result = await runBtwTurn(
|
|
458
506
|
buildBtwPrompt(context, question, { full, history, preferences }),
|
|
459
507
|
selection,
|
|
460
508
|
{ full, cwd: ctx.cwd, conversationId },
|
|
461
509
|
turnController.signal,
|
|
462
|
-
|
|
463
|
-
if (closed || turnController.signal.aborted) return;
|
|
464
|
-
pending.answer = partial;
|
|
465
|
-
modal.setText(transcript());
|
|
466
|
-
},
|
|
510
|
+
showBackendProgress,
|
|
467
511
|
);
|
|
468
512
|
if (closed || turnController.signal.aborted) return;
|
|
469
513
|
if (result.expiredContinuation) {
|
|
@@ -471,17 +515,15 @@ export async function openBtwModal(
|
|
|
471
515
|
// transcript AND its captured main-session context (the local `context` is undefined
|
|
472
516
|
// whenever a continuation existed), and run once more so nothing is silently lost.
|
|
473
517
|
thread.conversationId = undefined;
|
|
518
|
+
stage = "Restoring side thread";
|
|
519
|
+
updateProgress();
|
|
474
520
|
modal.setNotice("Side thread expired — reseeded from the transcript and session context.", "warning");
|
|
475
521
|
const reseeded = await runBtwTurn(
|
|
476
522
|
buildBtwPrompt(thread.context, question, { full, history: formatBtwTranscript(thread.turns.slice(0, -1)), preferences }),
|
|
477
523
|
selection,
|
|
478
524
|
{ full, cwd: ctx.cwd },
|
|
479
525
|
turnController.signal,
|
|
480
|
-
|
|
481
|
-
if (closed || turnController.signal.aborted) return;
|
|
482
|
-
pending.answer = partial;
|
|
483
|
-
modal.setText(transcript());
|
|
484
|
-
},
|
|
526
|
+
showBackendProgress,
|
|
485
527
|
);
|
|
486
528
|
result = reseeded;
|
|
487
529
|
}
|
|
@@ -496,6 +538,7 @@ export async function openBtwModal(
|
|
|
496
538
|
pending.answer = `_${errorMessage(error)}_`;
|
|
497
539
|
modal.setNotice(errorMessage(error), "error");
|
|
498
540
|
} finally {
|
|
541
|
+
stopProgress();
|
|
499
542
|
if (controller === turnController) controller = undefined;
|
|
500
543
|
if (activeTurn === work) {
|
|
501
544
|
if (closed || turnController.signal.aborted) discardUnfinished();
|