@gotgenes/pi-permission-system 18.1.0 → 18.1.2

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 (132) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/docs/assets/logo.png +0 -0
  3. package/docs/assets/logo.svg +213 -0
  4. package/docs/configuration.md +700 -0
  5. package/docs/cross-extension-api.md +525 -0
  6. package/docs/guides/permission-frontmatter-for-subagent-extensions.md +201 -0
  7. package/docs/guides/upstream-issue-template.md +113 -0
  8. package/docs/migration/legacy-to-flat.md +365 -0
  9. package/docs/opencode-compatibility.md +213 -0
  10. package/docs/session-approvals.md +68 -0
  11. package/docs/subagent-integration.md +102 -0
  12. package/docs/troubleshooting.md +53 -0
  13. package/package.json +5 -2
  14. package/src/access-intent/access-path.ts +29 -4
  15. package/src/access-intent/bash/bash-path-resolver.ts +39 -18
  16. package/src/access-intent/bash/msys-bash-tokens.ts +64 -0
  17. package/src/path-normalizer.ts +105 -2
  18. package/test/access-intent/access-path.test.ts +0 -277
  19. package/test/access-intent/bash/node-text.test.ts +0 -148
  20. package/test/access-intent/bash/parser.test.ts +0 -19
  21. package/test/access-intent/bash/program.test.ts +0 -673
  22. package/test/access-intent/bash/token-classification.test.ts +0 -363
  23. package/test/access-intent/bash/token-collection.test.ts +0 -300
  24. package/test/active-agent.test.ts +0 -155
  25. package/test/async-cache.test.ts +0 -48
  26. package/test/bash-arity.test.ts +0 -144
  27. package/test/bash-external-directory.test.ts +0 -1022
  28. package/test/builtin-tool-input-formatters.test.ts +0 -109
  29. package/test/canonicalize-path.test.ts +0 -119
  30. package/test/composition-root.test.ts +0 -698
  31. package/test/config-loader.test.ts +0 -740
  32. package/test/config-modal.test.ts +0 -320
  33. package/test/config-paths.test.ts +0 -83
  34. package/test/config-pipeline.test.ts +0 -90
  35. package/test/config-reporter.test.ts +0 -147
  36. package/test/config-store.test.ts +0 -466
  37. package/test/decision-audit.test.ts +0 -72
  38. package/test/decision-reporter.test.ts +0 -112
  39. package/test/denial-messages.test.ts +0 -714
  40. package/test/detect-permissive-bash-fallback.test.ts +0 -56
  41. package/test/expand-home.test.ts +0 -93
  42. package/test/extension-config.test.ts +0 -129
  43. package/test/extension-paths.test.ts +0 -108
  44. package/test/forwarded-permissions/io.test.ts +0 -251
  45. package/test/forwarding-manager.test.ts +0 -200
  46. package/test/handlers/before-agent-start.test.ts +0 -314
  47. package/test/handlers/external-directory-integration.test.ts +0 -515
  48. package/test/handlers/external-directory-session-dedup.test.ts +0 -175
  49. package/test/handlers/external-directory-symlink-acceptance.test.ts +0 -167
  50. package/test/handlers/gates/bash-command-metamorphic.test.ts +0 -88
  51. package/test/handlers/gates/bash-command.test.ts +0 -257
  52. package/test/handlers/gates/bash-external-directory.test.ts +0 -268
  53. package/test/handlers/gates/bash-path.test.ts +0 -346
  54. package/test/handlers/gates/candidate-check.test.ts +0 -52
  55. package/test/handlers/gates/external-directory-messages.test.ts +0 -85
  56. package/test/handlers/gates/external-directory-policy.test.ts +0 -134
  57. package/test/handlers/gates/external-directory.test.ts +0 -267
  58. package/test/handlers/gates/helpers.test.ts +0 -165
  59. package/test/handlers/gates/path.test.ts +0 -369
  60. package/test/handlers/gates/runner.test.ts +0 -408
  61. package/test/handlers/gates/skill-input-gate-pipeline.test.ts +0 -176
  62. package/test/handlers/gates/skill-input.test.ts +0 -128
  63. package/test/handlers/gates/skill-read.test.ts +0 -161
  64. package/test/handlers/gates/tool-call-gate-pipeline.test.ts +0 -356
  65. package/test/handlers/gates/tool.test.ts +0 -244
  66. package/test/handlers/input-events.test.ts +0 -168
  67. package/test/handlers/input.test.ts +0 -199
  68. package/test/handlers/lifecycle.test.ts +0 -221
  69. package/test/handlers/tool-call-boundary.test.ts +0 -145
  70. package/test/handlers/tool-call-events.test.ts +0 -277
  71. package/test/handlers/tool-call.test.ts +0 -395
  72. package/test/handlers/validate-requested-tool.test.ts +0 -92
  73. package/test/helpers/external-directory-fixtures.ts +0 -269
  74. package/test/helpers/gate-fixtures.ts +0 -316
  75. package/test/helpers/handler-fixtures.ts +0 -335
  76. package/test/helpers/make-fake-pi.ts +0 -100
  77. package/test/helpers/manager-harness.ts +0 -112
  78. package/test/helpers/session-fixtures.ts +0 -199
  79. package/test/input-normalizer.test.ts +0 -325
  80. package/test/logging.test.ts +0 -51
  81. package/test/mcp-targets.test.ts +0 -233
  82. package/test/node-modules-discovery.test.ts +0 -97
  83. package/test/normalize.test.ts +0 -247
  84. package/test/path-containment.test.ts +0 -161
  85. package/test/path-normalization.test.ts +0 -233
  86. package/test/path-normalizer.test.ts +0 -196
  87. package/test/path-surfaces.test.ts +0 -55
  88. package/test/pattern-suggest.test.ts +0 -248
  89. package/test/permission-dialog.test.ts +0 -205
  90. package/test/permission-event-rpc.test.ts +0 -560
  91. package/test/permission-events.test.ts +0 -400
  92. package/test/permission-forwarder.test.ts +0 -370
  93. package/test/permission-forwarding.test.ts +0 -315
  94. package/test/permission-gate.test.ts +0 -269
  95. package/test/permission-manager-unified.test.ts +0 -3714
  96. package/test/permission-merge.test.ts +0 -61
  97. package/test/permission-prompter.test.ts +0 -518
  98. package/test/permission-prompts.test.ts +0 -363
  99. package/test/permission-resolver.test.ts +0 -277
  100. package/test/permission-session.test.ts +0 -404
  101. package/test/permission-ui-prompt.test.ts +0 -146
  102. package/test/permissions-service.test.ts +0 -192
  103. package/test/pi-infrastructure-read.test.ts +0 -432
  104. package/test/policy-loader.test.ts +0 -561
  105. package/test/prompting-gateway.test.ts +0 -231
  106. package/test/rule.test.ts +0 -650
  107. package/test/safe-system-paths.test.ts +0 -46
  108. package/test/scope-merge.test.ts +0 -116
  109. package/test/service-lifecycle.test.ts +0 -163
  110. package/test/service.test.ts +0 -261
  111. package/test/session-approval.test.ts +0 -75
  112. package/test/session-logger.test.ts +0 -200
  113. package/test/session-rules.test.ts +0 -321
  114. package/test/session-start.test.ts +0 -112
  115. package/test/skill-prompt-sanitizer.test.ts +0 -418
  116. package/test/status.test.ts +0 -10
  117. package/test/subagent-context.test.ts +0 -372
  118. package/test/subagent-lifecycle-events.test.ts +0 -132
  119. package/test/subagent-registry.test.ts +0 -145
  120. package/test/synthesize.test.ts +0 -302
  121. package/test/system-prompt-sanitizer.test.ts +0 -382
  122. package/test/tool-access-extractor-registry.test.ts +0 -77
  123. package/test/tool-input-formatter-registry.test.ts +0 -75
  124. package/test/tool-input-path.test.ts +0 -84
  125. package/test/tool-input-preview.test.ts +0 -129
  126. package/test/tool-input-prompt-formatters.test.ts +0 -115
  127. package/test/tool-preview-formatter.test.ts +0 -458
  128. package/test/tool-registry.test.ts +0 -197
  129. package/test/value-guards.test.ts +0 -193
  130. package/test/wildcard-matcher.test.ts +0 -424
  131. package/test/yaml-frontmatter.test.ts +0 -91
  132. package/test/yolo-mode.test.ts +0 -188
