@mariozechner/pi-coding-agent 0.37.2 → 0.37.3
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/CHANGELOG.md +15 -0
- package/README.md +10 -1
- package/dist/core/agent-session.d.ts +11 -1
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +39 -0
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/extensions/index.d.ts +1 -1
- package/dist/core/extensions/index.d.ts.map +1 -1
- package/dist/core/extensions/index.js.map +1 -1
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +14 -3
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/runner.d.ts +2 -1
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +2 -0
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/types.d.ts +15 -0
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +35 -1
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/settings-manager.d.ts +3 -0
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +24 -14
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/modes/interactive/components/footer.d.ts.map +1 -1
- package/dist/modes/interactive/components/footer.js +31 -7
- package/dist/modes/interactive/components/footer.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector.d.ts +2 -0
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector.js +12 -0
- package/dist/modes/interactive/components/settings-selector.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +5 -0
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +45 -8
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/print-mode.d.ts.map +1 -1
- package/dist/modes/print-mode.js +5 -0
- package/dist/modes/print-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-mode.js +8 -0
- package/dist/modes/rpc/rpc-mode.js.map +1 -1
- package/dist/utils/clipboard-image.d.ts +11 -0
- package/dist/utils/clipboard-image.d.ts.map +1 -0
- package/dist/utils/clipboard-image.js +117 -0
- package/dist/utils/clipboard-image.js.map +1 -0
- package/docs/extensions.md +37 -2
- package/examples/extensions/README.md +1 -0
- package/examples/extensions/custom-footer.ts +86 -0
- package/examples/extensions/send-user-message.ts +97 -0
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- 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,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.
|
|
3
|
+
"version": "1.1.3",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "pi-extension-with-deps",
|
|
9
|
-
"version": "1.1.
|
|
9
|
+
"version": "1.1.3",
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"ms": "^2.1.3"
|
|
12
12
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mariozechner/pi-coding-agent",
|
|
3
|
-
"version": "0.37.
|
|
3
|
+
"version": "0.37.3",
|
|
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.
|
|
43
|
-
"@mariozechner/pi-ai": "^0.37.
|
|
44
|
-
"@mariozechner/pi-tui": "^0.37.
|
|
42
|
+
"@mariozechner/pi-agent-core": "^0.37.3",
|
|
43
|
+
"@mariozechner/pi-ai": "^0.37.3",
|
|
44
|
+
"@mariozechner/pi-tui": "^0.37.3",
|
|
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
|
},
|