@diegopetrucci/pi-notify 0.1.4 → 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.
- package/.pi-fleet-tested-version +1 -1
- package/README.md +2 -0
- package/index.ts +17 -4
- package/package.json +1 -1
package/.pi-fleet-tested-version
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.
|
|
1
|
+
0.78.0
|
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
|
|
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 =
|
|
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
|
|
261
|
+
const config = loadConfig(ctx);
|
|
249
262
|
if (!config.enabled) return;
|
|
250
263
|
if (config.onlyWhenInteractive && !ctx.hasUI) return;
|
|
251
264
|
|