@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/CHANGELOG.md +27 -0
- package/README.md +1 -0
- package/config/config.example.json +1 -1
- package/docs/configuration.md +8 -2
- package/docs/migration/strict-config-validation.md +38 -0
- package/docs/opencode-compatibility.md +1 -1
- package/package.json +4 -2
- package/schemas/permissions.schema.json +57 -45
- package/src/config-loader.ts +48 -79
- package/src/config-schema.ts +204 -0
- package/src/extension-config.ts +7 -0
- package/src/forwarded-permissions/permission-forwarder.ts +6 -3
- package/src/handlers/gates/helpers.ts +1 -1
- package/src/handlers/gates/runner.ts +22 -0
- package/src/index.ts +10 -6
- package/src/permission-manager.ts +21 -1
- package/src/permission-prompter.ts +10 -16
- package/src/policy-loader.ts +8 -4
- package/src/prompting-gateway.ts +13 -17
- package/src/rule.ts +21 -1
- package/src/status.ts +1 -1
- package/src/types.ts +16 -26
- package/src/value-guards.ts +0 -17
- package/src/yolo-mode.ts +0 -30
package/src/types.ts
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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.
|
package/src/value-guards.ts
CHANGED
|
@@ -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
|
-
}
|