@astrofoundry/pi-astro 0.6.7 → 0.7.0

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,7 +62,9 @@ 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
+ - `notify-on-stop` — runs a shell command when the agent finishes a turn (sound, voice, desktop notification). macOS default: plays the Glass system sound **and** speaks "Agent done" via `say` using the **`Samantha (Enhanced)`** voice. Linux default: `notify-send "pi" "Agent done"`. Override the voice with `PI_STOP_NOTIFY_VOICE=<voice-name>` (macOS only; e.g. `Alex`, `Karen`, `Daniel (Enhanced)`). Replace the full command with `PI_STOP_NOTIFY='afplay /System/Library/Sounds/Glass.aiff && say "Done"'`. Disable everything with `PI_STOP_NOTIFY_OFF=1`. `/notify status|test|off`.
66
+ - **macOS voice install (required once for the default):** open **System Settings → Accessibility → Spoken Content → System Voice → Manage Voices…**, expand **English**, check **Samantha (Enhanced)**, click **Done** to download (~500 MB – 1 GB). Verify with `say -v "Samantha (Enhanced)" hi`. If the voice is missing, `say` errors silently and you'll only hear the Glass sound.
67
+ - `vscode-image` — only active inside VS Code's integrated terminal (`TERM_PROGRAM=vscode`). Switches pi-tui's image output to the **Kitty graphics protocol** so images returned by tools like `gemini_image` render as real pixels instead of the `[Image: …]` text fallback. **Requires enabling `Terminal › Integrated: Enable Images` in VS Code settings** (off by default); restart the integrated terminal after flipping it. Disable with `PI_VSCODE_IMAGE_OFF=1`. `/vscode-image` prints current status.
66
68
  - `claude-globals` — auto-injects `~/.claude/CLAUDE.md` into every pi session's system prompt
67
69
 
68
70
  **Bundled subagents** (callable via `astro_agent`):
