@gotgenes/pi-permission-system 18.1.1 → 18.2.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.
Files changed (133) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/docs/configuration.md +11 -0
  3. package/package.json +1 -2
  4. package/src/access-intent/access-path.ts +29 -4
  5. package/src/access-intent/bash/bash-path-resolver.ts +39 -18
  6. package/src/access-intent/bash/msys-bash-tokens.ts +64 -0
  7. package/src/extension-config.ts +7 -0
  8. package/src/forwarded-permissions/permission-forwarder.ts +6 -3
  9. package/src/handlers/gates/helpers.ts +1 -1
  10. package/src/handlers/gates/runner.ts +22 -0
  11. package/src/index.ts +10 -6
  12. package/src/path-normalizer.ts +105 -2
  13. package/src/permission-manager.ts +21 -1
  14. package/src/permission-prompter.ts +10 -16
  15. package/src/prompting-gateway.ts +13 -17
  16. package/src/rule.ts +21 -1
  17. package/src/status.ts +1 -1
  18. package/src/yolo-mode.ts +0 -30
  19. package/test/access-intent/access-path.test.ts +0 -277
  20. package/test/access-intent/bash/node-text.test.ts +0 -148
  21. package/test/access-intent/bash/parser.test.ts +0 -19
  22. package/test/access-intent/bash/program.test.ts +0 -673
  23. package/test/access-intent/bash/token-classification.test.ts +0 -363
  24. package/test/access-intent/bash/token-collection.test.ts +0 -300
  25. package/test/active-agent.test.ts +0 -155
  26. package/test/async-cache.test.ts +0 -48
  27. package/test/bash-arity.test.ts +0 -144
  28. package/test/bash-external-directory.test.ts +0 -1022
  29. package/test/builtin-tool-input-formatters.test.ts +0 -109
  30. package/test/canonicalize-path.test.ts +0 -119
  31. package/test/composition-root.test.ts +0 -698
  32. package/test/config-loader.test.ts +0 -740
  33. package/test/config-modal.test.ts +0 -320
  34. package/test/config-paths.test.ts +0 -83
  35. package/test/config-pipeline.test.ts +0 -90
  36. package/test/config-reporter.test.ts +0 -147
  37. package/test/config-store.test.ts +0 -466
  38. package/test/decision-audit.test.ts +0 -72
  39. package/test/decision-reporter.test.ts +0 -112
  40. package/test/denial-messages.test.ts +0 -714
  41. package/test/detect-permissive-bash-fallback.test.ts +0 -56
  42. package/test/expand-home.test.ts +0 -93
  43. package/test/extension-config.test.ts +0 -129
  44. package/test/extension-paths.test.ts +0 -108
  45. package/test/forwarded-permissions/io.test.ts +0 -251
  46. package/test/forwarding-manager.test.ts +0 -200
  47. package/test/handlers/before-agent-start.test.ts +0 -314
  48. package/test/handlers/external-directory-integration.test.ts +0 -515
  49. package/test/handlers/external-directory-session-dedup.test.ts +0 -175
  50. package/test/handlers/external-directory-symlink-acceptance.test.ts +0 -167
  51. package/test/handlers/gates/bash-command-metamorphic.test.ts +0 -88
  52. package/test/handlers/gates/bash-command.test.ts +0 -257
  53. package/test/handlers/gates/bash-external-directory.test.ts +0 -268
  54. package/test/handlers/gates/bash-path.test.ts +0 -346
  55. package/test/handlers/gates/candidate-check.test.ts +0 -52
  56. package/test/handlers/gates/external-directory-messages.test.ts +0 -85
  57. package/test/handlers/gates/external-directory-policy.test.ts +0 -134
  58. package/test/handlers/gates/external-directory.test.ts +0 -267
  59. package/test/handlers/gates/helpers.test.ts +0 -165
  60. package/test/handlers/gates/path.test.ts +0 -369
  61. package/test/handlers/gates/runner.test.ts +0 -408
  62. package/test/handlers/gates/skill-input-gate-pipeline.test.ts +0 -176
  63. package/test/handlers/gates/skill-input.test.ts +0 -128
  64. package/test/handlers/gates/skill-read.test.ts +0 -161
  65. package/test/handlers/gates/tool-call-gate-pipeline.test.ts +0 -356
  66. package/test/handlers/gates/tool.test.ts +0 -244
  67. package/test/handlers/input-events.test.ts +0 -168
  68. package/test/handlers/input.test.ts +0 -199
  69. package/test/handlers/lifecycle.test.ts +0 -221
  70. package/test/handlers/tool-call-boundary.test.ts +0 -145
  71. package/test/handlers/tool-call-events.test.ts +0 -277
  72. package/test/handlers/tool-call.test.ts +0 -395
  73. package/test/handlers/validate-requested-tool.test.ts +0 -92
  74. package/test/helpers/external-directory-fixtures.ts +0 -269
  75. package/test/helpers/gate-fixtures.ts +0 -316
  76. package/test/helpers/handler-fixtures.ts +0 -335
  77. package/test/helpers/make-fake-pi.ts +0 -100
  78. package/test/helpers/manager-harness.ts +0 -112
  79. package/test/helpers/session-fixtures.ts +0 -199
  80. package/test/input-normalizer.test.ts +0 -325
  81. package/test/logging.test.ts +0 -51
  82. package/test/mcp-targets.test.ts +0 -233
  83. package/test/node-modules-discovery.test.ts +0 -97
  84. package/test/normalize.test.ts +0 -247
  85. package/test/path-containment.test.ts +0 -161
  86. package/test/path-normalization.test.ts +0 -233
  87. package/test/path-normalizer.test.ts +0 -196
  88. package/test/path-surfaces.test.ts +0 -55
  89. package/test/pattern-suggest.test.ts +0 -248
  90. package/test/permission-dialog.test.ts +0 -205
  91. package/test/permission-event-rpc.test.ts +0 -560
  92. package/test/permission-events.test.ts +0 -400
  93. package/test/permission-forwarder.test.ts +0 -370
  94. package/test/permission-forwarding.test.ts +0 -315
  95. package/test/permission-gate.test.ts +0 -269
  96. package/test/permission-manager-unified.test.ts +0 -3714
  97. package/test/permission-merge.test.ts +0 -61
  98. package/test/permission-prompter.test.ts +0 -518
  99. package/test/permission-prompts.test.ts +0 -363
  100. package/test/permission-resolver.test.ts +0 -277
  101. package/test/permission-session.test.ts +0 -404
  102. package/test/permission-ui-prompt.test.ts +0 -146
  103. package/test/permissions-service.test.ts +0 -192
  104. package/test/pi-infrastructure-read.test.ts +0 -432
  105. package/test/policy-loader.test.ts +0 -561
  106. package/test/prompting-gateway.test.ts +0 -231
  107. package/test/rule.test.ts +0 -650
  108. package/test/safe-system-paths.test.ts +0 -46
  109. package/test/scope-merge.test.ts +0 -116
  110. package/test/service-lifecycle.test.ts +0 -163
  111. package/test/service.test.ts +0 -261
  112. package/test/session-approval.test.ts +0 -75
  113. package/test/session-logger.test.ts +0 -200
  114. package/test/session-rules.test.ts +0 -321
  115. package/test/session-start.test.ts +0 -112
  116. package/test/skill-prompt-sanitizer.test.ts +0 -418
  117. package/test/status.test.ts +0 -10
  118. package/test/subagent-context.test.ts +0 -372
  119. package/test/subagent-lifecycle-events.test.ts +0 -132
  120. package/test/subagent-registry.test.ts +0 -145
  121. package/test/synthesize.test.ts +0 -302
  122. package/test/system-prompt-sanitizer.test.ts +0 -382
  123. package/test/tool-access-extractor-registry.test.ts +0 -77
  124. package/test/tool-input-formatter-registry.test.ts +0 -75
  125. package/test/tool-input-path.test.ts +0 -84
  126. package/test/tool-input-preview.test.ts +0 -129
  127. package/test/tool-input-prompt-formatters.test.ts +0 -115
  128. package/test/tool-preview-formatter.test.ts +0 -458
  129. package/test/tool-registry.test.ts +0 -197
  130. package/test/value-guards.test.ts +0 -193
  131. package/test/wildcard-matcher.test.ts +0 -424
  132. package/test/yaml-frontmatter.test.ts +0 -91
  133. package/test/yolo-mode.test.ts +0 -188
