pi-polish 0.1.12 → 0.1.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.
@@ -45,7 +45,7 @@ export default function (pi: ExtensionAPI) {
45
45
  if (!(child instanceof Markdown) || (child as any).defaultTextStyle !== undefined || (child as any)[patched]) continue;
46
46
  const render = child.render.bind(child);
47
47
  child.render = (width: number) => {
48
- const lines: string[] = render(width);
48
+ const lines = [...render(width)];
49
49
  const first = lines.findIndex((l) => l.replace(/\x1b\[[0-9;]*m/g, "").trim());
50
50
  if (first >= 0) lines[first] = markFirstLine(lines[first], REPLY);
51
51
  return lines;
@@ -89,8 +89,9 @@ interface Group {
89
89
  started: number;
90
90
  ended?: number;
91
91
  timer?: NodeJS.Timeout;
92
- // Opened by a click, so it shows in full like ctrl+o does, but on its own
92
+ // Opened or folded by a click, overriding ctrl+o for this group until ctrl+o is toggled
93
93
  open?: boolean;
94
+ openUnder?: boolean;
94
95
  }
95
96
 
96
97
  type Result = { content: Array<{ type: string; text?: string }>; details?: unknown };
@@ -360,6 +361,7 @@ function withBackground(line: string, spans: Span[], on: string, off: string): s
360
361
  class DiffView implements Component {
361
362
  private highlighted: string[];
362
363
  private palette: Palette;
364
+ private cachedRender?: { width: number; lines: string[] };
363
365
 
364
366
  constructor(
365
367
  private lines: string[],
@@ -402,6 +404,8 @@ class DiffView implements Component {
402
404
  }
403
405
 
404
406
  render(width: number): string[] {
407
+ if (this.cachedRender?.width === width) return this.cachedRender.lines;
408
+
405
409
  const { addedBg, removedBg, addedGutter, removedGutter } = this.palette;
406
410
  const out = this.lines.map((line, i) => {
407
411
  const sign = line[0];
@@ -418,10 +422,13 @@ class DiffView implements Component {
418
422
  return `${bg}${text.replace(/\x1b\[0?m/g, (m) => m + bg)}${pad}${BG_RESET}`;
419
423
  });
420
424
  if (this.footer) out.push(truncateToWidth(this.footer, width));
425
+ this.cachedRender = { width, lines: out };
421
426
  return out;
422
427
  }
423
428
 
424
- invalidate(): void {}
429
+ invalidate(): void {
430
+ this.cachedRender = undefined;
431
+ }
425
432
  }
426
433
 
427
434
  function lineCount(n: number): string {
@@ -618,7 +625,7 @@ export default function (pi: ExtensionAPI) {
618
625
  // Live rows wait for tool_execution_start to place them; history rows without a group render alone
619
626
  if (!group) return live || !ready ? empty() : undefined;
620
627
  if (group.members[0].id !== toolCallId) return empty();
621
- if (context.expanded || group.open) return clickable(group, tree(group, theme));
628
+ if (shown(group, context.expanded)) return clickable(group, tree(group, theme), context.expanded);
622
629
 
623
630
  const running = group.members.some((m) => !m.done);
624
631
  const failed = group.members.filter((m) => m.error).length;
@@ -638,18 +645,24 @@ export default function (pi: ExtensionAPI) {
638
645
  const mark = failed ? theme.fg("error", `${MARK} `) : " ";
639
646
  // Always the summary, even for one call ("Ran 1 shell command"), like Claude Code; a click or ctrl+o shows each one
640
647
  const text = summary(group, false);
641
- return clickable(group, oneLine([mark + theme.fg("dim", text)], failNote));
648
+ return clickable(group, oneLine([mark + theme.fg("dim", text)], failNote), context.expanded);
642
649
  };
643
650
 
651
+ /** Whether a group shows as a tree: ctrl+o's state, unless a click changed it since ctrl+o was last toggled. */
652
+ const shown = (group: Group, expanded?: boolean) => (group.open !== undefined && group.openUnder === Boolean(expanded) ? group.open : Boolean(expanded));
644
653
  /** A row that opens or closes its group when clicked. */
645
- const clickable = (group: Group, row: Component): Component =>
654
+ const clickable = (group: Group, row: Component, expanded?: boolean): Component =>
646
655
  new MouseRegion(row, (event) => {
647
656
  if (event.type !== "click" || event.button !== "left") return undefined;
648
- group.open = !group.open;
657
+ group.open = !shown(group, expanded);
658
+ group.openUnder = Boolean(expanded);
649
659
  refresh(group);
650
660
  return { handled: true };
651
661
  });
652
- const isOpen = (context: { expanded?: boolean; toolCallId?: string }) => Boolean(context.expanded || groupOf.get(context.toolCallId ?? "")?.open);
662
+ const isOpen = (context: { expanded?: boolean; toolCallId?: string }) => {
663
+ const group = groupOf.get(context.toolCallId ?? "");
664
+ return group ? shown(group, context.expanded) : Boolean(context.expanded);
665
+ };
653
666
 
654
667
  // The ● carries the status, like Claude Code: dim while arguments stream, accent while running, green or red when done.
655
668
  // History rows redrawn after /reload have no execution state, so they count as done.
@@ -682,7 +695,7 @@ export default function (pi: ExtensionAPI) {
682
695
  };
683
696
  // A row of a group opened by a click closes it again
684
697
  const group = groupOf.get(context.toolCallId);
685
- return group?.open ? clickable(group, row) : row;
698
+ return group && shown(group, context.expanded) ? clickable(group, row, context.expanded) : row;
686
699
  },
687
700
  renderResult(result, { expanded }, theme, context) {
688
701
  // A group's first row draws every call's output in its tree
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-polish",
3
- "version": "0.1.12",
3
+ "version": "0.1.14",
4
4
  "license": "MIT",
5
5
  "author": "Thomas van Dongen",
6
6
  "type": "module",