@@ -51,12 +51,14 @@ function setPlatform(p: NodeJS.Platform): void {
51
51
  describe("notify-on-stop", () => {
52
52
  const origCmd = process.env.PI_STOP_NOTIFY;
53
53
  const origOff = process.env.PI_STOP_NOTIFY_OFF;
54
+ const origVoice = process.env.PI_STOP_NOTIFY_VOICE;
54
55
 
55
56
  beforeEach(() => {
56
57
  vi.resetModules();
57
58
  execMock.mockReset();
58
59
  delete process.env.PI_STOP_NOTIFY;
59
60
  delete process.env.PI_STOP_NOTIFY_OFF;
61
+ delete process.env.PI_STOP_NOTIFY_VOICE;
60
62
  });
61
63
 
62
64
  afterEach(() => {
@@ -65,16 +67,79 @@ describe("notify-on-stop", () => {
65
67
  else process.env.PI_STOP_NOTIFY = origCmd;
66
68
  if (origOff === undefined) delete process.env.PI_STOP_NOTIFY_OFF;
67
69
  else process.env.PI_STOP_NOTIFY_OFF = origOff;
70
+ if (origVoice === undefined) delete process.env.PI_STOP_NOTIFY_VOICE;
71
+ else process.env.PI_STOP_NOTIFY_VOICE = origVoice;
68
72
  });
69
73
 
70
- it("runs default command on agent_end (macOS)", async () => {
74
+ it("runs default command on agent_end (macOS): afplay + say with Samantha (Enhanced)", async () => {
71
75
  setPlatform("darwin");
72
76
  const mod = await import("./index.ts");
73
77
  const pi = makePi();
74
78
  mod.default(pi as unknown as Parameters<typeof mod.default>[0]);
75
79
  pi.handlers.agent_end({}, makeCtx());
76
80
  expect(execMock).toHaveBeenCalled();
77
- expect(execMock.mock.calls[0][0]).toMatch(/afplay/);
81
+ const cmd = execMock.mock.calls[0][0] as string;
82
+ expect(cmd).toMatch(/^afplay \/System\/Library\/Sounds\/Glass\.aiff && say -v /);
83
+ expect(cmd).toContain("'Samantha (Enhanced)'");
84
+ expect(cmd).toContain("'Agent done'");
85
+ });
86
+
87
+ it("PI_STOP_NOTIFY_VOICE overrides the default voice (macOS)", async () => {
88
+ setPlatform("darwin");
89
+ process.env.PI_STOP_NOTIFY_VOICE = "Alex";
90
+ const mod = await import("./index.ts");
91
+ const pi = makePi();
92
+ mod.default(pi as unknown as Parameters<typeof mod.default>[0]);
93
+ pi.handlers.agent_end({}, makeCtx());
94
+ const cmd = execMock.mock.calls[0][0] as string;
95
+ expect(cmd).toContain("say -v 'Alex'");
96
+ expect(cmd).not.toContain("Samantha");
97
+ });
98
+
99
+ it("PI_STOP_NOTIFY_VOICE with apostrophes is POSIX-safely quoted", async () => {
100
+ setPlatform("darwin");
101
+ process.env.PI_STOP_NOTIFY_VOICE = "O'Neill";
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
+ const cmd = execMock.mock.calls[0][0] as string;
107
+ expect(cmd).toContain("say -v 'O'\\''Neill'");
108
+ });
109
+
110
+ it("PI_STOP_NOTIFY_VOICE with only whitespace falls back to default voice (macOS)", async () => {
111
+ setPlatform("darwin");
112
+ process.env.PI_STOP_NOTIFY_VOICE = " ";
113
+ const mod = await import("./index.ts");
114
+ const pi = makePi();
115
+ mod.default(pi as unknown as Parameters<typeof mod.default>[0]);
116
+ pi.handlers.agent_end({}, makeCtx());
117
+ const cmd = execMock.mock.calls[0][0] as string;
118
+ expect(cmd).toContain("'Samantha (Enhanced)'");
119
+ });
120
+
121
+ it("PI_STOP_NOTIFY_VOICE is ignored when PI_STOP_NOTIFY overrides the full command", async () => {
122
+ setPlatform("darwin");
123
+ process.env.PI_STOP_NOTIFY = "my custom --cmd";
124
+ process.env.PI_STOP_NOTIFY_VOICE = "Alex";
125
+ const mod = await import("./index.ts");
126
+ const pi = makePi();
127
+ mod.default(pi as unknown as Parameters<typeof mod.default>[0]);
128
+ pi.handlers.agent_end({}, makeCtx());
129
+ expect(execMock.mock.calls[0][0]).toBe("my custom --cmd");
130
+ });
131
+
132
+ it("PI_STOP_NOTIFY_VOICE has no effect on Linux default", async () => {
133
+ setPlatform("linux");
134
+ process.env.PI_STOP_NOTIFY_VOICE = "Alex";
135
+ const mod = await import("./index.ts");
136
+ const pi = makePi();
137
+ mod.default(pi as unknown as Parameters<typeof mod.default>[0]);
138
+ pi.handlers.agent_end({}, makeCtx());
139
+ const cmd = execMock.mock.calls[0][0] as string;
140
+ expect(cmd).toMatch(/notify-send/);
141
+ expect(cmd).not.toContain("say");
142
+ expect(cmd).not.toContain("Alex");
78
143
  });
79
144
 
80
145
  it("runs custom PI_STOP_NOTIFY over default", async () => {
@@ -3,11 +3,21 @@ import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
3
3
 
4
4
  const ENV_CMD = "PI_STOP_NOTIFY";
5
5
  const ENV_OFF = "PI_STOP_NOTIFY_OFF";
6
+ const ENV_VOICE = "PI_STOP_NOTIFY_VOICE";
6
7
  const TIMEOUT_MS = 10_000;
8
+ const DEFAULT_VOICE = "Samantha (Enhanced)";
9
+ const MACOS_SPOKEN_MESSAGE = "Agent done";
10
+
11
+ function shellQuote(value: string): string {
12
+ return `'${value.replace(/'/g, "'\\''")}'`;
13
+ }
7
14
 
8
15
  function defaultCommand(): string | undefined {
9
16
  if (process.platform === "darwin") {
10
- return "afplay /System/Library/Sounds/Glass.aiff";
17
+ const voice = process.env[ENV_VOICE]?.trim() || DEFAULT_VOICE;
18
+ const sound = "afplay /System/Library/Sounds/Glass.aiff";
19
+ const speak = `say -v ${shellQuote(voice)} ${shellQuote(MACOS_SPOKEN_MESSAGE)}`;
20
+ return `${sound} && ${speak}`;
11
21
  }
12
22
  if (process.platform === "linux") {
13
23
  return 'command -v notify-send >/dev/null 2>&1 && notify-send "pi" "Agent done"';
@@ -39,7 +49,7 @@ export default function notifyOnStopExtension(pi: ExtensionAPI): void {
39
49
 
40
50
  pi.registerCommand("notify", {
41
51
  description:
42
- "Stop-notify status/test. Usage: /notify [status|test|off]. Configure via env PI_STOP_NOTIFY, disable with PI_STOP_NOTIFY_OFF=1.",
52
+ "Stop-notify status/test. Usage: /notify [status|test|off]. Configure via env PI_STOP_NOTIFY (full override) or PI_STOP_NOTIFY_VOICE (macOS default voice); disable with PI_STOP_NOTIFY_OFF=1.",
43
53
  handler: async (args, ctx) => {
44
54
  const sub = args.trim().toLowerCase() || "status";
45
55
  if (sub === "test") {
@@ -0,0 +1,114 @@
1
+ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
2
+
3
+ const setCapabilitiesMock = vi.fn();
4
+
5
+ vi.mock("@mariozechner/pi-tui", () => ({
6
+ setCapabilities: setCapabilitiesMock,
7
+ }));
8
+
9
+ type CommandHandler = (args: string, ctx: unknown) => Promise<void> | void;
10
+
11
+ function makePi(): {
12
+ commands: Map<string, { handler: CommandHandler }>;
13
+ registerCommand: (name: string, opts: { description?: string; handler: CommandHandler }) => void;
14
+ } {
15
+ const commands = new Map<string, { handler: CommandHandler }>();
16
+ return {
17
+ commands,
18
+ registerCommand: (name, opts) => {
19
+ commands.set(name, { handler: opts.handler });
20
+ },
21
+ };
22
+ }
23
+
24
+ function makeCtx(): { ui: { notify: ReturnType<typeof vi.fn> } } {
25
+ return { ui: { notify: vi.fn() } };
26
+ }
27
+
28
+ describe("vscode-image", () => {
29
+ const origTerm = process.env.TERM_PROGRAM;
30
+ const origOff = process.env.PI_VSCODE_IMAGE_OFF;
31
+
32
+ beforeEach(() => {
33
+ vi.resetModules();
34
+ setCapabilitiesMock.mockReset();
35
+ delete process.env.TERM_PROGRAM;
36
+ delete process.env.PI_VSCODE_IMAGE_OFF;
37
+ });
38
+
39
+ afterEach(() => {
40
+ if (origTerm === undefined) delete process.env.TERM_PROGRAM;
41
+ else process.env.TERM_PROGRAM = origTerm;
42
+ if (origOff === undefined) delete process.env.PI_VSCODE_IMAGE_OFF;
43
+ else process.env.PI_VSCODE_IMAGE_OFF = origOff;
44
+ });
45
+
46
+ it("does nothing when TERM_PROGRAM is unset", async () => {
47
+ const mod = await import("./index.ts");
48
+ const pi = makePi();
49
+ mod.default(pi as unknown as Parameters<typeof mod.default>[0]);
50
+ expect(setCapabilitiesMock).not.toHaveBeenCalled();
51
+ expect(pi.commands.has("vscode-image")).toBe(false);
52
+ });
53
+
54
+ it("does nothing when TERM_PROGRAM is not vscode", async () => {
55
+ process.env.TERM_PROGRAM = "iterm.app";
56
+ const mod = await import("./index.ts");
57
+ const pi = makePi();
58
+ mod.default(pi as unknown as Parameters<typeof mod.default>[0]);
59
+ expect(setCapabilitiesMock).not.toHaveBeenCalled();
60
+ expect(pi.commands.has("vscode-image")).toBe(false);
61
+ });
62
+
63
+ it("enables Kitty protocol when TERM_PROGRAM=vscode", async () => {
64
+ process.env.TERM_PROGRAM = "vscode";
65
+ const mod = await import("./index.ts");
66
+ const pi = makePi();
67
+ mod.default(pi as unknown as Parameters<typeof mod.default>[0]);
68
+ expect(setCapabilitiesMock).toHaveBeenCalledWith({
69
+ images: "kitty",
70
+ trueColor: true,
71
+ hyperlinks: true,
72
+ });
73
+ expect(pi.commands.has("vscode-image")).toBe(true);
74
+ });
75
+
76
+ it("matches TERM_PROGRAM case-insensitively", async () => {
77
+ process.env.TERM_PROGRAM = "VSCode";
78
+ const mod = await import("./index.ts");
79
+ const pi = makePi();
80
+ mod.default(pi as unknown as Parameters<typeof mod.default>[0]);
81
+ expect(setCapabilitiesMock).toHaveBeenCalled();
82
+ });
83
+
84
+ it("skips setCapabilities when PI_VSCODE_IMAGE_OFF=1 but still registers command", async () => {
85
+ process.env.TERM_PROGRAM = "vscode";
86
+ process.env.PI_VSCODE_IMAGE_OFF = "1";
87
+ const mod = await import("./index.ts");
88
+ const pi = makePi();
89
+ mod.default(pi as unknown as Parameters<typeof mod.default>[0]);
90
+ expect(setCapabilitiesMock).not.toHaveBeenCalled();
91
+ expect(pi.commands.has("vscode-image")).toBe(true);
92
+ });
93
+
94
+ it("/vscode-image reports enabled state", async () => {
95
+ process.env.TERM_PROGRAM = "vscode";
96
+ const mod = await import("./index.ts");
97
+ const pi = makePi();
98
+ mod.default(pi as unknown as Parameters<typeof mod.default>[0]);
99
+ const ctx = makeCtx();
100
+ await pi.commands.get("vscode-image")!.handler("", ctx);
101
+ expect(ctx.ui.notify).toHaveBeenCalledWith(expect.stringMatching(/Kitty/), "info");
102
+ });
103
+
104
+ it("/vscode-image reports disabled when PI_VSCODE_IMAGE_OFF=1", async () => {
105
+ process.env.TERM_PROGRAM = "vscode";
106
+ process.env.PI_VSCODE_IMAGE_OFF = "1";
107
+ const mod = await import("./index.ts");
108
+ const pi = makePi();
109
+ mod.default(pi as unknown as Parameters<typeof mod.default>[0]);
110
+ const ctx = makeCtx();
111
+ await pi.commands.get("vscode-image")!.handler("", ctx);
112
+ expect(ctx.ui.notify).toHaveBeenCalledWith(expect.stringMatching(/disabled/), "info");
113
+ });
114
+ });
@@ -0,0 +1,42 @@
1
+ import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
2
+ import { setCapabilities } from "@mariozechner/pi-tui";
3
+
4
+ const ENV_OFF = "PI_VSCODE_IMAGE_OFF";
5
+
6
+ function inVSCode(): boolean {
7
+ return process.env.TERM_PROGRAM?.toLowerCase() === "vscode";
8
+ }
9
+
10
+ function isDisabled(): boolean {
11
+ return process.env[ENV_OFF] === "1";
12
+ }
13
+
14
+ export default function vscodeImageExtension(pi: ExtensionAPI): void {
15
+ if (!inVSCode()) return;
16
+
17
+ if (!isDisabled()) {
18
+ setCapabilities({
19
+ images: "kitty",
20
+ trueColor: true,
21
+ hyperlinks: true,
22
+ });
23
+ }
24
+
25
+ pi.registerCommand("vscode-image", {
26
+ description:
27
+ "VSCode image-protocol status. Usage: /vscode-image. Disable with PI_VSCODE_IMAGE_OFF=1 (requires pi restart).",
28
+ handler: async (_args, ctx) => {
29
+ if (isDisabled()) {
30
+ ctx.ui.notify(
31
+ `vscode-image: disabled (${ENV_OFF}=1). Unset the env var and restart pi to re-enable.`,
32
+ "info",
33
+ );
34
+ return;
35
+ }
36
+ ctx.ui.notify(
37
+ "vscode-image: Kitty graphics protocol enabled. Ensure \"Terminal > Integrated: Enable Images\" is ON in VS Code settings.",
38
+ "info",
39
+ );
40
+ },
41
+ });
42
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrofoundry/pi-astro",
3
- "version": "0.6.7",
3
+ "version": "0.7.0",
4
4
  "description": "Personal pi customizations (extensions, skills, prompts, themes) for the pi coding agent.",
5
5
  "keywords": [
6
6
  "pi-package"