@gotgenes/pi-permission-system 10.5.2 → 10.5.3

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 CHANGED
@@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [10.5.3](https://github.com/gotgenes/pi-packages/compare/pi-permission-system-v10.5.2...pi-permission-system-v10.5.3) (2026-06-08)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * merge tool preview length fields across config layers ([803fbb4](https://github.com/gotgenes/pi-packages/commit/803fbb4a118d4c26dc7b23fcec3f88d23aec0065))
14
+ * parse tool preview length fields in unified config loader ([3241956](https://github.com/gotgenes/pi-packages/commit/3241956b5656bc44788061c4a0a4ee334cb3ace5))
15
+
8
16
  ## [10.5.2](https://github.com/gotgenes/pi-packages/compare/pi-permission-system-v10.5.1...pi-permission-system-v10.5.2) (2026-06-08)
9
17
 
10
18
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gotgenes/pi-permission-system",
3
- "version": "10.5.2",
3
+ "version": "10.5.3",
4
4
  "description": "Permission enforcement extension for the Pi coding agent.",
5
5
  "type": "module",
6
6
  "exports": {
package/src/common.ts CHANGED
@@ -17,6 +17,13 @@ export function getNonEmptyString(value: unknown): string | null {
17
17
  return trimmed.length > 0 ? trimmed : null;
18
18
  }
19
19
 
20
+ /** Returns `raw` if it is a positive integer; otherwise `undefined`. */
21
+ export function normalizeOptionalPositiveInt(raw: unknown): number | undefined {
22
+ return typeof raw === "number" && Number.isInteger(raw) && raw > 0
23
+ ? raw
24
+ : undefined;
25
+ }
26
+
20
27
  export function isPermissionState(value: unknown): value is PermissionState {
21
28
  return value === "allow" || value === "deny" || value === "ask";
22
29
  }
@@ -1,7 +1,11 @@
1
1
  import { existsSync, readFileSync } from "node:fs";
2
2
  import { normalize } from "node:path";
3
3
 
4
- import { isPermissionState, toRecord } from "./common";
4
+ import {
5
+ isPermissionState,
6
+ normalizeOptionalPositiveInt,
7
+ toRecord,
8
+ } from "./common";
5
9
  import {
6
10
  getGlobalConfigPath,
7
11
  getLegacyExtensionConfigPath,
@@ -21,6 +25,8 @@ export interface UnifiedPermissionConfig {
21
25
  debugLog?: boolean;
22
26
  permissionReviewLog?: boolean;
23
27
  yoloMode?: boolean;
28
+ toolInputPreviewMaxLength?: number;
29
+ toolTextSummaryMaxLength?: number;
24
30
 
25
31
  // Flat permission policy
26
32
  permission?: FlatPermissionConfig;
@@ -183,6 +189,18 @@ export function normalizeUnifiedConfig(raw: unknown): {
183
189
  const yoloMode = normalizeOptionalBoolean(record.yoloMode);
184
190
  if (yoloMode !== undefined) config.yoloMode = yoloMode;
185
191
 
192
+ const toolInputPreviewMaxLength = normalizeOptionalPositiveInt(
193
+ record.toolInputPreviewMaxLength,
194
+ );
195
+ if (toolInputPreviewMaxLength !== undefined)
196
+ config.toolInputPreviewMaxLength = toolInputPreviewMaxLength;
197
+
198
+ const toolTextSummaryMaxLength = normalizeOptionalPositiveInt(
199
+ record.toolTextSummaryMaxLength,
200
+ );
201
+ if (toolTextSummaryMaxLength !== undefined)
202
+ config.toolTextSummaryMaxLength = toolTextSummaryMaxLength;
203
+
186
204
  // Flat permission policy
187
205
  const permission = normalizeFlatPermissionValue(record.permission);
188
206
  if (permission !== undefined) config.permission = permission;
@@ -202,7 +220,7 @@ export function mergeUnifiedConfigs(
202
220
  ): UnifiedPermissionConfig {
203
221
  const merged: UnifiedPermissionConfig = {};
204
222
 
205
- // Scalars: override replaces base when defined
223
+ // Boolean scalars: override replaces base when defined
206
224
  for (const key of ["debugLog", "permissionReviewLog", "yoloMode"] as const) {
207
225
  const value = override[key] ?? base[key];
208
226
  if (value !== undefined) {
@@ -210,6 +228,17 @@ export function mergeUnifiedConfigs(
210
228
  }
211
229
  }
212
230
 
231
+ // Number scalars: override replaces base when defined
232
+ for (const key of [
233
+ "toolInputPreviewMaxLength",
234
+ "toolTextSummaryMaxLength",
235
+ ] as const) {
236
+ const value = override[key] ?? base[key];
237
+ if (value !== undefined) {
238
+ merged[key] = value;
239
+ }
240
+ }
241
+
213
242
  // Permission: deep-shallow merge
214
243
  const basePerm = base.permission;
215
244
  const overridePerm = override.permission;
@@ -2,7 +2,7 @@ import { mkdirSync } from "node:fs";
2
2
  import { dirname, join } from "node:path";
3
3
  import { fileURLToPath } from "node:url";
4
4
 
5
- import { toRecord } from "./common";
5
+ import { normalizeOptionalPositiveInt, toRecord } from "./common";
6
6
 
7
7
  export const EXTENSION_ID = "pi-permission-system";
8
8
 
@@ -46,13 +46,6 @@ export function detectMisplacedPermissionKeys(
46
46
  return Object.keys(raw).filter((key) => PERMISSION_POLICY_KEYS.has(key));
47
47
  }
48
48
 
49
- /** Returns `raw` if it is a positive integer; otherwise `undefined`. */
50
- export function normalizeOptionalPositiveInt(raw: unknown): number | undefined {
51
- return typeof raw === "number" && Number.isInteger(raw) && raw > 0
52
- ? raw
53
- : undefined;
54
- }
55
-
56
49
  export function normalizePermissionSystemConfig(
57
50
  raw: unknown,
58
51
  ): PermissionSystemExtensionConfig {
@@ -1,9 +1,10 @@
1
- import { afterEach, describe, expect, test, vi } from "vitest";
1
+ import { afterEach, describe, expect, it, test, vi } from "vitest";
2
2
 
3
3
  import {
4
4
  extractFrontmatter,
5
5
  getNonEmptyString,
6
6
  isPermissionState,
7
+ normalizeOptionalPositiveInt,
7
8
  parseSimpleYamlMap,
8
9
  toRecord,
9
10
  } from "#src/common";
@@ -187,3 +188,33 @@ describe("parseSimpleYamlMap", () => {
187
188
  expect(result["quoted-key"]).toBe("value");
188
189
  });
189
190
  });
191
+
192
+ describe("normalizeOptionalPositiveInt", () => {
193
+ it("returns the value for a valid positive integer", () => {
194
+ expect(normalizeOptionalPositiveInt(1)).toBe(1);
195
+ expect(normalizeOptionalPositiveInt(200)).toBe(200);
196
+ expect(normalizeOptionalPositiveInt(9999)).toBe(9999);
197
+ });
198
+
199
+ it("returns undefined for zero", () => {
200
+ expect(normalizeOptionalPositiveInt(0)).toBeUndefined();
201
+ });
202
+
203
+ it("returns undefined for negative integers", () => {
204
+ expect(normalizeOptionalPositiveInt(-1)).toBeUndefined();
205
+ expect(normalizeOptionalPositiveInt(-100)).toBeUndefined();
206
+ });
207
+
208
+ it("returns undefined for non-integer numbers (floats)", () => {
209
+ expect(normalizeOptionalPositiveInt(400.5)).toBeUndefined();
210
+ expect(normalizeOptionalPositiveInt(1.1)).toBeUndefined();
211
+ });
212
+
213
+ it("returns undefined for non-number types", () => {
214
+ expect(normalizeOptionalPositiveInt("200")).toBeUndefined();
215
+ expect(normalizeOptionalPositiveInt(true)).toBeUndefined();
216
+ expect(normalizeOptionalPositiveInt(null)).toBeUndefined();
217
+ expect(normalizeOptionalPositiveInt(undefined)).toBeUndefined();
218
+ expect(normalizeOptionalPositiveInt({})).toBeUndefined();
219
+ });
220
+ });
@@ -258,6 +258,72 @@ describe("loadUnifiedConfig", () => {
258
258
  const result = loadUnifiedConfig(configPath);
259
259
  expect(result.config.permission).toBeUndefined();
260
260
  });
261
+
262
+ it("parses toolInputPreviewMaxLength when a valid positive integer is present", () => {
263
+ const configPath = join(tempDir, "config.json");
264
+ writeFileSync(
265
+ configPath,
266
+ JSON.stringify({ toolInputPreviewMaxLength: 1000 }),
267
+ );
268
+ const result = loadUnifiedConfig(configPath);
269
+ expect(result.config.toolInputPreviewMaxLength).toBe(1000);
270
+ });
271
+
272
+ it("parses toolTextSummaryMaxLength when a valid positive integer is present", () => {
273
+ const configPath = join(tempDir, "config.json");
274
+ writeFileSync(
275
+ configPath,
276
+ JSON.stringify({ toolTextSummaryMaxLength: 120 }),
277
+ );
278
+ const result = loadUnifiedConfig(configPath);
279
+ expect(result.config.toolTextSummaryMaxLength).toBe(120);
280
+ });
281
+
282
+ it("omits toolInputPreviewMaxLength when absent", () => {
283
+ const configPath = join(tempDir, "config.json");
284
+ writeFileSync(configPath, JSON.stringify({ debugLog: false }));
285
+ const result = loadUnifiedConfig(configPath);
286
+ expect(result.config).not.toHaveProperty("toolInputPreviewMaxLength");
287
+ });
288
+
289
+ it("omits toolTextSummaryMaxLength when absent", () => {
290
+ const configPath = join(tempDir, "config.json");
291
+ writeFileSync(configPath, JSON.stringify({ debugLog: false }));
292
+ const result = loadUnifiedConfig(configPath);
293
+ expect(result.config).not.toHaveProperty("toolTextSummaryMaxLength");
294
+ });
295
+
296
+ it.each([
297
+ ["zero", 0],
298
+ ["negative", -1],
299
+ ["float", 1.5],
300
+ ["string", "200"],
301
+ ["boolean", true],
302
+ ] as const)("omits toolInputPreviewMaxLength for invalid value: %s", (_label, value) => {
303
+ const configPath = join(tempDir, "config.json");
304
+ writeFileSync(
305
+ configPath,
306
+ JSON.stringify({ toolInputPreviewMaxLength: value }),
307
+ );
308
+ const result = loadUnifiedConfig(configPath);
309
+ expect(result.config).not.toHaveProperty("toolInputPreviewMaxLength");
310
+ });
311
+
312
+ it.each([
313
+ ["zero", 0],
314
+ ["negative", -1],
315
+ ["float", 1.5],
316
+ ["string", "80"],
317
+ ["boolean", false],
318
+ ] as const)("omits toolTextSummaryMaxLength for invalid value: %s", (_label, value) => {
319
+ const configPath = join(tempDir, "config.json");
320
+ writeFileSync(
321
+ configPath,
322
+ JSON.stringify({ toolTextSummaryMaxLength: value }),
323
+ );
324
+ const result = loadUnifiedConfig(configPath);
325
+ expect(result.config).not.toHaveProperty("toolTextSummaryMaxLength");
326
+ });
261
327
  });
262
328
 
263
329
  describe("mergeUnifiedConfigs", () => {
@@ -352,6 +418,48 @@ describe("mergeUnifiedConfigs", () => {
352
418
  expect(merged).not.toHaveProperty("permissionReviewLog");
353
419
  expect(merged).not.toHaveProperty("permission");
354
420
  });
421
+
422
+ it("override toolInputPreviewMaxLength replaces base value", () => {
423
+ const merged = mergeUnifiedConfigs(
424
+ { toolInputPreviewMaxLength: 200 },
425
+ { toolInputPreviewMaxLength: 1000 },
426
+ );
427
+ expect(merged.toolInputPreviewMaxLength).toBe(1000);
428
+ });
429
+
430
+ it("base toolInputPreviewMaxLength survives when override omits it", () => {
431
+ const merged = mergeUnifiedConfigs(
432
+ { toolInputPreviewMaxLength: 500 },
433
+ { debugLog: true },
434
+ );
435
+ expect(merged.toolInputPreviewMaxLength).toBe(500);
436
+ });
437
+
438
+ it("toolInputPreviewMaxLength is absent when both base and override omit it", () => {
439
+ const merged = mergeUnifiedConfigs({ debugLog: true }, { yoloMode: false });
440
+ expect(merged).not.toHaveProperty("toolInputPreviewMaxLength");
441
+ });
442
+
443
+ it("override toolTextSummaryMaxLength replaces base value", () => {
444
+ const merged = mergeUnifiedConfigs(
445
+ { toolTextSummaryMaxLength: 80 },
446
+ { toolTextSummaryMaxLength: 200 },
447
+ );
448
+ expect(merged.toolTextSummaryMaxLength).toBe(200);
449
+ });
450
+
451
+ it("base toolTextSummaryMaxLength survives when override omits it", () => {
452
+ const merged = mergeUnifiedConfigs(
453
+ { toolTextSummaryMaxLength: 120 },
454
+ { debugLog: false },
455
+ );
456
+ expect(merged.toolTextSummaryMaxLength).toBe(120);
457
+ });
458
+
459
+ it("toolTextSummaryMaxLength is absent when both base and override omit it", () => {
460
+ const merged = mergeUnifiedConfigs({}, { permissionReviewLog: true });
461
+ expect(merged).not.toHaveProperty("toolTextSummaryMaxLength");
462
+ });
355
463
  });
356
464
 
357
465
  describe("loadAndMergeConfigs", () => {
@@ -371,6 +371,20 @@ describe("ConfigStore", () => {
371
371
  store.save({ ...DEFAULT_EXTENSION_CONFIG }, ctx);
372
372
  expect(mockUnlinkSync).toHaveBeenCalled();
373
373
  });
374
+
375
+ it("preserves an existing global toolInputPreviewMaxLength on save", () => {
376
+ const { store } = makeStore();
377
+ // Simulate a global config.json that already has the preview-length field.
378
+ mockLoadUnifiedConfig.mockReturnValue({
379
+ config: { toolInputPreviewMaxLength: 800 },
380
+ });
381
+ store.save({ ...DEFAULT_EXTENSION_CONFIG }, makeCommandCtx());
382
+ expect(mockWriteFileSync).toHaveBeenCalledWith(
383
+ expect.stringContaining(".tmp"),
384
+ expect.stringContaining('"toolInputPreviewMaxLength": 800'),
385
+ "utf-8",
386
+ );
387
+ });
374
388
  });
375
389
 
376
390
  // ── logResolvedPaths() ─────────────────────────────────────────────────
@@ -2,7 +2,6 @@ import { describe, expect, it } from "vitest";
2
2
 
3
3
  import {
4
4
  detectMisplacedPermissionKeys,
5
- normalizeOptionalPositiveInt,
6
5
  normalizePermissionSystemConfig,
7
6
  } from "#src/extension-config";
8
7
 
@@ -75,36 +74,6 @@ describe("detectMisplacedPermissionKeys", () => {
75
74
  });
76
75
  });
77
76
 
78
- describe("normalizeOptionalPositiveInt", () => {
79
- it("returns the value for a valid positive integer", () => {
80
- expect(normalizeOptionalPositiveInt(1)).toBe(1);
81
- expect(normalizeOptionalPositiveInt(200)).toBe(200);
82
- expect(normalizeOptionalPositiveInt(9999)).toBe(9999);
83
- });
84
-
85
- it("returns undefined for zero", () => {
86
- expect(normalizeOptionalPositiveInt(0)).toBeUndefined();
87
- });
88
-
89
- it("returns undefined for negative integers", () => {
90
- expect(normalizeOptionalPositiveInt(-1)).toBeUndefined();
91
- expect(normalizeOptionalPositiveInt(-100)).toBeUndefined();
92
- });
93
-
94
- it("returns undefined for non-integer numbers (floats)", () => {
95
- expect(normalizeOptionalPositiveInt(400.5)).toBeUndefined();
96
- expect(normalizeOptionalPositiveInt(1.1)).toBeUndefined();
97
- });
98
-
99
- it("returns undefined for non-number types", () => {
100
- expect(normalizeOptionalPositiveInt("200")).toBeUndefined();
101
- expect(normalizeOptionalPositiveInt(true)).toBeUndefined();
102
- expect(normalizeOptionalPositiveInt(null)).toBeUndefined();
103
- expect(normalizeOptionalPositiveInt(undefined)).toBeUndefined();
104
- expect(normalizeOptionalPositiveInt({})).toBeUndefined();
105
- });
106
- });
107
-
108
77
  describe("normalizePermissionSystemConfig", () => {
109
78
  it("normalizes a valid config object", () => {
110
79
  const result = normalizePermissionSystemConfig({