forked from earendil-works/pi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproject-trust.ts
More file actions
64 lines (57 loc) · 2.08 KB
/
Copy pathproject-trust.ts
File metadata and controls
64 lines (57 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**
* Project Trust Extension
*
* Demonstrates the project_trust event. Install globally or pass via -e:
*
* mkdir -p ~/.pi/agent/extensions
* cp packages/coding-agent/examples/extensions/project-trust.ts ~/.pi/agent/extensions/
*
* Or:
*
* pi -e packages/coding-agent/examples/extensions/project-trust.ts
*
* Try it in a project containing .pi, AGENTS.md/CLAUDE.md, or .agents/skills.
*/
import type { ExtensionAPI, ProjectTrustEventResult } from "@earendil-works/pi-coding-agent";
export default function (pi: ExtensionAPI) {
let loadCount = 0;
loadCount++;
// Multiple handlers in one extension are allowed. The first handler that returns
// { trusted: "yes" } or { trusted: "no" } wins and suppresses the built-in
// trust prompt. Return { trusted: "undecided" } to let another handler or the
// built-in flow decide.
pi.on("project_trust", async (event, ctx): Promise<ProjectTrustEventResult> => {
ctx.ui.notify(`project_trust fired for ${event.cwd} (mode: ${ctx.mode}, load: ${loadCount})`, "info");
if (!ctx.hasUI) {
return { trusted: "undecided" };
}
const choice = await ctx.ui.select(`Project trust for:\n${event.cwd}`, [
"Trust and remember",
"Trust with note and remember",
"Trust this session",
"Do not trust this session",
"Let built-in prompt decide",
]);
if (choice === "Trust with note and remember") {
const note = await ctx.ui.input("Project trust note", "Optional note for this demo");
ctx.ui.notify(note ? `Recorded demo note: ${note}` : "No demo note entered", "info");
return { trusted: "yes", remember: true };
}
if (choice === "Trust and remember") {
return { trusted: "yes", remember: true };
}
if (choice === "Trust this session") {
return { trusted: "yes" };
}
if (choice === "Do not trust this session") {
return { trusted: "no" };
}
if (choice === "Let built-in prompt decide") {
return { trusted: "undecided" };
}
return { trusted: "undecided" };
});
pi.on("session_start", (_event, ctx) => {
ctx.ui.notify(`project-trust example loaded after trust resolution in ${ctx.cwd}`, "info");
});
}