@@ -1,320 +0,0 @@
1
- import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
2
- import { tmpdir } from "node:os";
3
- import { join } from "node:path";
4
- import { expect, test, vi } from "vitest";
5
- import { loadUnifiedConfig } from "#src/config-loader";
6
- import { registerPermissionSystemCommand } from "#src/config-modal";
7
- import type { CommandConfigStore } from "#src/config-store";
8
- import {
9
- DEFAULT_EXTENSION_CONFIG,
10
- normalizePermissionSystemConfig,
11
- type PermissionSystemExtensionConfig,
12
- } from "#src/extension-config";
13
- import type { Rule, Ruleset } from "#src/rule";
14
-
15
- vi.mock("@earendil-works/pi-coding-agent", () => ({
16
- getSettingsListTheme: () => ({}),
17
- }));
18
-
19
- vi.mock("@earendil-works/pi-tui", () => ({
20
- SettingsList: class {
21
- handleInput(): void {}
22
- updateValue(): void {}
23
- render(): string[] {
24
- return [];
25
- }
26
- invalidate(): void {}
27
- },
28
- }));
29
-
30
- type Notification = { message: string; level: "info" | "warning" | "error" };
31
-
32
- type CommandContextStub = {
33
- hasUI: boolean;
34
- ui: {
35
- notify(message: string, level: "info" | "warning" | "error"): void;
36
- custom<T>(
37
- renderer: (...args: unknown[]) => unknown,
38
- options?: unknown,
39
- ): Promise<T>;
40
- };
41
- };
42
-
43
- function createCommandContext(hasUI: boolean): {
44
- ctx: CommandContextStub;
45
- notifications: Notification[];
46
- getCustomCalls(): number;
47
- } {
48
- const notifications: Notification[] = [];
49
- let customCalls = 0;
50
-
51
- return {
52
- ctx: {
53
- hasUI,
54
- ui: {
55
- notify(message: string, level: "info" | "warning" | "error") {
56
- notifications.push({ message, level });
57
- },
58
- async custom<T>(
59
- _renderer: (...args: unknown[]) => unknown,
60
- _options?: unknown,
61
- ): Promise<T> {
62
- customCalls += 1;
63
- return undefined as T;
64
- },
65
- },
66
- },
67
- notifications,
68
- getCustomCalls: () => customCalls,
69
- };
70
- }
71
-
72
- function lastNotification(notifications: Notification[]): Notification {
73
- return notifications[notifications.length - 1];
74
- }
75
-
76
- test("permission-system command completions expose top-level config actions", () => {
77
- const baseDir = mkdtempSync(
78
- join(tmpdir(), "pi-permission-system-command-completions-"),
79
- );
80
- const configPath = join(baseDir, "config.json");
81
- let config: PermissionSystemExtensionConfig = { ...DEFAULT_EXTENSION_CONFIG };
82
-
83
- try {
84
- const configStore: CommandConfigStore = {
85
- current: () => config,
86
- save: (next) => {
87
- config = next;
88
- },
89
- };
90
- const controller = {
91
- config: configStore,
92
- configPath,
93
- getActiveAgentConfigRules: () => [] as Ruleset,
94
- };
95
-
96
- let definition: {
97
- description: string;
98
- getArgumentCompletions?: (
99
- argumentPrefix: string,
100
- ) => Array<{ value: string; label: string; description?: string }> | null;
101
- handler: (args: string, ctx: CommandContextStub) => Promise<void>;
102
- } | null = null;
103
-
104
- registerPermissionSystemCommand(
105
- {
106
- registerCommand(_name: string, nextDefinition: typeof definition) {
107
- definition = nextDefinition;
108
- },
109
- } as never,
110
- controller,
111
- );
112
-
113
- expect(definition!.getArgumentCompletions).toBeTypeOf("function");
114
-
115
- const topLevel = definition!.getArgumentCompletions?.("");
116
- expect(Array.isArray(topLevel)).toBeTruthy();
117
- expect(topLevel?.some((item) => item.value === "show")).toBeTruthy();
118
- expect(topLevel?.some((item) => item.value === "reset")).toBeTruthy();
119
-
120
- const filtered = definition!.getArgumentCompletions?.("pa");
121
- expect(filtered?.map((item) => item.value)).toEqual(["path"]);
122
- expect(definition!.getArgumentCompletions?.("path extra")).toBe(null);
123
- expect(definition!.getArgumentCompletions?.("zzz")).toBe(null);
124
- } finally {
125
- rmSync(baseDir, { recursive: true, force: true });
126
- }
127
- });
128
-
129
- test("permission-system command handlers manage config summary, persistence, and modal routing", async () => {
130
- const baseDir = mkdtempSync(join(tmpdir(), "pi-permission-system-command-"));
131
- const configPath = join(baseDir, "config.json");
132
- let config: PermissionSystemExtensionConfig = {
133
- debugLog: true,
134
- permissionReviewLog: false,
135
- yoloMode: true,
136
- };
137
-
138
- try {
139
- writeFileSync(
140
- configPath,
141
- `${JSON.stringify(normalizePermissionSystemConfig(config), null, 2)}\n`,
142
- "utf-8",
143
- );
144
-
145
- const configStore: CommandConfigStore = {
146
- current: () => config,
147
- save: (next) => {
148
- const currentConfig = normalizePermissionSystemConfig(
149
- loadUnifiedConfig(configPath).config,
150
- );
151
- const normalized = normalizePermissionSystemConfig(next);
152
- writeFileSync(
153
- configPath,
154
- `${JSON.stringify(normalized, null, 2)}\n`,
155
- "utf-8",
156
- );
157
- config = normalizePermissionSystemConfig(
158
- loadUnifiedConfig(configPath).config,
159
- );
160
- expect(config).not.toEqual(currentConfig);
161
- },
162
- };
163
- const controller = {
164
- config: configStore,
165
- configPath,
166
- getActiveAgentConfigRules: () => [] as Ruleset,
167
- };
168
-
169
- let registeredName = "";
170
- let definition: {
171
- description: string;
172
- getArgumentCompletions?: (
173
- argumentPrefix: string,
174
- ) => Array<{ value: string; label: string; description?: string }> | null;
175
- handler: (args: string, ctx: CommandContextStub) => Promise<void>;
176
- } | null = null;
177
-
178
- registerPermissionSystemCommand(
179
- {
180
- registerCommand(name: string, nextDefinition: typeof definition) {
181
- registeredName = name;
182
- definition = nextDefinition;
183
- },
184
- } as never,
185
- controller,
186
- );
187
-
188
- expect(registeredName).toBe("permission-system");
189
- expect(definition!.description).toContain("Configure pi-permission-system");
190
-
191
- const infoCtx = createCommandContext(true);
192
- await definition!.handler("show", infoCtx.ctx);
193
- expect(lastNotification(infoCtx.notifications).message).toContain(
194
- "yoloMode=on",
195
- );
196
- expect(lastNotification(infoCtx.notifications).message).toContain(
197
- "debugLog=on",
198
- );
199
-
200
- await definition!.handler("path", infoCtx.ctx);
201
- expect(lastNotification(infoCtx.notifications).message).toBe(
202
- `permission-system config: ${configPath}`,
203
- );
204
-
205
- await definition!.handler("help", infoCtx.ctx);
206
- expect(lastNotification(infoCtx.notifications).message).toContain(
207
- "Usage: /permission-system",
208
- );
209
-
210
- await definition!.handler("reset", infoCtx.ctx);
211
- expect(config).toEqual(DEFAULT_EXTENSION_CONFIG);
212
- expect(lastNotification(infoCtx.notifications).message).toBe(
213
- "Permission system settings reset to defaults.",
214
- );
215
-
216
- const persisted = JSON.parse(readFileSync(configPath, "utf8")) as Record<
217
- string,
218
- unknown
219
- >;
220
- expect(persisted).toEqual(DEFAULT_EXTENSION_CONFIG);
221
-
222
- await definition!.handler("unknown", infoCtx.ctx);
223
- expect(lastNotification(infoCtx.notifications).level).toBe("warning");
224
- expect(lastNotification(infoCtx.notifications).message).toContain(
225
- "Usage: /permission-system",
226
- );
227
-
228
- const headlessCtx = createCommandContext(false);
229
- await definition!.handler("", headlessCtx.ctx);
230
- expect(lastNotification(headlessCtx.notifications).message).toBe(
231
- "/permission-system requires interactive TUI mode.",
232
- );
233
-
234
- const modalCtx = createCommandContext(true);
235
- await definition!.handler("", modalCtx.ctx);
236
- expect(modalCtx.getCustomCalls()).toBe(1);
237
- } finally {
238
- rmSync(baseDir, { recursive: true, force: true });
239
- }
240
- });
241
-
242
- test("show output includes rule origins when getComposedRules is provided", async () => {
243
- const config = { ...DEFAULT_EXTENSION_CONFIG };
244
- const composedRules: Rule[] = [
245
- {
246
- surface: "read",
247
- pattern: "*",
248
- action: "allow",
249
- layer: "config",
250
- origin: "global",
251
- },
252
- {
253
- surface: "bash",
254
- pattern: "rm *",
255
- action: "deny",
256
- layer: "config",
257
- origin: "project",
258
- },
259
- ];
260
-
261
- const controller = {
262
- config: { current: () => config, save: () => {} } as CommandConfigStore,
263
- configPath: "/fake/config.json",
264
- getActiveAgentConfigRules: () => composedRules,
265
- };
266
-
267
- let definition: {
268
- handler: (args: string, ctx: CommandContextStub) => Promise<void>;
269
- } | null = null;
270
-
271
- registerPermissionSystemCommand(
272
- {
273
- registerCommand(_name: string, nextDef: typeof definition) {
274
- definition = nextDef;
275
- },
276
- } as never,
277
- controller,
278
- );
279
-
280
- const ctx = createCommandContext(true);
281
- await definition!.handler("show", ctx.ctx);
282
- const msg = lastNotification(ctx.notifications).message;
283
-
284
- expect(msg).toContain("global");
285
- expect(msg).toContain("project");
286
- expect(msg).toContain("read");
287
- expect(msg).toContain("bash");
288
- });
289
-
290
- test("show output omits rule summary when getComposedRules is not provided", async () => {
291
- const config = { ...DEFAULT_EXTENSION_CONFIG, yoloMode: true };
292
-
293
- const controller = {
294
- config: { current: () => config, save: () => {} } as CommandConfigStore,
295
- configPath: "/fake/config.json",
296
- getActiveAgentConfigRules: () => [] as Ruleset,
297
- };
298
-
299
- let definition: {
300
- handler: (args: string, ctx: CommandContextStub) => Promise<void>;
301
- } | null = null;
302
-
303
- registerPermissionSystemCommand(
304
- {
305
- registerCommand(_name: string, nextDef: typeof definition) {
306
- definition = nextDef;
307
- },
308
- } as never,
309
- controller,
310
- );
311
-
312
- const ctx = createCommandContext(true);
313
- await definition!.handler("show", ctx.ctx);
314
- const msg = lastNotification(ctx.notifications).message;
315
-
316
- // Config knobs still present.
317
- expect(msg).toContain("yoloMode=on");
318
- // No rule annotation lines.
319
- expect(msg).not.toContain("(global)");
320
- });
@@ -1,83 +0,0 @@
1
- import { join } from "node:path";
2
- import { describe, expect, it } from "vitest";
3
-
4
- import {
5
- DEBUG_LOG_FILENAME,
6
- getGlobalConfigDir,
7
- getGlobalConfigPath,
8
- getGlobalLogsDir,
9
- getLegacyExtensionConfigPath,
10
- getLegacyGlobalPolicyPath,
11
- getLegacyProjectPolicyPath,
12
- getProjectAgentsDir,
13
- getProjectConfigPath,
14
- REVIEW_LOG_FILENAME,
15
- } from "#src/config-paths";
16
-
17
- describe("config-paths", () => {
18
- const agentDir = "/home/user/.pi/agent";
19
- const cwd = "/projects/my-app";
20
- const extensionRoot = "/opt/extensions/pi-permission-system";
21
-
22
- describe("new layout paths", () => {
23
- it("getGlobalConfigDir returns extensions/pi-permission-system under agentDir", () => {
24
- expect(getGlobalConfigDir(agentDir)).toBe(
25
- join(agentDir, "extensions", "pi-permission-system"),
26
- );
27
- });
28
-
29
- it("getGlobalConfigPath returns config.json under the global config dir", () => {
30
- expect(getGlobalConfigPath(agentDir)).toBe(
31
- join(agentDir, "extensions", "pi-permission-system", "config.json"),
32
- );
33
- });
34
-
35
- it("getGlobalLogsDir returns logs under the global config dir", () => {
36
- expect(getGlobalLogsDir(agentDir)).toBe(
37
- join(agentDir, "extensions", "pi-permission-system", "logs"),
38
- );
39
- });
40
-
41
- it("getProjectConfigPath returns .pi/extensions/pi-permission-system/config.json under cwd", () => {
42
- expect(getProjectConfigPath(cwd)).toBe(
43
- join(cwd, ".pi", "extensions", "pi-permission-system", "config.json"),
44
- );
45
- });
46
-
47
- it("getProjectAgentsDir returns .pi/agents under cwd", () => {
48
- expect(getProjectAgentsDir(cwd)).toBe(join(cwd, ".pi", "agents"));
49
- });
50
- });
51
-
52
- describe("legacy paths", () => {
53
- it("getLegacyGlobalPolicyPath returns pi-permissions.jsonc under agentDir", () => {
54
- expect(getLegacyGlobalPolicyPath(agentDir)).toBe(
55
- join(agentDir, "pi-permissions.jsonc"),
56
- );
57
- });
58
-
59
- it("getLegacyProjectPolicyPath returns .pi/agent/pi-permissions.jsonc under cwd", () => {
60
- expect(getLegacyProjectPolicyPath(cwd)).toBe(
61
- join(cwd, ".pi", "agent", "pi-permissions.jsonc"),
62
- );
63
- });
64
-
65
- it("getLegacyExtensionConfigPath returns config.json under extensionRoot", () => {
66
- expect(getLegacyExtensionConfigPath(extensionRoot)).toBe(
67
- join(extensionRoot, "config.json"),
68
- );
69
- });
70
- });
71
-
72
- describe("log filenames", () => {
73
- it("DEBUG_LOG_FILENAME is a .jsonl file", () => {
74
- expect(DEBUG_LOG_FILENAME).toBe("pi-permission-system-debug.jsonl");
75
- });
76
-
77
- it("REVIEW_LOG_FILENAME is a .jsonl file", () => {
78
- expect(REVIEW_LOG_FILENAME).toBe(
79
- "pi-permission-system-permission-review.jsonl",
80
- );
81
- });
82
- });
83
- });
@@ -1,90 +0,0 @@
1
- import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
2
- import { tmpdir } from "node:os";
3
- import { join } from "node:path";
4
- import { afterEach, beforeEach, describe, expect, it } from "vitest";
5
-
6
- import { loadAndMergeConfigs } from "#src/config-loader";
7
- import { normalizePermissionSystemConfig } from "#src/extension-config";
8
-
9
- /**
10
- * Full-pipeline seam tests: write a temp config.json → loadAndMergeConfigs →
11
- * normalizePermissionSystemConfig → assert values survive end to end.
12
- *
13
- * These tests guard the seam between the two normalizers — the class of bug
14
- * fixed in #332, where a field declared on PermissionSystemExtensionConfig was
15
- * silently dropped by the UnifiedPermissionConfig intermediate.
16
- */
17
- describe("config pipeline seam", () => {
18
- let tempDir: string;
19
- let agentDir: string;
20
- let cwd: string;
21
- let extensionRoot: string;
22
-
23
- beforeEach(() => {
24
- tempDir = mkdtempSync(join(tmpdir(), "config-pipeline-test-"));
25
- agentDir = join(tempDir, "agent");
26
- cwd = join(tempDir, "project");
27
- extensionRoot = join(tempDir, "ext");
28
- });
29
-
30
- afterEach(() => {
31
- rmSync(tempDir, { recursive: true, force: true });
32
- });
33
-
34
- function writeGlobal(content: Record<string, unknown>): void {
35
- const dir = join(agentDir, "extensions", "pi-permission-system");
36
- mkdirSync(dir, { recursive: true });
37
- writeFileSync(join(dir, "config.json"), JSON.stringify(content));
38
- }
39
-
40
- it("runtime knob and preview-length field both survive the full pipeline", () => {
41
- writeGlobal({
42
- debugLog: true,
43
- toolInputPreviewMaxLength: 1000,
44
- });
45
-
46
- const mergeResult = loadAndMergeConfigs(agentDir, cwd, extensionRoot);
47
- const config = normalizePermissionSystemConfig(mergeResult.merged);
48
-
49
- expect(config.debugLog).toBe(true);
50
- expect(config.toolInputPreviewMaxLength).toBe(1000);
51
- });
52
-
53
- it("text summary length field survives the full pipeline", () => {
54
- writeGlobal({
55
- toolTextSummaryMaxLength: 250,
56
- });
57
-
58
- const mergeResult = loadAndMergeConfigs(agentDir, cwd, extensionRoot);
59
- const config = normalizePermissionSystemConfig(mergeResult.merged);
60
-
61
- expect(config.toolTextSummaryMaxLength).toBe(250);
62
- });
63
-
64
- it("project config overrides global preview-length field end to end", () => {
65
- writeGlobal({ toolInputPreviewMaxLength: 200 });
66
- const projectDir = join(cwd, ".pi", "extensions", "pi-permission-system");
67
- mkdirSync(projectDir, { recursive: true });
68
- writeFileSync(
69
- join(projectDir, "config.json"),
70
- JSON.stringify({ toolInputPreviewMaxLength: 500 }),
71
- );
72
-
73
- const mergeResult = loadAndMergeConfigs(agentDir, cwd, extensionRoot);
74
- const config = normalizePermissionSystemConfig(mergeResult.merged);
75
-
76
- expect(config.toolInputPreviewMaxLength).toBe(500);
77
- });
78
-
79
- it("defaults apply when config file is absent", () => {
80
- // No config files written — agentDir and cwd directories don't exist.
81
- const mergeResult = loadAndMergeConfigs(agentDir, cwd, extensionRoot);
82
- const config = normalizePermissionSystemConfig(mergeResult.merged);
83
-
84
- expect(config.debugLog).toBe(false);
85
- expect(config.permissionReviewLog).toBe(true);
86
- expect(config.yoloMode).toBe(false);
87
- expect(config.toolInputPreviewMaxLength).toBeUndefined();
88
- expect(config.toolTextSummaryMaxLength).toBeUndefined();
89
- });
90
- });
@@ -1,147 +0,0 @@
1
- import {
2
- mkdirSync,
3
- mkdtempSync,
4
- readFileSync,
5
- rmSync,
6
- writeFileSync,
7
- } from "node:fs";
8
- import { tmpdir } from "node:os";
9
- import { join } from "node:path";
10
- import { expect, test } from "vitest";
11
- import { buildResolvedConfigLogEntry } from "#src/config-reporter";
12
- import { createPermissionSystemLogger } from "#src/logging";
13
- import type { ResolvedPolicyPaths } from "#src/permission-manager";
14
- import { PermissionManager } from "#src/permission-manager";
15
-
16
- test("buildResolvedConfigLogEntry includes policy paths and legacy detection flags", () => {
17
- const policyPaths: ResolvedPolicyPaths = {
18
- globalConfigPath:
19
- "/home/user/.pi/agent/extensions/pi-permission-system/config.json",
20
- globalConfigExists: true,
21
- projectConfigPath:
22
- "/projects/my-app/.pi/extensions/pi-permission-system/config.json",
23
- projectConfigExists: false,
24
- agentsDir: "/home/user/.pi/agent/agents",
25
- agentsDirExists: true,
26
- projectAgentsDir: "/projects/my-app/.pi/agent/agents",
27
- projectAgentsDirExists: false,
28
- };
29
-
30
- const result = buildResolvedConfigLogEntry({ policyPaths });
31
-
32
- expect(result.globalConfigPath).toBe(
33
- "/home/user/.pi/agent/extensions/pi-permission-system/config.json",
34
- );
35
- expect(result.globalConfigExists).toBe(true);
36
- expect(result.projectConfigPath).toBe(
37
- "/projects/my-app/.pi/extensions/pi-permission-system/config.json",
38
- );
39
- expect(result.projectConfigExists).toBe(false);
40
- expect(result.agentsDir).toBe("/home/user/.pi/agent/agents");
41
- expect(result.agentsDirExists).toBe(true);
42
- expect(result.projectAgentsDir).toBe("/projects/my-app/.pi/agent/agents");
43
- expect(result.projectAgentsDirExists).toBe(false);
44
- expect(result.legacyGlobalPolicyDetected).toBe(false);
45
- expect(result.legacyProjectPolicyDetected).toBe(false);
46
- expect(result.legacyExtensionConfigDetected).toBe(false);
47
- });
48
-
49
- test("buildResolvedConfigLogEntry handles null project paths", () => {
50
- const policyPaths: ResolvedPolicyPaths = {
51
- globalConfigPath:
52
- "/home/user/.pi/agent/extensions/pi-permission-system/config.json",
53
- globalConfigExists: false,
54
- projectConfigPath: null,
55
- projectConfigExists: false,
56
- agentsDir: "/home/user/.pi/agent/agents",
57
- agentsDirExists: false,
58
- projectAgentsDir: null,
59
- projectAgentsDirExists: false,
60
- };
61
-
62
- const result = buildResolvedConfigLogEntry({ policyPaths });
63
-
64
- expect(result.projectConfigPath).toBe(null);
65
- expect(result.projectConfigExists).toBe(false);
66
- expect(result.projectAgentsDir).toBe(null);
67
- expect(result.projectAgentsDirExists).toBe(false);
68
- });
69
-
70
- test("buildResolvedConfigLogEntry surfaces legacy detection flags", () => {
71
- const policyPaths: ResolvedPolicyPaths = {
72
- globalConfigPath:
73
- "/home/user/.pi/agent/extensions/pi-permission-system/config.json",
74
- globalConfigExists: true,
75
- projectConfigPath: null,
76
- projectConfigExists: false,
77
- agentsDir: "/home/user/.pi/agent/agents",
78
- agentsDirExists: false,
79
- projectAgentsDir: null,
80
- projectAgentsDirExists: false,
81
- };
82
-
83
- const result = buildResolvedConfigLogEntry({
84
- policyPaths,
85
- legacyGlobalPolicyDetected: true,
86
- legacyExtensionConfigDetected: true,
87
- });
88
-
89
- expect(result.legacyGlobalPolicyDetected).toBe(true);
90
- expect(result.legacyProjectPolicyDetected).toBe(false);
91
- expect(result.legacyExtensionConfigDetected).toBe(true);
92
- });
93
-
94
- test("config.resolved entry appears in review log via logger", () => {
95
- const tempDir = mkdtempSync(join(tmpdir(), "config-resolved-log-"));
96
- try {
97
- const logsDir = join(tempDir, "logs");
98
- mkdirSync(logsDir, { recursive: true });
99
- const reviewLogPath = join(logsDir, "review.jsonl");
100
- const debugLogPath = join(logsDir, "debug.jsonl");
101
-
102
- const globalConfigPath = join(tempDir, "pi-permissions.jsonc");
103
- writeFileSync(globalConfigPath, "{}", "utf-8");
104
- const agentsDir = join(tempDir, "agents");
105
-
106
- const pm = new PermissionManager({
107
- globalConfigPath,
108
- agentsDir,
109
- });
110
-
111
- const logger = createPermissionSystemLogger({
112
- getConfig: () => ({
113
- debugLog: false,
114
- permissionReviewLog: true,
115
- yoloMode: false,
116
- }),
117
- debugLogPath,
118
- reviewLogPath,
119
- ensureLogsDirectory: () => undefined,
120
- });
121
-
122
- const policyPaths = pm.getResolvedPolicyPaths();
123
- const entry = buildResolvedConfigLogEntry({ policyPaths });
124
- logger.review(
125
- "config.resolved",
126
- entry as unknown as Record<string, unknown>,
127
- );
128
-
129
- const logContent = readFileSync(reviewLogPath, "utf-8").trim();
130
- const parsed = JSON.parse(logContent) as Record<string, unknown>;
131
-
132
- expect(parsed.event).toBe("config.resolved");
133
- expect(parsed.globalConfigPath).toBe(globalConfigPath);
134
- expect(parsed.globalConfigExists).toBe(true);
135
- expect(parsed.agentsDir).toBe(agentsDir);
136
- expect(parsed.agentsDirExists).toBe(false);
137
- expect(parsed.projectConfigPath).toBe(null);
138
- expect(parsed.projectConfigExists).toBe(false);
139
- expect(parsed.projectAgentsDir).toBe(null);
140
- expect(parsed.projectAgentsDirExists).toBe(false);
141
- expect(parsed.legacyGlobalPolicyDetected).toBe(false);
142
- expect(parsed.legacyProjectPolicyDetected).toBe(false);
143
- expect(parsed.legacyExtensionConfigDetected).toBe(false);
144
- } finally {
145
- rmSync(tempDir, { recursive: true, force: true });
146
- }
147
- });