@mariozechner/pi-coding-agent 0.37.2 → 0.37.4

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 (64) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/README.md +13 -1
  3. package/dist/core/agent-session.d.ts +11 -1
  4. package/dist/core/agent-session.d.ts.map +1 -1
  5. package/dist/core/agent-session.js +39 -0
  6. package/dist/core/agent-session.js.map +1 -1
  7. package/dist/core/auth-storage.d.ts.map +1 -1
  8. package/dist/core/auth-storage.js +4 -6
  9. package/dist/core/auth-storage.js.map +1 -1
  10. package/dist/core/extensions/index.d.ts +1 -1
  11. package/dist/core/extensions/index.d.ts.map +1 -1
  12. package/dist/core/extensions/index.js.map +1 -1
  13. package/dist/core/extensions/loader.d.ts.map +1 -1
  14. package/dist/core/extensions/loader.js +15 -3
  15. package/dist/core/extensions/loader.js.map +1 -1
  16. package/dist/core/extensions/runner.d.ts +2 -1
  17. package/dist/core/extensions/runner.d.ts.map +1 -1
  18. package/dist/core/extensions/runner.js +3 -0
  19. package/dist/core/extensions/runner.js.map +1 -1
  20. package/dist/core/extensions/types.d.ts +19 -0
  21. package/dist/core/extensions/types.d.ts.map +1 -1
  22. package/dist/core/extensions/types.js.map +1 -1
  23. package/dist/core/sdk.d.ts.map +1 -1
  24. package/dist/core/sdk.js +36 -1
  25. package/dist/core/sdk.js.map +1 -1
  26. package/dist/core/settings-manager.d.ts +3 -0
  27. package/dist/core/settings-manager.d.ts.map +1 -1
  28. package/dist/core/settings-manager.js +24 -14
  29. package/dist/core/settings-manager.js.map +1 -1
  30. package/dist/main.d.ts.map +1 -1
  31. package/dist/main.js +20 -1
  32. package/dist/main.js.map +1 -1
  33. package/dist/modes/interactive/components/footer.d.ts.map +1 -1
  34. package/dist/modes/interactive/components/footer.js +31 -7
  35. package/dist/modes/interactive/components/footer.js.map +1 -1
  36. package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
  37. package/dist/modes/interactive/components/session-selector.js +1 -1
  38. package/dist/modes/interactive/components/session-selector.js.map +1 -1
  39. package/dist/modes/interactive/components/settings-selector.d.ts +2 -0
  40. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  41. package/dist/modes/interactive/components/settings-selector.js +12 -0
  42. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  43. package/dist/modes/interactive/interactive-mode.d.ts +11 -0
  44. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  45. package/dist/modes/interactive/interactive-mode.js +88 -12
  46. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  47. package/dist/modes/print-mode.d.ts.map +1 -1
  48. package/dist/modes/print-mode.js +5 -0
  49. package/dist/modes/print-mode.js.map +1 -1
  50. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  51. package/dist/modes/rpc/rpc-mode.js +11 -0
  52. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  53. package/dist/utils/clipboard-image.d.ts +11 -0
  54. package/dist/utils/clipboard-image.d.ts.map +1 -0
  55. package/dist/utils/clipboard-image.js +117 -0
  56. package/dist/utils/clipboard-image.js.map +1 -0
  57. package/docs/extensions.md +37 -2
  58. package/examples/extensions/README.md +1 -0
  59. package/examples/extensions/custom-footer.ts +86 -0
  60. package/examples/extensions/custom-header.ts +72 -0
  61. package/examples/extensions/send-user-message.ts +97 -0
  62. package/examples/extensions/with-deps/package-lock.json +2 -2
  63. package/examples/extensions/with-deps/package.json +1 -1
  64. package/package.json +5 -4
