pi-polish 0.1.8 → 0.1.9

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/README.md CHANGED
@@ -13,7 +13,7 @@ pi install npm:pi-polish
13
13
 
14
14
  ## Features
15
15
 
16
- - Shell commands, file reads, searches and MCP tool calls in a row fold into one line that updates while they run (`Running 2 shell commands… · 5s`, with the command and its latest output line below) and then sums them up (`Ran 3 shell commands, read 2 files` or `Called 2 MCP tools`). `ctrl+o` shows the full output.
16
+ - Shell commands, file reads, searches and MCP tool calls in a row fold into one line that updates while they run (`Running 2 shell commands… · 5s`, with the command and its latest output line below) and then sums them up (`Ran 3 shell commands, read 2 files` or `Called 2 MCP tools`). Click a row to see its commands and their full output, and click again to fold it; `ctrl+o` does this for every row.
17
17
  - Edits and new files show as diffs with syntax highlighting and the changed words marked, in colors that follow your Pi theme, dark or light.
18
18
  - Reads, searches, shell commands and MCP calls show a pulsing dot in your theme's accent color while they run, then turn into a quiet grey row once done, with a red dot if one failed. Edits and writes keep a green dot with their diff.
19
19
  - An orange status line shows what Pi is doing, how long it has been at it and how many tokens it has written. When Pi finishes, a dim line says how long it worked and when it was done.
@@ -7,7 +7,7 @@ import {
7
7
  type ExtensionAPI,
8
8
  type ToolRenderers,
9
9
  } from "@earendil-works/pi-coding-agent";
10
- import { type Component, Container, stripTerminalSequences, Text, truncateToWidth, visibleWidth, wrapTextWithAnsi } from "@earendil-works/pi-tui";
10
+ import { type Component, Container, MouseRegion, stripTerminalSequences, Text, truncateToWidth, visibleWidth, wrapTextWithAnsi } from "@earendil-works/pi-tui";
11
11
  import { shortCommand } from "./command.ts";
12
12
  import bash from "@shikijs/langs/shellscript";
13
13
  import css from "@shikijs/langs/css";
@@ -85,6 +85,8 @@ interface Group {
85
85
  started: number;
86
86
  ended?: number;
87
87
  timer?: NodeJS.Timeout;
88
+ // Opened by a click, so it shows in full like ctrl+o does, but on its own
89
+ open?: boolean;
88
90
  }
89
91
 
90
92
  type Result = { content: Array<{ type: string; text?: string }>; details?: unknown };
@@ -554,8 +556,8 @@ export default function (pi: ExtensionAPI) {
554
556
  /** Collapsed rendering for a grouped tool row; the group's first row draws the whole group. */
555
557
  const renderGrouped = (toolCallId: string, theme: any, context: any): Component | undefined => {
556
558
  rowInvalidate.set(toolCallId, context.invalidate);
557
- if (context.expanded) return undefined;
558
559
  const group = groupOf.get(toolCallId);
560
+ if (context.expanded || group?.open) return undefined;
559
561
  // Live rows wait for tool_execution_start to place them; history rows without a group render alone
560
562
  if (!group) return live || !ready ? empty() : undefined;
561
563
  if (group.members[0].id !== toolCallId) return empty();
@@ -576,11 +578,21 @@ export default function (pi: ExtensionAPI) {
576
578
  }
577
579
  // Finished rows go quiet, like Claude Code's: dim text, with a red ● only when something failed
578
580
  const mark = failed ? theme.fg("error", `${MARK} `) : " ";
579
- // Always the summary, even for one call ("Ran 1 shell command"), like Claude Code; ctrl+o shows each one
581
+ // Always the summary, even for one call ("Ran 1 shell command"), like Claude Code; a click or ctrl+o shows each one
580
582
  const text = summary(group, false);
581
- return oneLine([mark + theme.fg("dim", text)], failNote);
583
+ return clickable(group, oneLine([mark + theme.fg("dim", text)], failNote));
582
584
  };
583
585
 
586
+ /** A row that opens or closes its group when clicked. */
587
+ const clickable = (group: Group, row: Component): Component =>
588
+ new MouseRegion(row, (event) => {
589
+ if (event.type !== "click" || event.button !== "left") return undefined;
590
+ group.open = !group.open;
591
+ refresh(group);
592
+ return { handled: true };
593
+ });
594
+ const isOpen = (context: { expanded?: boolean; toolCallId?: string }) => Boolean(context.expanded || groupOf.get(context.toolCallId ?? "")?.open);
595
+
584
596
  // The ● carries the status, like Claude Code: dim while arguments stream, accent while running, green or red when done.
585
597
  // History rows redrawn after /reload have no execution state, so they count as done.
586
598
  const status = (context: { isPartial?: boolean; isError?: boolean; executionStarted?: boolean }) => {
@@ -597,20 +609,23 @@ export default function (pi: ExtensionAPI) {
597
609
  const grouped = renderGrouped(context.toolCallId, theme, context);
598
610
  if (grouped) return grouped;
599
611
  // Expanded, a shell command shows in full, with its cd and every line; collapsed rows keep the short label
600
- const command = context.expanded && toolName === "bash" ? String(args?.command ?? "").trim().split("\n") : undefined;
612
+ const command = isOpen(context) && toolName === "bash" ? String(args?.command ?? "").trim().split("\n") : undefined;
601
613
  const text = command ? `$ ${command.slice(0, 60).join("\n")}${command.length > 60 ? `\n... ${command.length - 60} more lines` : ""}` : truncateToWidth(label(toolName, args, cwd), 400);
602
614
  // Finished rows are dim without a dot; running and failed ones keep it
603
615
  const done = status(context) === "success";
604
616
  const mark = done ? " " : dot(theme, context);
605
617
  // Wrapped lines continue under the text, past the dot, instead of at the left edge
606
- return {
618
+ const row = {
607
619
  invalidate() {},
608
620
  render: (width: number) =>
609
621
  wrapTextWithAnsi(text, Math.max(10, width - 2)).map((line, i) => (i === 0 ? mark : " ") + theme.fg(done ? "dim" : "toolTitle", line)),
610
622
  };
623
+ // A row of a group opened by a click closes it again
624
+ const group = groupOf.get(context.toolCallId);
625
+ return group?.open ? clickable(group, row) : row;
611
626
  },
612
- renderResult(result, { expanded }, theme) {
613
- if (!expanded) return empty();
627
+ renderResult(result, { expanded }, theme, context) {
628
+ if (!expanded && !isOpen(context)) return empty();
614
629
  return new Text(expandedBody(theme, resultText(result as Result)), 0, 0);
615
630
  },
616
631
  });
@@ -666,7 +681,7 @@ export default function (pi: ExtensionAPI) {
666
681
  return {
667
682
  ...own,
668
683
  renderResult: (result, options, theme, context) =>
669
- options.expanded && pis ? pis(result, options, theme, { ...context, lastComponent: undefined }) : own.renderResult!(result, options, theme, context),
684
+ isOpen({ expanded: options.expanded, toolCallId: context.toolCallId }) && pis ? pis(result, { ...options, expanded: true }, theme, { ...context, lastComponent: undefined }) : own.renderResult!(result, options, theme, context),
670
685
  };
671
686
  });
672
687
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-polish",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "license": "MIT",
5
5
  "author": "Thomas van Dongen",
6
6
  "type": "module",