pi-polish 0.1.8 → 0.1.10

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,16 +13,17 @@ 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.
20
+ - Tools from other extensions keep their own look, but without Pi's colored box: they sit under the same status dot as the other rows.
20
21
  - `❯` marks your messages and `●` marks Pi's replies.
21
22
  - A short instruction to the model to change files with Pi's edit and write tools instead of shell commands like `sed -i`, so you see the changes as diffs.
22
23
 
23
24
  ## Compatibility
24
25
 
25
- pi-polish only changes how Pi's built-in tools and MCP tools are drawn; the tools themselves run exactly as before. The chat styling (the markers and the status line) reaches into Pi's internal UI, so a new Pi release can break that part of the look until pi-polish is updated. Your sessions are never affected. Tested with Pi 1.4.
26
+ pi-polish only changes how tools are drawn; the tools themselves run exactly as before. The chat styling (the markers and the status line) reaches into Pi's internal UI, so a new Pi release can break that part of the look until pi-polish is updated. Your sessions are never affected. Tested with Pi 1.4.
26
27
 
27
28
  ## License
28
29
 
@@ -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
  });
@@ -655,9 +670,38 @@ export default function (pi: ExtensionAPI) {
655
670
  return [`Wrote ${lineCount(lines.length)}`, lines.map((line, i) => `+${String(i + 1).padStart(width)} ${line}`)];
656
671
  }),
657
672
  };
673
+ // Other extensions' tools keep their own drawing, without pi's colored box: indented under the status dot like
674
+ // the rows above. Their renderer gets back its own component, not the wrapper, to reuse.
675
+ type Framed = Component & { inner: Component };
676
+ const frame = (inner: Component, mark: string): Framed => ({
677
+ inner,
678
+ invalidate: () => inner.invalidate(),
679
+ render: (width: number) => inner.render(Math.max(10, width - 2)).map((line, i) => (i === 0 ? mark : " ") + line),
680
+ });
681
+ const unframed = <C extends { lastComponent?: Component }>(context: C): C => ({ ...context, lastComponent: (context.lastComponent as Framed | undefined)?.inner });
682
+ const otherTool = (toolName: string, own: ToolRenderers): ToolRenderers => ({
683
+ renderShell: "self",
684
+ renderCall(args: any, theme, context) {
685
+ const mark = status(context) === "success" ? " " : dot(theme, context);
686
+ const first = Object.values(args ?? {}).find((v) => typeof v === "string") as string | undefined;
687
+ const fallback = () => new Text(theme.fg("toolTitle", theme.bold(toolName)) + (first ? theme.fg("dim", ` ${first.split("\n")[0]}`) : ""), 0, 0);
688
+ return frame(own.renderCall ? own.renderCall(args, theme, unframed(context)) : fallback(), mark);
689
+ },
690
+ renderResult(result, options, theme, context) {
691
+ if (own.renderResult) return frame(own.renderResult(result, options, theme, unframed(context)), " ");
692
+ const text = resultText(result as Result);
693
+ return options.expanded && text ? frame(new Text(expandedBody(theme, text), 0, 0), " ") : empty();
694
+ },
695
+ });
696
+
658
697
  // Only the drawing changes: pi's own tools keep running, with their own schema and on/off state
659
698
  pi.registerToolRenderer((toolName, next) => {
660
- if (renderers[toolName] || !kindOf(toolName)) return renderers[toolName] ?? next();
699
+ if (renderers[toolName]) return renderers[toolName];
700
+ if (!kindOf(toolName)) {
701
+ const own = next();
702
+ // Tools that draw their own frame, like bg_run, already fit in
703
+ return own && own.renderShell !== "self" ? otherTool(toolName, own) : own;
704
+ }
661
705
  const own = groupedTool(toolName);
662
706
  if (kindOf(toolName) !== "mcp") return own;
663
707
  // Expanded MCP results keep pi's own view, which shows images and limits long one-line JSON. It gets
@@ -666,7 +710,7 @@ export default function (pi: ExtensionAPI) {
666
710
  return {
667
711
  ...own,
668
712
  renderResult: (result, options, theme, context) =>
669
- options.expanded && pis ? pis(result, options, theme, { ...context, lastComponent: undefined }) : own.renderResult!(result, options, theme, context),
713
+ isOpen({ expanded: options.expanded, toolCallId: context.toolCallId }) && pis ? pis(result, { ...options, expanded: true }, theme, { ...context, lastComponent: undefined }) : own.renderResult!(result, options, theme, context),
670
714
  };
671
715
  });
672
716
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-polish",
3
- "version": "0.1.8",
3
+ "version": "0.1.10",
4
4
  "license": "MIT",
5
5
  "author": "Thomas van Dongen",
6
6
  "type": "module",