@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,231 +0,0 @@
1
- /**
2
- * Unit tests for PromptingGateway.
3
- *
4
- * The gateway owns the stored ExtensionContext and is the sole implementation
5
- * of the GatePrompter role. These tests exercise canConfirm() across all
6
- * policy permutations and verify the prompt/reject contract for promptPermission().
7
- */
8
- import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
9
- import { afterEach, describe, expect, it, vi } from "vitest";
10
-
11
- import type { ConfigReader } from "#src/config-store";
12
- import { DEFAULT_EXTENSION_CONFIG } from "#src/extension-config";
13
- import type { PermissionPromptDecision } from "#src/permission-dialog";
14
- import type {
15
- PermissionPrompterApi,
16
- PromptPermissionDetails,
17
- } from "#src/permission-prompter";
18
- import {
19
- PromptingGateway,
20
- type PromptingGatewayDeps,
21
- } from "#src/prompting-gateway";
22
-
23
- // ── Test helpers ──────────────────────────────────────────────────────────
24
-
25
- function makeCtx(overrides: Partial<ExtensionContext> = {}): ExtensionContext {
26
- return {
27
- cwd: "/test/project",
28
- hasUI: true,
29
- ui: {
30
- setStatus: vi.fn(),
31
- notify: vi.fn(),
32
- select: vi.fn(),
33
- input: vi.fn(),
34
- },
35
- sessionManager: {
36
- getEntries: vi.fn().mockReturnValue([]),
37
- getSessionDir: vi.fn().mockReturnValue("/sessions/test"),
38
- getSessionId: vi.fn().mockReturnValue(null),
39
- addEntry: vi.fn(),
40
- },
41
- ...overrides,
42
- } as unknown as ExtensionContext;
43
- }
44
-
45
- function makeConfigReader(
46
- overrides: Partial<typeof DEFAULT_EXTENSION_CONFIG> = {},
47
- ): ConfigReader {
48
- return {
49
- current: vi
50
- .fn<() => typeof DEFAULT_EXTENSION_CONFIG>()
51
- .mockReturnValue({ ...DEFAULT_EXTENSION_CONFIG, ...overrides }),
52
- };
53
- }
54
-
55
- function makePrompterApi(): PermissionPrompterApi & {
56
- prompt: ReturnType<typeof vi.fn>;
57
- } {
58
- return {
59
- prompt: vi
60
- .fn<PermissionPrompterApi["prompt"]>()
61
- .mockResolvedValue({ approved: true, state: "approved" }),
62
- };
63
- }
64
-
65
- function makeDetails(): PromptPermissionDetails {
66
- return {
67
- requestId: "req-1",
68
- source: "tool_call",
69
- agentName: null,
70
- message: "Allow this?",
71
- };
72
- }
73
-
74
- function makeDeps(
75
- overrides: Partial<PromptingGatewayDeps> = {},
76
- ): PromptingGatewayDeps {
77
- return {
78
- config: overrides.config ?? makeConfigReader(),
79
- subagentSessionsDir:
80
- overrides.subagentSessionsDir ?? "/test/agent/subagent-sessions",
81
- platform: overrides.platform ?? "linux",
82
- registry: overrides.registry,
83
- prompter: overrides.prompter ?? makePrompterApi(),
84
- };
85
- }
86
-
87
- // ── Tests ─────────────────────────────────────────────────────────────────
88
-
89
- describe("PromptingGateway", () => {
90
- describe("canConfirm", () => {
91
- it("returns false before activate", () => {
92
- const gateway = new PromptingGateway(makeDeps());
93
- expect(gateway.canConfirm()).toBe(false);
94
- });
95
-
96
- it("returns true after activate when context has UI", () => {
97
- const gateway = new PromptingGateway(makeDeps());
98
- gateway.activate(makeCtx({ hasUI: true }));
99
- expect(gateway.canConfirm()).toBe(true);
100
- });
101
-
102
- it("returns false when context has no UI, is not a subagent, and yolo mode is off", () => {
103
- const gateway = new PromptingGateway(
104
- makeDeps({ config: makeConfigReader({ yoloMode: false }) }),
105
- );
106
- gateway.activate(makeCtx({ hasUI: false }));
107
- expect(gateway.canConfirm()).toBe(false);
108
- });
109
-
110
- it("returns true when yolo mode is enabled (no UI, not subagent)", () => {
111
- const gateway = new PromptingGateway(
112
- makeDeps({ config: makeConfigReader({ yoloMode: true }) }),
113
- );
114
- gateway.activate(makeCtx({ hasUI: false }));
115
- expect(gateway.canConfirm()).toBe(true);
116
- });
117
-
118
- it("returns true when running as a subagent (env hint)", () => {
119
- vi.stubEnv("PI_IS_SUBAGENT", "1");
120
- const gateway = new PromptingGateway(
121
- makeDeps({ config: makeConfigReader({ yoloMode: false }) }),
122
- );
123
- gateway.activate(makeCtx({ hasUI: false }));
124
- expect(gateway.canConfirm()).toBe(true);
125
- vi.unstubAllEnvs();
126
- });
127
-
128
- it("returns false after deactivate", () => {
129
- const gateway = new PromptingGateway(makeDeps());
130
- gateway.activate(makeCtx({ hasUI: true }));
131
- gateway.deactivate();
132
- expect(gateway.canConfirm()).toBe(false);
133
- });
134
-
135
- it("returns true after re-activate following deactivate", () => {
136
- const gateway = new PromptingGateway(makeDeps());
137
- gateway.activate(makeCtx({ hasUI: true }));
138
- gateway.deactivate();
139
- gateway.activate(makeCtx({ hasUI: true }));
140
- expect(gateway.canConfirm()).toBe(true);
141
- });
142
- });
143
-
144
- describe("prompt", () => {
145
- it("rejects before activate", async () => {
146
- const gateway = new PromptingGateway(makeDeps());
147
- await expect(gateway.prompt(makeDetails())).rejects.toThrow(
148
- "prompt called before the session was activated",
149
- );
150
- });
151
-
152
- it("delegates to deps.prompter.prompt with the stored context", async () => {
153
- const prompter = makePrompterApi();
154
- const gateway = new PromptingGateway(makeDeps({ prompter }));
155
- const ctx = makeCtx();
156
- gateway.activate(ctx);
157
- const details = makeDetails();
158
-
159
- const result = await gateway.prompt(details);
160
-
161
- expect(prompter.prompt).toHaveBeenCalledWith(ctx, details);
162
- expect(result).toEqual({ approved: true, state: "approved" });
163
- });
164
-
165
- it("uses the most recently activated context", async () => {
166
- const prompter = makePrompterApi();
167
- const gateway = new PromptingGateway(makeDeps({ prompter }));
168
- const firstCtx = makeCtx({ cwd: "/first" });
169
- const secondCtx = makeCtx({ cwd: "/second" });
170
-
171
- gateway.activate(firstCtx);
172
- gateway.activate(secondCtx);
173
-
174
- await gateway.prompt(makeDetails());
175
-
176
- expect(prompter.prompt).toHaveBeenCalledWith(
177
- secondCtx,
178
- expect.anything(),
179
- );
180
- });
181
-
182
- it("rejects after deactivate", async () => {
183
- const gateway = new PromptingGateway(makeDeps());
184
- gateway.activate(makeCtx());
185
- gateway.deactivate();
186
- await expect(gateway.prompt(makeDetails())).rejects.toThrow(
187
- "prompt called before the session was activated",
188
- );
189
- });
190
-
191
- it("returns the prompter decision", async () => {
192
- const decision: PermissionPromptDecision = {
193
- approved: false,
194
- state: "denied",
195
- denialReason: "user declined",
196
- };
197
- const prompter = makePrompterApi();
198
- prompter.prompt.mockResolvedValue(decision);
199
- const gateway = new PromptingGateway(makeDeps({ prompter }));
200
- gateway.activate(makeCtx());
201
-
202
- const result = await gateway.prompt(makeDetails());
203
-
204
- expect(result).toEqual(decision);
205
- });
206
- });
207
-
208
- describe("lifecycle", () => {
209
- afterEach(() => {
210
- vi.unstubAllEnvs();
211
- });
212
-
213
- it("activate then deactivate clears the stored context", () => {
214
- const gateway = new PromptingGateway(makeDeps());
215
- gateway.activate(makeCtx());
216
- gateway.deactivate();
217
- expect(gateway.canConfirm()).toBe(false);
218
- });
219
-
220
- it("multiple activate calls update the stored context", () => {
221
- const prompter = makePrompterApi();
222
- const gateway = new PromptingGateway(makeDeps({ prompter }));
223
- const ctx2 = makeCtx({ cwd: "/new" });
224
- gateway.activate(makeCtx({ cwd: "/old" }));
225
- gateway.activate(ctx2);
226
-
227
- // canConfirm still works (context set)
228
- expect(gateway.canConfirm()).toBe(true);
229
- });
230
- });
231
- });