pi-polish 0.1.7 → 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`) 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, 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";
@@ -76,6 +76,8 @@ interface Member {
76
76
  label: string;
77
77
  done: boolean;
78
78
  error: boolean;
79
+ // The latest output line of a running shell command
80
+ latest?: string;
79
81
  }
80
82
 
81
83
  interface Group {
@@ -83,6 +85,8 @@ interface Group {
83
85
  started: number;
84
86
  ended?: number;
85
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;
86
90
  }
87
91
 
88
92
  type Result = { content: Array<{ type: string; text?: string }>; details?: unknown };
@@ -434,6 +438,8 @@ function oneLine(lines: string[], suffix = ""): Component {
434
438
  }
435
439
 
436
440
  export default function (pi: ExtensionAPI) {
441
+ // Tells pi-background that its ctrl+b hint goes under the running command's row, drawn below
442
+ (globalThis as any)[Symbol.for("pi-polish.showsMoveHint")] = true;
437
443
  const cwd = process.cwd();
438
444
  const groupOf = new Map<string, Group>();
439
445
  const rowInvalidate = new Map<string, () => void>();
@@ -524,6 +530,18 @@ export default function (pi: ExtensionAPI) {
524
530
  tick(group);
525
531
  refresh(group);
526
532
  });
533
+ // Pi streams a running command's output; its row shows the latest line, as a terminal would, redrawn with the timer
534
+ pi.on("tool_execution_update", async (event) => {
535
+ const member = groupOf.get(event.toolCallId)?.members.find((m) => m.id === event.toolCallId);
536
+ if (!member || member.kind !== "bash") return;
537
+ const text = (event.partialResult?.content ?? []).map((c: any) => c.text ?? "").join("");
538
+ const latest = text
539
+ .split("\n")
540
+ .map((line: string) => (stripTerminalSequences(line).split("\r").filter((part) => part.trim()).at(-1) ?? "").replace(/[\x00-\x1f\x7f]/g, " ").trim())
541
+ .filter(Boolean)
542
+ .at(-1);
543
+ if (latest) member.latest = latest;
544
+ });
527
545
  pi.on("tool_execution_end", async (event) => {
528
546
  const group = groupOf.get(event.toolCallId);
529
547
  const member = group?.members.find((m) => m.id === event.toolCallId);
@@ -538,8 +556,8 @@ export default function (pi: ExtensionAPI) {
538
556
  /** Collapsed rendering for a grouped tool row; the group's first row draws the whole group. */
539
557
  const renderGrouped = (toolCallId: string, theme: any, context: any): Component | undefined => {
540
558
  rowInvalidate.set(toolCallId, context.invalidate);
541
- if (context.expanded) return undefined;
542
559
  const group = groupOf.get(toolCallId);
560
+ if (context.expanded || group?.open) return undefined;
543
561
  // Live rows wait for tool_execution_start to place them; history rows without a group render alone
544
562
  if (!group) return live || !ready ? empty() : undefined;
545
563
  if (group.members[0].id !== toolCallId) return empty();
@@ -553,15 +571,28 @@ export default function (pi: ExtensionAPI) {
553
571
  // The dot pulses once a second while the group runs, in step with the seconds counter
554
572
  const pulse = secs % 2 ? "dim" : "accent";
555
573
  const head = theme.fg(pulse, `${MARK} `) + theme.fg("toolTitle", `${summary(group, true)}…`) + theme.fg("dim", ` · ${secs}s`) + failNote;
556
- return oneLine([head, theme.fg("dim", ` └ ${active.label}`)]);
574
+ const latest = active.latest ? [theme.fg("dim", ` ${active.latest}`)] : [];
575
+ // pi-background marks commands that ctrl+b can move to the background
576
+ const movable = (globalThis as any)[Symbol.for("pi-background.movable")]?.has(active.id) ? [theme.fg("dim", " (ctrl+b to run in background)")] : [];
577
+ return oneLine([head, theme.fg("dim", ` └ ${active.label}`), ...latest, ...movable]);
557
578
  }
558
579
  // Finished rows go quiet, like Claude Code's: dim text, with a red ● only when something failed
559
580
  const mark = failed ? theme.fg("error", `${MARK} `) : " ";
560
- // 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
561
582
  const text = summary(group, false);
562
- return oneLine([mark + theme.fg("dim", text)], failNote);
583
+ return clickable(group, oneLine([mark + theme.fg("dim", text)], failNote));
563
584
  };
564
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
+
565
596
  // The ● carries the status, like Claude Code: dim while arguments stream, accent while running, green or red when done.
566
597
  // History rows redrawn after /reload have no execution state, so they count as done.
567
598
  const status = (context: { isPartial?: boolean; isError?: boolean; executionStarted?: boolean }) => {
@@ -578,20 +609,23 @@ export default function (pi: ExtensionAPI) {
578
609
  const grouped = renderGrouped(context.toolCallId, theme, context);
579
610
  if (grouped) return grouped;
580
611
  // Expanded, a shell command shows in full, with its cd and every line; collapsed rows keep the short label
581
- 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;
582
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);
583
614
  // Finished rows are dim without a dot; running and failed ones keep it
584
615
  const done = status(context) === "success";
585
616
  const mark = done ? " " : dot(theme, context);
586
617
  // Wrapped lines continue under the text, past the dot, instead of at the left edge
587
- return {
618
+ const row = {
588
619
  invalidate() {},
589
620
  render: (width: number) =>
590
621
  wrapTextWithAnsi(text, Math.max(10, width - 2)).map((line, i) => (i === 0 ? mark : " ") + theme.fg(done ? "dim" : "toolTitle", line)),
591
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;
592
626
  },
593
- renderResult(result, { expanded }, theme) {
594
- if (!expanded) return empty();
627
+ renderResult(result, { expanded }, theme, context) {
628
+ if (!expanded && !isOpen(context)) return empty();
595
629
  return new Text(expandedBody(theme, resultText(result as Result)), 0, 0);
596
630
  },
597
631
  });
@@ -647,7 +681,7 @@ export default function (pi: ExtensionAPI) {
647
681
  return {
648
682
  ...own,
649
683
  renderResult: (result, options, theme, context) =>
650
- 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),
651
685
  };
652
686
  });
653
687
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-polish",
3
- "version": "0.1.7",
3
+ "version": "0.1.9",
4
4
  "license": "MIT",
5
5
  "author": "Thomas van Dongen",
6
6
  "type": "module",