@astrofoundry/pi-astro 0.6.6 → 0.6.7

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/README.md CHANGED
@@ -62,6 +62,7 @@ pi # launch; confirm [Extensions] lists astro-agents, claude-glob
62
62
  - `multi-edit` — registers the enhanced `edit` tool
63
63
  - `gemini-image` — registers `gemini_image` tool (requires a Gemini API key; prompts and saves on first use)
64
64
  - `security-guard` — blocks/prompts destructive bash commands and sensitive file access; configure at `~/.pi/agent/security-guard.json` (example written on first run); `/security-guard status|reload|test`
65
+ - `notify-on-stop` — runs a shell command when the agent finishes a turn (sound, voice, desktop notification). Configure via env `PI_STOP_NOTIFY='afplay /System/Library/Sounds/Glass.aiff && say "Done"'`. Defaults to macOS Glass sound / Linux `notify-send`. Disable with `PI_STOP_NOTIFY_OFF=1`. `/notify status|test|off`.
65
66
  - `claude-globals` — auto-injects `~/.claude/CLAUDE.md` into every pi session's system prompt
66
67
 
67
68
  **Bundled subagents** (callable via `astro_agent`):
@@ -0,0 +1,179 @@
1
+ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
2
+
3
+ const execMock = vi.fn();
4
+
5
+ vi.mock("node:child_process", () => ({
6
+ exec: (cmd: string, opts: unknown, cb?: unknown) => {
7
+ execMock(cmd, opts, cb);
8
+ // Return a chainable fake child with on/stdout/stderr
9
+ const fake = {
10
+ on: vi.fn(),
11
+ stdout: { on: vi.fn() },
12
+ stderr: { on: vi.fn() },
13
+ };
14
+ return fake;
15
+ },
16
+ }));
17
+
18
+ type Handler = (event: unknown, ctx: unknown) => void | Promise<void>;
19
+ type CommandHandler = (args: string, ctx: unknown) => Promise<void> | void;
20
+
21
+ function makePi(): {
22
+ handlers: Record<string, Handler>;
23
+ commands: Map<string, { handler: CommandHandler }>;
24
+ on: (event: string, h: Handler) => void;
25
+ registerCommand: (name: string, opts: { description?: string; handler: CommandHandler }) => void;
26
+ } {
27
+ const handlers: Record<string, Handler> = {};
28
+ const commands = new Map();
29
+ return {
30
+ handlers,
31
+ commands,
32
+ on: (event, h) => {
33
+ handlers[event] = h;
34
+ },
35
+ registerCommand: (name, opts) => {
36
+ commands.set(name, { handler: opts.handler });
37
+ },
38
+ };
39
+ }
40
+
41
+ function makeCtx(): { ui: { notify: ReturnType<typeof vi.fn> } } {
42
+ return { ui: { notify: vi.fn() } };
43
+ }
44
+
45
+ const origPlatform = Object.getOwnPropertyDescriptor(process, "platform")!;
46
+
47
+ function setPlatform(p: NodeJS.Platform): void {
48
+ Object.defineProperty(process, "platform", { value: p, configurable: true });
49
+ }
50
+
51
+ describe("notify-on-stop", () => {
52
+ const origCmd = process.env.PI_STOP_NOTIFY;
53
+ const origOff = process.env.PI_STOP_NOTIFY_OFF;
54
+
55
+ beforeEach(() => {
56
+ vi.resetModules();
57
+ execMock.mockReset();
58
+ delete process.env.PI_STOP_NOTIFY;
59
+ delete process.env.PI_STOP_NOTIFY_OFF;
60
+ });
61
+
62
+ afterEach(() => {
63
+ Object.defineProperty(process, "platform", origPlatform);
64
+ if (origCmd === undefined) delete process.env.PI_STOP_NOTIFY;
65
+ else process.env.PI_STOP_NOTIFY = origCmd;
66
+ if (origOff === undefined) delete process.env.PI_STOP_NOTIFY_OFF;
67
+ else process.env.PI_STOP_NOTIFY_OFF = origOff;
68
+ });
69
+
70
+ it("runs default command on agent_end (macOS)", async () => {
71
+ setPlatform("darwin");
72
+ const mod = await import("./index.ts");
73
+ const pi = makePi();
74
+ mod.default(pi as unknown as Parameters<typeof mod.default>[0]);
75
+ pi.handlers.agent_end({}, makeCtx());
76
+ expect(execMock).toHaveBeenCalled();
77
+ expect(execMock.mock.calls[0][0]).toMatch(/afplay/);
78
+ });
79
+
80
+ it("runs custom PI_STOP_NOTIFY over default", async () => {
81
+ setPlatform("darwin");
82
+ process.env.PI_STOP_NOTIFY = "my custom --cmd";
83
+ const mod = await import("./index.ts");
84
+ const pi = makePi();
85
+ mod.default(pi as unknown as Parameters<typeof mod.default>[0]);
86
+ pi.handlers.agent_end({}, makeCtx());
87
+ expect(execMock.mock.calls[0][0]).toBe("my custom --cmd");
88
+ });
89
+
90
+ it("does NOT run anything when PI_STOP_NOTIFY_OFF=1", async () => {
91
+ setPlatform("darwin");
92
+ process.env.PI_STOP_NOTIFY_OFF = "1";
93
+ const mod = await import("./index.ts");
94
+ const pi = makePi();
95
+ mod.default(pi as unknown as Parameters<typeof mod.default>[0]);
96
+ pi.handlers.agent_end({}, makeCtx());
97
+ expect(execMock).not.toHaveBeenCalled();
98
+ });
99
+
100
+ it("does nothing on an unsupported platform with no env", async () => {
101
+ setPlatform("win32");
102
+ const mod = await import("./index.ts");
103
+ const pi = makePi();
104
+ mod.default(pi as unknown as Parameters<typeof mod.default>[0]);
105
+ pi.handlers.agent_end({}, makeCtx());
106
+ expect(execMock).not.toHaveBeenCalled();
107
+ });
108
+
109
+ it("Linux default uses notify-send", async () => {
110
+ setPlatform("linux");
111
+ const mod = await import("./index.ts");
112
+ const pi = makePi();
113
+ mod.default(pi as unknown as Parameters<typeof mod.default>[0]);
114
+ pi.handlers.agent_end({}, makeCtx());
115
+ expect(execMock.mock.calls[0][0]).toMatch(/notify-send/);
116
+ });
117
+
118
+ it("trims whitespace on PI_STOP_NOTIFY and ignores empty strings", async () => {
119
+ setPlatform("darwin");
120
+ process.env.PI_STOP_NOTIFY = " ";
121
+ const mod = await import("./index.ts");
122
+ const pi = makePi();
123
+ mod.default(pi as unknown as Parameters<typeof mod.default>[0]);
124
+ pi.handlers.agent_end({}, makeCtx());
125
+ expect(execMock.mock.calls[0][0]).toMatch(/afplay/);
126
+ });
127
+
128
+ it("/notify status reports current command", async () => {
129
+ setPlatform("darwin");
130
+ const mod = await import("./index.ts");
131
+ const pi = makePi();
132
+ mod.default(pi as unknown as Parameters<typeof mod.default>[0]);
133
+ const ctx = makeCtx();
134
+ await pi.commands.get("notify")!.handler("status", ctx);
135
+ expect(ctx.ui.notify).toHaveBeenCalledWith(expect.stringMatching(/afplay/), "info");
136
+ });
137
+
138
+ it("/notify status reports disabled when PI_STOP_NOTIFY_OFF", async () => {
139
+ setPlatform("darwin");
140
+ process.env.PI_STOP_NOTIFY_OFF = "1";
141
+ const mod = await import("./index.ts");
142
+ const pi = makePi();
143
+ mod.default(pi as unknown as Parameters<typeof mod.default>[0]);
144
+ const ctx = makeCtx();
145
+ await pi.commands.get("notify")!.handler("", ctx);
146
+ expect(ctx.ui.notify).toHaveBeenCalledWith(expect.stringMatching(/disabled/), "info");
147
+ });
148
+
149
+ it("/notify test runs the command immediately", async () => {
150
+ setPlatform("darwin");
151
+ process.env.PI_STOP_NOTIFY = "test-cmd";
152
+ const mod = await import("./index.ts");
153
+ const pi = makePi();
154
+ mod.default(pi as unknown as Parameters<typeof mod.default>[0]);
155
+ const ctx = makeCtx();
156
+ await pi.commands.get("notify")!.handler("test", ctx);
157
+ expect(execMock.mock.calls[0][0]).toBe("test-cmd");
158
+ });
159
+
160
+ it("/notify test warns when nothing configured", async () => {
161
+ setPlatform("win32");
162
+ const mod = await import("./index.ts");
163
+ const pi = makePi();
164
+ mod.default(pi as unknown as Parameters<typeof mod.default>[0]);
165
+ const ctx = makeCtx();
166
+ await pi.commands.get("notify")!.handler("test", ctx);
167
+ expect(ctx.ui.notify).toHaveBeenCalledWith(expect.stringMatching(/nothing configured/), "warning");
168
+ });
169
+
170
+ it("/notify off gives persistence guidance", async () => {
171
+ setPlatform("darwin");
172
+ const mod = await import("./index.ts");
173
+ const pi = makePi();
174
+ mod.default(pi as unknown as Parameters<typeof mod.default>[0]);
175
+ const ctx = makeCtx();
176
+ await pi.commands.get("notify")!.handler("off", ctx);
177
+ expect(ctx.ui.notify).toHaveBeenCalledWith(expect.stringMatching(/PI_STOP_NOTIFY_OFF/), "info");
178
+ });
179
+ });
@@ -0,0 +1,71 @@
1
+ import { exec } from "node:child_process";
2
+ import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
3
+
4
+ const ENV_CMD = "PI_STOP_NOTIFY";
5
+ const ENV_OFF = "PI_STOP_NOTIFY_OFF";
6
+ const TIMEOUT_MS = 10_000;
7
+
8
+ function defaultCommand(): string | undefined {
9
+ if (process.platform === "darwin") {
10
+ return "afplay /System/Library/Sounds/Glass.aiff";
11
+ }
12
+ if (process.platform === "linux") {
13
+ return 'command -v notify-send >/dev/null 2>&1 && notify-send "pi" "Agent done"';
14
+ }
15
+ return undefined;
16
+ }
17
+
18
+ function resolveCommand(): string | undefined {
19
+ if (process.env[ENV_OFF] === "1") return undefined;
20
+ const custom = process.env[ENV_CMD]?.trim();
21
+ if (custom) return custom;
22
+ return defaultCommand();
23
+ }
24
+
25
+ function runNotify(cmd: string): void {
26
+ const child = exec(cmd, { shell: "/bin/sh", timeout: TIMEOUT_MS });
27
+ // Swallow errors so a broken notify command never surfaces into pi output.
28
+ child.on("error", () => {});
29
+ child.stderr?.on("data", () => {});
30
+ child.stdout?.on("data", () => {});
31
+ }
32
+
33
+ export default function notifyOnStopExtension(pi: ExtensionAPI): void {
34
+ pi.on("agent_end", () => {
35
+ const cmd = resolveCommand();
36
+ if (!cmd) return;
37
+ runNotify(cmd);
38
+ });
39
+
40
+ pi.registerCommand("notify", {
41
+ description:
42
+ "Stop-notify status/test. Usage: /notify [status|test|off]. Configure via env PI_STOP_NOTIFY, disable with PI_STOP_NOTIFY_OFF=1.",
43
+ handler: async (args, ctx) => {
44
+ const sub = args.trim().toLowerCase() || "status";
45
+ if (sub === "test") {
46
+ const cmd = resolveCommand();
47
+ if (!cmd) {
48
+ ctx.ui.notify("notify: nothing configured / disabled", "warning");
49
+ return;
50
+ }
51
+ runNotify(cmd);
52
+ ctx.ui.notify(`notify: ran "${cmd}"`, "info");
53
+ return;
54
+ }
55
+ if (sub === "off") {
56
+ ctx.ui.notify(
57
+ `notify: to disable persistently, set ${ENV_OFF}=1 in your shell rc; this session's behavior is driven by env at startup.`,
58
+ "info",
59
+ );
60
+ return;
61
+ }
62
+ const cmd = resolveCommand();
63
+ ctx.ui.notify(
64
+ cmd
65
+ ? `notify: will run "${cmd}" on agent_end`
66
+ : `notify: disabled (no default for this platform or ${ENV_OFF}=1)`,
67
+ "info",
68
+ );
69
+ },
70
+ });
71
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrofoundry/pi-astro",
3
- "version": "0.6.6",
3
+ "version": "0.6.7",
4
4
  "description": "Personal pi customizations (extensions, skills, prompts, themes) for the pi coding agent.",
5
5
  "keywords": [
6
6
  "pi-package"