pi-render-btw 0.6.21 → 0.6.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.6.23 — 2026-11-24
4
+
5
+ - Keep the selected BTW transcript rail continuous across blank Markdown rows within the same message block.
6
+ - Leave inter-block spacers and turn separators unrailed so message boundaries remain visually distinct.
7
+
8
+ ## 0.6.22 — 2026-11-24
9
+
10
+ - Align BTW transcript focus rails with Agent View: reserve a leading railable cell before fitting each selectable row, then replace it with `▎` only for the selected block.
11
+ - Prevent right-edge clipping for long tool headers and ANSI/CJK transcript content; preserve borders, scrollbar, and selected rail at the minimum renderable width.
12
+ - Skip rendering below four columns instead of emitting a clipped partial frame.
13
+
3
14
  ## 0.6.21 — 2026-11-24
4
15
 
5
16
  - Fix BTW overlay clipping at host widths below 24 columns by laying out the frame at the actual host width instead of expanding first and truncating the completed frame afterward.
@@ -3,6 +3,7 @@ import { tmpdir } from "node:os";
3
3
  import path from "node:path";
4
4
  import type { AgentSession } from "@earendil-works/pi-coding-agent";
5
5
  import { describe, expect, it } from "vitest";
6
+ import { visibleWidth } from "@earendil-works/pi-tui";
6
7
  import { BtwOverlayComponent, stopBtwRun, submitBtwPrompt } from "./btw.ts";
7
8
  import { BtwTranscriptStore } from "./btw/transcript-store.ts";
8
9
 
