pi-render-btw 0.6.10 → 0.6.12
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/README.md +18 -1
- package/extensions/btw/peek.test.ts +33 -0
- package/extensions/btw/peek.ts +164 -7
- package/extensions/btw/transcript-store.ts +616 -0
- package/extensions/btw-transcript.test.ts +512 -2
- package/extensions/btw.ts +1050 -118
- package/package.json +2 -1
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.6.12 — 2026-09-13
|
|
4
|
+
|
|
5
|
+
- Recover interrupted streaming turns as closed history after reload.
|
|
6
|
+
- Rehydrate read-only Peek and live Tool Output from durable artifact details and diffs.
|
|
7
|
+
- Expand regression coverage for durable storage and live tool interactions.
|
|
8
|
+
- Show runtime-provided partial tool output in the read-only viewer with a `STREAMING` marker, then update the same tool row in place when the final result arrives.
|
|
9
|
+
- Consume `Ctrl+O` with no focused tool instead of forwarding it to the composer; show an explicit no-output state when a tool has not emitted output.
|
|
10
|
+
|
|
11
|
+
## 0.6.11 — 2026-09-13
|
|
12
|
+
|
|
13
|
+
- Persist BTW transcript snapshots and complete tool artifacts under `.pi-subagents/btw/`.
|
|
14
|
+
- Rehydrate the active branch's BTW transcript after reload without leaking data across branches.
|
|
15
|
+
- Add live tool focus, click-to-expand/double-click collapse, and read-only `Ctrl+O` Tool Output.
|
|
16
|
+
- Keep wheel, Escape, Peek, and composer interactions scoped to the active BTW surface.
|
package/README.md
CHANGED
|
@@ -96,6 +96,9 @@ pi install /path/to/pi-render-btw
|
|
|
96
96
|
- `Ctrl+G` opens the current BTW draft in `$VISUAL`/`$EDITOR` (falling back to `nano`) and reads it back when the editor exits successfully
|
|
97
97
|
- the composer uses Pi's native editor behavior for undo, paste, prompt history, and Tab file-path completion (including `@` prefixes) relative to the BTW working directory
|
|
98
98
|
- `Esc` still dismisses BTW immediately while the overlay is focused
|
|
99
|
+
- hovering and left-clicking a transcript row focuses one shared USER/ASSISTANT/Tool target; clicking a Tool row toggles its compact details and double-clicking collapses it
|
|
100
|
+
- with a focused Tool row, `Ctrl+O` opens a read-only Input/Output viewer; while the runtime emits partial tool updates it shows the latest provided data with a `STREAMING` marker, and after tool completion it switches to the final result
|
|
101
|
+
- if the runtime has not provided tool output yet, the viewer shows an explicit no-output state rather than inventing content; its wheel, `j/k`, arrows, `g/G`, PageUp/PageDown, and `Esc` controls stay inside the viewer
|
|
99
102
|
- BTW opens top-centered so the main session remains visible underneath it
|
|
100
103
|
|
|
101
104
|
### `/btw:new [question]`
|
|
@@ -117,11 +120,15 @@ pi install /path/to/pi-render-btw
|
|
|
117
120
|
|
|
118
121
|
- switches the BTW overlay into Peek mode for the current side thread
|
|
119
122
|
- `Ctrl+P` enters Peek mode from the BTW composer, even when it contains a draft
|
|
120
|
-
- `j/k` scroll one
|
|
123
|
+
- `j/k` scroll one rendered line, `J/K` jump between USER/THINKING/ASSISTANT messages, and `g/G` go to the top/bottom
|
|
124
|
+
- arrow keys and PageUp/PageDown provide the corresponding line/page scrolling
|
|
121
125
|
- `/` searches with smartcase; `n/N` moves between matches
|
|
122
126
|
- `t` toggles tool messages
|
|
127
|
+
- `w` opens a read-only tool Input/Output preview when the selected tool has data; `Enter` expands a tool card and a host double-click collapses it
|
|
128
|
+
- normalized mouse hover highlights a block and a left click selects it; press/release events do not change selection
|
|
123
129
|
- `M` copies the selected message; `o` opens it read-only in nvim
|
|
124
130
|
- `Esc`, `q`, or `Ctrl+C` returns to the BTW composer; press `Esc` again in the composer to dismiss BTW
|
|
131
|
+
- the Peek and Tool Output headers show `[Esc]`; wheel input is handled locally without changing the main viewport
|
|
125
132
|
|
|
126
133
|
### `/btw:clear`
|
|
127
134
|
|
|
@@ -190,6 +197,16 @@ BTW exchanges are persisted in the session as hidden custom entries so they:
|
|
|
190
197
|
- preserve the current BTW-only model and thinking overrides for that session history
|
|
191
198
|
- stay out of the main agent's LLM context
|
|
192
199
|
|
|
200
|
+
### Durable BTW transcript and tool artifacts
|
|
201
|
+
|
|
202
|
+
In addition to the small hidden session locators, BTW stores its immutable transcript snapshots and complete tool payloads under:
|
|
203
|
+
|
|
204
|
+
```text
|
|
205
|
+
<project>/.pi-subagents/btw/threads/<session-id>/
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
Tool input, output, details, and available unified diffs are kept outside the main LLM context. On reload, the active branch locator rehydrates the transcript; missing or corrupt records are ignored safely rather than replaced with fabricated output.
|
|
209
|
+
|
|
193
210
|
### Visible saved notes
|
|
194
211
|
|
|
195
212
|
If you use `--save`, that one BTW exchange is also written as a visible custom message in the session transcript.
|
|
@@ -6,6 +6,9 @@ import {
|
|
|
6
6
|
findNextSearchMatch,
|
|
7
7
|
getBlockText,
|
|
8
8
|
getBlockTypeLabel,
|
|
9
|
+
getToolPreviewText,
|
|
10
|
+
hasToolPreview,
|
|
11
|
+
parsePeekMouseInput,
|
|
9
12
|
type PeekBlock,
|
|
10
13
|
type PeekEntry,
|
|
11
14
|
type PeekModeState,
|
|
@@ -22,7 +25,10 @@ function makeEntry(
|
|
|
22
25
|
type: overrides.type,
|
|
23
26
|
text: overrides.text,
|
|
24
27
|
content: overrides.content,
|
|
28
|
+
toolCallId: overrides.toolCallId,
|
|
25
29
|
toolName: overrides.toolName,
|
|
30
|
+
args: overrides.args,
|
|
31
|
+
fullContent: overrides.fullContent,
|
|
26
32
|
isError: overrides.isError,
|
|
27
33
|
truncated: overrides.truncated,
|
|
28
34
|
streaming: overrides.streaming,
|
|
@@ -102,6 +108,18 @@ describe("buildPeekBlocks", () => {
|
|
|
102
108
|
expect(blocks).toHaveLength(1);
|
|
103
109
|
});
|
|
104
110
|
|
|
111
|
+
it("pairs tool input and output for a safe read-only preview", () => {
|
|
112
|
+
const blocks = buildPeekBlocks([
|
|
113
|
+
makeEntry({ id: 1, type: "tool-call", toolCallId: "call-1", toolName: "read", args: "src/index.ts" }),
|
|
114
|
+
makeEntry({ id: 2, type: "tool-result", toolCallId: "call-1", toolName: "read", content: "summary", fullContent: "complete contents" }),
|
|
115
|
+
], true);
|
|
116
|
+
|
|
117
|
+
expect(hasToolPreview(blocks[0])).toBe(true);
|
|
118
|
+
expect(getToolPreviewText(blocks[0])).toContain("src/index.ts");
|
|
119
|
+
expect(blocks[0].toolOutput).toBe("complete contents");
|
|
120
|
+
expect(getToolPreviewText(blocks[0])).toContain("complete contents");
|
|
121
|
+
});
|
|
122
|
+
|
|
105
123
|
it("produces sequential blocks from transcript entries in order", () => {
|
|
106
124
|
const entries: PeekEntry[] = [
|
|
107
125
|
makeEntry({ id: 1, type: "user-message", text: "Q1" }),
|
|
@@ -261,6 +279,21 @@ describe("getBlockText", () => {
|
|
|
261
279
|
});
|
|
262
280
|
});
|
|
263
281
|
|
|
282
|
+
describe("parsePeekMouseInput", () => {
|
|
283
|
+
it("normalizes bounded SGR wheel and button events without terminal side effects", () => {
|
|
284
|
+
expect(parsePeekMouseInput("\x1b[<64;12;8M")).toMatchObject({ action: "wheel", x: 12, y: 8, delta: -1 });
|
|
285
|
+
expect(parsePeekMouseInput("\x1b[<0;12;8M")).toMatchObject({ action: "press", button: 0, x: 12, y: 8 });
|
|
286
|
+
expect(parsePeekMouseInput("\x1b[<0;12;8m")).toMatchObject({ action: "release", button: 0, x: 12, y: 8 });
|
|
287
|
+
expect(parsePeekMouseInput("\x1b[<0;10001;1M")).toBeNull();
|
|
288
|
+
expect(parsePeekMouseInput("not mouse")).toBeNull();
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
it("normalizes legacy X10 wheel events", () => {
|
|
292
|
+
const x10WheelDown = "\x1b[M" + String.fromCharCode(32 + 65, 32 + 12, 32 + 8);
|
|
293
|
+
expect(parsePeekMouseInput(x10WheelDown)).toMatchObject({ action: "wheel", x: 12, y: 8, delta: 1 });
|
|
294
|
+
});
|
|
295
|
+
});
|
|
296
|
+
|
|
264
297
|
describe("getBlockTypeLabel", () => {
|
|
265
298
|
it("returns 'You' for user", () => {
|
|
266
299
|
expect(getBlockTypeLabel({ id: 0, entryId: 1, turnId: 1, type: "user", text: "" })).toBe("You");
|
package/extensions/btw/peek.ts
CHANGED
|
@@ -13,7 +13,12 @@ export interface PeekEntry {
|
|
|
13
13
|
turnId: number;
|
|
14
14
|
text?: string;
|
|
15
15
|
content?: string;
|
|
16
|
+
toolCallId?: string;
|
|
16
17
|
toolName?: string;
|
|
18
|
+
/** Serialized tool input retained by BTW's transcript model. */
|
|
19
|
+
args?: string;
|
|
20
|
+
/** Untruncated result retained for the read-only preview when available. */
|
|
21
|
+
fullContent?: string;
|
|
17
22
|
isError?: boolean;
|
|
18
23
|
truncated?: boolean;
|
|
19
24
|
streaming?: boolean;
|
|
@@ -34,7 +39,13 @@ export interface PeekBlock {
|
|
|
34
39
|
turnId: number;
|
|
35
40
|
type: PeekBlockType;
|
|
36
41
|
text: string;
|
|
42
|
+
toolCallId?: string;
|
|
37
43
|
toolName?: string;
|
|
44
|
+
/** Serialized input/output used only for the read-only tool preview. */
|
|
45
|
+
toolInput?: string;
|
|
46
|
+
toolOutput?: string;
|
|
47
|
+
/** True while the runtime has only supplied a partial tool result. */
|
|
48
|
+
streaming?: boolean;
|
|
38
49
|
isError?: boolean;
|
|
39
50
|
truncated?: boolean;
|
|
40
51
|
}
|
|
@@ -87,8 +98,29 @@ export function buildPeekBlocks(
|
|
|
87
98
|
showTools: boolean,
|
|
88
99
|
): PeekBlock[] {
|
|
89
100
|
const blocks: PeekBlock[] = [];
|
|
101
|
+
const toolData = new Map<string, { input?: string; output?: string; isError?: boolean; streaming?: boolean; toolName?: string }>();
|
|
102
|
+
const toolResultIds = new Set<string>();
|
|
90
103
|
let id = 0;
|
|
91
104
|
|
|
105
|
+
// Tool calls and results are separate transcript entries, but a preview should
|
|
106
|
+
// present their paired input/output together. Keep this lookup local to the
|
|
107
|
+
// renderer so the persisted BTW thread remains unchanged.
|
|
108
|
+
for (const entry of entries) {
|
|
109
|
+
if (!entry.toolCallId || (entry.type !== "tool-call" && entry.type !== "tool-result")) continue;
|
|
110
|
+
const current = toolData.get(entry.toolCallId) ?? {};
|
|
111
|
+
if (entry.type === "tool-call") {
|
|
112
|
+
current.input = entry.args ?? entry.text ?? current.input;
|
|
113
|
+
current.toolName = entry.toolName ?? current.toolName;
|
|
114
|
+
} else {
|
|
115
|
+
current.output = entry.fullContent ?? entry.content ?? entry.text ?? current.output;
|
|
116
|
+
current.isError = entry.isError;
|
|
117
|
+
current.streaming = entry.streaming === true;
|
|
118
|
+
current.toolName = entry.toolName ?? current.toolName;
|
|
119
|
+
toolResultIds.add(entry.toolCallId);
|
|
120
|
+
}
|
|
121
|
+
toolData.set(entry.toolCallId, current);
|
|
122
|
+
}
|
|
123
|
+
|
|
92
124
|
for (const entry of entries) {
|
|
93
125
|
if (entry.type === "turn-boundary") continue;
|
|
94
126
|
|
|
@@ -118,23 +150,34 @@ export function buildPeekBlocks(
|
|
|
118
150
|
});
|
|
119
151
|
} else if (entry.type === "tool-call") {
|
|
120
152
|
if (!showTools) continue;
|
|
153
|
+
const paired = entry.toolCallId ? toolData.get(entry.toolCallId) : undefined;
|
|
121
154
|
blocks.push({
|
|
122
155
|
id: id++,
|
|
123
156
|
entryId: entry.id,
|
|
124
157
|
turnId: entry.turnId,
|
|
125
158
|
type: "tool-call",
|
|
126
|
-
text: "",
|
|
127
|
-
|
|
159
|
+
text: entry.args ?? entry.text ?? "",
|
|
160
|
+
toolCallId: entry.toolCallId,
|
|
161
|
+
toolName: entry.toolName ?? paired?.toolName,
|
|
162
|
+
toolInput: entry.args ?? entry.text ?? paired?.input,
|
|
163
|
+
toolOutput: paired?.output,
|
|
164
|
+
streaming: paired?.streaming ?? !toolResultIds.has(entry.toolCallId ?? ""),
|
|
165
|
+
isError: paired?.isError,
|
|
128
166
|
});
|
|
129
167
|
} else if (entry.type === "tool-result") {
|
|
130
168
|
if (!showTools) continue;
|
|
169
|
+
const paired = entry.toolCallId ? toolData.get(entry.toolCallId) : undefined;
|
|
131
170
|
blocks.push({
|
|
132
171
|
id: id++,
|
|
133
172
|
entryId: entry.id,
|
|
134
173
|
turnId: entry.turnId,
|
|
135
174
|
type: "tool-result",
|
|
136
|
-
text: entry.content ?? entry.text ?? "",
|
|
137
|
-
|
|
175
|
+
text: entry.fullContent ?? entry.content ?? entry.text ?? "",
|
|
176
|
+
toolCallId: entry.toolCallId,
|
|
177
|
+
toolName: entry.toolName ?? paired?.toolName,
|
|
178
|
+
toolInput: paired?.input,
|
|
179
|
+
toolOutput: entry.fullContent ?? entry.content ?? entry.text ?? paired?.output,
|
|
180
|
+
streaming: entry.streaming === true || paired?.streaming === true,
|
|
138
181
|
isError: entry.isError,
|
|
139
182
|
truncated: entry.truncated,
|
|
140
183
|
});
|
|
@@ -163,7 +206,13 @@ export function findSearchMatches(
|
|
|
163
206
|
|
|
164
207
|
for (let i = 0; i < blocks.length; i++) {
|
|
165
208
|
const block = blocks[i];
|
|
166
|
-
const
|
|
209
|
+
const searchable = [
|
|
210
|
+
getBlockTypeLabel(block),
|
|
211
|
+
block.text,
|
|
212
|
+
block.toolInput ?? "",
|
|
213
|
+
block.toolOutput ?? "",
|
|
214
|
+
].join("\n");
|
|
215
|
+
const haystack = caseSensitive ? searchable : searchable.toLowerCase();
|
|
167
216
|
const needle = caseSensitive ? query : query.toLowerCase();
|
|
168
217
|
if (haystack.includes(needle)) {
|
|
169
218
|
matches.push(i);
|
|
@@ -193,6 +242,20 @@ export function findNextSearchMatch(
|
|
|
193
242
|
|
|
194
243
|
// ── Block text for copy/nvim ────────────────────────────────────────
|
|
195
244
|
|
|
245
|
+
export function hasToolPreview(block: PeekBlock | undefined): boolean {
|
|
246
|
+
return Boolean(
|
|
247
|
+
block &&
|
|
248
|
+
(block.type === "tool-call" || block.type === "tool-result") &&
|
|
249
|
+
(block.toolInput || block.toolOutput || (block.type === "tool-result" && block.text)),
|
|
250
|
+
);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
export function getToolPreviewText(block: PeekBlock): string {
|
|
254
|
+
const input = block.toolInput || (block.type === "tool-call" ? block.text : "") || "(no input)";
|
|
255
|
+
const output = block.toolOutput || (block.type === "tool-result" ? block.text : "") || "(no output)";
|
|
256
|
+
return `Input:\n${input}\n\nOutput${block.isError ? " (error)" : ""}:\n${output}`;
|
|
257
|
+
}
|
|
258
|
+
|
|
196
259
|
export function getBlockText(block: PeekBlock): string {
|
|
197
260
|
switch (block.type) {
|
|
198
261
|
case "user":
|
|
@@ -202,9 +265,9 @@ export function getBlockText(block: PeekBlock): string {
|
|
|
202
265
|
case "assistant-text":
|
|
203
266
|
return `## Assistant\n\n${block.text}`;
|
|
204
267
|
case "tool-call":
|
|
205
|
-
return `## Tool Call: ${block.toolName ?? "unknown"}`;
|
|
268
|
+
return `## Tool Call: ${block.toolName ?? "unknown"}\n\n${getToolPreviewText(block)}`;
|
|
206
269
|
case "tool-result":
|
|
207
|
-
return `## Tool Result${block.isError ? " (error)" : ""}: ${block.toolName ?? "unknown"}\n\n${block
|
|
270
|
+
return `## Tool Result${block.isError ? " (error)" : ""}: ${block.toolName ?? "unknown"}\n\n${getToolPreviewText(block)}`;
|
|
208
271
|
}
|
|
209
272
|
}
|
|
210
273
|
|
|
@@ -224,3 +287,97 @@ export function getBlockTypeLabel(block: PeekBlock): string {
|
|
|
224
287
|
return `Result${block.isError ? " (error)" : ""}: ${block.toolName ?? "?"}`;
|
|
225
288
|
}
|
|
226
289
|
}
|
|
290
|
+
|
|
291
|
+
/** Semantic labels used by the viewer surface; copy labels above stay stable. */
|
|
292
|
+
export function getSemanticBlockLabel(block: PeekBlock): string {
|
|
293
|
+
switch (block.type) {
|
|
294
|
+
case "user":
|
|
295
|
+
return "USER";
|
|
296
|
+
case "thinking":
|
|
297
|
+
return "THINKING";
|
|
298
|
+
case "assistant-text":
|
|
299
|
+
return "ASSISTANT";
|
|
300
|
+
case "tool-call":
|
|
301
|
+
return `TOOL ${block.toolName ?? "?"}`;
|
|
302
|
+
case "tool-result":
|
|
303
|
+
return `TOOL RESULT ${block.toolName ?? "?"}`;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
export function getToolResultSummary(text: string): string {
|
|
308
|
+
const normalized = text.replace(/\r\n?/g, "\n");
|
|
309
|
+
const firstLine = normalized.split("\n").find((line) => line.trim().length > 0)?.trim() || "(no output)";
|
|
310
|
+
const lineCount = normalized ? normalized.split("\n").length : 0;
|
|
311
|
+
return `${firstLine} · ${lineCount}L/${normalized.length}c`;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
// A normalized mouse event is intentionally independent of Pi's optional host
|
|
315
|
+
// mouse dispatch. Raw SGR parsing is bounded and does not enable terminal modes.
|
|
316
|
+
export type PeekMouseAction = "press" | "release" | "wheel" | "move" | "drag";
|
|
317
|
+
export interface PeekMouseEvent {
|
|
318
|
+
action: PeekMouseAction | "click";
|
|
319
|
+
button: number;
|
|
320
|
+
x: number;
|
|
321
|
+
y: number;
|
|
322
|
+
/** Consecutive click count when the host supplies one. */
|
|
323
|
+
clickCount?: number;
|
|
324
|
+
/** For wheel events, -1 is up and +1 is down. */
|
|
325
|
+
delta?: number;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
export function parsePeekMouseInput(data: string): PeekMouseEvent | null {
|
|
329
|
+
const match = data.match(/^\x1b\[<(\d+);(\d+);(\d+)([mM])$/);
|
|
330
|
+
if (match) {
|
|
331
|
+
const encodedButton = Number(match[1]);
|
|
332
|
+
const x = Number(match[2]);
|
|
333
|
+
const y = Number(match[3]);
|
|
334
|
+
if (!Number.isSafeInteger(encodedButton) || !Number.isSafeInteger(x) || !Number.isSafeInteger(y)) return null;
|
|
335
|
+
if (x < 1 || y < 1 || x > 10000 || y > 10000) return null;
|
|
336
|
+
|
|
337
|
+
if ((encodedButton & 64) !== 0) {
|
|
338
|
+
return {
|
|
339
|
+
action: "wheel",
|
|
340
|
+
button: encodedButton & 3,
|
|
341
|
+
x,
|
|
342
|
+
y,
|
|
343
|
+
delta: (encodedButton & 1) === 0 ? -1 : 1,
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
return {
|
|
348
|
+
action: match[4] === "M" ? "press" : "release",
|
|
349
|
+
button: encodedButton & 3,
|
|
350
|
+
x,
|
|
351
|
+
y,
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
// Some terminals/multiplexers still emit the six-byte X10 mouse form.
|
|
356
|
+
// Pi's newer TUI normalizes this before dispatch, but accepting it here
|
|
357
|
+
// keeps the fallback handleInput path from dropping wheel events.
|
|
358
|
+
if (data.length !== 6 || !data.startsWith("\x1b[M")) return null;
|
|
359
|
+
const encodedButton = data.charCodeAt(3) - 32;
|
|
360
|
+
const x = data.charCodeAt(4) - 32;
|
|
361
|
+
const y = data.charCodeAt(5) - 32;
|
|
362
|
+
if (encodedButton < 0 || x < 1 || y < 1 || x > 223 || y > 223) return null;
|
|
363
|
+
|
|
364
|
+
if ((encodedButton & 64) !== 0) {
|
|
365
|
+
const direction = encodedButton & 3;
|
|
366
|
+
if (direction !== 0 && direction !== 1) return null;
|
|
367
|
+
return {
|
|
368
|
+
action: "wheel",
|
|
369
|
+
button: encodedButton & 3,
|
|
370
|
+
x,
|
|
371
|
+
y,
|
|
372
|
+
delta: direction === 0 ? -1 : 1,
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
const button = encodedButton & 3;
|
|
377
|
+
return {
|
|
378
|
+
action: button === 3 ? "release" : (encodedButton & 32) !== 0 ? "move" : "press",
|
|
379
|
+
button,
|
|
380
|
+
x,
|
|
381
|
+
y,
|
|
382
|
+
};
|
|
383
|
+
}
|