@vamsitalupula/pi-run
v1.9.0
Published
Run Typescript within the Node.js context of the Pi coding agent
Downloads
1,466
Maintainers
Readme
pi-run
This is a Pi extension for Pi extension developers. It enables running Typescript within the Node.js context of the Pi coding agent
Installation
pi install npm:@vamsitalupula/pi-runHow to use?
- Create a new file by running
/pi-run ./debug.tsin Pi user prompt - You should see a new file called
debug.tscreated in the current folder
import type {
ExtensionAPI,
ExtensionContext,
} from "@mariozechner/pi-coding-agent";
const LAST_ACCESS_ENTRY_TYPE = "state-drift-detection:last-access";
export default function (pi: ExtensionAPI, getCtx: () => ExtensionContext) {
// Your code here
// return getCtx().getSystemPrompt();
return pi.getActiveTools();
}- Now run the file with
/pi-run ./debug.ts - The data/object returned by the
default export functionis shown as a pi notification - The package
@mariozechner/pi-coding-agentis available in the node environment running pi. But if you need LSP/linting support in your editor, you need to point your editor tools to the install location of the package one way or an other. The easiest is to just runpnpm i --save-dev @mariozechner/pi-coding-agentin the project or local directory
Examples
To see the runtime system prompt
export default function (pi: ExtensionAPI, getCtx: () => ExtensionContext) {
return getCtx().getSystemPrompt();
}To get assistant message details with decreasing cache reads
const ctx = getCtx();
const branch = ctx.sessionManager.getBranch();
const messages = branch
.filter((entry) => entry.type === "message")
.map((entry) => entry.message);
return messages
.slice(1)
.filter((msg, index) => {
if (msg.role !== "assistant" || !msg.usage) return false;
const prevMsg = messages[index];
const prevCache =
prevMsg?.role === "assistant"
? (prevMsg.usage?.cacheRead ?? 0)
: 0;
const currCache = msg.usage.cacheRead ?? 0;
return currCache > prevCache;
})
.map((msg) => {
return {
timestamp: msg.timestamp,
responseId: msg.responseId,
usage: msg.usage,
};
});