@diegopetrucci/pi-brrr 0.1.2 → 0.1.3
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 +2 -0
- package/index.ts +17 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -35,6 +35,8 @@ Config files are merged, with project config overriding global config:
|
|
|
35
35
|
- `~/.pi/agent/extensions/brrr.json`
|
|
36
36
|
- `<project>/.pi/brrr.json`
|
|
37
37
|
|
|
38
|
+
Project config is only read after Pi reports that the project is trusted.
|
|
39
|
+
|
|
38
40
|
The default config expects your webhook in `BRRR_WEBHOOK_URL`:
|
|
39
41
|
|
|
40
42
|
```bash
|
package/index.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* Config files (project overrides global):
|
|
8
8
|
* - ~/.pi/agent/extensions/brrr.json
|
|
9
|
-
* - <cwd>/.pi/brrr.json
|
|
9
|
+
* - <cwd>/.pi/brrr.json, when the project is trusted
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
import { execFile } from "node:child_process";
|
|
@@ -16,6 +16,7 @@ import { promisify } from "node:util";
|
|
|
16
16
|
import { getAgentDir, type ExtensionAPI, type ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
|
|
17
17
|
|
|
18
18
|
const execFileAsync = promisify(execFile);
|
|
19
|
+
const CONFIG_DIR_NAME = ".pi";
|
|
19
20
|
|
|
20
21
|
interface BrrrConfig {
|
|
21
22
|
enabled: boolean;
|
|
@@ -40,6 +41,11 @@ interface BrrrPayload {
|
|
|
40
41
|
image_url?: string;
|
|
41
42
|
}
|
|
42
43
|
|
|
44
|
+
type ProjectConfigContext = {
|
|
45
|
+
cwd: string;
|
|
46
|
+
isProjectTrusted?: () => boolean;
|
|
47
|
+
};
|
|
48
|
+
|
|
43
49
|
const DEFAULT_CONFIG: BrrrConfig = {
|
|
44
50
|
enabled: true,
|
|
45
51
|
onlyWhenInteractive: true,
|
|
@@ -71,9 +77,15 @@ function mergeConfig(base: BrrrConfig, overrides: Partial<BrrrConfig>): BrrrConf
|
|
|
71
77
|
};
|
|
72
78
|
}
|
|
73
79
|
|
|
74
|
-
function
|
|
80
|
+
function canReadProjectConfig(ctx: ProjectConfigContext): boolean {
|
|
81
|
+
return typeof ctx.isProjectTrusted === "function" && ctx.isProjectTrusted();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function loadConfig(ctx: ProjectConfigContext): BrrrConfig {
|
|
75
85
|
const globalConfig = readConfigFile(join(getAgentDir(), "extensions", "brrr.json"));
|
|
76
|
-
const projectConfig =
|
|
86
|
+
const projectConfig = canReadProjectConfig(ctx)
|
|
87
|
+
? readConfigFile(join(ctx.cwd, CONFIG_DIR_NAME, "brrr.json"))
|
|
88
|
+
: {};
|
|
77
89
|
return mergeConfig(mergeConfig(DEFAULT_CONFIG, globalConfig), projectConfig);
|
|
78
90
|
}
|
|
79
91
|
|
|
@@ -219,13 +231,13 @@ export default function brrrExtension(pi: ExtensionAPI) {
|
|
|
219
231
|
pi.registerCommand("brrr", {
|
|
220
232
|
description: "Show brrr notification status",
|
|
221
233
|
handler: async (_args, ctx) => {
|
|
222
|
-
const config = loadConfig(ctx
|
|
234
|
+
const config = loadConfig(ctx);
|
|
223
235
|
notify(ctx, describeConfig(config, resolveWebhook(config.webhook)));
|
|
224
236
|
},
|
|
225
237
|
});
|
|
226
238
|
|
|
227
239
|
pi.on("agent_end", async (event, ctx) => {
|
|
228
|
-
const config = loadConfig(ctx
|
|
240
|
+
const config = loadConfig(ctx);
|
|
229
241
|
if (!config.enabled) return;
|
|
230
242
|
if (config.onlyWhenInteractive && !ctx.hasUI) return;
|
|
231
243
|
|