@@ -1,269 +0,0 @@
1
- import { describe, expect, it, vi } from "vitest";
2
- import type { PermissionPromptDecision } from "#src/permission-dialog";
3
- import {
4
- applyPermissionGate,
5
- type PermissionGateParams,
6
- } from "#src/permission-gate";
7
-
8
- function makeParams(
9
- overrides: Partial<PermissionGateParams> = {},
10
- ): PermissionGateParams {
11
- return {
12
- state: "allow",
13
- canConfirm: true,
14
- promptForApproval: vi.fn<() => Promise<PermissionPromptDecision>>(),
15
- writeLog: vi.fn(),
16
- logContext: { source: "test" },
17
- messages: {
18
- denyReason: "Denied by policy.",
19
- unavailableReason: "No interactive UI available.",
20
- userDeniedReason: (d) =>
21
- d.denialReason
22
- ? `User denied. Reason: ${d.denialReason}.`
23
- : "User denied.",
24
- },
25
- ...overrides,
26
- };
27
- }
28
-
29
- describe("applyPermissionGate", () => {
30
- describe("deny branch", () => {
31
- it("returns block with deny reason when state is deny", async () => {
32
- const params = makeParams({ state: "deny" });
33
- const result = await applyPermissionGate(params);
34
- expect(result).toEqual({
35
- action: "block",
36
- reason: "Denied by policy.",
37
- });
38
- });
39
-
40
- it("calls writeLog with policy_denied resolution", async () => {
41
- const params = makeParams({
42
- state: "deny",
43
- logContext: { source: "tool_call", toolName: "bash" },
44
- });
45
- await applyPermissionGate(params);
46
- expect(params.writeLog).toHaveBeenCalledOnce();
47
- expect(params.writeLog).toHaveBeenCalledWith(
48
- "permission_request.blocked",
49
- {
50
- source: "tool_call",
51
- toolName: "bash",
52
- resolution: "policy_denied",
53
- },
54
- );
55
- });
56
-
57
- it("does not call promptForApproval when state is deny", async () => {
58
- const params = makeParams({ state: "deny" });
59
- await applyPermissionGate(params);
60
- expect(params.promptForApproval).not.toHaveBeenCalled();
61
- });
62
- });
63
-
64
- describe("ask branch — unavailable", () => {
65
- it("returns block with unavailable reason when canConfirm is false", async () => {
66
- const params = makeParams({ state: "ask", canConfirm: false });
67
- const result = await applyPermissionGate(params);
68
- expect(result).toEqual({
69
- action: "block",
70
- reason: "No interactive UI available.",
71
- });
72
- });
73
-
74
- it("calls writeLog with confirmation_unavailable resolution", async () => {
75
- const params = makeParams({
76
- state: "ask",
77
- canConfirm: false,
78
- logContext: { source: "skill_read", skillName: "foo" },
79
- });
80
- await applyPermissionGate(params);
81
- expect(params.writeLog).toHaveBeenCalledOnce();
82
- expect(params.writeLog).toHaveBeenCalledWith(
83
- "permission_request.blocked",
84
- {
85
- source: "skill_read",
86
- skillName: "foo",
87
- resolution: "confirmation_unavailable",
88
- },
89
- );
90
- });
91
-
92
- it("does not call promptForApproval when canConfirm is false", async () => {
93
- const params = makeParams({ state: "ask", canConfirm: false });
94
- await applyPermissionGate(params);
95
- expect(params.promptForApproval).not.toHaveBeenCalled();
96
- });
97
- });
98
-
99
- describe("ask branch — user rejects", () => {
100
- it("returns block with user-denied reason when user rejects", async () => {
101
- const decision: PermissionPromptDecision = {
102
- approved: false,
103
- state: "denied",
104
- };
105
- const promptForApproval = vi.fn().mockResolvedValue(decision);
106
- const params = makeParams({
107
- state: "ask",
108
- canConfirm: true,
109
- promptForApproval,
110
- });
111
- const result = await applyPermissionGate(params);
112
- expect(result).toEqual({ action: "block", reason: "User denied." });
113
- });
114
-
115
- it("passes denial reason through userDeniedReason formatter", async () => {
116
- const decision: PermissionPromptDecision = {
117
- approved: false,
118
- state: "denied_with_reason",
119
- denialReason: "not now",
120
- };
121
- const promptForApproval = vi.fn().mockResolvedValue(decision);
122
- const params = makeParams({
123
- state: "ask",
124
- canConfirm: true,
125
- promptForApproval,
126
- });
127
- const result = await applyPermissionGate(params);
128
- expect(result).toEqual({
129
- action: "block",
130
- reason: "User denied. Reason: not now.",
131
- });
132
- });
133
-
134
- it("does not call writeLog when user rejects (logged by promptPermission)", async () => {
135
- const decision: PermissionPromptDecision = {
136
- approved: false,
137
- state: "denied",
138
- };
139
- const promptForApproval = vi.fn().mockResolvedValue(decision);
140
- const params = makeParams({
141
- state: "ask",
142
- canConfirm: true,
143
- promptForApproval,
144
- });
145
- await applyPermissionGate(params);
146
- expect(params.writeLog).not.toHaveBeenCalled();
147
- });
148
- });
149
-
150
- describe("ask branch — user approves", () => {
151
- it("returns allow when user approves", async () => {
152
- const decision: PermissionPromptDecision = {
153
- approved: true,
154
- state: "approved",
155
- };
156
- const promptForApproval = vi.fn().mockResolvedValue(decision);
157
- const params = makeParams({
158
- state: "ask",
159
- canConfirm: true,
160
- promptForApproval,
161
- });
162
- const result = await applyPermissionGate(params);
163
- expect(result).toEqual({ action: "allow" });
164
- });
165
-
166
- it("does not call writeLog when user approves", async () => {
167
- const decision: PermissionPromptDecision = {
168
- approved: true,
169
- state: "approved",
170
- };
171
- const promptForApproval = vi.fn().mockResolvedValue(decision);
172
- const params = makeParams({
173
- state: "ask",
174
- canConfirm: true,
175
- promptForApproval,
176
- });
177
- await applyPermissionGate(params);
178
- expect(params.writeLog).not.toHaveBeenCalled();
179
- });
180
- });
181
-
182
- describe("ask branch — approved_for_session with sessionApproval", () => {
183
- it("attaches sessionApproval to result when decision is approved_for_session and param provided", async () => {
184
- const decision: PermissionPromptDecision = {
185
- approved: true,
186
- state: "approved_for_session",
187
- };
188
- const promptForApproval = vi.fn().mockResolvedValue(decision);
189
- const params = makeParams({
190
- state: "ask",
191
- canConfirm: true,
192
- promptForApproval,
193
- sessionApproval: { surface: "bash", pattern: "git *" },
194
- });
195
- const result = await applyPermissionGate(params);
196
- expect(result).toEqual({
197
- action: "allow",
198
- sessionApproval: { surface: "bash", pattern: "git *" },
199
- });
200
- });
201
-
202
- it("does not attach sessionApproval when decision is approved (once)", async () => {
203
- const decision: PermissionPromptDecision = {
204
- approved: true,
205
- state: "approved",
206
- };
207
- const promptForApproval = vi.fn().mockResolvedValue(decision);
208
- const params = makeParams({
209
- state: "ask",
210
- canConfirm: true,
211
- promptForApproval,
212
- sessionApproval: { surface: "bash", pattern: "git *" },
213
- });
214
- const result = await applyPermissionGate(params);
215
- expect(result).toEqual({ action: "allow" });
216
- });
217
-
218
- it("does not attach sessionApproval when no sessionApproval param", async () => {
219
- const decision: PermissionPromptDecision = {
220
- approved: true,
221
- state: "approved_for_session",
222
- };
223
- const promptForApproval = vi.fn().mockResolvedValue(decision);
224
- const params = makeParams({
225
- state: "ask",
226
- canConfirm: true,
227
- promptForApproval,
228
- });
229
- const result = await applyPermissionGate(params);
230
- expect(result).toEqual({ action: "allow" });
231
- });
232
-
233
- it("does not attach sessionApproval when user denies", async () => {
234
- const decision: PermissionPromptDecision = {
235
- approved: false,
236
- state: "denied",
237
- };
238
- const promptForApproval = vi.fn().mockResolvedValue(decision);
239
- const params = makeParams({
240
- state: "ask",
241
- canConfirm: true,
242
- promptForApproval,
243
- sessionApproval: { surface: "bash", pattern: "git *" },
244
- });
245
- const result = await applyPermissionGate(params);
246
- expect(result).toEqual({ action: "block", reason: "User denied." });
247
- });
248
- });
249
-
250
- describe("allow branch", () => {
251
- it("returns allow immediately when state is allow", async () => {
252
- const params = makeParams({ state: "allow" });
253
- const result = await applyPermissionGate(params);
254
- expect(result).toEqual({ action: "allow" });
255
- });
256
-
257
- it("does not call writeLog when state is allow", async () => {
258
- const params = makeParams({ state: "allow" });
259
- await applyPermissionGate(params);
260
- expect(params.writeLog).not.toHaveBeenCalled();
261
- });
262
-
263
- it("does not call promptForApproval when state is allow", async () => {
264
- const params = makeParams({ state: "allow" });
265
- await applyPermissionGate(params);
266
- expect(params.promptForApproval).not.toHaveBeenCalled();
267
- });
268
- });
269
- });