@vamsitalupula/pi-run 1.0.1

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/LICENSE ADDED
@@ -0,0 +1,15 @@
1
+ ISC License
2
+
3
+ Copyright (c) 2026 Talupula Vamsi
4
+
5
+ Permission to use, copy, modify, and/or distribute this software for any
6
+ purpose with or without fee is hereby granted, provided that the above
7
+ copyright notice and this permission notice appear in all copies.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
10
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
12
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
14
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15
+ PERFORMANCE OF THIS SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # pi-run
2
+
3
+ Run debugging typescript within the node context of pi coding agent
4
+
5
+ ## Installation
6
+
7
+ ```sh
8
+ pi install npm:@vamsitalupula/pi-run
9
+ ```
10
+
11
+ ## How to use?
12
+ 1. Create a new file using `/pi-run ./debug.ts` inside *pi*
13
+ 2. You should see a new file called `debug.ts` created in the current folder
14
+ ```ts
15
+ import type {
16
+ ExtensionAPI,
17
+ ExtensionContext,
18
+ } from "@mariozechner/pi-coding-agent";
19
+
20
+ export default function (
21
+ pi: ExtensionAPI,
22
+ getCtx: () => ExtensionContext | null,
23
+ ) {
24
+ // Your code here
25
+ return pi.getActiveTools();
26
+ }
27
+ ```
28
+ 3. The package `@mariozechner/pi-coding-agent` is 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 run `pnpm i --save-dev @mariozechner/pi-coding-agent` in the project or local directory
29
+ 4. Now run the file with
30
+ `/pi-run ./debug.ts`
31
+ 5. The data/object returned by the `default export function` is shown as a pi notification
package/dist/index.js ADDED
@@ -0,0 +1,74 @@
1
+ // src/index.ts
2
+ import { existsSync, writeFileSync, readFileSync } from "fs";
3
+ import { resolve } from "path";
4
+ import { createJiti } from "jiti";
5
+ var TEMPLATE = `import type {
6
+ ExtensionAPI,
7
+ ExtensionContext,
8
+ } from "@mariozechner/pi-coding-agent";
9
+
10
+ export default function (pi: ExtensionAPI, getCtx: () => ExtensionContext | null) {
11
+ return pi.getActiveTools();
12
+ }
13
+ `;
14
+ function index_default(pi) {
15
+ let lastCtx = null;
16
+ const jiti = createJiti(import.meta.url);
17
+ pi.on("session_start", async (_event, ctx) => {
18
+ lastCtx = ctx;
19
+ });
20
+ pi.on("turn_start", async (_event, ctx) => {
21
+ lastCtx = ctx;
22
+ });
23
+ pi.registerCommand("pi-run", {
24
+ description: "Run a .ts file with default export function",
25
+ handler: async (args, ctx) => {
26
+ lastCtx = ctx;
27
+ let filePath = args?.trim() || "";
28
+ if (filePath.startsWith("@")) filePath = filePath.slice(1);
29
+ if (!filePath) {
30
+ ctx.ui.notify("Usage: /pi-run <file-path>", "info");
31
+ return;
32
+ }
33
+ const fullPath = resolve(ctx.cwd, filePath);
34
+ if (!existsSync(fullPath)) {
35
+ writeFileSync(fullPath, TEMPLATE, "utf-8");
36
+ ctx.ui.notify(`Created new file: ${fullPath}`, "info");
37
+ return;
38
+ }
39
+ const code = readFileSync(fullPath, "utf-8");
40
+ if (!code.trim()) {
41
+ writeFileSync(fullPath, TEMPLATE, "utf-8");
42
+ ctx.ui.notify(
43
+ `File was empty, reset to template: ${fullPath}`,
44
+ "info"
45
+ );
46
+ return;
47
+ }
48
+ try {
49
+ const mod = await jiti.import(fullPath);
50
+ const fn = mod?.default || mod;
51
+ if (typeof fn !== "function") {
52
+ ctx.ui.notify(
53
+ `Error: No default export function found`,
54
+ "error"
55
+ );
56
+ return;
57
+ }
58
+ const result = await fn(pi, () => lastCtx);
59
+ if (result !== void 0) {
60
+ const str = typeof result === "object" ? JSON.stringify(result, null, 2) : String(result);
61
+ ctx.ui.notify(`Result:
62
+ ${str}`, "info");
63
+ } else {
64
+ ctx.ui.notify("Done (no return value)", "info");
65
+ }
66
+ } catch (e) {
67
+ ctx.ui.notify(`Error: ${e.message}`, "error");
68
+ }
69
+ }
70
+ });
71
+ }
72
+ export {
73
+ index_default as default
74
+ };
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "@vamsitalupula/pi-run",
3
+ "version": "1.0.1",
4
+ "description": "A pi coding agent extension to run TypeScript files with a default export function",
5
+ "type": "module",
6
+ "scripts": {
7
+ "build": "tsup src/index.ts --format esm --clean",
8
+ "dev": "tsup src/index.ts --format esm --watch"
9
+ },
10
+ "files": [
11
+ "dist",
12
+ "package.json"
13
+ ],
14
+ "main": "dist/index.js",
15
+ "keywords": [
16
+ "pi",
17
+ "coding-agent",
18
+ "extension",
19
+ "typescript",
20
+ "jiti",
21
+ "devtool",
22
+ "runner"
23
+ ],
24
+ "author": "",
25
+ "license": "ISC",
26
+ "dependencies": {
27
+ "jiti": "^2.6.1"
28
+ },
29
+ "devDependencies": {
30
+ "@mariozechner/pi-coding-agent": "^0.58.3",
31
+ "tsup": "^8.5.1",
32
+ "typescript": "^5.9.3"
33
+ },
34
+ "access": "public"
35
+ }