@diegopetrucci/pi-notify 0.1.5 → 0.1.6

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.
Files changed (3) hide show
  1. package/README.md +2 -0
  2. package/index.ts +17 -4
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -67,6 +67,8 @@ Config files are merged, with project config overriding global config:
67
67
  - `~/.pi/agent/extensions/notify.json`
68
68
  - `<project>/.pi/notify.json`
69
69
 
70
+ Project config is only read after Pi reports that the project is trusted.
71
+
70
72
  A ready-to-copy sample file is included at [`notify.example.json`](./notify.example.json).
71
73
 
72
74
  Example:
package/index.ts CHANGED
@@ -10,7 +10,7 @@
10
10
  *
11
11
  * Config files (project overrides global):
12
12
  * - ~/.pi/agent/extensions/notify.json
13
- * - <cwd>/.pi/notify.json
13
+ * - <cwd>/.pi/notify.json, when the project is trusted
14
14
  */
15
15
 
16
16
  import { execFile } from "node:child_process";
@@ -19,10 +19,17 @@ import { join } from "node:path";
19
19
  import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
20
20
  import { getAgentDir } from "@earendil-works/pi-coding-agent";
21
21
 
22
+ const CONFIG_DIR_NAME = ".pi";
23
+
22
24
  type TerminalBackend = "auto" | "osc777" | "osc99" | "none";
23
25
  type DesktopBackend = "auto" | "macos" | "linux" | "windows-toast" | "none";
24
26
  type SoundBackend = "auto" | "macos" | "linux" | "windows-beep" | "command" | "none";
25
27
 
28
+ type ProjectConfigContext = {
29
+ cwd: string;
30
+ isProjectTrusted?: () => boolean;
31
+ };
32
+
26
33
  interface NotifyConfig {
27
34
  enabled: boolean;
28
35
  onlyWhenInteractive: boolean;
@@ -111,9 +118,15 @@ function mergeConfig(base: NotifyConfig, overrides: Partial<NotifyConfig>): Noti
111
118
  };
112
119
  }
113
120
 
114
- function loadConfig(cwd: string): NotifyConfig {
121
+ function canReadProjectConfig(ctx: ProjectConfigContext): boolean {
122
+ return typeof ctx.isProjectTrusted === "function" && ctx.isProjectTrusted();
123
+ }
124
+
125
+ function loadConfig(ctx: ProjectConfigContext): NotifyConfig {
115
126
  const globalConfig = readConfigFile(join(getAgentDir(), "extensions", "notify.json"));
116
- const projectConfig = readConfigFile(join(cwd, ".pi", "notify.json"));
127
+ const projectConfig = canReadProjectConfig(ctx)
128
+ ? readConfigFile(join(ctx.cwd, CONFIG_DIR_NAME, "notify.json"))
129
+ : {};
117
130
  return mergeConfig(mergeConfig(DEFAULT_CONFIG, globalConfig), projectConfig);
118
131
  }
119
132
 
@@ -245,7 +258,7 @@ async function playSound(config: NotifyConfig, backend: Exclude<SoundBackend, "a
245
258
 
246
259
  export default function notifyExtension(pi: ExtensionAPI) {
247
260
  pi.on("agent_end", async (_event, ctx) => {
248
- const config = loadConfig(ctx.cwd);
261
+ const config = loadConfig(ctx);
249
262
  if (!config.enabled) return;
250
263
  if (config.onlyWhenInteractive && !ctx.hasUI) return;
251
264
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@diegopetrucci/pi-notify",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "description": "A pi extension that sends a notification when the agent is ready for input.",
5
5
  "keywords": [
6
6
  "pi-package",