pi-render-btw 0.6.16 → 0.6.17

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,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.6.17 — 2026-09-18
4
+
5
+ - Add clickable `[preview]` actions beside `[Esc]` in BTW and BTW Peek for opening the focused tool's read-only Tool Output.
6
+
3
7
  ## 0.6.16 — 2026-09-18
4
8
 
5
9
  - Extract textual tool-result content for readable Tool Output instead of rendering the raw `{ content: [...] }` envelope.
@@ -573,6 +573,10 @@ describe("BTW transcript message layout", () => {
573
573
  component.handleMouse({ type: "click", button: "left", x: 5, y: hostToolRow } as any);
574
574
  expect((component as any).liveFocusedToolCallId).toBe("call-1");
575
575
  expect((component as any).liveExpandedToolCallId).toBe("call-1");
576
+ component.handleMouse({ type: "click", button: "left", x: 64, y: 1 } as any);
577
+ expect((component as any).toolPreviewParent).toBe("live");
578
+ component.handleInput("\x1b");
579
+ expect((component as any).toolPreviewParent).toBeNull();
576
580
  (component as any).followTranscript = false;
577
581
  (component as any).transcriptScrollOffset = 0;
578
582
  expect(component.render(80).join("\n")).toContain("line 0");
@@ -721,8 +725,18 @@ describe("BTW transcript message layout", () => {
721
725
  );
722
726
 
723
727
  const lines = component.render(24);
728
+ expect(lines[1]).toContain("[preview]");
729
+ expect(lines[1].indexOf("[preview]")).toBeLessThan(lines[1].indexOf("[Esc]"));
724
730
  expect(lines[1]).toMatch(/\[Esc\]│$/);
725
731
 
732
+ const previewHover = component.handleMouse({ type: "move", button: "none", x: 10, y: 1 } as any);
733
+ expect((component as any).hoveredPreviewHint).toBe(true);
734
+ expect(previewHover).toEqual({ handled: true, render: true });
735
+ const noPreview = component.handleMouse({ type: "click", button: "left", x: 10, y: 1 } as any);
736
+ expect(noPreview).toEqual({ handled: true, render: false });
737
+ expect((component as any).toolPreviewParent).toBeNull();
738
+ expect(dismissed).toBe(0);
739
+
726
740
  const hover = component.handleMouse({ type: "move", button: "none", x: 20, y: 1 } as any);
727
741
  expect((component as any).hoveredEscapeHint).toBe(true);
728
742
  expect(hover).toEqual({ handled: true, render: true });
@@ -754,6 +768,31 @@ describe("BTW transcript message layout", () => {
754
768
  expect(dismissed).toBe(0);
755
769
  });
756
770
 
771
+ it("opens the selected Peek tool from the title [preview] button", () => {
772
+ const entries = [
773
+ { id: 1, turnId: 1, type: "tool-call", toolCallId: "call-peek", toolName: "read", args: "{\"path\":\"src/index.ts\"}" },
774
+ { id: 2, turnId: 1, type: "tool-result", toolCallId: "call-peek", toolName: "read", content: "preview text", fullContent: "preview text", truncated: false, isError: false, streaming: false },
775
+ ] as any;
776
+ const component = new BtwOverlayComponent(
777
+ tui,
778
+ theme,
779
+ keybindings,
780
+ () => entries,
781
+ () => null,
782
+ () => "contextual",
783
+ () => {},
784
+ () => {},
785
+ () => {},
786
+ );
787
+
788
+ component.handleInput("\x10");
789
+ component.render(80);
790
+ component.handleMouse({ type: "click", button: "left", x: 64, y: 1 } as any);
791
+
792
+ expect((component as any).peekState.active).toBe(true);
793
+ expect((component as any).toolPreviewParent).toBe("peek");
794
+ });
795
+
757
796
  it("closes from the title [Esc] button through the raw SGR fallback", () => {
758
797
  let dismissed = 0;
759
798
  const component = new BtwOverlayComponent(
package/extensions/btw.ts CHANGED
@@ -74,6 +74,15 @@ const BTW_MODEL_OVERRIDE_TYPE = "btw-model-override";
74
74
  const BTW_THINKING_OVERRIDE_TYPE = "btw-thinking-override";
75
75
  const BTW_FOCUS_SHORTCUTS = [Key.alt("/"), Key.ctrlAlt("w")] as const;
76
76
  const BTW_TOOL_OUTPUT_SHORTCUT = Key.ctrl("o");
77
+ const BTW_PREVIEW_LABEL = "[preview]";
78
+ const BTW_ESCAPE_LABEL = "[Esc]";
79
+
80
+ type BtwTitleActionGeometry = {
81
+ previewStart: number | null;
82
+ previewEnd: number | null;
83
+ escapeStart: number;
84
+ escapeEnd: number;
85
+ };
77
86
 
78
87
  function matchesBtwFocusShortcut(data: string): boolean {
79
88
  return BTW_FOCUS_SHORTCUTS.some((shortcut) => matchesKey(data, shortcut));
@@ -1222,7 +1231,9 @@ export class BtwOverlayComponent extends Container implements Focusable {
1222
1231
  private peekToolPreviewScrollOffset = 0;
1223
1232
  private expandedToolId: number | null = null;
1224
1233
  private hoveredEscapeHint = false;
1234
+ private hoveredPreviewHint = false;
1225
1235
  private rawEscapePress = false;
1236
+ private rawPreviewPress = false;
1226
1237
  /** The same bounded preview is used by Peek and by the live BTW panel. */
1227
1238
  private toolPreviewParent: "peek" | "live" | null = null;
1228
1239
  private liveToolPreviewBlock: PeekBlock | null = null;
@@ -1430,18 +1441,42 @@ export class BtwOverlayComponent extends Container implements Focusable {
1430
1441
  return this.theme.fg("border", `${left}${"─".repeat(innerWidth)}${right}`);
1431
1442
  }
1432
1443
 
1433
- private titleLine(title: string, innerWidth: number): string {
1434
- const escapeLabel = "[Esc]";
1444
+ private titleActionGeometry(innerWidth: number, showPreview: boolean): BtwTitleActionGeometry {
1445
+ const escapeWidth = visibleWidth(BTW_ESCAPE_LABEL);
1446
+ const previewWidth = showPreview ? visibleWidth(BTW_PREVIEW_LABEL) : 0;
1447
+ const actionGap = showPreview ? 1 : 0;
1448
+ const actionsWidth = previewWidth + actionGap + escapeWidth;
1449
+ const actionStart = innerWidth - actionsWidth + 1;
1450
+ const escapeStart = innerWidth - escapeWidth + 1;
1451
+
1452
+ return {
1453
+ previewStart: showPreview ? actionStart : null,
1454
+ previewEnd: showPreview ? actionStart + previewWidth - 1 : null,
1455
+ escapeStart,
1456
+ escapeEnd: escapeStart + escapeWidth - 1,
1457
+ };
1458
+ }
1459
+
1460
+ private titleLine(title: string, innerWidth: number, showPreview = false): string {
1461
+ const geometry = this.titleActionGeometry(innerWidth, showPreview);
1462
+ const actionWidth = innerWidth - geometry.escapeStart + 1 +
1463
+ (geometry.previewStart === null ? 0 : geometry.escapeStart - geometry.previewStart);
1435
1464
  const escapeHint = this.hoveredEscapeHint
1436
- ? this.theme.fg("text", this.theme.bold(escapeLabel))
1437
- : this.theme.fg("dim", escapeLabel);
1438
- const escapeWidth = visibleWidth(escapeLabel);
1439
- // Reserve the close label before truncating the title so a long tool name
1440
- // can never hide the only visible mouse/keyboard dismissal affordance.
1441
- const titleWidth = Math.max(0, innerWidth - escapeWidth - 1);
1465
+ ? this.theme.fg("text", this.theme.bold(BTW_ESCAPE_LABEL))
1466
+ : this.theme.fg("dim", BTW_ESCAPE_LABEL);
1467
+ const previewEnabled = showPreview && this.canEnterPreview();
1468
+ const previewHint = showPreview
1469
+ ? this.hoveredPreviewHint && previewEnabled
1470
+ ? this.theme.fg("text", this.theme.bold(BTW_PREVIEW_LABEL))
1471
+ : this.theme.fg("dim", BTW_PREVIEW_LABEL)
1472
+ : "";
1473
+ // Reserve the title actions before truncating the title so a long title
1474
+ // can never hide either visible mouse/keyboard affordance.
1475
+ const titleWidth = Math.max(0, (geometry.previewStart ?? geometry.escapeStart) - 2);
1442
1476
  const clippedTitle = truncateToWidth(title, titleWidth, "");
1443
- const gap = Math.max(1, innerWidth - visibleWidth(clippedTitle) - escapeWidth);
1444
- return this.frameLine(`${clippedTitle}${" ".repeat(gap)}${escapeHint}`, innerWidth);
1477
+ const gap = Math.max(1, innerWidth - visibleWidth(clippedTitle) - actionWidth);
1478
+ const actions = showPreview ? `${previewHint} ${escapeHint}` : escapeHint;
1479
+ return this.frameLine(`${clippedTitle}${" ".repeat(gap)}${actions}`, innerWidth);
1445
1480
  }
1446
1481
 
1447
1482
  private resetDraftRecall(): void {
@@ -1720,11 +1755,48 @@ export class BtwOverlayComponent extends Container implements Focusable {
1720
1755
  return null;
1721
1756
  }
1722
1757
 
1758
+ private titleShowsPreviewAction(): boolean {
1759
+ return this.toolPreviewParent === null;
1760
+ }
1761
+
1762
+ private currentTitleActionGeometry(): BtwTitleActionGeometry {
1763
+ const dialogWidth = Math.max(24, this.lastRenderWidth);
1764
+ const innerWidth = Math.max(22, dialogWidth - 2);
1765
+ const local = this.titleActionGeometry(innerWidth, this.titleShowsPreviewAction());
1766
+ return {
1767
+ previewStart: local.previewStart === null ? null : local.previewStart + 1,
1768
+ previewEnd: local.previewEnd === null ? null : local.previewEnd + 1,
1769
+ escapeStart: local.escapeStart + 1,
1770
+ escapeEnd: local.escapeEnd + 1,
1771
+ };
1772
+ }
1773
+
1774
+ private hasFocusedLiveToolPreview(): boolean {
1775
+ if (this.peekState.active || this.toolPreviewParent !== null || !this.liveFocusedToolCallId) return false;
1776
+ const block = buildPeekBlocks(
1777
+ this.readTranscriptEntries() as unknown as PeekEntry[],
1778
+ true,
1779
+ ).find((candidate) => candidate.toolCallId === this.liveFocusedToolCallId);
1780
+ return hasToolPreview(block);
1781
+ }
1782
+
1783
+ private canEnterPreview(): boolean {
1784
+ if (!this.titleShowsPreviewAction()) return false;
1785
+ return this.peekState.active
1786
+ ? hasToolPreview(this.getSelectedPeekBlock())
1787
+ : this.hasFocusedLiveToolPreview();
1788
+ }
1789
+
1723
1790
  /** The title row is line 2 in one-based local coordinates. */
1724
1791
  private isEscapeHintHit(x: number, y: number): boolean {
1725
- const labelWidth = visibleWidth("[Esc]");
1726
- const labelStart = this.lastRenderWidth - labelWidth;
1727
- return y === 2 && x >= labelStart && x < this.lastRenderWidth;
1792
+ const geometry = this.currentTitleActionGeometry();
1793
+ return y === 2 && x >= geometry.escapeStart && x <= geometry.escapeEnd;
1794
+ }
1795
+
1796
+ private isPreviewHintHit(x: number, y: number): boolean {
1797
+ const geometry = this.currentTitleActionGeometry();
1798
+ return y === 2 && geometry.previewStart !== null && geometry.previewEnd !== null &&
1799
+ x >= geometry.previewStart && x <= geometry.previewEnd;
1728
1800
  }
1729
1801
 
1730
1802
  private closeEscapeTarget(): void {
@@ -1780,19 +1852,35 @@ export class BtwOverlayComponent extends Container implements Focusable {
1780
1852
  delta: event.wheelDelta,
1781
1853
  };
1782
1854
 
1855
+ const overPreviewHint = this.isPreviewHintHit(normalized.x, normalized.y);
1783
1856
  const overEscapeHint = this.isEscapeHintHit(normalized.x, normalized.y);
1784
1857
  if (normalized.action === "move" || normalized.action === "drag") {
1785
- const hoverChanged = overEscapeHint !== this.hoveredEscapeHint;
1858
+ const previewHoverChanged = overPreviewHint !== this.hoveredPreviewHint;
1859
+ const escapeHoverChanged = overEscapeHint !== this.hoveredEscapeHint;
1860
+ this.hoveredPreviewHint = overPreviewHint;
1786
1861
  this.hoveredEscapeHint = overEscapeHint;
1787
- if (overEscapeHint) {
1788
- return { handled: true, render: hoverChanged };
1862
+ if (overPreviewHint || overEscapeHint) {
1863
+ return { handled: true, render: previewHoverChanged || escapeHoverChanged };
1789
1864
  }
1790
1865
  // Continue routing a move outside the title to update transcript/block
1791
1866
  // hover state. In preview mode there is no other hover target.
1792
- if (hoverChanged && this.toolPreviewParent !== null) {
1867
+ if ((previewHoverChanged || escapeHoverChanged) && this.toolPreviewParent !== null) {
1793
1868
  return { handled: true, render: true };
1794
1869
  }
1795
1870
  }
1871
+ if (overPreviewHint && normalized.button === 0) {
1872
+ if (normalized.action === "press") {
1873
+ return { handled: true, capture: true, render: false };
1874
+ }
1875
+ if (normalized.action === "click") {
1876
+ if (this.peekState.active) this.enterToolPreview();
1877
+ else this.enterLiveToolPreview();
1878
+ return { handled: true, render: false };
1879
+ }
1880
+ if (normalized.action === "release") {
1881
+ return { handled: true, render: false };
1882
+ }
1883
+ }
1796
1884
  if (overEscapeHint && normalized.button === 0) {
1797
1885
  if (normalized.action === "press") {
1798
1886
  return { handled: true, capture: true, render: false };
@@ -1935,21 +2023,31 @@ export class BtwOverlayComponent extends Container implements Focusable {
1935
2023
  }
1936
2024
  return;
1937
2025
  }
1938
- // Consume bounded SGR button events locally. Older hosts do not expose
1939
- // normalized click dispatch, so retain the close-button press/release
1940
- // pair as the one actionable fallback; transcript clicks remain read-only.
2026
+ // Consume bounded SGR button events locally. Older hosts do not expose
2027
+ // normalized click dispatch, so retain preview/close press/release pairs
2028
+ // as the actionable fallback; transcript clicks remain read-only.
1941
2029
  if (mouseEvent) {
2030
+ const overPreviewHint = this.isPreviewHintHit(mouseEvent.x, mouseEvent.y);
1942
2031
  const overEscapeHint = this.isEscapeHintHit(mouseEvent.x, mouseEvent.y);
1943
2032
  this.handleMouse(mouseEvent);
1944
2033
  if (mouseEvent.button === 0 && mouseEvent.action === "press") {
2034
+ this.rawPreviewPress = overPreviewHint;
1945
2035
  this.rawEscapePress = overEscapeHint;
1946
2036
  } else if (mouseEvent.button === 0 && mouseEvent.action === "release") {
2037
+ const preview = this.rawPreviewPress && overPreviewHint;
1947
2038
  const close = this.rawEscapePress && overEscapeHint;
2039
+ this.rawPreviewPress = false;
1948
2040
  this.rawEscapePress = false;
1949
- if (close) this.closeEscapeTarget();
2041
+ if (preview) {
2042
+ if (this.peekState.active) this.enterToolPreview();
2043
+ else this.enterLiveToolPreview();
2044
+ } else if (close) {
2045
+ this.closeEscapeTarget();
2046
+ }
1950
2047
  }
1951
2048
  return;
1952
2049
  }
2050
+ this.rawPreviewPress = false;
1953
2051
  this.rawEscapePress = false;
1954
2052
 
1955
2053
  // Peek mode active → route all input to peek handler
@@ -2038,7 +2136,7 @@ export class BtwOverlayComponent extends Container implements Focusable {
2038
2136
 
2039
2137
  const lines = [this.borderLine(innerWidth, "top")];
2040
2138
 
2041
- lines.push(this.titleLine(this.theme.fg("accent", this.theme.bold(this.modeTextValue.trim())), innerWidth));
2139
+ lines.push(this.titleLine(this.theme.fg("accent", this.theme.bold(this.modeTextValue.trim())), innerWidth, true));
2042
2140
  lines.push(this.frameLine(this.theme.fg("dim", summary), innerWidth));
2043
2141
  lines.push(this.scrollRule(innerWidth, "top", hiddenAbove));
2044
2142
 
@@ -2417,7 +2515,7 @@ export class BtwOverlayComponent extends Container implements Focusable {
2417
2515
  ? ` search ${this.peekState.currentMatchIndex + 1}/${this.peekState.searchMatches.length}`
2418
2516
  : "");
2419
2517
  lines.push(this.borderLine(innerWidth, "top"));
2420
- lines.push(this.titleLine(this.theme.fg("accent", this.theme.bold(title)), innerWidth));
2518
+ lines.push(this.titleLine(this.theme.fg("accent", this.theme.bold(title)), innerWidth, true));
2421
2519
  lines.push(this.ruleLine(innerWidth));
2422
2520
 
2423
2521
  // ── Search bar ───────────────────────────────────────────────────
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-render-btw",
3
- "version": "0.6.16",
3
+ "version": "0.6.17",
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",