@gotgenes/pi-permission-system 9.2.0 → 10.0.0
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/CHANGELOG.md +26 -0
- package/README.md +11 -10
- package/package.json +1 -1
- package/src/forwarded-permissions/io.ts +29 -0
- package/src/forwarded-permissions/polling.ts +34 -2
- package/src/index.ts +2 -0
- package/src/permission-event-rpc.ts +7 -0
- package/src/permission-events.ts +89 -8
- package/src/permission-forwarding.ts +23 -0
- package/src/permission-prompter.ts +22 -0
- package/src/permission-ui-prompt.ts +127 -0
- package/src/service.ts +17 -0
- package/test/composition-root.test.ts +5 -0
- package/test/permission-event-rpc.test.ts +39 -0
- package/test/permission-events.test.ts +78 -10
- package/test/permission-forwarding.test.ts +282 -0
- package/test/permission-prompter.test.ts +120 -0
- package/test/permission-ui-prompt.test.ts +146 -0
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
buildDirectUiPrompt,
|
|
5
|
+
buildForwardedUiPrompt,
|
|
6
|
+
buildRpcUiPrompt,
|
|
7
|
+
} from "#src/permission-ui-prompt";
|
|
8
|
+
|
|
9
|
+
describe("buildDirectUiPrompt", () => {
|
|
10
|
+
it("maps a tool_call prompt to the tool surface and command value", () => {
|
|
11
|
+
expect(
|
|
12
|
+
buildDirectUiPrompt({
|
|
13
|
+
requestId: "req-1",
|
|
14
|
+
source: "tool_call",
|
|
15
|
+
agentName: "Explore",
|
|
16
|
+
message: "Allow git push?",
|
|
17
|
+
toolName: "bash",
|
|
18
|
+
command: "git push",
|
|
19
|
+
}),
|
|
20
|
+
).toEqual({
|
|
21
|
+
requestId: "req-1",
|
|
22
|
+
source: "tool_call",
|
|
23
|
+
surface: "bash",
|
|
24
|
+
value: "git push",
|
|
25
|
+
agentName: "Explore",
|
|
26
|
+
message: "Allow git push?",
|
|
27
|
+
forwarding: null,
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("normalizes a skill prompt to the skill surface and skill-name value", () => {
|
|
32
|
+
expect(
|
|
33
|
+
buildDirectUiPrompt({
|
|
34
|
+
requestId: "req-2",
|
|
35
|
+
source: "skill_input",
|
|
36
|
+
agentName: null,
|
|
37
|
+
message: "Allow skill?",
|
|
38
|
+
skillName: "deploy-helper",
|
|
39
|
+
}),
|
|
40
|
+
).toEqual({
|
|
41
|
+
requestId: "req-2",
|
|
42
|
+
source: "skill_input",
|
|
43
|
+
surface: "skill",
|
|
44
|
+
value: "deploy-helper",
|
|
45
|
+
agentName: null,
|
|
46
|
+
message: "Allow skill?",
|
|
47
|
+
forwarding: null,
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("derives value with command > path > target > skillName > toolName precedence", () => {
|
|
52
|
+
expect(
|
|
53
|
+
buildDirectUiPrompt({
|
|
54
|
+
requestId: "req-3",
|
|
55
|
+
source: "tool_call",
|
|
56
|
+
agentName: null,
|
|
57
|
+
message: "m",
|
|
58
|
+
toolName: "read",
|
|
59
|
+
path: "/etc/hosts",
|
|
60
|
+
target: "ignored",
|
|
61
|
+
}).value,
|
|
62
|
+
).toBe("/etc/hosts");
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
describe("buildRpcUiPrompt", () => {
|
|
67
|
+
it("maps an RPC prompt to the rpc_prompt source with passthrough surface/value", () => {
|
|
68
|
+
expect(
|
|
69
|
+
buildRpcUiPrompt({
|
|
70
|
+
requestId: "req-rpc",
|
|
71
|
+
surface: "bash",
|
|
72
|
+
value: "git push",
|
|
73
|
+
agentName: "Worker",
|
|
74
|
+
message: "Allow git push?",
|
|
75
|
+
}),
|
|
76
|
+
).toEqual({
|
|
77
|
+
requestId: "req-rpc",
|
|
78
|
+
source: "rpc_prompt",
|
|
79
|
+
surface: "bash",
|
|
80
|
+
value: "git push",
|
|
81
|
+
agentName: "Worker",
|
|
82
|
+
message: "Allow git push?",
|
|
83
|
+
forwarding: null,
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it("defaults missing surface, value, and agentName to null", () => {
|
|
88
|
+
expect(
|
|
89
|
+
buildRpcUiPrompt({ requestId: "req-rpc-2", message: "Allow?" }),
|
|
90
|
+
).toEqual({
|
|
91
|
+
requestId: "req-rpc-2",
|
|
92
|
+
source: "rpc_prompt",
|
|
93
|
+
surface: null,
|
|
94
|
+
value: null,
|
|
95
|
+
agentName: null,
|
|
96
|
+
message: "Allow?",
|
|
97
|
+
forwarding: null,
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
describe("buildForwardedUiPrompt", () => {
|
|
103
|
+
it("populates forwarding context and carries the original source/surface/value", () => {
|
|
104
|
+
expect(
|
|
105
|
+
buildForwardedUiPrompt({
|
|
106
|
+
requestId: "req-fwd",
|
|
107
|
+
message: "Subagent 'Explore' requested permission.\n\nAllow git push?",
|
|
108
|
+
requesterAgentName: "Explore",
|
|
109
|
+
requesterSessionId: "child-session",
|
|
110
|
+
source: "tool_call",
|
|
111
|
+
surface: "bash",
|
|
112
|
+
value: "git push",
|
|
113
|
+
}),
|
|
114
|
+
).toEqual({
|
|
115
|
+
requestId: "req-fwd",
|
|
116
|
+
source: "tool_call",
|
|
117
|
+
surface: "bash",
|
|
118
|
+
value: "git push",
|
|
119
|
+
agentName: "Explore",
|
|
120
|
+
message: "Subagent 'Explore' requested permission.\n\nAllow git push?",
|
|
121
|
+
forwarding: {
|
|
122
|
+
requesterAgentName: "Explore",
|
|
123
|
+
requesterSessionId: "child-session",
|
|
124
|
+
},
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it("falls back to source tool_call with null surface/value when the request omits them", () => {
|
|
129
|
+
expect(
|
|
130
|
+
buildForwardedUiPrompt({
|
|
131
|
+
requestId: "req-fwd-old",
|
|
132
|
+
message: "Allow?",
|
|
133
|
+
requesterAgentName: null,
|
|
134
|
+
requesterSessionId: null,
|
|
135
|
+
}),
|
|
136
|
+
).toEqual({
|
|
137
|
+
requestId: "req-fwd-old",
|
|
138
|
+
source: "tool_call",
|
|
139
|
+
surface: null,
|
|
140
|
+
value: null,
|
|
141
|
+
agentName: null,
|
|
142
|
+
message: "Allow?",
|
|
143
|
+
forwarding: { requesterAgentName: null, requesterSessionId: null },
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
});
|