pi-render-btw 0.6.15 → 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,14 @@
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
+
7
+ ## 0.6.16 — 2026-09-18
8
+
9
+ - Extract textual tool-result content for readable Tool Output instead of rendering the raw `{ content: [...] }` envelope.
10
+ - Omit duplicated Details content while preserving structured metadata such as duration and diffs.
11
+
3
12
  ## 0.6.15 — 2026-09-18
4
13
 
5
14
  - Use one local Cc-style Input/Output card renderer for Peek and read-only Tool Output, including stable input key/value rows, rails, error styling, and width-safe synchronous highlighting.
@@ -542,7 +542,7 @@ describe("BTW transcript message layout", () => {
542
542
  isError: false,
543
543
  input: { path: "full.txt" },
544
544
  output: { content: [{ type: "text", text: "full output" }] },
545
- details: { durationMs: 3 },
545
+ details: { content: [{ type: "text", text: "full output" }], durationMs: 3 },
546
546
  diff: "@@ -1 +1 @@\n",
547
547
  };
548
548
  let dismissed = 0;
@@ -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");
@@ -584,7 +588,10 @@ describe("BTW transcript message layout", () => {
584
588
  const output = component.render(80).join("\n");
585
589
  expect(output).toContain("BTW Tool Output");
586
590
  expect(output).toContain("full.txt");
591
+ expect(output).toContain("full output");
587
592
  expect(output).toContain("durationMs");
593
+ expect(output).not.toContain('"content"');
594
+ expect(output).not.toContain('"text"');
588
595
  expect(output).toContain("Diff:");
589
596
  component.handleInput("\x1b");
590
597
  expect((component as any).toolPreviewParent).toBeNull();
@@ -718,8 +725,18 @@ describe("BTW transcript message layout", () => {
718
725
  );
719
726
 
720
727
  const lines = component.render(24);
728
+ expect(lines[1]).toContain("[preview]");
729
+ expect(lines[1].indexOf("[preview]")).toBeLessThan(lines[1].indexOf("[Esc]"));
721
730
  expect(lines[1]).toMatch(/\[Esc\]│$/);
722
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
+
723
740
  const hover = component.handleMouse({ type: "move", button: "none", x: 20, y: 1 } as any);
724
741
  expect((component as any).hoveredEscapeHint).toBe(true);
725
742
  expect(hover).toEqual({ handled: true, render: true });
@@ -751,6 +768,31 @@ describe("BTW transcript message layout", () => {
751
768
  expect(dismissed).toBe(0);
752
769
  });
753
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
+
754
796
  it("closes from the title [Esc] button through the raw SGR fallback", () => {
755
797
  let dismissed = 0;
756
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));
@@ -435,8 +444,23 @@ function buildBtwSeedState(
435
444
  };
436
445
  }
437
446
 
447
+ function extractToolText(value: unknown): string | undefined {
448
+ if (Array.isArray(value)) {
449
+ const text = value
450
+ .filter((item): item is Record<string, unknown> => isRecord(item) && item.type === "text" && typeof item.text === "string")
451
+ .map((item) => item.text as string)
452
+ .join("\n");
453
+ return text || undefined;
454
+ }
455
+ if (!isRecord(value)) return undefined;
456
+ if (Array.isArray(value.content)) {
457
+ return extractToolText(value.content);
458
+ }
459
+ return value.type === "text" && typeof value.text === "string" ? value.text : undefined;
460
+ }
461
+
438
462
  function formatToolPreview(value: unknown): string {
439
- if (value === undefined) {
463
+ if (value === undefined || value === null) {
440
464
  return "";
441
465
  }
442
466
 
@@ -444,8 +468,11 @@ function formatToolPreview(value: unknown): string {
444
468
  return value;
445
469
  }
446
470
 
471
+ const text = extractToolText(value);
472
+ if (text !== undefined) return text;
473
+
447
474
  try {
448
- const preview = JSON.stringify(value);
475
+ const preview = JSON.stringify(value, null, 2);
449
476
  if (!preview || preview === "{}") {
450
477
  return "";
451
478
  }
@@ -458,6 +485,20 @@ function formatToolPreview(value: unknown): string {
458
485
  }
459
486
  }
460
487
 
488
+ function formatToolDetails(value: unknown, output: string): string {
489
+ if (!isRecord(value) || !Array.isArray(value.content)) {
490
+ return formatToolPreview(value);
491
+ }
492
+
493
+ const content = extractToolText(value);
494
+ const remaining = Object.fromEntries(
495
+ Object.entries(value).filter(([key]) => key !== "content"),
496
+ );
497
+ const remainingText = formatToolPreview(remaining);
498
+ if (content === output || !remainingText) return remainingText;
499
+ return formatToolPreview(value);
500
+ }
501
+
461
502
  function createEmptyTranscriptState(): BtwTranscriptState {
462
503
  return {
463
504
  entries: [],
@@ -1190,7 +1231,9 @@ export class BtwOverlayComponent extends Container implements Focusable {
1190
1231
  private peekToolPreviewScrollOffset = 0;
1191
1232
  private expandedToolId: number | null = null;
1192
1233
  private hoveredEscapeHint = false;
1234
+ private hoveredPreviewHint = false;
1193
1235
  private rawEscapePress = false;
1236
+ private rawPreviewPress = false;
1194
1237
  /** The same bounded preview is used by Peek and by the live BTW panel. */
1195
1238
  private toolPreviewParent: "peek" | "live" | null = null;
1196
1239
  private liveToolPreviewBlock: PeekBlock | null = null;
@@ -1398,18 +1441,42 @@ export class BtwOverlayComponent extends Container implements Focusable {
1398
1441
  return this.theme.fg("border", `${left}${"─".repeat(innerWidth)}${right}`);
1399
1442
  }
1400
1443
 
1401
- private titleLine(title: string, innerWidth: number): string {
1402
- 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);
1403
1464
  const escapeHint = this.hoveredEscapeHint
1404
- ? this.theme.fg("text", this.theme.bold(escapeLabel))
1405
- : this.theme.fg("dim", escapeLabel);
1406
- const escapeWidth = visibleWidth(escapeLabel);
1407
- // Reserve the close label before truncating the title so a long tool name
1408
- // can never hide the only visible mouse/keyboard dismissal affordance.
1409
- 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);
1410
1476
  const clippedTitle = truncateToWidth(title, titleWidth, "");
1411
- const gap = Math.max(1, innerWidth - visibleWidth(clippedTitle) - escapeWidth);
1412
- 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);
1413
1480
  }
1414
1481
 
1415
1482
  private resetDraftRecall(): void {
@@ -1688,11 +1755,48 @@ export class BtwOverlayComponent extends Container implements Focusable {
1688
1755
  return null;
1689
1756
  }
1690
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
+
1691
1790
  /** The title row is line 2 in one-based local coordinates. */
1692
1791
  private isEscapeHintHit(x: number, y: number): boolean {
1693
- const labelWidth = visibleWidth("[Esc]");
1694
- const labelStart = this.lastRenderWidth - labelWidth;
1695
- 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;
1696
1800
  }
1697
1801
 
1698
1802
  private closeEscapeTarget(): void {
@@ -1748,19 +1852,35 @@ export class BtwOverlayComponent extends Container implements Focusable {
1748
1852
  delta: event.wheelDelta,
1749
1853
  };
1750
1854
 
1855
+ const overPreviewHint = this.isPreviewHintHit(normalized.x, normalized.y);
1751
1856
  const overEscapeHint = this.isEscapeHintHit(normalized.x, normalized.y);
1752
1857
  if (normalized.action === "move" || normalized.action === "drag") {
1753
- const hoverChanged = overEscapeHint !== this.hoveredEscapeHint;
1858
+ const previewHoverChanged = overPreviewHint !== this.hoveredPreviewHint;
1859
+ const escapeHoverChanged = overEscapeHint !== this.hoveredEscapeHint;
1860
+ this.hoveredPreviewHint = overPreviewHint;
1754
1861
  this.hoveredEscapeHint = overEscapeHint;
1755
- if (overEscapeHint) {
1756
- return { handled: true, render: hoverChanged };
1862
+ if (overPreviewHint || overEscapeHint) {
1863
+ return { handled: true, render: previewHoverChanged || escapeHoverChanged };
1757
1864
  }
1758
1865
  // Continue routing a move outside the title to update transcript/block
1759
1866
  // hover state. In preview mode there is no other hover target.
1760
- if (hoverChanged && this.toolPreviewParent !== null) {
1867
+ if ((previewHoverChanged || escapeHoverChanged) && this.toolPreviewParent !== null) {
1761
1868
  return { handled: true, render: true };
1762
1869
  }
1763
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
+ }
1764
1884
  if (overEscapeHint && normalized.button === 0) {
1765
1885
  if (normalized.action === "press") {
1766
1886
  return { handled: true, capture: true, render: false };
@@ -1903,21 +2023,31 @@ export class BtwOverlayComponent extends Container implements Focusable {
1903
2023
  }
1904
2024
  return;
1905
2025
  }
1906
- // Consume bounded SGR button events locally. Older hosts do not expose
1907
- // normalized click dispatch, so retain the close-button press/release
1908
- // 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.
1909
2029
  if (mouseEvent) {
2030
+ const overPreviewHint = this.isPreviewHintHit(mouseEvent.x, mouseEvent.y);
1910
2031
  const overEscapeHint = this.isEscapeHintHit(mouseEvent.x, mouseEvent.y);
1911
2032
  this.handleMouse(mouseEvent);
1912
2033
  if (mouseEvent.button === 0 && mouseEvent.action === "press") {
2034
+ this.rawPreviewPress = overPreviewHint;
1913
2035
  this.rawEscapePress = overEscapeHint;
1914
2036
  } else if (mouseEvent.button === 0 && mouseEvent.action === "release") {
2037
+ const preview = this.rawPreviewPress && overPreviewHint;
1915
2038
  const close = this.rawEscapePress && overEscapeHint;
2039
+ this.rawPreviewPress = false;
1916
2040
  this.rawEscapePress = false;
1917
- 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
+ }
1918
2047
  }
1919
2048
  return;
1920
2049
  }
2050
+ this.rawPreviewPress = false;
1921
2051
  this.rawEscapePress = false;
1922
2052
 
1923
2053
  // Peek mode active → route all input to peek handler
@@ -2006,7 +2136,7 @@ export class BtwOverlayComponent extends Container implements Focusable {
2006
2136
 
2007
2137
  const lines = [this.borderLine(innerWidth, "top")];
2008
2138
 
2009
- 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));
2010
2140
  lines.push(this.frameLine(this.theme.fg("dim", summary), innerWidth));
2011
2141
  lines.push(this.scrollRule(innerWidth, "top", hiddenAbove));
2012
2142
 
@@ -2114,10 +2244,10 @@ export class BtwOverlayComponent extends Container implements Focusable {
2114
2244
  const hydrated = { ...block };
2115
2245
  const input = formatToolPreview(artifact.input);
2116
2246
  const output = formatToolPreview(artifact.output);
2117
- const details = formatToolPreview(artifact.details);
2247
+ const details = formatToolDetails(artifact.details, output);
2118
2248
  if (input) hydrated.toolInput = input;
2119
2249
  if (output) hydrated.toolOutput = output;
2120
- if (details) {
2250
+ if (details && details.trim() !== output.trim()) {
2121
2251
  hydrated.toolOutput = `${hydrated.toolOutput || "(no output)"}\n\nDetails:\n${details}`;
2122
2252
  }
2123
2253
  if (artifact.diff) {
@@ -2385,7 +2515,7 @@ export class BtwOverlayComponent extends Container implements Focusable {
2385
2515
  ? ` search ${this.peekState.currentMatchIndex + 1}/${this.peekState.searchMatches.length}`
2386
2516
  : "");
2387
2517
  lines.push(this.borderLine(innerWidth, "top"));
2388
- 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));
2389
2519
  lines.push(this.ruleLine(innerWidth));
2390
2520
 
2391
2521
  // ── Search bar ───────────────────────────────────────────────────
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-render-btw",
3
- "version": "0.6.15",
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",