pi-polish 0.1.4 → 0.1.5
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/extensions/chrome.ts +19 -5
- package/extensions/tools.ts +5 -2
- package/package.json +1 -1
package/extensions/chrome.ts
CHANGED
|
@@ -1,5 +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";
|
|
2
|
+
import { Markdown, MouseRegion, Spacer, Text, truncateToWidth } from "@earendil-works/pi-tui";
|
|
3
3
|
import { shortCommand } from "./command.ts";
|
|
4
4
|
|
|
5
5
|
const PROMPT = "❯";
|
|
@@ -119,7 +119,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
119
119
|
});
|
|
120
120
|
pi.on("agent_start", async (_event, ctx) => {
|
|
121
121
|
if (!ctx.hasUI) return;
|
|
122
|
-
|
|
122
|
+
showTurn(undefined);
|
|
123
123
|
started = Date.now();
|
|
124
124
|
tokens = 0;
|
|
125
125
|
streamed = 0;
|
|
@@ -157,11 +157,25 @@ export default function (pi: ExtensionAPI) {
|
|
|
157
157
|
const secs = Math.round((Date.now() - started) / 1000);
|
|
158
158
|
const took = secs < 60 ? `${secs}s` : `${Math.floor(secs / 60)}m ${secs % 60}s`;
|
|
159
159
|
const done = new Date().toLocaleTimeString([], { hour: "numeric", minute: "2-digit" });
|
|
160
|
-
|
|
160
|
+
showTurn(`✻ Worked for ${took} · done ${done}`);
|
|
161
161
|
});
|
|
162
162
|
// A jump in the session tree leaves the turn behind, so its summary goes too
|
|
163
|
-
pi.on("session_tree", async (
|
|
164
|
-
|
|
163
|
+
pi.on("session_tree", async () => showTurn(undefined));
|
|
164
|
+
// Set once and updated in place: setting a widget again moves it below the ones other extensions added since,
|
|
165
|
+
// while the turn line belongs at the top, where the working line was
|
|
166
|
+
let turnLine: string | undefined;
|
|
167
|
+
let redrawTurn = () => {};
|
|
168
|
+
const showTurn = (line: string | undefined) => {
|
|
169
|
+
turnLine = line;
|
|
170
|
+
redrawTurn();
|
|
171
|
+
};
|
|
172
|
+
pi.on("session_start", async (_event, ctx) => {
|
|
173
|
+
if (!ctx.hasUI) return;
|
|
174
|
+
turnLine = undefined;
|
|
175
|
+
ctx.ui.setWidget("pi-polish-turn", (tui, theme) => {
|
|
176
|
+
redrawTurn = () => tui.requestRender();
|
|
177
|
+
return { invalidate() {}, render: (width: number) => (turnLine ? [truncateToWidth(theme.fg("dim", turnLine), width)] : []) };
|
|
178
|
+
});
|
|
165
179
|
});
|
|
166
180
|
pi.on("session_shutdown", async () => clearInterval(timer));
|
|
167
181
|
|
package/extensions/tools.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
}
|