@mariozechner/pi-coding-agent 0.54.1 → 0.54.2

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.
Files changed (26) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +1 -1
  3. package/dist/core/model-resolver.d.ts.map +1 -1
  4. package/dist/core/model-resolver.js +49 -20
  5. package/dist/core/model-resolver.js.map +1 -1
  6. package/dist/core/settings-manager.d.ts.map +1 -1
  7. package/dist/core/settings-manager.js +13 -5
  8. package/dist/core/settings-manager.js.map +1 -1
  9. package/dist/modes/interactive/components/tool-execution.d.ts +5 -0
  10. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  11. package/dist/modes/interactive/components/tool-execution.js +120 -4
  12. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  13. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  14. package/dist/modes/interactive/interactive-mode.js +3 -0
  15. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  16. package/examples/extensions/README.md +1 -0
  17. package/examples/extensions/built-in-tool-renderer.ts +246 -0
  18. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  19. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  20. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  21. package/examples/extensions/custom-provider-qwen-cli/package.json +1 -1
  22. package/examples/extensions/with-deps/package-lock.json +2 -2
  23. package/examples/extensions/with-deps/package.json +1 -1
  24. package/examples/server-web-client/node_modules/.vite/deps/_metadata.json +8 -0
  25. package/examples/server-web-client/node_modules/.vite/deps/package.json +3 -0
  26. package/package.json +4 -4
@@ -33,6 +33,7 @@ cp permission-gate.ts ~/.pi/agent/extensions/
33
33
  | `question.ts` | Demonstrates `ctx.ui.select()` for asking the user questions with custom UI |
34
34
  | `questionnaire.ts` | Multi-question input with tab bar navigation between questions |
35
35
  | `tool-override.ts` | Override built-in tools (e.g., add logging/access control to `read`) |
36
+ | `built-in-tool-renderer.ts` | Custom compact rendering for built-in tools (read, bash, edit, write) while keeping original behavior |
36
37
  | `minimal-mode.ts` | Override built-in tool rendering for minimal display (only tool calls, no output in collapsed mode) |
37
38
  | `truncated-tool.ts` | Wraps ripgrep with proper output truncation (50KB/2000 lines) |
38
39
  | `antigravity-image-gen.ts` | Generate images via Google Antigravity with optional save-to-disk modes |
