pi-arsenal 0.4.0 → 0.4.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.
@@ -2,47 +2,59 @@ import { spawn } from "node:child_process";
2
2
  import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
3
3
  import { Type } from "typebox";
4
4
 
5
- // ─── Toast via WinRT ──────────────────────────────────────────────────────────
6
- // Uses Windows.UI.Notifications WinRT API (available on Windows 10/11).
7
- // Falls back to a simple `msg %USERNAME%` if WinRT fails.
5
+ // ─── Platform dispatch ────────────────────────────────────────────────────────
8
6
 
9
- const APP_ID = "Pi Arsenal";
10
-
11
- function escapeXml(s: string): string {
12
- return s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
7
+ function sendNotification(title: string, body: string, urgency: "info" | "warning" | "error"): Promise<void> {
8
+ switch (process.platform) {
9
+ case "win32": return sendWindows(title, body, urgency);
10
+ case "darwin": return sendMac(title, body);
11
+ default: return sendLinux(title, body, urgency);
12
+ }
13
13
  }
14
14
 
15
- function sendToast(title: string, body: string, urgency: "info" | "warning" | "error"): Promise<void> {
16
- const scenario = urgency === "error" ? "urgent" : urgency === "warning" ? "reminder" : "default";
17
- // WinRT XML template
18
- const xml = `<toast scenario="${scenario}"><visual><binding template="ToastGeneric"><text>${escapeXml(title)}</text><text>${escapeXml(body)}</text></binding></visual></toast>`;
15
+ // ─── Windows — NotifyIcon balloon (System.Windows.Forms) ─────────────────────
16
+ // WinRT ToastNotificationManager requires a registered AppUserModelID;
17
+ // NotifyIcon works without registration and is available on all Windows versions.
18
+
19
+ function sendWindows(title: string, body: string, _urgency: "info" | "warning" | "error"): Promise<void> {
19
20
  const ps = `
20
- $xml = '${xml.replace(/'/g, "''")}';
21
- $dom = New-Object Windows.Data.Xml.Dom.XmlDocument;
22
- $dom.LoadXml($xml);
23
- [Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType=WindowsRuntime] | Out-Null;
24
- [Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom, ContentType=WindowsRuntime] | Out-Null;
25
- $toast = [Windows.UI.Notifications.ToastNotification]::new($dom);
26
- $notifier = [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier('${APP_ID.replace(/'/g, "''")}');
27
- $notifier.Show($toast);
21
+ Add-Type -AssemblyName System.Windows.Forms
22
+ $n = New-Object System.Windows.Forms.NotifyIcon
23
+ $n.Icon = [System.Drawing.SystemIcons]::Information
24
+ $n.Visible = $true
25
+ $n.ShowBalloonTip(6000, '${esc(title)}', '${esc(body)}', [System.Windows.Forms.ToolTipIcon]::Info)
26
+ Start-Sleep -Seconds 4
27
+ $n.Dispose()
28
28
  `;
29
- return new Promise((resolve) => {
30
- const proc = spawn("powershell.exe", ["-NoProfile", "-NonInteractive", "-Command", ps], { stdio: "ignore" });
31
- proc.on("close", (code) => {
32
- if (code !== 0) sendFallback(title, body).then(resolve);
33
- else resolve();
34
- });
35
- proc.on("error", () => sendFallback(title, body).then(resolve));
36
- });
29
+ return run("powershell.exe", ["-NoProfile", "-NonInteractive", "-Command", ps]);
30
+ }
31
+
32
+ // ─── macOS — osascript (zero dependencies) ───────────────────────────────────
33
+
34
+ function sendMac(title: string, body: string): Promise<void> {
35
+ const script = `display notification "${esc(body)}" with title "${esc(title)}"`;
36
+ return run("osascript", ["-e", script]);
37
+ }
38
+
39
+ // ─── Linux — notify-send ─────────────────────────────────────────────────────
40
+
41
+ function sendLinux(title: string, body: string, urgency: "info" | "warning" | "error"): Promise<void> {
42
+ const level = urgency === "error" ? "critical" : urgency === "warning" ? "normal" : "low";
43
+ return run("notify-send", ["-u", level, "-t", "6000", title, body]);
44
+ }
45
+
46
+ // ─── Helpers ─────────────────────────────────────────────────────────────────
47
+
48
+ /** Escape single quotes for embedding in PS / AppleScript strings. */
49
+ function esc(s: string): string {
50
+ return s.replace(/'/g, "\\'").replace(/"/g, '\\"');
37
51
  }
38
52
 
39
- function sendFallback(title: string, body: string): Promise<void> {
40
- // msg.exe: works on all Windows versions, shows a dialog to the current user session.
53
+ function run(cmd: string, args: string[]): Promise<void> {
41
54
  return new Promise((resolve) => {
42
- const text = `${title}\n\n${body}`;
43
- const proc = spawn("msg.exe", ["%USERNAME%", text], { stdio: "ignore" });
55
+ const proc = spawn(cmd, args, { stdio: "ignore" });
44
56
  proc.on("close", () => resolve());
45
- proc.on("error", () => resolve()); // silent fail — notification is best-effort
57
+ proc.on("error", () => resolve()); // best-effort — never throw
46
58
  });
47
59
  }
48
60
 
@@ -67,7 +79,7 @@ export default function piNotify(pi: ExtensionAPI) {
67
79
  }),
68
80
  async execute(_id, input, _signal, _onUpdate, _ctx) {
69
81
  const { title, body, urgency } = input as { title: string; body: string; urgency: "info" | "warning" | "error" };
70
- await sendToast(title.slice(0, 128), body.slice(0, 256), urgency);
82
+ await sendNotification(title.slice(0, 128), body.slice(0, 256), urgency);
71
83
  return { content: [{ type: "text" as const, text: `Notification sent: "${title}"` }] };
72
84
  },
73
85
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-arsenal",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "A terminal control deck for Pi: workspaces, sessions, skills, MCP, tasks, theme, and splash.",
5
5
  "type": "module",
6
6
  "license": "MIT",