@@ -0,0 +1,86 @@
1
+ /**
2
+ * Custom Footer Extension
3
+ *
4
+ * Demonstrates ctx.ui.setFooter() for replacing the built-in footer
5
+ * with a custom component showing session context usage.
6
+ */
7
+
8
+ import type { AssistantMessage } from "@mariozechner/pi-ai";
9
+ import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
10
+ import { truncateToWidth, visibleWidth } from "@mariozechner/pi-tui";
11
+
12
+ export default function (pi: ExtensionAPI) {
13
+ let isCustomFooter = false;
14
+
15
+ // Toggle custom footer with /footer command
16
+ pi.registerCommand("footer", {
17
+ description: "Toggle custom footer showing context usage",
18
+ handler: async (_args, ctx) => {
19
+ isCustomFooter = !isCustomFooter;
20
+
21
+ if (isCustomFooter) {
22
+ ctx.ui.setFooter((_tui, theme) => {
23
+ return {
24
+ render(width: number): string[] {
25
+ // Calculate usage from branch entries
26
+ let totalInput = 0;
27
+ let totalOutput = 0;
28
+ let totalCost = 0;
29
+ let lastAssistant: AssistantMessage | undefined;
30
+
31
+ for (const entry of ctx.sessionManager.getBranch()) {
32
+ if (entry.type === "message" && entry.message.role === "assistant") {
33
+ const msg = entry.message as AssistantMessage;
34
+ totalInput += msg.usage.input;
35
+ totalOutput += msg.usage.output;
36
+ totalCost += msg.usage.cost.total;
37
+ lastAssistant = msg;
38
+ }
39
+ }
40
+
41
+ // Context percentage from last assistant message
42
+ const contextTokens = lastAssistant
43
+ ? lastAssistant.usage.input +
44
+ lastAssistant.usage.output +
45
+ lastAssistant.usage.cacheRead +
46
+ lastAssistant.usage.cacheWrite
47
+ : 0;
48
+ const contextWindow = ctx.model?.contextWindow || 0;
49
+ const contextPercent = contextWindow > 0 ? (contextTokens / contextWindow) * 100 : 0;
50
+
51
+ // Format tokens
52
+ const fmt = (n: number) => (n < 1000 ? `${n}` : `${(n / 1000).toFixed(1)}k`);
53
+
54
+ // Build footer line
55
+ const left = [
56
+ theme.fg("dim", `↑${fmt(totalInput)}`),
57
+ theme.fg("dim", `↓${fmt(totalOutput)}`),
58
+ theme.fg("dim", `$${totalCost.toFixed(3)}`),
59
+ ].join(" ");
60
+
61
+ // Color context percentage based on usage
62
+ let contextStr = `${contextPercent.toFixed(1)}%`;
63
+ if (contextPercent > 90) {
64
+ contextStr = theme.fg("error", contextStr);
65
+ } else if (contextPercent > 70) {
66
+ contextStr = theme.fg("warning", contextStr);
67
+ } else {
68
+ contextStr = theme.fg("success", contextStr);
69
+ }
70
+
71
+ const right = `${contextStr} ${theme.fg("dim", ctx.model?.id || "no model")}`;
72
+ const padding = " ".repeat(Math.max(1, width - visibleWidth(left) - visibleWidth(right)));
73
+
74
+ return [truncateToWidth(left + padding + right, width)];
75
+ },
76
+ invalidate() {},
77
+ };
78
+ });
79
+ ctx.ui.notify("Custom footer enabled", "info");
80
+ } else {
81
+ ctx.ui.setFooter(undefined);
82
+ ctx.ui.notify("Built-in footer restored", "info");
83
+ }
84
+ },
85
+ });
86
+ }
@@ -0,0 +1,72 @@
1
+ /**
2
+ * Custom Header Extension
3
+ *
4
+ * Demonstrates ctx.ui.setHeader() for replacing the built-in header
5
+ * (logo + keybinding hints) with a custom component showing the pi mascot.
6
+ */
7
+
8
+ import type { ExtensionAPI, Theme } from "@mariozechner/pi-coding-agent";
9
+
10
+ // --- PI MASCOT ---
11
+ // Based on pi_mascot.ts - the pi agent character
12
+ function getPiMascot(theme: Theme): string[] {
13
+ // --- COLORS ---
14
+ // 3b1b Blue: R=80, G=180, B=230
15
+ const piBlue = (text: string) => theme.fg("accent", text);
16
+ const white = (text: string) => text; // Use plain white (or theme.fg("text", text))
17
+ const black = (text: string) => theme.fg("dim", text); // Use dim for contrast
18
+
19
+ // --- GLYPHS ---
20
+ const BLOCK = "█";
21
+ const PUPIL = "▌"; // Vertical half-block for the pupil
22
+
23
+ // --- CONSTRUCTION ---
24
+
25
+ // 1. The Eye Unit: [White Full Block][Black Vertical Sliver]
26
+ // This creates the "looking sideways" effect
27
+ const eye = `${white(BLOCK)}${black(PUPIL)}`;
28
+
29
+ // 2. Line 1: The Eyes
30
+ // 5 spaces indent aligns them with the start of the legs
31
+ const lineEyes = ` ${eye} ${eye}`;
32
+
33
+ // 3. Line 2: The Wide Top Bar (The "Overhang")
34
+ // 14 blocks wide for that serif-style roof
35
+ const lineBar = ` ${piBlue(BLOCK.repeat(14))}`;
36
+
37
+ // 4. Lines 3-6: The Legs
38
+ // Indented 5 spaces relative to the very left edge
39
+ // Leg width: 2 blocks | Gap: 4 blocks
40
+ const lineLeg = ` ${piBlue(BLOCK.repeat(2))} ${piBlue(BLOCK.repeat(2))}`;
41
+
42
+ // --- ASSEMBLY ---
43
+ return ["", lineEyes, lineBar, lineLeg, lineLeg, lineLeg, lineLeg, ""];
44
+ }
45
+
46
+ export default function (pi: ExtensionAPI) {
47
+ // Set custom header immediately on load (if UI is available)
48
+ pi.on("session_start", async (_event, ctx) => {
49
+ if (ctx.hasUI) {
50
+ ctx.ui.setHeader((_tui, theme) => {
51
+ return {
52
+ render(_width: number): string[] {
53
+ const mascotLines = getPiMascot(theme);
54
+ // Add a subtitle with hint
55
+ const subtitle = theme.fg("muted", " shitty coding agent");
56
+ return [...mascotLines, subtitle];
57
+ },
58
+ invalidate() {},
59
+ };
60
+ });
61
+ }
62
+ });
63
+
64
+ // Command to restore built-in header
65
+ pi.registerCommand("builtin-header", {
66
+ description: "Restore built-in header with keybinding hints",
67
+ handler: async (_args, ctx) => {
68
+ ctx.ui.setHeader(undefined);
69
+ ctx.ui.notify("Built-in header restored", "info");
70
+ },
71
+ });
72
+ }
@@ -0,0 +1,97 @@
1
+ /**
2
+ * Send User Message Example
3
+ *
4
+ * Demonstrates pi.sendUserMessage() for sending user messages from extensions.
5
+ * Unlike pi.sendMessage() which sends custom messages, sendUserMessage() sends
6
+ * actual user messages that appear in the conversation as if typed by the user.
7
+ *
8
+ * Usage:
9
+ * /ask What is 2+2? - Sends a user message (always triggers a turn)
10
+ * /steer Focus on X - Sends while streaming with steer delivery
11
+ * /followup And then? - Sends while streaming with followUp delivery
12
+ */
13
+
14
+ import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
15
+
16
+ export default function (pi: ExtensionAPI) {
17
+ // Simple command that sends a user message
18
+ pi.registerCommand("ask", {
19
+ description: "Send a user message to the agent",
20
+ handler: async (args, ctx) => {
21
+ if (!args.trim()) {
22
+ ctx.ui.notify("Usage: /ask <message>", "warning");
23
+ return;
24
+ }
25
+
26
+ // sendUserMessage always triggers a turn when not streaming
27
+ // If streaming, it will throw (no deliverAs specified)
28
+ if (!ctx.isIdle()) {
29
+ ctx.ui.notify("Agent is busy. Use /steer or /followup instead.", "warning");
30
+ return;
31
+ }
32
+
33
+ pi.sendUserMessage(args);
34
+ },
35
+ });
36
+
37
+ // Command that steers the agent mid-conversation
38
+ pi.registerCommand("steer", {
39
+ description: "Send a steering message (interrupts current processing)",
40
+ handler: async (args, ctx) => {
41
+ if (!args.trim()) {
42
+ ctx.ui.notify("Usage: /steer <message>", "warning");
43
+ return;
44
+ }
45
+
46
+ if (ctx.isIdle()) {
47
+ // Not streaming, just send normally
48
+ pi.sendUserMessage(args);
49
+ } else {
50
+ // Streaming - use steer to interrupt
51
+ pi.sendUserMessage(args, { deliverAs: "steer" });
52
+ }
53
+ },
54
+ });
55
+
56
+ // Command that queues a follow-up message
57
+ pi.registerCommand("followup", {
58
+ description: "Queue a follow-up message (waits for current processing)",
59
+ handler: async (args, ctx) => {
60
+ if (!args.trim()) {
61
+ ctx.ui.notify("Usage: /followup <message>", "warning");
62
+ return;
63
+ }
64
+
65
+ if (ctx.isIdle()) {
66
+ // Not streaming, just send normally
67
+ pi.sendUserMessage(args);
68
+ } else {
69
+ // Streaming - queue as follow-up
70
+ pi.sendUserMessage(args, { deliverAs: "followUp" });
71
+ ctx.ui.notify("Follow-up queued", "info");
72
+ }
73
+ },
74
+ });
75
+
76
+ // Example with content array (text + images would go here)
77
+ pi.registerCommand("askwith", {
78
+ description: "Send a user message with structured content",
79
+ handler: async (args, ctx) => {
80
+ if (!args.trim()) {
81
+ ctx.ui.notify("Usage: /askwith <message>", "warning");
82
+ return;
83
+ }
84
+
85
+ if (!ctx.isIdle()) {
86
+ ctx.ui.notify("Agent is busy", "warning");
87
+ return;
88
+ }
89
+
90
+ // sendUserMessage accepts string or (TextContent | ImageContent)[]
91
+ pi.sendUserMessage([
92
+ { type: "text", text: `User request: ${args}` },
93
+ { type: "text", text: "Please respond concisely." },
94
+ ]);
95
+ },
96
+ });
97
+ }
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "pi-extension-with-deps",
3
- "version": "1.1.2",
3
+ "version": "1.1.4",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "pi-extension-with-deps",
9
- "version": "1.1.2",
9
+ "version": "1.1.4",
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.1.2",
4
+ "version": "1.1.4",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "clean": "echo 'nothing to clean'",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mariozechner/pi-coding-agent",
3
- "version": "0.37.2",
3
+ "version": "0.37.4",
4
4
  "description": "Coding agent CLI with read, bash, edit, write tools and session management",
5
5
  "type": "module",
6
6
  "piConfig": {
@@ -39,9 +39,9 @@
39
39
  },
40
40
  "dependencies": {
41
41
  "@crosscopy/clipboard": "^0.2.8",
42
- "@mariozechner/pi-agent-core": "^0.37.2",
43
- "@mariozechner/pi-ai": "^0.37.2",
44
- "@mariozechner/pi-tui": "^0.37.2",
42
+ "@mariozechner/pi-agent-core": "^0.37.4",
43
+ "@mariozechner/pi-ai": "^0.37.4",
44
+ "@mariozechner/pi-tui": "^0.37.4",
45
45
  "chalk": "^5.5.0",
46
46
  "cli-highlight": "^2.1.11",
47
47
  "diff": "^8.0.2",
@@ -49,6 +49,7 @@
49
49
  "glob": "^11.0.3",
50
50
  "jiti": "^2.6.1",
51
51
  "marked": "^15.0.12",
52
+ "minimatch": "^10.1.1",
52
53
  "proper-lockfile": "^4.1.2",
53
54
  "sharp": "^0.34.2"
54
55
  },