@@ -23,7 +24,7 @@ const tui = {
23
24
 
24
25
  const visibleText = (value: string): string => value.replace(/\x1b\[[0-9;?]*[ -/]*[@-~]/g, "");
25
26
 
26
- function transcriptLines(entries: unknown[]): string[] {
27
+ function transcriptLines(entries: unknown[], innerWidth = 80): string[] {
27
28
  const component = new BtwOverlayComponent(
28
29
  tui,
29
30
  theme,
@@ -35,7 +36,7 @@ function transcriptLines(entries: unknown[]): string[] {
35
36
  () => {},
36
37
  () => {},
37
38
  );
38
- return (component as any).buildTranscriptLines(80) as string[];
39
+ return (component as any).buildTranscriptLines(innerWidth) as string[];
39
40
  }
40
41
 
41
42
  describe("BTW transcript message layout", () => {
@@ -44,7 +45,7 @@ describe("BTW transcript message layout", () => {
44
45
  { id: 1, turnId: 1, type: "user-message", text: "Prompt" },
45
46
  ]);
46
47
 
47
- expect(lines.slice(0, 2)).toEqual(["▎USER ", "▎ Prompt"]);
48
+ expect(lines.slice(0, 2)).toEqual(["▎ USER ", "▎ Prompt"]);
48
49
  });
49
50
 
50
51
  it("keeps assistant heading and response on separate lines", () => {
@@ -52,10 +53,42 @@ describe("BTW transcript message layout", () => {
52
53
  { id: 1, turnId: 1, type: "assistant-text", text: "Response", streaming: false },
53
54
  ]);
54
55
 
55
- expect(lines[0]).toBe("▎ASSISTANT ");
56
+ expect(lines[0]).toBe("▎ ASSISTANT ");
56
57
  expect(lines[1].startsWith("▎ Response")).toBe(true);
57
58
  });
58
59
 
60
+ it("keeps the selected rail continuous through blank markdown rows", () => {
61
+ const lines = transcriptLines([
62
+ { id: 1, turnId: 1, type: "assistant-text", text: "First paragraph.\n\nSecond paragraph.", streaming: false },
63
+ ]);
64
+
65
+ expect(lines).toEqual([
66
+ "▎ ASSISTANT ",
67
+ "▎ First paragraph.",
68
+ "▎ ",
69
+ "▎ Second paragraph.",
70
+ ]);
71
+ });
72
+
73
+ it("does not draw the selected rail in the spacer between blocks", () => {
74
+ const lines = transcriptLines([
75
+ { id: 1, turnId: 1, type: "user-message", text: "Question" },
76
+ { id: 2, turnId: 1, type: "assistant-text", text: "Answer", streaming: false },
77
+ ]);
78
+
79
+ expect(lines).toContain("");
80
+ expect(lines[lines.indexOf("") + 1]).toBe("▎ ASSISTANT ");
81
+ });
82
+
83
+ it("reserves the selected rail cell before framing long tool headers", () => {
84
+ const lines = transcriptLines([
85
+ { id: 1, turnId: 1, type: "tool-call", toolCallId: "call-long", toolName: "read", args: "x".repeat(100) },
86
+ ], 20);
87
+
88
+ expect(lines[0].startsWith("▎")).toBe(true);
89
+ expect(visibleText(lines[0]).length).toBeLessThanOrEqual(19);
90
+ });
91
+
59
92
  it("keeps the selected transcript frame intact at narrow host widths", () => {
60
93
  const component = new BtwOverlayComponent(
61
94
  tui,
@@ -75,6 +108,48 @@ describe("BTW transcript message layout", () => {
75
108
  expect(lines.find((line) => line.includes("1234567890123"))?.endsWith("│")).toBe(true);
76
109
  });
77
110
 
111
+ it("keeps selected ANSI-styled CJK lines inside the framed viewport", () => {
112
+ const styledTheme = {
113
+ ...theme,
114
+ fg: (_name: string, text: string) => `\x1b[38;5;39m${text}\x1b[0m`,
115
+ } as any;
116
+ const component = new BtwOverlayComponent(
117
+ tui,
118
+ styledTheme,
119
+ keybindings,
120
+ () => [{ id: 1, turnId: 1, type: "assistant-text", text: "中文".repeat(20), streaming: false }] as any,
121
+ () => null,
122
+ () => "contextual",
123
+ () => {},
124
+ () => {},
125
+ () => {},
126
+ );
127
+
128
+ const body = component.render(24).find((line) => visibleText(line).includes("中文"));
129
+ expect(body).toBeDefined();
130
+ expect(visibleWidth(body!)).toBe(24);
131
+ expect(visibleText(body!).endsWith("│")).toBe(true);
132
+ });
133
+
134
+ it("does not clip its own frame below the minimum transcript width", () => {
135
+ const component = new BtwOverlayComponent(
136
+ tui,
137
+ theme,
138
+ keybindings,
139
+ () => [{ id: 1, turnId: 1, type: "assistant-text", text: "Text", streaming: false }] as any,
140
+ () => null,
141
+ () => "contextual",
142
+ () => {},
143
+ () => {},
144
+ () => {},
145
+ );
146
+
147
+ expect(component.render(3)).toEqual([]);
148
+ const minimumWidthLines = component.render(4);
149
+ expect(minimumWidthLines.map(visibleText)).toContain("┌──┐");
150
+ expect(minimumWidthLines.every((line) => visibleWidth(line) === 4)).toBe(true);
151
+ });
152
+
78
153
  it("opens Peek with Ctrl+P even when the composer contains a draft", () => {
79
154
  const component = new BtwOverlayComponent(
80
155
  tui,
package/extensions/btw.ts CHANGED
@@ -1616,21 +1616,28 @@ export class BtwOverlayComponent extends Container implements Focusable {
1616
1616
  const plain = (line: string) => line.replace(/\x1b\[[0-9;?]*[ -\/]*[@-~]/g, "");
1617
1617
  for (let index = start; index < allLines.length; index++) {
1618
1618
  const value = plain(allLines[index]);
1619
- lineEntryIds[index] = value.trim() && !/^─+$/.test(value.trim()) ? entryId : null;
1619
+ const trimmed = value.trim();
1620
+ // The first blank row is the inter-block spacer inserted by pushBlank.
1621
+ // Later blank rows belong to this block's Markdown and must carry its rail.
1622
+ lineEntryIds[index] = !/^─+$/.test(trimmed) && (trimmed || index > start) ? entryId : null;
1620
1623
  }
1621
1624
  };
1622
1625
  const userBadge = buildTranscriptBadge(this.theme, "USER", "userMessageBg", "accent");
1623
1626
  const thinkingBadge = buildTranscriptBadge(this.theme, "THINKING", "toolPendingBg", "warning");
1624
1627
  const assistantBadge = buildTranscriptBadge(this.theme, "ASSISTANT", "customMessageBg", "success");
1625
1628
  const separator = this.theme.fg("borderMuted", "─".repeat(40));
1626
- const blockIndent = " ";
1629
+ // Match Agent View: every selectable row reserves its first content cell
1630
+ // for a potential focus rail before its text is fitted to the viewport.
1631
+ const blockIndent = " ";
1627
1632
  const toolArgsByCall = new Map<string, string>();
1628
1633
  for (const entry of entries) {
1629
1634
  if (entry.type === "tool-call") toolArgsByCall.set(entry.toolCallId, entry.args);
1630
1635
  }
1631
- // Reserve the final inner cell for the right-hand ScrollView rail.
1636
+ // Reserve the final inner cell for the right-hand ScrollView rail and
1637
+ // one leading cell for the persistent selected-block rail.
1632
1638
  const scrollContentWidth = Math.max(1, innerWidth - 1);
1633
- const mdContentWidth = Math.max(1, scrollContentWidth - visibleWidth(blockIndent));
1639
+ const railableContentWidth = Math.max(0, scrollContentWidth - 1);
1640
+ const mdContentWidth = Math.max(1, railableContentWidth - visibleWidth(blockIndent));
1634
1641
 
1635
1642
  const pushBlank = (): void => {
1636
1643
  if (allLines.length > 0 && allLines[allLines.length - 1] !== "") {
@@ -1739,11 +1746,15 @@ export class BtwOverlayComponent extends Container implements Focusable {
1739
1746
 
1740
1747
  this.transcriptLineEntryIds = lineEntryIds;
1741
1748
  return allLines.map((line, index) => {
1742
- if (lineEntryIds[index] !== this.liveFocusedEntryId) {
1749
+ if (lineEntryIds[index] === null) {
1743
1750
  return line;
1744
1751
  }
1745
- const rail = this.theme.fg("accent", "▎");
1746
- return line.startsWith(" ") ? `${rail}${line.slice(1)}` : `${rail}${line}`;
1752
+ const railableText = railableContentWidth > 0 ? truncateToWidth(line, railableContentWidth, "") : "";
1753
+ const railableLine = ` ${railableText}`;
1754
+ if (lineEntryIds[index] !== this.liveFocusedEntryId) {
1755
+ return railableLine;
1756
+ }
1757
+ return `${this.theme.fg("accent", "▎")}${railableLine.slice(1)}`;
1747
1758
  });
1748
1759
  }
1749
1760
 
@@ -2171,10 +2182,11 @@ export class BtwOverlayComponent extends Container implements Focusable {
2171
2182
  }
2172
2183
 
2173
2184
  override render(width: number): string[] {
2174
- // Layout must use the host's real width. Expanding to a cosmetic minimum
2175
- // and truncating afterward drops the rightmost transcript cells.
2176
- const dialogWidth = Math.max(3, width);
2177
- const innerWidth = Math.max(1, dialogWidth - 2);
2185
+ // A framed scroll row needs left/right borders, one content cell, and the
2186
+ // scrollbar cell. Refuse smaller hosts rather than crop a completed frame.
2187
+ if (width < 4) return [];
2188
+ const dialogWidth = width;
2189
+ const innerWidth = dialogWidth - 2;
2178
2190
  this.lastRenderWidth = dialogWidth;
2179
2191
 
2180
2192
  // Tool Output is a read-only view over the currently focused live tool.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-render-btw",
3
- "version": "0.6.21",
3
+ "version": "0.6.23",
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",