@gotgenes/pi-permission-system 18.1.2 → 19.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/src/types.ts CHANGED
@@ -1,20 +1,21 @@
1
- export type PermissionState = "allow" | "deny" | "ask";
2
-
1
+ import type {
2
+ DenyWithReason,
3
+ FlatPermissionConfig,
4
+ PatternValue,
5
+ PermissionState,
6
+ } from "./config-schema";
3
7
  import type { RuleOrigin } from "./rule";
4
8
 
5
- export type { RuleOrigin };
6
-
7
- /**
8
- * A deny action with an optional reason annotation, used when a pattern maps
9
- * to an object instead of a plain PermissionState string.
10
- */
11
- export interface DenyWithReason {
12
- action: "deny";
13
- reason?: string;
14
- }
15
-
16
- /** A pattern value: a PermissionState string OR a DenyWithReason object. */
17
- export type PatternValue = PermissionState | DenyWithReason;
9
+ // The config-file shape types are derived from the zod schema
10
+ // (config-schema.ts) — the single source of truth — and re-exported here so
11
+ // existing importers keep their import path.
12
+ export type {
13
+ DenyWithReason,
14
+ FlatPermissionConfig,
15
+ PatternValue,
16
+ PermissionState,
17
+ RuleOrigin,
18
+ };
18
19
 
19
20
  /**
20
21
  * Predicate deciding whether a bare bash token should be promoted into the
@@ -27,17 +28,6 @@ export type PatternValue = PermissionState | DenyWithReason;
27
28
  */
28
29
  export type PathRuleTokenMatcher = (token: string) => boolean;
29
30
 
30
- /**
31
- * The on-disk permission shape inside the `"permission"` key.
32
- * A surface value is a PermissionState string (shorthand for `{ "*": action }`)
33
- * or a pattern→value map. Pattern values may be a PermissionState string or a
34
- * DenyWithReason object. A top-level value is never a bare DenyWithReason.
35
- */
36
- export type FlatPermissionConfig = Record<
37
- string,
38
- PermissionState | Record<string, PatternValue>
39
- >;
40
-
41
31
  /**
42
32
  * Per-scope permission config shape after loading and validation.
43
33
  * Holds only the flat permission map — all policy is expressed there.
@@ -17,23 +17,6 @@ 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 an array of strings; otherwise `undefined`. */
21
- export function normalizeOptionalStringArray(
22
- raw: unknown,
23
- ): string[] | undefined {
24
- return Array.isArray(raw) &&
25
- raw.every((p): p is string => typeof p === "string")
26
- ? raw
27
- : undefined;
28
- }
29
-
30
- /** Returns `raw` if it is a positive integer; otherwise `undefined`. */
31
- export function normalizeOptionalPositiveInt(raw: unknown): number | undefined {
32
- return typeof raw === "number" && Number.isInteger(raw) && raw > 0
33
- ? raw
34
- : undefined;
35
- }
36
-
37
20
  export function isPermissionState(value: unknown): value is PermissionState {
38
21
  return value === "allow" || value === "deny" || value === "ask";
39
22
  }
package/src/yolo-mode.ts DELETED
@@ -1,30 +0,0 @@
1
- import type { PermissionSystemExtensionConfig } from "./extension-config";
2
- import type { PermissionState } from "./types";
3
-
4
- export interface AskPermissionResolutionOptions {
5
- config: PermissionSystemExtensionConfig;
6
- hasUI: boolean;
7
- isSubagent: boolean;
8
- }
9
-
10
- export function isYoloModeEnabled(
11
- config: PermissionSystemExtensionConfig,
12
- ): boolean {
13
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-conversion -- typed as boolean but may be undefined at runtime (untyped callers); Boolean() guards against that
14
- return Boolean(config.yoloMode);
15
- }
16
-
17
- export function shouldAutoApprovePermissionState(
18
- state: PermissionState,
19
- config: PermissionSystemExtensionConfig,
20
- ): boolean {
21
- return state === "ask" && isYoloModeEnabled(config);
22
- }
23
-
24
- export function canResolveAskPermissionRequest(
25
- options: AskPermissionResolutionOptions,
26
- ): boolean {
27
- return (
28
- options.hasUI || options.isSubagent || isYoloModeEnabled(options.config)
29
- );
30
- }