pi-render-btw 0.6.13 → 0.6.14
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 +6 -0
- package/README.md +3 -1
- package/extensions/btw/render-utils.ts +175 -0
- package/extensions/btw-transcript.test.ts +26 -0
- package/extensions/btw.ts +246 -89
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.6.14 — 2026-09-18
|
|
4
|
+
|
|
5
|
+
- Keep BTW, Peek, and read-only Tool Output rendering aligned with Pi Markdown/tool colors and syntax highlighting, including safe terminal-text sanitization.
|
|
6
|
+
- Add a native-style right-hand scrollbar with `↑ N more` / `↓ N more` viewport affordances to the BTW transcript, Peek, and Tool Output surfaces.
|
|
7
|
+
- Add local BTW draft recall for `Alt+Up`, `a-up`, and `alt+up`; busy-session saved notes and handoffs continue through Pi follow-up delivery without mutating the read-only viewers.
|
|
8
|
+
|
|
3
9
|
## 0.6.13 — 2026-09-14
|
|
4
10
|
|
|
5
11
|
- Keep the BTW/Peek/Tool Output title-row `[Esc]` affordance visible beside long titles.
|
package/README.md
CHANGED
|
@@ -22,6 +22,7 @@ with **full markdown rendering** (syntax highlighting, bold, code blocks, lists,
|
|
|
22
22
|
- lets you inject the full thread, or a summary of it, back into the main agent
|
|
23
23
|
- optionally saves an individual BTW exchange as a visible session note with `--save`
|
|
24
24
|
- includes an internal Peek mode for browsing the current BTW side thread
|
|
25
|
+
- keeps a native-style right-hand scrollbar in the BTW transcript, Peek, and read-only Tool Output views, with `↑ N more` / `↓ N more` affordances at the viewport edges
|
|
25
26
|
|
|
26
27
|
## ✨ Markdown rendering
|
|
27
28
|
|
|
@@ -94,7 +95,7 @@ pi install /path/to/pi-render-btw
|
|
|
94
95
|
- `Alt+/` toggles focus between BTW and the main editor without closing the overlay
|
|
95
96
|
- `Ctrl+Alt+W` is a fallback focus toggle for terminals that do not deliver `Alt+/` as a usable shortcut
|
|
96
97
|
- `Ctrl+G` opens the current BTW draft in `$VISUAL`/`$EDITOR` (falling back to `nano`) and reads it back when the editor exits successfully
|
|
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
|
+
- 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; `Alt+Up` (`a-up`/`alt+up`) recalls a submitted draft
|
|
98
99
|
- `Esc` still dismisses BTW immediately while the overlay is focused
|
|
99
100
|
- 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
101
|
- 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
|
|
@@ -129,6 +130,7 @@ pi install /path/to/pi-render-btw
|
|
|
129
130
|
- `M` copies the selected message; `o` opens it read-only in nvim
|
|
130
131
|
- `Esc`, `q`, or `Ctrl+C` returns to the BTW composer; press `Esc` again in the composer to dismiss BTW
|
|
131
132
|
- the Peek and Tool Output headers show a hoverable `[Esc]` close/back affordance; wheel input is handled locally without changing the main viewport
|
|
133
|
+
- the BTW transcript, Peek, and Tool Output keep their scroll thumb in the rightmost cell, show hidden-line counts above/below the viewport, and support line/page/top/bottom navigation without entering the composer
|
|
132
134
|
|
|
133
135
|
### `/btw:clear`
|
|
134
136
|
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { getLanguageFromPath, getMarkdownTheme, highlightCode } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import {
|
|
3
|
+
Markdown,
|
|
4
|
+
truncateToWidth,
|
|
5
|
+
visibleWidth,
|
|
6
|
+
wrapTextWithAnsi,
|
|
7
|
+
type MarkdownTheme,
|
|
8
|
+
} from "@earendil-works/pi-tui";
|
|
9
|
+
import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
10
|
+
|
|
11
|
+
export type BtwTheme = Pick<ExtensionContext["ui"]["theme"], "fg" | "bold" | "italic">;
|
|
12
|
+
export type BtwMarkdownRole = "user" | "assistant" | "thinking";
|
|
13
|
+
|
|
14
|
+
const UNSAFE_TERMINAL_ESCAPE = new RegExp(
|
|
15
|
+
"(?:\\u001B\\]|\\u009D)[\\s\\S]*?(?:\\u0007|\\u001B\\x5C|\\u009C)" +
|
|
16
|
+
"|(?:\\u001B[PX^_]|\\u0090)[\\s\\S]*?(?:\\u001B\\x5C|\\u009C)" +
|
|
17
|
+
"|(?:\\u001B\\[|\\u009B)[0-?]*[ -/]*[@-~]" +
|
|
18
|
+
"|\\u001B[@-_]",
|
|
19
|
+
"g",
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
/** Strip terminal control sequences before captured tool text is rendered again. */
|
|
23
|
+
export function sanitizeBtwText(value: string): string {
|
|
24
|
+
return value
|
|
25
|
+
.replace(UNSAFE_TERMINAL_ESCAPE, "")
|
|
26
|
+
.replace(/\x1B/g, "")
|
|
27
|
+
.replace(/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x9F]/g, "")
|
|
28
|
+
.replace(/\r\n?/g, "\n");
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function fitLine(line: string, width: number): string {
|
|
32
|
+
const safeWidth = Math.max(1, Math.floor(Number.isFinite(width) ? width : 1));
|
|
33
|
+
return truncateToWidth(line, safeWidth, "");
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function fitLines(lines: readonly string[], width: number): string[] {
|
|
37
|
+
return lines.length > 0 ? lines.map((line) => fitLine(line, width)) : [""];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Render BTW text with the same Markdown component/theme contract as Pi's
|
|
42
|
+
* native user and assistant message components. The role color is only a
|
|
43
|
+
* default style; Markdown code spans and blocks retain the native token colors.
|
|
44
|
+
*/
|
|
45
|
+
export function renderBtwMarkdown(
|
|
46
|
+
text: string,
|
|
47
|
+
width: number,
|
|
48
|
+
theme: BtwTheme,
|
|
49
|
+
role: BtwMarkdownRole,
|
|
50
|
+
markdownTheme: MarkdownTheme = getMarkdownTheme(),
|
|
51
|
+
): string[] {
|
|
52
|
+
const color = role === "user" ? "userMessageText" : role === "thinking" ? "thinkingText" : "text";
|
|
53
|
+
const source = sanitizeBtwText(text);
|
|
54
|
+
try {
|
|
55
|
+
const markdown = new Markdown(
|
|
56
|
+
source || "∅",
|
|
57
|
+
0,
|
|
58
|
+
0,
|
|
59
|
+
markdownTheme,
|
|
60
|
+
{ color: (value) => theme.fg(color, value) },
|
|
61
|
+
role === "user"
|
|
62
|
+
? { preserveOrderedListMarkers: true, preserveBackslashEscapes: true }
|
|
63
|
+
: undefined,
|
|
64
|
+
);
|
|
65
|
+
return fitLines(markdown.render(Math.max(1, Math.floor(width))), width);
|
|
66
|
+
} catch {
|
|
67
|
+
return fitLines(wrapTextWithAnsi(source || "∅", Math.max(1, Math.floor(width))), width);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function parseToolArgs(args: string | undefined): Record<string, unknown> | undefined {
|
|
72
|
+
if (!args?.trim()) return undefined;
|
|
73
|
+
try {
|
|
74
|
+
const parsed: unknown = JSON.parse(args);
|
|
75
|
+
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
76
|
+
return parsed as Record<string, unknown>;
|
|
77
|
+
}
|
|
78
|
+
} catch {
|
|
79
|
+
// A compact transcript may retain only the path as its tool input.
|
|
80
|
+
}
|
|
81
|
+
return { path: args.trim() };
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function languageFromArgs(args: string | undefined): string | undefined {
|
|
85
|
+
const parsed = parseToolArgs(args);
|
|
86
|
+
const candidate = parsed?.file_path ?? parsed?.filePath ?? parsed?.path;
|
|
87
|
+
if (typeof candidate !== "string" || !candidate.trim()) return undefined;
|
|
88
|
+
try {
|
|
89
|
+
return getLanguageFromPath(candidate.replace(/^@/, "").trim());
|
|
90
|
+
} catch {
|
|
91
|
+
return undefined;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function languageFromFence(text: string): string | undefined {
|
|
96
|
+
const match = text.match(/^\s*(`{3,}|~{3,})\s*([A-Za-z][\w+.-]*)\b[^\n]*$/m);
|
|
97
|
+
return match?.[2];
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Render tool output using Pi's synchronous native syntax highlighter when a
|
|
102
|
+
* tool path or explicit fenced language identifies the output. Plain output
|
|
103
|
+
* keeps the tool-output semantic color and is always terminal-safe.
|
|
104
|
+
*/
|
|
105
|
+
export function renderBtwToolText(
|
|
106
|
+
text: string,
|
|
107
|
+
width: number,
|
|
108
|
+
theme: BtwTheme,
|
|
109
|
+
args?: string,
|
|
110
|
+
isError = false,
|
|
111
|
+
): string[] {
|
|
112
|
+
const source = sanitizeBtwText(text);
|
|
113
|
+
const language = languageFromArgs(args) ?? languageFromFence(source);
|
|
114
|
+
let highlighted: string[] | undefined;
|
|
115
|
+
if (language && source.trim() && source.length <= 200_000) {
|
|
116
|
+
try {
|
|
117
|
+
// highlightCode is Pi's own renderer and returns only terminal SGR
|
|
118
|
+
// styling; preserve those token colors while the source itself remains
|
|
119
|
+
// sanitized before entering the highlighter.
|
|
120
|
+
highlighted = highlightCode(source, language);
|
|
121
|
+
} catch {
|
|
122
|
+
highlighted = undefined;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const output = highlighted ?? source.split("\n");
|
|
127
|
+
const color = isError ? "error" : "toolOutput";
|
|
128
|
+
const safeWidth = Math.max(1, Math.floor(Number.isFinite(width) ? width : 1));
|
|
129
|
+
const rendered: string[] = [];
|
|
130
|
+
for (const line of output.length > 0 ? output : [""]) {
|
|
131
|
+
const styled = highlighted ? line : theme.fg(color, line);
|
|
132
|
+
rendered.push(...fitLines(wrapTextWithAnsi(styled, safeWidth), safeWidth));
|
|
133
|
+
}
|
|
134
|
+
return rendered.length > 0 ? rendered : [""];
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export function renderBtwScrollRail(
|
|
138
|
+
theme: BtwTheme,
|
|
139
|
+
totalLines: number,
|
|
140
|
+
viewportHeight: number,
|
|
141
|
+
scrollOffset: number,
|
|
142
|
+
lineIndex: number,
|
|
143
|
+
scrollbarActive = false,
|
|
144
|
+
): string {
|
|
145
|
+
const total = Math.max(0, Math.floor(totalLines));
|
|
146
|
+
const viewport = Math.max(1, Math.floor(viewportHeight));
|
|
147
|
+
const offset = Math.max(0, Math.min(Math.max(0, total - viewport), Math.floor(scrollOffset)));
|
|
148
|
+
if (total <= viewport) return theme.fg("scrollbarTrack", " ");
|
|
149
|
+
|
|
150
|
+
const thumbHeight = Math.max(1, Math.round((viewport * viewport) / total));
|
|
151
|
+
const thumbStart = Math.round(((viewport - thumbHeight) * offset) / (total - viewport));
|
|
152
|
+
const inThumb = lineIndex >= thumbStart && lineIndex < thumbStart + thumbHeight;
|
|
153
|
+
return theme.fg(
|
|
154
|
+
inThumb ? "scrollbarThumb" : "scrollbarTrack",
|
|
155
|
+
inThumb ? (scrollbarActive ? "█" : "┃") : "│",
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export function renderBtwScrollRule(
|
|
160
|
+
theme: BtwTheme,
|
|
161
|
+
innerWidth: number,
|
|
162
|
+
direction: "top" | "bottom",
|
|
163
|
+
hiddenLines: number,
|
|
164
|
+
): string | undefined {
|
|
165
|
+
if (hiddenLines <= 0) return undefined;
|
|
166
|
+
const safeWidth = Math.max(1, Math.floor(innerWidth));
|
|
167
|
+
const label = `${direction === "top" ? "↑" : "↓"} ${hiddenLines} more`;
|
|
168
|
+
const labelWidth = visibleWidth(label);
|
|
169
|
+
if (labelWidth + 2 > safeWidth) {
|
|
170
|
+
return theme.fg("border", `├${"─".repeat(Math.max(0, safeWidth - 1))}┤`);
|
|
171
|
+
}
|
|
172
|
+
const left = Math.floor((safeWidth - labelWidth) / 2);
|
|
173
|
+
const right = Math.max(0, safeWidth - left - labelWidth);
|
|
174
|
+
return `${theme.fg("border", `├${"─".repeat(left)}`)}${theme.fg("dim", label)}${theme.fg("border", `${"─".repeat(right)}┤`)}`;
|
|
175
|
+
}
|
|
@@ -144,6 +144,32 @@ describe("BTW transcript message layout", () => {
|
|
|
144
144
|
expect(component.getDraft()).toBe(testValue);
|
|
145
145
|
});
|
|
146
146
|
|
|
147
|
+
it("recalls the newest submitted draft through Alt+Up aliases", () => {
|
|
148
|
+
const submitted: string[] = [];
|
|
149
|
+
const component = new BtwOverlayComponent(
|
|
150
|
+
tui,
|
|
151
|
+
theme,
|
|
152
|
+
keybindings,
|
|
153
|
+
() => [],
|
|
154
|
+
() => null,
|
|
155
|
+
() => "contextual",
|
|
156
|
+
(value) => submitted.push(value),
|
|
157
|
+
() => {},
|
|
158
|
+
() => {},
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
component.setDraft("first side question");
|
|
162
|
+
component.handleInput("\r");
|
|
163
|
+
expect(submitted).toEqual(["first side question"]);
|
|
164
|
+
|
|
165
|
+
component.setDraft("new draft");
|
|
166
|
+
component.handleInput("alt+up");
|
|
167
|
+
expect(component.getDraft()).toBe("first side question");
|
|
168
|
+
component.setDraft("new draft");
|
|
169
|
+
component.handleInput("a-up");
|
|
170
|
+
expect(component.getDraft()).toBe("first side question");
|
|
171
|
+
});
|
|
172
|
+
|
|
147
173
|
it("routes Ctrl+G to the external-editor callback", () => {
|
|
148
174
|
let opened = 0;
|
|
149
175
|
const externalKeybindings = {
|
package/extensions/btw.ts
CHANGED
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
type ExtensionAPI,
|
|
15
15
|
type ExtensionCommandContext,
|
|
16
16
|
type ExtensionContext,
|
|
17
|
+
type ModelRuntime,
|
|
17
18
|
type ResourceLoader,
|
|
18
19
|
} from "@earendil-works/pi-coding-agent";
|
|
19
20
|
import { type AssistantMessage, type Message, type ThinkingLevel as AiThinkingLevel, type UserMessage } from "@earendil-works/pi-ai";
|
|
@@ -21,7 +22,6 @@ import {
|
|
|
21
22
|
Box,
|
|
22
23
|
Container,
|
|
23
24
|
Key,
|
|
24
|
-
Markdown,
|
|
25
25
|
Text,
|
|
26
26
|
matchesKey,
|
|
27
27
|
truncateToWidth,
|
|
@@ -50,6 +50,12 @@ import {
|
|
|
50
50
|
type PeekEntry,
|
|
51
51
|
type PeekModeState,
|
|
52
52
|
} from "./btw/peek.ts";
|
|
53
|
+
import {
|
|
54
|
+
renderBtwMarkdown,
|
|
55
|
+
renderBtwScrollRail,
|
|
56
|
+
renderBtwScrollRule,
|
|
57
|
+
renderBtwToolText,
|
|
58
|
+
} from "./btw/render-utils.ts";
|
|
53
59
|
import {
|
|
54
60
|
BTW_TRANSCRIPT_SCHEMA_VERSION,
|
|
55
61
|
BtwTranscriptStore,
|
|
@@ -253,7 +259,9 @@ function createBtwResourceLoader(
|
|
|
253
259
|
getThemes: () => ({ themes: [], diagnostics: [] }),
|
|
254
260
|
getAgentsFiles: () => ({ agentsFiles: [] }),
|
|
255
261
|
getSystemPrompt: () => systemPrompt,
|
|
262
|
+
getSystemPromptSource: () => undefined,
|
|
256
263
|
getAppendSystemPrompt: () => appendSystemPrompt,
|
|
264
|
+
getAppendSystemPromptSources: () => [],
|
|
257
265
|
extendResources: () => {},
|
|
258
266
|
reload: async () => {},
|
|
259
267
|
};
|
|
@@ -1141,6 +1149,10 @@ export class BtwOverlayComponent extends Container implements Focusable {
|
|
|
1141
1149
|
private readonly onUnfocusCallback: () => void;
|
|
1142
1150
|
private readonly onExternalEditorCallback?: () => void;
|
|
1143
1151
|
private readonly readToolArtifact?: (toolCallId: string) => ToolArtifact | null;
|
|
1152
|
+
/** BTW keeps its own recall cursor so Alt+Up works even when host history bindings are unset. */
|
|
1153
|
+
private draftHistory: string[] = [];
|
|
1154
|
+
private draftHistoryIndex = -1;
|
|
1155
|
+
private draftHistoryDraft = "";
|
|
1144
1156
|
private externalEditorActive = false;
|
|
1145
1157
|
private readonly tui: TUI;
|
|
1146
1158
|
private readonly theme: ExtensionContext["ui"]["theme"];
|
|
@@ -1150,6 +1162,7 @@ export class BtwOverlayComponent extends Container implements Focusable {
|
|
|
1150
1162
|
private transcriptScrollOffset = 0;
|
|
1151
1163
|
private transcriptViewportHeight = 8;
|
|
1152
1164
|
private followTranscript = true;
|
|
1165
|
+
private scrollbarActive = false;
|
|
1153
1166
|
private liveHoveredEntryId: number | null = null;
|
|
1154
1167
|
private liveFocusedEntryId: number | null = null;
|
|
1155
1168
|
private liveFocusedToolCallId: string | null = null;
|
|
@@ -1242,6 +1255,7 @@ export class BtwOverlayComponent extends Container implements Focusable {
|
|
|
1242
1255
|
this.input = new CustomEditor(tui, editorTheme, editorKeybindings);
|
|
1243
1256
|
this.input.onSubmit = (value) => {
|
|
1244
1257
|
this.input.addToHistory(value);
|
|
1258
|
+
this.rememberDraft(value);
|
|
1245
1259
|
this.followTranscript = true;
|
|
1246
1260
|
this.onSubmitCallback(value);
|
|
1247
1261
|
};
|
|
@@ -1260,6 +1274,15 @@ export class BtwOverlayComponent extends Container implements Focusable {
|
|
|
1260
1274
|
|
|
1261
1275
|
const originalHandleInput = this.input.handleInput.bind(this.input);
|
|
1262
1276
|
this.input.handleInput = (data: string) => {
|
|
1277
|
+
// Some hosts expose Alt+Up as the symbolic `a-up` token rather than a
|
|
1278
|
+
// terminal escape sequence. Keep draft recall local to BTW so this does
|
|
1279
|
+
// not depend on the host having configured an editor history binding.
|
|
1280
|
+
if (matchesKey(data, Key.alt("up")) || data === "a-up" || data === "alt+up") {
|
|
1281
|
+
this.recallDraft(-1);
|
|
1282
|
+
this.tui.requestRender();
|
|
1283
|
+
return;
|
|
1284
|
+
}
|
|
1285
|
+
|
|
1263
1286
|
if (keybindings.matches(data, "app.editor.external")) {
|
|
1264
1287
|
if (this.onExternalEditorCallback) {
|
|
1265
1288
|
this.onExternalEditorCallback();
|
|
@@ -1272,6 +1295,7 @@ export class BtwOverlayComponent extends Container implements Focusable {
|
|
|
1272
1295
|
// app.clear with non-empty input → clear input
|
|
1273
1296
|
if (keybindings.matches(data, "app.clear") && this.input.getText().length > 0) {
|
|
1274
1297
|
this.input.setText("");
|
|
1298
|
+
this.resetDraftRecall();
|
|
1275
1299
|
this.tui.requestRender();
|
|
1276
1300
|
return;
|
|
1277
1301
|
}
|
|
@@ -1279,7 +1303,11 @@ export class BtwOverlayComponent extends Container implements Focusable {
|
|
|
1279
1303
|
// Everything else (including Escape → dismiss, Enter → submit,
|
|
1280
1304
|
// Ctrl+Enter → newline) goes to CustomEditor's own handler
|
|
1281
1305
|
// (CustomEditor delegates app keybindings, then Editor).
|
|
1306
|
+
const before = this.input.getText();
|
|
1282
1307
|
originalHandleInput(data);
|
|
1308
|
+
if (before !== this.input.getText()) {
|
|
1309
|
+
this.resetDraftRecall();
|
|
1310
|
+
}
|
|
1283
1311
|
};
|
|
1284
1312
|
|
|
1285
1313
|
this.refresh();
|
|
@@ -1325,6 +1353,40 @@ export class BtwOverlayComponent extends Container implements Focusable {
|
|
|
1325
1353
|
return `${this.theme.fg("border", "│")}${truncated}${" ".repeat(padding)}${this.theme.fg("border", "│")}`;
|
|
1326
1354
|
}
|
|
1327
1355
|
|
|
1356
|
+
/**
|
|
1357
|
+
* Frame one row of a bounded ScrollView-like viewport. The rail occupies
|
|
1358
|
+
* the last cell inside the box, so content never gets painted over it.
|
|
1359
|
+
*/
|
|
1360
|
+
private frameScrollableLine(
|
|
1361
|
+
content: string,
|
|
1362
|
+
innerWidth: number,
|
|
1363
|
+
totalLines: number,
|
|
1364
|
+
viewportHeight: number,
|
|
1365
|
+
scrollOffset: number,
|
|
1366
|
+
lineIndex: number,
|
|
1367
|
+
): string {
|
|
1368
|
+
const contentWidth = Math.max(1, innerWidth - 1);
|
|
1369
|
+
const truncated = truncateToWidth(content, contentWidth, "");
|
|
1370
|
+
const padding = Math.max(0, contentWidth - visibleWidth(truncated));
|
|
1371
|
+
const rail = renderBtwScrollRail(
|
|
1372
|
+
this.theme,
|
|
1373
|
+
totalLines,
|
|
1374
|
+
viewportHeight,
|
|
1375
|
+
scrollOffset,
|
|
1376
|
+
lineIndex,
|
|
1377
|
+
this.scrollbarActive,
|
|
1378
|
+
);
|
|
1379
|
+
return `${this.theme.fg("border", "│")}${truncated}${" ".repeat(padding)}${rail}${this.theme.fg("border", "│")}`;
|
|
1380
|
+
}
|
|
1381
|
+
|
|
1382
|
+
private scrollRule(
|
|
1383
|
+
innerWidth: number,
|
|
1384
|
+
direction: "top" | "bottom",
|
|
1385
|
+
hiddenLines: number,
|
|
1386
|
+
): string {
|
|
1387
|
+
return renderBtwScrollRule(this.theme, innerWidth, direction, hiddenLines) ?? this.ruleLine(innerWidth);
|
|
1388
|
+
}
|
|
1389
|
+
|
|
1328
1390
|
private ruleLine(innerWidth: number): string {
|
|
1329
1391
|
return this.theme.fg("border", `├${"─".repeat(innerWidth)}┤`);
|
|
1330
1392
|
}
|
|
@@ -1349,6 +1411,46 @@ export class BtwOverlayComponent extends Container implements Focusable {
|
|
|
1349
1411
|
return this.frameLine(`${clippedTitle}${" ".repeat(gap)}${escapeHint}`, innerWidth);
|
|
1350
1412
|
}
|
|
1351
1413
|
|
|
1414
|
+
private resetDraftRecall(): void {
|
|
1415
|
+
this.draftHistoryIndex = -1;
|
|
1416
|
+
this.draftHistoryDraft = "";
|
|
1417
|
+
}
|
|
1418
|
+
|
|
1419
|
+
private rememberDraft(value: string): void {
|
|
1420
|
+
const draft = value.trim();
|
|
1421
|
+
if (!draft) {
|
|
1422
|
+
this.resetDraftRecall();
|
|
1423
|
+
return;
|
|
1424
|
+
}
|
|
1425
|
+
// Match the native editor's useful behavior without creating an endless
|
|
1426
|
+
// run of identical entries when a prompt is submitted repeatedly.
|
|
1427
|
+
if (this.draftHistory[this.draftHistory.length - 1] !== value) {
|
|
1428
|
+
this.draftHistory.push(value);
|
|
1429
|
+
}
|
|
1430
|
+
this.resetDraftRecall();
|
|
1431
|
+
}
|
|
1432
|
+
|
|
1433
|
+
private recallDraft(direction: -1 | 1): void {
|
|
1434
|
+
if (this.draftHistory.length === 0) return;
|
|
1435
|
+
|
|
1436
|
+
if (this.draftHistoryIndex === -1) {
|
|
1437
|
+
this.draftHistoryDraft = this.input.getText();
|
|
1438
|
+
this.draftHistoryIndex = direction < 0 ? this.draftHistory.length - 1 : 0;
|
|
1439
|
+
} else {
|
|
1440
|
+
const next = this.draftHistoryIndex + direction;
|
|
1441
|
+
if (next < 0 || next >= this.draftHistory.length) {
|
|
1442
|
+
if (direction > 0 && this.draftHistoryIndex === this.draftHistory.length - 1) {
|
|
1443
|
+
this.draftHistoryIndex = -1;
|
|
1444
|
+
this.input.setText(this.draftHistoryDraft);
|
|
1445
|
+
}
|
|
1446
|
+
return;
|
|
1447
|
+
}
|
|
1448
|
+
this.draftHistoryIndex = next;
|
|
1449
|
+
}
|
|
1450
|
+
|
|
1451
|
+
this.input.setText(this.draftHistory[this.draftHistoryIndex]);
|
|
1452
|
+
}
|
|
1453
|
+
|
|
1352
1454
|
private wrapTranscript(innerWidth: number): string[] {
|
|
1353
1455
|
const wrapped: string[] = [];
|
|
1354
1456
|
for (const line of this.transcriptLines) {
|
|
@@ -1384,7 +1486,13 @@ export class BtwOverlayComponent extends Container implements Focusable {
|
|
|
1384
1486
|
const assistantBadge = buildTranscriptBadge(this.theme, "ASSISTANT", "customMessageBg", "success");
|
|
1385
1487
|
const separator = this.theme.fg("borderMuted", "─".repeat(40));
|
|
1386
1488
|
const blockIndent = " ";
|
|
1387
|
-
const
|
|
1489
|
+
const toolArgsByCall = new Map<string, string>();
|
|
1490
|
+
for (const entry of entries) {
|
|
1491
|
+
if (entry.type === "tool-call") toolArgsByCall.set(entry.toolCallId, entry.args);
|
|
1492
|
+
}
|
|
1493
|
+
// Reserve the final inner cell for the right-hand ScrollView rail.
|
|
1494
|
+
const scrollContentWidth = Math.max(1, innerWidth - 1);
|
|
1495
|
+
const mdContentWidth = Math.max(1, scrollContentWidth - visibleWidth(blockIndent));
|
|
1388
1496
|
|
|
1389
1497
|
const pushBlank = (): void => {
|
|
1390
1498
|
if (allLines.length > 0 && allLines[allLines.length - 1] !== "") {
|
|
@@ -1406,7 +1514,7 @@ export class BtwOverlayComponent extends Container implements Focusable {
|
|
|
1406
1514
|
pushBlank();
|
|
1407
1515
|
allLines.push(`${focusRail(entry.id)}${userBadge}`);
|
|
1408
1516
|
const boundedText = entry.text.length > 16_000 ? `${entry.text.slice(0, 15_970)}\n… [truncated]` : entry.text;
|
|
1409
|
-
const mdLines =
|
|
1517
|
+
const mdLines = renderBtwMarkdown(boundedText, mdContentWidth, this.theme, "user", this.mdTheme);
|
|
1410
1518
|
for (const line of mdLines) {
|
|
1411
1519
|
allLines.push(`${blockIndent}${line.replace(/[ \t]+$/u, "")}`);
|
|
1412
1520
|
}
|
|
@@ -1418,9 +1526,9 @@ export class BtwOverlayComponent extends Container implements Focusable {
|
|
|
1418
1526
|
const thinkingHeader = entry.streaming ? `${thinkingBadge} ${this.theme.fg("warning", "▍")}` : thinkingBadge;
|
|
1419
1527
|
pushBlank();
|
|
1420
1528
|
allLines.push(`${focusRail(entry.id)}${thinkingHeader}`);
|
|
1421
|
-
const
|
|
1422
|
-
for (const line of
|
|
1423
|
-
allLines.push(`${blockIndent}${
|
|
1529
|
+
const markdownLines = renderBtwMarkdown(entry.text, mdContentWidth, this.theme, "thinking", this.mdTheme);
|
|
1530
|
+
for (const line of markdownLines) {
|
|
1531
|
+
allLines.push(`${blockIndent}${line.replace(/[ \t]+$/u, "")}`);
|
|
1424
1532
|
}
|
|
1425
1533
|
markBlock(entry.id, blockStart);
|
|
1426
1534
|
continue;
|
|
@@ -1434,8 +1542,9 @@ export class BtwOverlayComponent extends Container implements Focusable {
|
|
|
1434
1542
|
pushBlank();
|
|
1435
1543
|
allLines.push(`${focusRail(entry.id)}${toolLabel}${argsLabel}${moreLabel}`);
|
|
1436
1544
|
if (isExpanded && entry.args) {
|
|
1437
|
-
|
|
1438
|
-
|
|
1545
|
+
const toolLines = renderBtwToolText(entry.args, mdContentWidth, this.theme);
|
|
1546
|
+
for (const line of toolLines) {
|
|
1547
|
+
allLines.push(`${blockIndent}${line}`);
|
|
1439
1548
|
}
|
|
1440
1549
|
}
|
|
1441
1550
|
markBlock(entry.id, blockStart);
|
|
@@ -1453,8 +1562,15 @@ export class BtwOverlayComponent extends Container implements Focusable {
|
|
|
1453
1562
|
pushBlank();
|
|
1454
1563
|
allLines.push(`${focusRail(entry.id)}${resultLabel}${summary}${truncLabel}${moreLabel}`);
|
|
1455
1564
|
if (isExpanded) {
|
|
1456
|
-
|
|
1457
|
-
|
|
1565
|
+
const toolLines = renderBtwToolText(
|
|
1566
|
+
entry.fullContent ?? entry.content,
|
|
1567
|
+
mdContentWidth,
|
|
1568
|
+
this.theme,
|
|
1569
|
+
entry.toolCallId ? toolArgsByCall.get(entry.toolCallId) : entry.toolName,
|
|
1570
|
+
entry.isError,
|
|
1571
|
+
);
|
|
1572
|
+
for (const line of toolLines) {
|
|
1573
|
+
allLines.push(`${blockIndent}${line}`);
|
|
1458
1574
|
}
|
|
1459
1575
|
}
|
|
1460
1576
|
markBlock(entry.id, blockStart);
|
|
@@ -1466,27 +1582,17 @@ export class BtwOverlayComponent extends Container implements Focusable {
|
|
|
1466
1582
|
const header = entry.streaming ? `${assistantBadge} ${this.theme.fg("warning", "▍")}` : assistantBadge;
|
|
1467
1583
|
allLines.push(`${focusRail(entry.id)}${header}`);
|
|
1468
1584
|
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
for (const line of mdLines) {
|
|
1481
|
-
allLines.push(`${blockIndent}${line.replace(/[ \t]+$/u, "")}`);
|
|
1482
|
-
}
|
|
1483
|
-
}
|
|
1484
|
-
} else {
|
|
1485
|
-
// While streaming, use plain text for speed and stability
|
|
1486
|
-
const styledLines = wrapTextWithAnsi(entry.text, mdContentWidth);
|
|
1487
|
-
for (const line of styledLines) {
|
|
1488
|
-
allLines.push(`${blockIndent}${line}`);
|
|
1489
|
-
}
|
|
1585
|
+
// Use the same Pi Markdown renderer for completed and streaming text.
|
|
1586
|
+
// Markdown is intentionally cheap here because the overlay already
|
|
1587
|
+
// coalesces streaming refreshes, and it avoids a visual mode switch at
|
|
1588
|
+
// the end of a response.
|
|
1589
|
+
const cached = this.mdLineCache.get(entry.id);
|
|
1590
|
+
const mdLines = cached && cached.renderedAtWidth === mdContentWidth
|
|
1591
|
+
? cached.lines
|
|
1592
|
+
: renderBtwMarkdown(entry.text, mdContentWidth, this.theme, "assistant", this.mdTheme);
|
|
1593
|
+
this.mdLineCache.set(entry.id, { lines: mdLines, renderedAtWidth: mdContentWidth });
|
|
1594
|
+
for (const line of mdLines) {
|
|
1595
|
+
allLines.push(`${blockIndent}${line.replace(/[ \t]+$/u, "")}`);
|
|
1490
1596
|
}
|
|
1491
1597
|
markBlock(entry.id, blockStart);
|
|
1492
1598
|
continue;
|
|
@@ -1520,10 +1626,12 @@ export class BtwOverlayComponent extends Container implements Focusable {
|
|
|
1520
1626
|
this.followTranscript = false;
|
|
1521
1627
|
}
|
|
1522
1628
|
const maxScroll = Math.max(0, this.transcriptLines.length - this.transcriptViewportHeight);
|
|
1523
|
-
|
|
1629
|
+
const nextOffset = Math.max(
|
|
1524
1630
|
0,
|
|
1525
1631
|
Math.min(maxScroll, this.transcriptScrollOffset + delta),
|
|
1526
1632
|
);
|
|
1633
|
+
if (nextOffset !== this.transcriptScrollOffset) this.scrollbarActive = true;
|
|
1634
|
+
this.transcriptScrollOffset = nextOffset;
|
|
1527
1635
|
if (this.transcriptScrollOffset >= maxScroll) {
|
|
1528
1636
|
this.followTranscript = true;
|
|
1529
1637
|
}
|
|
@@ -1888,7 +1996,6 @@ export class BtwOverlayComponent extends Container implements Focusable {
|
|
|
1888
1996
|
this.transcriptScrollOffset,
|
|
1889
1997
|
this.transcriptScrollOffset + transcriptHeight,
|
|
1890
1998
|
);
|
|
1891
|
-
const transcriptPadCount = Math.max(0, transcriptHeight - visibleTranscript.length);
|
|
1892
1999
|
const hiddenAbove = this.transcriptScrollOffset;
|
|
1893
2000
|
const hiddenBelow = Math.max(0, maxScroll - this.transcriptScrollOffset);
|
|
1894
2001
|
const summary =
|
|
@@ -1900,16 +2007,20 @@ export class BtwOverlayComponent extends Container implements Focusable {
|
|
|
1900
2007
|
|
|
1901
2008
|
lines.push(this.titleLine(this.theme.fg("accent", this.theme.bold(this.modeTextValue.trim())), innerWidth));
|
|
1902
2009
|
lines.push(this.frameLine(this.theme.fg("dim", summary), innerWidth));
|
|
1903
|
-
lines.push(this.
|
|
1904
|
-
|
|
1905
|
-
for (
|
|
1906
|
-
lines.push(this.
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
2010
|
+
lines.push(this.scrollRule(innerWidth, "top", hiddenAbove));
|
|
2011
|
+
|
|
2012
|
+
for (let i = 0; i < transcriptHeight; i++) {
|
|
2013
|
+
lines.push(this.frameScrollableLine(
|
|
2014
|
+
visibleTranscript[i] ?? "",
|
|
2015
|
+
innerWidth,
|
|
2016
|
+
transcriptLines.length,
|
|
2017
|
+
transcriptHeight,
|
|
2018
|
+
this.transcriptScrollOffset,
|
|
2019
|
+
i,
|
|
2020
|
+
));
|
|
1910
2021
|
}
|
|
1911
2022
|
|
|
1912
|
-
lines.push(this.
|
|
2023
|
+
lines.push(this.scrollRule(innerWidth, "bottom", hiddenBelow));
|
|
1913
2024
|
lines.push(this.frameLine(this.theme.fg("warning", this.statusTextValue.trim()), innerWidth));
|
|
1914
2025
|
lines.push(...this.inputFrameLines(innerWidth, inputLineCount));
|
|
1915
2026
|
lines.push(this.frameLine(this.theme.fg("dim", this.hintsTextValue.trim()), innerWidth));
|
|
@@ -1920,6 +2031,7 @@ export class BtwOverlayComponent extends Container implements Focusable {
|
|
|
1920
2031
|
|
|
1921
2032
|
setDraft(value: string): void {
|
|
1922
2033
|
this.input.setText(value);
|
|
2034
|
+
this.resetDraftRecall();
|
|
1923
2035
|
this.tui.requestRender();
|
|
1924
2036
|
}
|
|
1925
2037
|
|
|
@@ -1973,13 +2085,21 @@ export class BtwOverlayComponent extends Container implements Focusable {
|
|
|
1973
2085
|
|
|
1974
2086
|
private buildToolPreviewLines(block: PeekBlock, innerWidth: number): string[] {
|
|
1975
2087
|
// Keep the preview read-only and complete. The viewport, not the data,
|
|
1976
|
-
// supplies the bound: only the visible slice is emitted below.
|
|
1977
|
-
|
|
1978
|
-
const
|
|
2088
|
+
// supplies the bound: only the visible slice is emitted below. Inputs and
|
|
2089
|
+
// outputs use the same Pi tool highlighter as expanded transcript rows.
|
|
2090
|
+
const bodyWidth = Math.max(1, innerWidth - 1 - 2);
|
|
2091
|
+
const input = block.toolInput || (block.type === "tool-call" ? block.text : "") || "(no input)";
|
|
2092
|
+
const output = block.toolOutput || (block.type === "tool-result" ? block.text : "") || "(no output)";
|
|
1979
2093
|
const lines: string[] = [];
|
|
1980
|
-
|
|
1981
|
-
lines.push(
|
|
2094
|
+
if (block.streaming) {
|
|
2095
|
+
lines.push(this.theme.fg("warning", "Status: STREAMING"));
|
|
2096
|
+
lines.push("");
|
|
1982
2097
|
}
|
|
2098
|
+
lines.push(this.theme.fg("toolTitle", this.theme.bold("Input:")));
|
|
2099
|
+
lines.push(...renderBtwToolText(input, bodyWidth, this.theme).map((line) => ` ${line}`));
|
|
2100
|
+
lines.push("");
|
|
2101
|
+
lines.push(this.theme.fg(block.isError ? "error" : "toolTitle", this.theme.bold(`Output${block.isError ? " (error)" : ""}:`)));
|
|
2102
|
+
lines.push(...renderBtwToolText(output, bodyWidth, this.theme, block.toolInput, block.isError).map((line) => ` ${line}`));
|
|
1983
2103
|
return lines.length > 0 ? lines : ["(no tool data)"];
|
|
1984
2104
|
}
|
|
1985
2105
|
|
|
@@ -2035,10 +2155,12 @@ export class BtwOverlayComponent extends Container implements Focusable {
|
|
|
2035
2155
|
if (this.toolPreviewParent === null) return;
|
|
2036
2156
|
const viewportHeight = Math.max(1, this.peekState.viewportHeight);
|
|
2037
2157
|
const maxScroll = Math.max(0, this.peekToolPreviewLines.length - viewportHeight);
|
|
2038
|
-
|
|
2158
|
+
const nextOffset = Math.max(
|
|
2039
2159
|
0,
|
|
2040
2160
|
Math.min(maxScroll, this.peekToolPreviewScrollOffset + delta),
|
|
2041
2161
|
);
|
|
2162
|
+
if (nextOffset !== this.peekToolPreviewScrollOffset) this.scrollbarActive = true;
|
|
2163
|
+
this.peekToolPreviewScrollOffset = nextOffset;
|
|
2042
2164
|
this.tui.requestRender();
|
|
2043
2165
|
}
|
|
2044
2166
|
|
|
@@ -2064,21 +2186,29 @@ export class BtwOverlayComponent extends Container implements Focusable {
|
|
|
2064
2186
|
|
|
2065
2187
|
const streamingLabel = block.streaming ? " · STREAMING" : "";
|
|
2066
2188
|
const title = `BTW Tool Output · ${getSemanticBlockLabel(block)}${streamingLabel} · read-only`;
|
|
2067
|
-
const lines = [
|
|
2068
|
-
this.borderLine(innerWidth, "top"),
|
|
2069
|
-
this.titleLine(this.theme.fg("accent", this.theme.bold(title)), innerWidth),
|
|
2070
|
-
this.ruleLine(innerWidth),
|
|
2071
|
-
];
|
|
2072
2189
|
const visible = this.peekToolPreviewLines.slice(
|
|
2073
2190
|
this.peekToolPreviewScrollOffset,
|
|
2074
2191
|
this.peekToolPreviewScrollOffset + viewportHeight,
|
|
2075
2192
|
);
|
|
2076
|
-
for (const line of visible) lines.push(this.frameLine(line, innerWidth));
|
|
2077
|
-
for (let i = visible.length; i < viewportHeight; i++) lines.push(this.frameLine("", innerWidth));
|
|
2078
2193
|
const hiddenAbove = this.peekToolPreviewScrollOffset;
|
|
2079
2194
|
const hiddenBelow = Math.max(0, maxScroll - this.peekToolPreviewScrollOffset);
|
|
2195
|
+
const lines = [
|
|
2196
|
+
this.borderLine(innerWidth, "top"),
|
|
2197
|
+
this.titleLine(this.theme.fg("accent", this.theme.bold(title)), innerWidth),
|
|
2198
|
+
this.scrollRule(innerWidth, "top", hiddenAbove),
|
|
2199
|
+
];
|
|
2200
|
+
for (let i = 0; i < viewportHeight; i++) {
|
|
2201
|
+
lines.push(this.frameScrollableLine(
|
|
2202
|
+
visible[i] ?? "",
|
|
2203
|
+
innerWidth,
|
|
2204
|
+
this.peekToolPreviewLines.length,
|
|
2205
|
+
viewportHeight,
|
|
2206
|
+
this.peekToolPreviewScrollOffset,
|
|
2207
|
+
i,
|
|
2208
|
+
));
|
|
2209
|
+
}
|
|
2210
|
+
lines.push(this.scrollRule(innerWidth, "bottom", hiddenBelow));
|
|
2080
2211
|
const counts = hiddenAbove || hiddenBelow ? ` · ↑${hiddenAbove} ↓${hiddenBelow}` : "";
|
|
2081
|
-
lines.push(this.ruleLine(innerWidth));
|
|
2082
2212
|
lines.push(this.frameLine(this.theme.fg("dim", `j/k ↑↓ g/G PgUp/PgDn Esc:back${counts}`), innerWidth));
|
|
2083
2213
|
lines.push(this.borderLine(innerWidth, "bottom"));
|
|
2084
2214
|
return lines.map((line) => this.fitRenderedLine(line, fullWidth));
|
|
@@ -2110,24 +2240,29 @@ export class BtwOverlayComponent extends Container implements Focusable {
|
|
|
2110
2240
|
);
|
|
2111
2241
|
|
|
2112
2242
|
const title = `BTW Peek · ${getSemanticBlockLabel(block)} · read-only`;
|
|
2113
|
-
const lines = [
|
|
2114
|
-
this.borderLine(innerWidth, "top"),
|
|
2115
|
-
this.titleLine(this.theme.fg("accent", this.theme.bold(title)), innerWidth),
|
|
2116
|
-
this.ruleLine(innerWidth),
|
|
2117
|
-
];
|
|
2118
2243
|
const visible = this.peekToolPreviewLines.slice(
|
|
2119
2244
|
this.peekToolPreviewScrollOffset,
|
|
2120
2245
|
this.peekToolPreviewScrollOffset + viewportHeight,
|
|
2121
2246
|
);
|
|
2122
|
-
for (const line of visible) lines.push(this.frameLine(line, innerWidth));
|
|
2123
|
-
while (visible.length < viewportHeight) {
|
|
2124
|
-
visible.push("");
|
|
2125
|
-
lines.push(this.frameLine("", innerWidth));
|
|
2126
|
-
}
|
|
2127
2247
|
const hiddenAbove = this.peekToolPreviewScrollOffset;
|
|
2128
2248
|
const hiddenBelow = Math.max(0, maxScroll - this.peekToolPreviewScrollOffset);
|
|
2249
|
+
const lines = [
|
|
2250
|
+
this.borderLine(innerWidth, "top"),
|
|
2251
|
+
this.titleLine(this.theme.fg("accent", this.theme.bold(title)), innerWidth),
|
|
2252
|
+
this.scrollRule(innerWidth, "top", hiddenAbove),
|
|
2253
|
+
];
|
|
2254
|
+
for (let i = 0; i < viewportHeight; i++) {
|
|
2255
|
+
lines.push(this.frameScrollableLine(
|
|
2256
|
+
visible[i] ?? "",
|
|
2257
|
+
innerWidth,
|
|
2258
|
+
this.peekToolPreviewLines.length,
|
|
2259
|
+
viewportHeight,
|
|
2260
|
+
this.peekToolPreviewScrollOffset,
|
|
2261
|
+
i,
|
|
2262
|
+
));
|
|
2263
|
+
}
|
|
2264
|
+
lines.push(this.scrollRule(innerWidth, "bottom", hiddenBelow));
|
|
2129
2265
|
const counts = hiddenAbove || hiddenBelow ? ` · ↑${hiddenAbove} ↓${hiddenBelow}` : "";
|
|
2130
|
-
lines.push(this.ruleLine(innerWidth));
|
|
2131
2266
|
lines.push(this.frameLine(this.theme.fg("dim", `j/k ↑↓ g/G PgUp/PgDn q/Esc:back${counts}`), innerWidth));
|
|
2132
2267
|
lines.push(this.borderLine(innerWidth, "bottom"));
|
|
2133
2268
|
return lines.map((line) => this.fitRenderedLine(line, fullWidth));
|
|
@@ -2155,6 +2290,7 @@ export class BtwOverlayComponent extends Container implements Focusable {
|
|
|
2155
2290
|
this.toolPreviewParent = "live";
|
|
2156
2291
|
this.peekToolPreviewScrollOffset = 0;
|
|
2157
2292
|
this.peekToolPreviewLines = [];
|
|
2293
|
+
this.scrollbarActive = false;
|
|
2158
2294
|
this.tui.requestRender();
|
|
2159
2295
|
}
|
|
2160
2296
|
|
|
@@ -2266,7 +2402,8 @@ export class BtwOverlayComponent extends Container implements Focusable {
|
|
|
2266
2402
|
}
|
|
2267
2403
|
|
|
2268
2404
|
// ── Content ──────────────────────────────────────────────────────
|
|
2269
|
-
|
|
2405
|
+
// Keep one inner cell free for the right-hand ScrollView rail.
|
|
2406
|
+
const mdContentWidth = Math.max(1, innerWidth - 7);
|
|
2270
2407
|
this.peekContentTop = 4;
|
|
2271
2408
|
// Build rendered lines and remember each block's starting line so j/k
|
|
2272
2409
|
// can scroll by line while J/K still jump by message.
|
|
@@ -2308,21 +2445,14 @@ export class BtwOverlayComponent extends Container implements Focusable {
|
|
|
2308
2445
|
if (this.expandedToolId === block.id && hasToolPreview(block)) {
|
|
2309
2446
|
const toolLines = this.buildToolPreviewLines(block, innerWidth);
|
|
2310
2447
|
for (const toolLine of toolLines) {
|
|
2311
|
-
blockLines.push(`${isCurrent ? "▎ " : " "}${
|
|
2448
|
+
blockLines.push(`${isCurrent ? "▎ " : " "}${toolLine}`);
|
|
2312
2449
|
}
|
|
2313
2450
|
}
|
|
2314
2451
|
} else if (block.text) {
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
blockLines.push(`${isCurrent ? "▎ " : " "}${mdLine.replace(/[ \t]+$/u, "")}`);
|
|
2320
|
-
}
|
|
2321
|
-
} else if (block.type === "thinking") {
|
|
2322
|
-
const styledLines = wrapTextWithAnsi(block.text, mdContentWidth);
|
|
2323
|
-
for (const sl of styledLines) {
|
|
2324
|
-
blockLines.push(`${isCurrent ? "▎ " : " "}${this.theme.fg("warning", this.theme.italic(sl))}`);
|
|
2325
|
-
}
|
|
2452
|
+
const role = block.type === "user" ? "user" : block.type === "thinking" ? "thinking" : "assistant";
|
|
2453
|
+
const markdownLines = renderBtwMarkdown(block.text, mdContentWidth, this.theme, role, this.mdTheme);
|
|
2454
|
+
for (const markdownLine of markdownLines) {
|
|
2455
|
+
blockLines.push(`${isCurrent ? "▎ " : " "}${markdownLine.replace(/[ \t]+$/u, "")}`);
|
|
2326
2456
|
}
|
|
2327
2457
|
}
|
|
2328
2458
|
|
|
@@ -2342,6 +2472,11 @@ export class BtwOverlayComponent extends Container implements Focusable {
|
|
|
2342
2472
|
this.peekState.scrollOffset = Math.max(0, Math.min(this.peekState.scrollOffset, maxScroll));
|
|
2343
2473
|
|
|
2344
2474
|
const visibleStart = this.peekState.scrollOffset;
|
|
2475
|
+
const hiddenAbove = visibleStart;
|
|
2476
|
+
const hiddenBelow = Math.max(0, maxScroll - visibleStart);
|
|
2477
|
+
// The header rule is the top ScrollView more indicator. It is emitted
|
|
2478
|
+
// before content so the hit-test coordinates remain stable.
|
|
2479
|
+
lines[2] = this.scrollRule(innerWidth, "top", hiddenAbove);
|
|
2345
2480
|
this.peekStickyHeaderIndex = null;
|
|
2346
2481
|
const displayLines = this.peekRenderedLines.slice(visibleStart, visibleStart + vh);
|
|
2347
2482
|
if (blockCount === 0) {
|
|
@@ -2357,9 +2492,16 @@ export class BtwOverlayComponent extends Container implements Focusable {
|
|
|
2357
2492
|
displayLines.push("");
|
|
2358
2493
|
}
|
|
2359
2494
|
|
|
2360
|
-
// Frame each line
|
|
2361
|
-
for (
|
|
2362
|
-
lines.push(this.
|
|
2495
|
+
// Frame each line and reserve the final inner cell for the scrollbar.
|
|
2496
|
+
for (let i = 0; i < vh; i++) {
|
|
2497
|
+
lines.push(this.frameScrollableLine(
|
|
2498
|
+
displayLines[i] ?? "",
|
|
2499
|
+
innerWidth,
|
|
2500
|
+
this.peekRenderedLines.length,
|
|
2501
|
+
vh,
|
|
2502
|
+
this.peekState.scrollOffset,
|
|
2503
|
+
i,
|
|
2504
|
+
));
|
|
2363
2505
|
}
|
|
2364
2506
|
|
|
2365
2507
|
// ── Status bar ───────────────────────────────────────────────────
|
|
@@ -2371,7 +2513,7 @@ export class BtwOverlayComponent extends Container implements Focusable {
|
|
|
2371
2513
|
const previewHint = hasToolPreview(selected) ? " w:preview" : "";
|
|
2372
2514
|
const expandHint = hasToolPreview(selected) ? " Enter:expand" : "";
|
|
2373
2515
|
const statusText = `j/k ↑↓ J/K msg g/G /search${searchHint} ${toolsHint}${previewHint} M:copy o:nvim${expandHint} q:exit`;
|
|
2374
|
-
lines.push(this.
|
|
2516
|
+
lines.push(this.scrollRule(innerWidth, "bottom", hiddenBelow));
|
|
2375
2517
|
lines.push(this.frameLine(this.theme.fg("dim", statusText), innerWidth));
|
|
2376
2518
|
lines.push(this.borderLine(innerWidth, "bottom"));
|
|
2377
2519
|
|
|
@@ -2381,6 +2523,7 @@ export class BtwOverlayComponent extends Container implements Focusable {
|
|
|
2381
2523
|
enterPeekMode(): void {
|
|
2382
2524
|
this.peekState = createPeekState();
|
|
2383
2525
|
this.peekState.active = true;
|
|
2526
|
+
this.scrollbarActive = false;
|
|
2384
2527
|
const entries = this.readTranscriptEntries();
|
|
2385
2528
|
this.peekState.showTools = true;
|
|
2386
2529
|
this.peekBlocks = this.hydrateToolBlocks(buildPeekBlocks(
|
|
@@ -3242,15 +3385,22 @@ export default function (pi: ExtensionAPI) {
|
|
|
3242
3385
|
throw new Error(settings.fallbackReason || "No active model selected.");
|
|
3243
3386
|
}
|
|
3244
3387
|
|
|
3245
|
-
const {
|
|
3388
|
+
const parentModelRuntime = (ctx.modelRegistry as unknown as { runtime?: ModelRuntime | null }).runtime ?? undefined;
|
|
3389
|
+
const sessionOptions: Parameters<typeof createAgentSession>[0] & {
|
|
3390
|
+
modelRegistry?: ExtensionContext["modelRegistry"];
|
|
3391
|
+
modelRuntime?: ModelRuntime;
|
|
3392
|
+
} = {
|
|
3246
3393
|
sessionManager: SessionManager.inMemory(),
|
|
3247
3394
|
model: settings.model,
|
|
3248
|
-
|
|
3395
|
+
...(parentModelRuntime !== undefined && { modelRuntime: parentModelRuntime }),
|
|
3249
3396
|
thinkingLevel: settings.thinkingLevel,
|
|
3250
3397
|
// Match pi's default coding-agent toolset (read/bash/edit/write).
|
|
3251
3398
|
tools: ["read", "bash", "edit", "write"],
|
|
3252
3399
|
resourceLoader: createBtwResourceLoader(ctx),
|
|
3253
|
-
|
|
3400
|
+
// Keep the pre-ModelRuntime facade available for older Pi hosts.
|
|
3401
|
+
modelRegistry: ctx.modelRegistry,
|
|
3402
|
+
};
|
|
3403
|
+
const { session } = await createAgentSession(sessionOptions);
|
|
3254
3404
|
|
|
3255
3405
|
const { messages: seedMessages, sideThreadStartIndex } = buildBtwSeedState(ctx, pendingThread, mode, settings.model);
|
|
3256
3406
|
if (seedMessages.length > 0) {
|
|
@@ -3879,14 +4029,21 @@ export default function (pi: ExtensionAPI) {
|
|
|
3879
4029
|
throw new Error(auth.ok ? `No credentials available for ${model.provider}/${model.id}.` : auth.error);
|
|
3880
4030
|
}
|
|
3881
4031
|
|
|
3882
|
-
const {
|
|
4032
|
+
const parentModelRuntime = (ctx.modelRegistry as unknown as { runtime?: ModelRuntime | null }).runtime ?? undefined;
|
|
4033
|
+
const sessionOptions: Parameters<typeof createAgentSession>[0] & {
|
|
4034
|
+
modelRegistry?: ExtensionContext["modelRegistry"];
|
|
4035
|
+
modelRuntime?: ModelRuntime;
|
|
4036
|
+
} = {
|
|
3883
4037
|
sessionManager: SessionManager.inMemory(),
|
|
3884
4038
|
model,
|
|
3885
|
-
|
|
4039
|
+
...(parentModelRuntime !== undefined && { modelRuntime: parentModelRuntime }),
|
|
3886
4040
|
thinkingLevel: "off",
|
|
3887
4041
|
tools: [],
|
|
3888
4042
|
resourceLoader: createBtwResourceLoader(ctx, [BTW_SUMMARIZE_SYSTEM_PROMPT]),
|
|
3889
|
-
|
|
4043
|
+
// Keep the pre-ModelRuntime facade available for older Pi hosts.
|
|
4044
|
+
modelRegistry: ctx.modelRegistry,
|
|
4045
|
+
};
|
|
4046
|
+
const { session } = await createAgentSession(sessionOptions);
|
|
3890
4047
|
|
|
3891
4048
|
try {
|
|
3892
4049
|
await session.prompt(formatThread(thread), { source: "extension" });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-render-btw",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.14",
|
|
4
4
|
"description": "A pi extension for parallel side conversations with /btw — with markdown rendering in the floating window",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -47,9 +47,9 @@
|
|
|
47
47
|
"image": "https://raw.githubusercontent.com/ESSO0428/pi-render-btw/main/docs/btw-overlay.png"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
|
-
"@earendil-works/pi-ai": ">=0.
|
|
51
|
-
"@earendil-works/pi-coding-agent": ">=0.
|
|
52
|
-
"@earendil-works/pi-tui": ">=0.
|
|
50
|
+
"@earendil-works/pi-ai": ">=0.80.8 <1",
|
|
51
|
+
"@earendil-works/pi-coding-agent": ">=0.80.8 <1",
|
|
52
|
+
"@earendil-works/pi-tui": ">=0.80.8 <1"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"typescript": "^6.0.2",
|