pi-polish 0.1.9 → 0.1.11
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 +3 -2
- package/extensions/tools.ts +49 -9
- package/package.json +1 -1
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
|
|
16
|
+
- Shell commands, file reads, searches, MCP tool calls and codemode scripts 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
|
|
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
|
|
package/extensions/tools.ts
CHANGED
|
@@ -57,8 +57,8 @@ const DIFF_PREVIEW_LINES = 16;
|
|
|
57
57
|
const BG_RESET = "\x1b[49m";
|
|
58
58
|
const FG_RESET = "\x1b[39m";
|
|
59
59
|
|
|
60
|
-
type Kind = "bash" | "read" | "search" | "list" | "tools" | "mcp";
|
|
61
|
-
const KIND_OF: Record<string, Kind> = { bash: "bash", read: "read", grep: "search", find: "search", ls: "list", tool_search: "tools" };
|
|
60
|
+
type Kind = "bash" | "read" | "search" | "list" | "tools" | "mcp" | "code";
|
|
61
|
+
const KIND_OF: Record<string, Kind> = { bash: "bash", read: "read", grep: "search", find: "search", ls: "list", tool_search: "tools", codemode: "code" };
|
|
62
62
|
// Pi names MCP tools mcp__<server>__<tool>
|
|
63
63
|
const kindOf = (toolName: string): Kind | undefined => KIND_OF[toolName] ?? (toolName.startsWith("mcp__") ? "mcp" : undefined);
|
|
64
64
|
const VERBS: Record<Kind, [done: string, running: string, one: string, many: string]> = {
|
|
@@ -68,6 +68,7 @@ const VERBS: Record<Kind, [done: string, running: string, one: string, many: str
|
|
|
68
68
|
list: ["Listed", "Listing", "directory", "directories"],
|
|
69
69
|
tools: ["Ran", "Running", "tool search", "tool searches"],
|
|
70
70
|
mcp: ["Called", "Calling", "MCP tool", "MCP tools"],
|
|
71
|
+
code: ["Ran", "Running", "codemode script", "codemode scripts"],
|
|
71
72
|
};
|
|
72
73
|
|
|
73
74
|
interface Member {
|
|
@@ -118,6 +119,11 @@ function label(toolName: string, args: any, cwd: string): string {
|
|
|
118
119
|
return `Search tools "${args?.query ?? ""}"`;
|
|
119
120
|
case "ls":
|
|
120
121
|
return `List ${args?.path ? shortPath(args.path, cwd) : "."}`;
|
|
122
|
+
case "codemode": {
|
|
123
|
+
// The script's first line of code, which usually names the tool it calls
|
|
124
|
+
const first = String(args?.code ?? "").split("\n").map((l) => l.trim()).find(Boolean);
|
|
125
|
+
return `codemode${first ? ` ${first}` : ""}`;
|
|
126
|
+
}
|
|
121
127
|
default: {
|
|
122
128
|
// server/tool like pi's own MCP rows, with the first text argument, which is usually the query
|
|
123
129
|
const [, server, ...tool] = toolName.split("__");
|
|
@@ -522,6 +528,8 @@ export default function (pi: ExtensionAPI) {
|
|
|
522
528
|
if (msg.role === "assistant" && (msg.content ?? []).some((c: any) => c.type === "text" && c.text.trim())) current = undefined;
|
|
523
529
|
});
|
|
524
530
|
pi.on("tool_execution_start", async (event) => {
|
|
531
|
+
// Calls a codemode script makes show inside its own row, so they don't join or end a group
|
|
532
|
+
if (event.parentToolCallId) return;
|
|
525
533
|
if (!kindOf(event.toolName)) {
|
|
526
534
|
current = undefined;
|
|
527
535
|
return;
|
|
@@ -608,9 +616,11 @@ export default function (pi: ExtensionAPI) {
|
|
|
608
616
|
renderCall(args: any, theme, context) {
|
|
609
617
|
const grouped = renderGrouped(context.toolCallId, theme, context);
|
|
610
618
|
if (grouped) return grouped;
|
|
611
|
-
// Expanded, a shell command shows in full, with
|
|
612
|
-
const
|
|
613
|
-
const
|
|
619
|
+
// Expanded, a shell command or a codemode script shows in full, with every line; collapsed rows keep the short label
|
|
620
|
+
const source = toolName === "bash" ? args?.command : toolName === "codemode" ? args?.code : undefined;
|
|
621
|
+
const lines = isOpen(context) && source !== undefined ? String(source ?? "").trim().split("\n") : undefined;
|
|
622
|
+
const prefix = toolName === "bash" ? "$ " : "codemode\n";
|
|
623
|
+
const text = lines ? `${prefix}${lines.slice(0, 60).join("\n")}${lines.length > 60 ? `\n... ${lines.length - 60} more lines` : ""}` : truncateToWidth(label(toolName, args, cwd), 400);
|
|
614
624
|
// Finished rows are dim without a dot; running and failed ones keep it
|
|
615
625
|
const done = status(context) === "success";
|
|
616
626
|
const mark = done ? " " : dot(theme, context);
|
|
@@ -670,13 +680,43 @@ export default function (pi: ExtensionAPI) {
|
|
|
670
680
|
return [`Wrote ${lineCount(lines.length)}`, lines.map((line, i) => `+${String(i + 1).padStart(width)} ${line}`)];
|
|
671
681
|
}),
|
|
672
682
|
};
|
|
683
|
+
// Other extensions' tools keep their own drawing, without pi's colored box: indented under the status dot like
|
|
684
|
+
// the rows above. Their renderer gets back its own component, not the wrapper, to reuse.
|
|
685
|
+
type Framed = Component & { inner: Component };
|
|
686
|
+
const frame = (inner: Component, mark: string): Framed => ({
|
|
687
|
+
inner,
|
|
688
|
+
invalidate: () => inner.invalidate(),
|
|
689
|
+
render: (width: number) => inner.render(Math.max(10, width - 2)).map((line, i) => (i === 0 ? mark : " ") + line),
|
|
690
|
+
});
|
|
691
|
+
const unframed = <C extends { lastComponent?: Component }>(context: C): C => ({ ...context, lastComponent: (context.lastComponent as Framed | undefined)?.inner });
|
|
692
|
+
const otherTool = (toolName: string, own: ToolRenderers): ToolRenderers => ({
|
|
693
|
+
renderShell: "self",
|
|
694
|
+
renderCall(args: any, theme, context) {
|
|
695
|
+
const mark = status(context) === "success" ? " " : dot(theme, context);
|
|
696
|
+
const first = Object.values(args ?? {}).find((v) => typeof v === "string") as string | undefined;
|
|
697
|
+
const fallback = () => new Text(theme.fg("toolTitle", theme.bold(toolName)) + (first ? theme.fg("dim", ` ${first.split("\n")[0]}`) : ""), 0, 0);
|
|
698
|
+
return frame(own.renderCall ? own.renderCall(args, theme, unframed(context)) : fallback(), mark);
|
|
699
|
+
},
|
|
700
|
+
renderResult(result, options, theme, context) {
|
|
701
|
+
if (own.renderResult) return frame(own.renderResult(result, options, theme, unframed(context)), " ");
|
|
702
|
+
const text = resultText(result as Result);
|
|
703
|
+
return options.expanded && text ? frame(new Text(expandedBody(theme, text), 0, 0), " ") : empty();
|
|
704
|
+
},
|
|
705
|
+
});
|
|
706
|
+
|
|
673
707
|
// Only the drawing changes: pi's own tools keep running, with their own schema and on/off state
|
|
674
708
|
pi.registerToolRenderer((toolName, next) => {
|
|
675
|
-
if (renderers[toolName]
|
|
709
|
+
if (renderers[toolName]) return renderers[toolName];
|
|
710
|
+
if (!kindOf(toolName)) {
|
|
711
|
+
const own = next();
|
|
712
|
+
// Tools that draw their own frame, like bg_run, already fit in
|
|
713
|
+
return own && own.renderShell !== "self" ? otherTool(toolName, own) : own;
|
|
714
|
+
}
|
|
676
715
|
const own = groupedTool(toolName);
|
|
677
|
-
if (kindOf(toolName) !== "mcp") return own;
|
|
678
|
-
// Expanded MCP results keep pi's own view, which shows images
|
|
679
|
-
// no lastComponent, since that may be the empty component drawn
|
|
716
|
+
if (kindOf(toolName) !== "mcp" && kindOf(toolName) !== "code") return own;
|
|
717
|
+
// Expanded MCP and codemode results keep pi's own view, which shows images, limits long one-line JSON and
|
|
718
|
+
// lists a script's nested calls. It gets no lastComponent, since that may be the empty component drawn
|
|
719
|
+
// while the row was collapsed.
|
|
680
720
|
const pis = next()?.renderResult;
|
|
681
721
|
return {
|
|
682
722
|
...own,
|