pi-polish 0.1.4 → 0.1.6

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.
@@ -1,6 +1,5 @@
1
1
  import { AssistantMessageComponent, CustomEditor, type ExtensionAPI, UserMessageComponent } from "@earendil-works/pi-coding-agent";
2
- import { Markdown, MouseRegion, Spacer, Text } from "@earendil-works/pi-tui";
3
- import { shortCommand } from "./command.ts";
2
+ import { Markdown, MouseRegion, Spacer, Text, truncateToWidth } from "@earendil-works/pi-tui";
4
3
 
5
4
  const PROMPT = "❯";
6
5
  const REPLY = "●";
@@ -90,28 +89,28 @@ export default function (pi: ExtensionAPI) {
90
89
  const stats = `(${secs}s · ↓ ${fmtTokens(tokens + Math.round(streamed / 4))} tokens)`;
91
90
  ctx.ui.setWorkingMessage(`${ORANGE}${phase}…${RESET} ${DIM}${stats}${RESET}`);
92
91
  };
93
- const toolPhase = (name: string, args: any) => {
94
- const path = String(args?.path ?? "").split("/").pop();
92
+ // Just the verb for tools that pi-polish draws as live rows, which already show what is running;
93
+ // other extensions' tools keep their name, since their rows may not
94
+ const toolPhase = (name: string) => {
95
95
  switch (name) {
96
96
  case "bash":
97
- return `Running ${shortCommand(String(args?.command ?? ""), process.cwd()).slice(0, 60)}`;
97
+ return "Running";
98
98
  case "read":
99
- return `Reading ${path}`;
99
+ return "Reading";
100
100
  case "edit":
101
- return `Editing ${path}`;
101
+ return "Editing";
102
102
  case "write":
103
- return `Writing ${path}`;
103
+ return "Writing";
104
104
  case "grep":
105
105
  case "find":
106
- return `Searching for ${String(args?.pattern ?? "").slice(0, 40)}`;
106
+ case "tool_search":
107
+ return "Searching";
107
108
  case "bg_run":
108
109
  return "Starting a background job";
109
110
  case "questionnaire":
110
111
  return "Waiting for your answer";
111
- case "tool_search":
112
- return "Searching tools";
113
112
  default:
114
- return name.startsWith("mcp__") ? `Calling ${name.split("__")[1]}/${name.split("__").slice(2).join("__")}` : `Running ${name}`;
113
+ return name.startsWith("mcp__") ? "Calling" : `Running ${name}`;
115
114
  }
116
115
  };
117
116
  pi.on("session_start", async (_event, ctx) => {
@@ -119,7 +118,7 @@ export default function (pi: ExtensionAPI) {
119
118
  });
120
119
  pi.on("agent_start", async (_event, ctx) => {
121
120
  if (!ctx.hasUI) return;
122
- ctx.ui.setWidget("pi-polish-turn", undefined);
121
+ showTurn(undefined);
123
122
  started = Date.now();
124
123
  tokens = 0;
125
124
  streamed = 0;
@@ -142,7 +141,7 @@ export default function (pi: ExtensionAPI) {
142
141
  });
143
142
  pi.on("tool_execution_start", async (event, ctx) => {
144
143
  if (!ctx.hasUI) return;
145
- phase = toolPhase(event.toolName, event.args);
144
+ phase = toolPhase(event.toolName);
146
145
  show(ctx);
147
146
  });
148
147
  pi.on("tool_execution_end", async () => {
@@ -157,11 +156,25 @@ export default function (pi: ExtensionAPI) {
157
156
  const secs = Math.round((Date.now() - started) / 1000);
158
157
  const took = secs < 60 ? `${secs}s` : `${Math.floor(secs / 60)}m ${secs % 60}s`;
159
158
  const done = new Date().toLocaleTimeString([], { hour: "numeric", minute: "2-digit" });
160
- ctx.ui.setWidget("pi-polish-turn", (_tui, theme) => new Text(theme.fg("dim", `✻ Worked for ${took} · done ${done}`), 0, 0));
159
+ showTurn(`✻ Worked for ${took} · done ${done}`);
161
160
  });
162
161
  // A jump in the session tree leaves the turn behind, so its summary goes too
163
- pi.on("session_tree", async (_event, ctx) => {
164
- if (ctx.hasUI) ctx.ui.setWidget("pi-polish-turn", undefined);
162
+ pi.on("session_tree", async () => showTurn(undefined));
163
+ // Set once and updated in place: setting a widget again moves it below the ones other extensions added since,
164
+ // while the turn line belongs at the top, where the working line was
165
+ let turnLine: string | undefined;
166
+ let redrawTurn = () => {};
167
+ const showTurn = (line: string | undefined) => {
168
+ turnLine = line;
169
+ redrawTurn();
170
+ };
171
+ pi.on("session_start", async (_event, ctx) => {
172
+ if (!ctx.hasUI) return;
173
+ turnLine = undefined;
174
+ ctx.ui.setWidget("pi-polish-turn", (tui, theme) => {
175
+ redrawTurn = () => tui.requestRender();
176
+ return { invalidate() {}, render: (width: number) => (turnLine ? [truncateToWidth(theme.fg("dim", turnLine), width)] : []) };
177
+ });
165
178
  });
166
179
  pi.on("session_shutdown", async () => clearInterval(timer));
167
180
 
@@ -448,7 +448,7 @@ export default function (pi: ExtensionAPI) {
448
448
 
449
449
  const tick = (group: Group) => {
450
450
  const running = group.members.some((m) => !m.done);
451
- if (running && !group.timer) group.timer = setInterval(() => rowInvalidate.get(group.members[0].id)?.(), 500);
451
+ if (running && !group.timer) group.timer = setInterval(() => rowInvalidate.get(group.members[0].id)?.(), 1000);
452
452
  if (!running && group.timer) {
453
453
  clearInterval(group.timer);
454
454
  group.timer = undefined;
@@ -473,7 +473,10 @@ export default function (pi: ExtensionAPI) {
473
473
  // Rebuild groups for history so resumed sessions collapse the same way
474
474
  pi.on("session_start", async (_event, ctx) => {
475
475
  reset();
476
- for (const entry of ctx.sessionManager.getBranch()) {
476
+ const branch = ctx.sessionManager.getBranch();
477
+ // Tool results come after their calls, so collect the failures first
478
+ const failed = new Set(branch.flatMap((e: any) => (e.type === "message" && e.message.role === "toolResult" && e.message.isError ? [e.message.toolCallId] : [])));
479
+ for (const entry of branch) {
477
480
  if (entry.type !== "message") continue;
478
481
  const msg = entry.message as any;
479
482
  if (msg.role === "user") current = undefined;
@@ -481,7 +484,7 @@ export default function (pi: ExtensionAPI) {
481
484
  for (const part of msg.content ?? []) {
482
485
  if (part.type === "text" && part.text.trim()) current = undefined;
483
486
  if (part.type !== "toolCall") continue;
484
- if (kindOf(part.name)) assign(part.id, part.name, part.arguments, true);
487
+ if (kindOf(part.name)) assign(part.id, part.name, part.arguments, true, failed.has(part.id));
485
488
  else current = undefined;
486
489
  }
487
490
  }
@@ -547,8 +550,8 @@ export default function (pi: ExtensionAPI) {
547
550
  if (running) {
548
551
  const secs = Math.round((Date.now() - group.started) / 1000);
549
552
  const active = [...group.members].reverse().find((m) => !m.done) ?? group.members[group.members.length - 1];
550
- // The dot pulses every half second while the group runs, like a cursor blink
551
- const pulse = Math.floor(Date.now() / 500) % 2 ? "dim" : "accent";
553
+ // The dot pulses once a second while the group runs, in step with the seconds counter
554
+ const pulse = secs % 2 ? "dim" : "accent";
552
555
  const head = theme.fg(pulse, `${MARK} `) + theme.fg("toolTitle", `${summary(group, true)}…`) + theme.fg("dim", ` · ${secs}s`) + failNote;
553
556
  return oneLine([head, theme.fg("dim", ` └ ${active.label}`)]);
554
557
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-polish",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "license": "MIT",
5
5
  "author": "Thomas van Dongen",
6
6
  "type": "module",