@gotgenes/pi-permission-system 20.7.3 → 20.9.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 (36) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/README.md +3 -0
  3. package/config/config.example.json +2 -0
  4. package/dist/public.d.ts +212 -75
  5. package/docs/configuration.md +45 -9
  6. package/package.json +1 -1
  7. package/schemas/permissions.schema.json +10 -0
  8. package/src/access-intent/input-normalizer.ts +34 -1
  9. package/src/authority/approval-escalator.ts +53 -23
  10. package/src/authority/authorizer-chain.ts +60 -0
  11. package/src/authority/authorizer-registry.ts +69 -0
  12. package/src/authority/authorizer-selection.ts +54 -8
  13. package/src/authority/authorizer.ts +31 -4
  14. package/src/authority/delegation-envelope.ts +52 -0
  15. package/src/authority/denying-authorizer.ts +2 -2
  16. package/src/authority/forwarded-request-server.ts +22 -32
  17. package/src/authority/forwarder-context.ts +7 -0
  18. package/src/authority/forwarding-io.ts +61 -0
  19. package/src/authority/local-user-authorizer.ts +2 -2
  20. package/src/authority/permission-forwarding.ts +46 -0
  21. package/src/authority/permission-prompter.ts +16 -5
  22. package/src/config-loader.ts +5 -4
  23. package/src/config-schema.ts +7 -0
  24. package/src/extension-config.ts +5 -0
  25. package/src/handlers/gates/bash-external-directory.ts +6 -0
  26. package/src/handlers/gates/bash-path.ts +2 -0
  27. package/src/handlers/gates/external-directory.ts +2 -0
  28. package/src/handlers/gates/helpers.ts +33 -0
  29. package/src/handlers/gates/path.ts +2 -0
  30. package/src/handlers/gates/skill-input.ts +2 -0
  31. package/src/handlers/gates/skill-read.ts +2 -0
  32. package/src/handlers/gates/tool.ts +19 -6
  33. package/src/index.ts +26 -13
  34. package/src/permission-resolver.ts +17 -2
  35. package/src/permissions-service.ts +10 -0
  36. package/src/service.ts +52 -14
package/src/service.ts CHANGED
@@ -11,10 +11,16 @@
11
11
  * reference — this ensures resilience across `/reload` and load-order edge cases.
12
12
  */
13
13
 
14
+ import type { Authorizer } from "./authority/authorizer";
14
15
  import type { ToolAccessExtractor } from "./tool-access-extractor-registry";
15
16
  import type { ToolInputFormatter } from "./tool-input-formatter-registry";
16
17
  import type { PermissionCheckResult, PermissionState } from "./types";
17
18
 
19
+ export type {
20
+ Authorizer,
21
+ AuthorizerVerdict,
22
+ } from "./authority/authorizer";
23
+ export type { PromptPermissionDetails } from "./authority/permission-prompter";
18
24
  export type {
19
25
  ForwardedPromptContext,
20
26
  PermissionDecisionEvent,
@@ -33,13 +39,12 @@ export type { PermissionCheckResult, PermissionState, ToolInputFormatter };
33
39
  const SERVICE_KEY = Symbol.for("@gotgenes/pi-permission-system:service");
34
40
 
35
41
  /**
36
- * Public interface exposed to other extensions via `getPermissionsService()`.
37
- *
38
- * `checkPermission` takes a surface + optional value + optional agent name,
39
- * and delegates to `PermissionManager.checkPermission()` with current session
40
- * rules internally.
42
+ * The narrow, read-only projection of {@link PermissionsService}: answer a
43
+ * policy query for a surface, and report a tool-level state. This is the
44
+ * capability an Authorizer chain link is handed (ISP) — it never sees the
45
+ * registration surface.
41
46
  */
42
- export interface PermissionsService {
47
+ export interface PermissionQuery {
43
48
  /**
44
49
  * Query the permission policy for a surface and value.
45
50
  *
@@ -57,6 +62,28 @@ export interface PermissionsService {
57
62
  agentName?: string,
58
63
  ): PermissionCheckResult;
59
64
 
65
+ /**
66
+ * Query the tool-level permission state for pre-filtering tools before
67
+ * creating a child session.
68
+ *
69
+ * Returns `"deny"` | `"allow"` | `"ask"` based on the composed policy.
70
+ * Does not consider command-level rules (e.g. per-bash-command patterns) —
71
+ * use `checkPermission` for runtime invocation gates.
72
+ *
73
+ * @param toolName - Tool name (e.g. `"bash"`, `"read"`, `"my-extension:tool"`).
74
+ * @param agentName - Optional agent name for per-agent policy resolution.
75
+ */
76
+ getToolPermission(toolName: string, agentName?: string): PermissionState;
77
+ }
78
+
79
+ /**
80
+ * Public interface exposed to other extensions via `getPermissionsService()`.
81
+ *
82
+ * `checkPermission` takes a surface + optional value + optional agent name,
83
+ * and delegates to `PermissionManager.checkPermission()` with current session
84
+ * rules internally.
85
+ */
86
+ export interface PermissionsService extends PermissionQuery {
60
87
  /**
61
88
  * Register a custom preview formatter for a specific tool name.
62
89
  *
@@ -100,17 +127,28 @@ export interface PermissionsService {
100
127
  ): () => void;
101
128
 
102
129
  /**
103
- * Query the tool-level permission state for pre-filtering tools before
104
- * creating a child session.
130
+ * Register a named live-authority chain link (ADR 0007 §4).
105
131
  *
106
- * Returns `"deny"` | `"allow"` | `"ask"` based on the composed policy.
107
- * Does not consider command-level rules (e.g. per-bash-command patterns) —
108
- * use `checkPermission` for runtime invocation gates.
132
+ * A link reviews an `ask` and returns `allow` / `deny` (with an optional
133
+ * teaching `reason`) / `defer`. It is handed a narrow, session-scoped
134
+ * {@link PermissionQuery} at `authorize` time so it can query the
135
+ * deterministic engine at gate parity. Register from a `permissions:ready`
136
+ * handler so registration is robust to load order and survives `/reload`.
109
137
  *
110
- * @param toolName - Tool name (e.g. `"bash"`, `"read"`, `"my-extension:tool"`).
111
- * @param agentName - Optional agent name for per-agent policy resolution.
138
+ * Registration alone grants **no authority**: the link decides nothing until
139
+ * the operator names it in the `authorizerChain` config (opt-in activation),
140
+ * and the chain owner caps every verdict with the bounded-delegation
141
+ * checkpoint (an `allow` on an excluded surface downgrades to `defer`). Only
142
+ * one link may be registered per name — a second call for the same name
143
+ * throws. The returned disposer unregisters the link.
144
+ *
145
+ * @param name - Operator-facing link name referenced from `authorizerChain`.
146
+ * @param authorize - The link's decision callback (`(details, query) => verdict`).
112
147
  */
113
- getToolPermission(toolName: string, agentName?: string): PermissionState;
148
+ registerAuthorizer(
149
+ name: string,
150
+ authorize: Authorizer["authorize"],
151
+ ): () => void;
114
152
  }
115
153
 
116
154
  /**