@@ -0,0 +1,246 @@
1
+ /**
2
+ * Built-in Tool Renderer Example - Custom rendering for built-in tools
3
+ *
4
+ * Demonstrates how to override the rendering of built-in tools (read, bash,
5
+ * edit, write) without changing their behavior. Each tool is re-registered
6
+ * with the same name, delegating execution to the original implementation
7
+ * while providing compact custom renderCall/renderResult functions.
8
+ *
9
+ * This is useful for users who prefer more concise tool output, or who want
10
+ * to highlight specific information (e.g., showing only the diff stats for
11
+ * edit, or just the exit code for bash).
12
+ *
13
+ * How it works:
14
+ * - registerTool() with the same name as a built-in replaces it entirely
15
+ * - We create instances of the original tools via createReadTool(), etc.
16
+ * and delegate execute() to them
17
+ * - renderCall() controls what's shown when the tool is invoked
18
+ * - renderResult() controls what's shown after execution completes
19
+ * - The `expanded` flag in renderResult indicates whether the user has
20
+ * toggled the tool output open (via ctrl+e or clicking)
21
+ *
22
+ * Usage:
23
+ * pi -e ./built-in-tool-renderer.ts
24
+ */
25
+
26
+ import type { BashToolDetails, EditToolDetails, ExtensionAPI, ReadToolDetails } from "@mariozechner/pi-coding-agent";
27
+ import { createBashTool, createEditTool, createReadTool, createWriteTool } from "@mariozechner/pi-coding-agent";
28
+ import { Text } from "@mariozechner/pi-tui";
29
+
30
+ export default function (pi: ExtensionAPI) {
31
+ const cwd = process.cwd();
32
+
33
+ // --- Read tool: show path and line count ---
34
+ const originalRead = createReadTool(cwd);
35
+ pi.registerTool({
36
+ name: "read",
37
+ label: "read",
38
+ description: originalRead.description,
39
+ parameters: originalRead.parameters,
40
+
41
+ async execute(toolCallId, params, signal, onUpdate) {
42
+ return originalRead.execute(toolCallId, params, signal, onUpdate);
43
+ },
44
+
45
+ renderCall(args, theme) {
46
+ let text = theme.fg("toolTitle", theme.bold("read "));
47
+ text += theme.fg("accent", args.path);
48
+ if (args.offset || args.limit) {
49
+ const parts: string[] = [];
50
+ if (args.offset) parts.push(`offset=${args.offset}`);
51
+ if (args.limit) parts.push(`limit=${args.limit}`);
52
+ text += theme.fg("dim", ` (${parts.join(", ")})`);
53
+ }
54
+ return new Text(text, 0, 0);
55
+ },
56
+
57
+ renderResult(result, { expanded, isPartial }, theme) {
58
+ if (isPartial) return new Text(theme.fg("warning", "Reading..."), 0, 0);
59
+
60
+ const details = result.details as ReadToolDetails | undefined;
61
+ const content = result.content[0];
62
+
63
+ if (content?.type === "image") {
64
+ return new Text(theme.fg("success", "Image loaded"), 0, 0);
65
+ }
66
+
67
+ if (content?.type !== "text") {
68
+ return new Text(theme.fg("error", "No content"), 0, 0);
69
+ }
70
+
71
+ const lineCount = content.text.split("\n").length;
72
+ let text = theme.fg("success", `${lineCount} lines`);
73
+
74
+ if (details?.truncation?.truncated) {
75
+ text += theme.fg("warning", ` (truncated from ${details.truncation.totalLines})`);
76
+ }
77
+
78
+ if (expanded) {
79
+ const lines = content.text.split("\n").slice(0, 15);
80
+ for (const line of lines) {
81
+ text += `\n${theme.fg("dim", line)}`;
82
+ }
83
+ if (lineCount > 15) {
84
+ text += `\n${theme.fg("muted", `... ${lineCount - 15} more lines`)}`;
85
+ }
86
+ }
87
+
88
+ return new Text(text, 0, 0);
89
+ },
90
+ });
91
+
92
+ // --- Bash tool: show command and exit code ---
93
+ const originalBash = createBashTool(cwd);
94
+ pi.registerTool({
95
+ name: "bash",
96
+ label: "bash",
97
+ description: originalBash.description,
98
+ parameters: originalBash.parameters,
99
+
100
+ async execute(toolCallId, params, signal, onUpdate) {
101
+ return originalBash.execute(toolCallId, params, signal, onUpdate);
102
+ },
103
+
104
+ renderCall(args, theme) {
105
+ let text = theme.fg("toolTitle", theme.bold("$ "));
106
+ const cmd = args.command.length > 80 ? `${args.command.slice(0, 77)}...` : args.command;
107
+ text += theme.fg("accent", cmd);
108
+ if (args.timeout) {
109
+ text += theme.fg("dim", ` (timeout: ${args.timeout}s)`);
110
+ }
111
+ return new Text(text, 0, 0);
112
+ },
113
+
114
+ renderResult(result, { expanded, isPartial }, theme) {
115
+ if (isPartial) return new Text(theme.fg("warning", "Running..."), 0, 0);
116
+
117
+ const details = result.details as BashToolDetails | undefined;
118
+ const content = result.content[0];
119
+ const output = content?.type === "text" ? content.text : "";
120
+
121
+ const exitMatch = output.match(/exit code: (\d+)/);
122
+ const exitCode = exitMatch ? parseInt(exitMatch[1], 10) : null;
123
+ const lineCount = output.split("\n").filter((l) => l.trim()).length;
124
+
125
+ let text = "";
126
+ if (exitCode === 0 || exitCode === null) {
127
+ text += theme.fg("success", "done");
128
+ } else {
129
+ text += theme.fg("error", `exit ${exitCode}`);
130
+ }
131
+ text += theme.fg("dim", ` (${lineCount} lines)`);
132
+
133
+ if (details?.truncation?.truncated) {
134
+ text += theme.fg("warning", " [truncated]");
135
+ }
136
+
137
+ if (expanded) {
138
+ const lines = output.split("\n").slice(0, 20);
139
+ for (const line of lines) {
140
+ text += `\n${theme.fg("dim", line)}`;
141
+ }
142
+ if (output.split("\n").length > 20) {
143
+ text += `\n${theme.fg("muted", "... more output")}`;
144
+ }
145
+ }
146
+
147
+ return new Text(text, 0, 0);
148
+ },
149
+ });
150
+
151
+ // --- Edit tool: show path and diff stats ---
152
+ const originalEdit = createEditTool(cwd);
153
+ pi.registerTool({
154
+ name: "edit",
155
+ label: "edit",
156
+ description: originalEdit.description,
157
+ parameters: originalEdit.parameters,
158
+
159
+ async execute(toolCallId, params, signal, onUpdate) {
160
+ return originalEdit.execute(toolCallId, params, signal, onUpdate);
161
+ },
162
+
163
+ renderCall(args, theme) {
164
+ let text = theme.fg("toolTitle", theme.bold("edit "));
165
+ text += theme.fg("accent", args.path);
166
+ return new Text(text, 0, 0);
167
+ },
168
+
169
+ renderResult(result, { expanded, isPartial }, theme) {
170
+ if (isPartial) return new Text(theme.fg("warning", "Editing..."), 0, 0);
171
+
172
+ const details = result.details as EditToolDetails | undefined;
173
+ const content = result.content[0];
174
+
175
+ if (content?.type === "text" && content.text.startsWith("Error")) {
176
+ return new Text(theme.fg("error", content.text.split("\n")[0]), 0, 0);
177
+ }
178
+
179
+ if (!details?.diff) {
180
+ return new Text(theme.fg("success", "Applied"), 0, 0);
181
+ }
182
+
183
+ // Count additions and removals from the diff
184
+ const diffLines = details.diff.split("\n");
185
+ let additions = 0;
186
+ let removals = 0;
187
+ for (const line of diffLines) {
188
+ if (line.startsWith("+") && !line.startsWith("+++")) additions++;
189
+ if (line.startsWith("-") && !line.startsWith("---")) removals++;
190
+ }
191
+
192
+ let text = theme.fg("success", `+${additions}`);
193
+ text += theme.fg("dim", " / ");
194
+ text += theme.fg("error", `-${removals}`);
195
+
196
+ if (expanded) {
197
+ for (const line of diffLines.slice(0, 30)) {
198
+ if (line.startsWith("+") && !line.startsWith("+++")) {
199
+ text += `\n${theme.fg("success", line)}`;
200
+ } else if (line.startsWith("-") && !line.startsWith("---")) {
201
+ text += `\n${theme.fg("error", line)}`;
202
+ } else {
203
+ text += `\n${theme.fg("dim", line)}`;
204
+ }
205
+ }
206
+ if (diffLines.length > 30) {
207
+ text += `\n${theme.fg("muted", `... ${diffLines.length - 30} more diff lines`)}`;
208
+ }
209
+ }
210
+
211
+ return new Text(text, 0, 0);
212
+ },
213
+ });
214
+
215
+ // --- Write tool: show path and size ---
216
+ const originalWrite = createWriteTool(cwd);
217
+ pi.registerTool({
218
+ name: "write",
219
+ label: "write",
220
+ description: originalWrite.description,
221
+ parameters: originalWrite.parameters,
222
+
223
+ async execute(toolCallId, params, signal, onUpdate) {
224
+ return originalWrite.execute(toolCallId, params, signal, onUpdate);
225
+ },
226
+
227
+ renderCall(args, theme) {
228
+ let text = theme.fg("toolTitle", theme.bold("write "));
229
+ text += theme.fg("accent", args.path);
230
+ const lineCount = args.content.split("\n").length;
231
+ text += theme.fg("dim", ` (${lineCount} lines)`);
232
+ return new Text(text, 0, 0);
233
+ },
234
+
235
+ renderResult(result, { isPartial }, theme) {
236
+ if (isPartial) return new Text(theme.fg("warning", "Writing..."), 0, 0);
237
+
238
+ const content = result.content[0];
239
+ if (content?.type === "text" && content.text.startsWith("Error")) {
240
+ return new Text(theme.fg("error", content.text.split("\n")[0]), 0, 0);
241
+ }
242
+
243
+ return new Text(theme.fg("success", "Written"), 0, 0);
244
+ },
245
+ });
246
+ }
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "pi-extension-custom-provider",
3
- "version": "1.5.1",
3
+ "version": "1.5.2",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "pi-extension-custom-provider",
9
- "version": "1.5.1",
9
+ "version": "1.5.2",
10
10
  "dependencies": {
11
11
  "@anthropic-ai/sdk": "^0.52.0"
12
12
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pi-extension-custom-provider-anthropic",
3
3
  "private": true,
4
- "version": "1.5.1",
4
+ "version": "1.5.2",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "clean": "echo 'nothing to clean'",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pi-extension-custom-provider-gitlab-duo",
3
3
  "private": true,
4
- "version": "1.5.1",
4
+ "version": "1.5.2",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "clean": "echo 'nothing to clean'",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pi-extension-custom-provider-qwen-cli",
3
3
  "private": true,
4
- "version": "1.4.1",
4
+ "version": "1.4.2",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "clean": "echo 'nothing to clean'",
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "pi-extension-with-deps",
3
- "version": "1.18.1",
3
+ "version": "1.18.2",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "pi-extension-with-deps",
9
- "version": "1.18.1",
9
+ "version": "1.18.2",
10
10
  "dependencies": {
11
11
  "ms": "^2.1.3"
12
12
  },
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pi-extension-with-deps",
3
3
  "private": true,
4
- "version": "1.18.1",
4
+ "version": "1.18.2",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "clean": "echo 'nothing to clean'",
@@ -0,0 +1,8 @@
1
+ {
2
+ "hash": "aa4bce83",
3
+ "configHash": "c964211b",
4
+ "lockfileHash": "693aa852",
5
+ "browserHash": "8b3dfc5b",
6
+ "optimized": {},
7
+ "chunks": {}
8
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "module"
3
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mariozechner/pi-coding-agent",
3
- "version": "0.54.1",
3
+ "version": "0.54.2",
4
4
  "description": "Coding agent CLI with read, bash, edit, write tools and session management",
5
5
  "type": "module",
6
6
  "piConfig": {
@@ -40,9 +40,9 @@
40
40
  },
41
41
  "dependencies": {
42
42
  "@mariozechner/jiti": "^2.6.2",
43
- "@mariozechner/pi-agent-core": "^0.54.1",
44
- "@mariozechner/pi-ai": "^0.54.1",
45
- "@mariozechner/pi-tui": "^0.54.1",
43
+ "@mariozechner/pi-agent-core": "^0.54.2",
44
+ "@mariozechner/pi-ai": "^0.54.2",
45
+ "@mariozechner/pi-tui": "^0.54.2",
46
46
  "@silvia-odwyer/photon-node": "^0.3.4",
47
47
  "chalk": "^5.5.0",
48
48
  "cli-highlight": "^2.1.11",