@gotgenes/pi-permission-system 19.0.0 → 20.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 +23 -0
- package/docs/cross-extension-api.md +17 -126
- package/docs/guides/permission-frontmatter-for-subagent-extensions.md +18 -50
- package/docs/guides/upstream-issue-template.md +2 -2
- package/docs/subagent-integration.md +0 -1
- package/package.json +1 -1
- package/src/{forwarded-permissions/permission-forwarder.ts → authority/approval-escalator.ts} +35 -301
- package/src/authority/forwarded-request-server.ts +285 -0
- package/src/authority/forwarder-context.ts +32 -0
- package/src/{forwarded-permissions/io.ts → authority/forwarding-io.ts} +0 -1
- package/src/{subagent-context.ts → authority/subagent-context.ts} +2 -2
- package/src/authority/subagent-detection.ts +65 -0
- package/src/forwarding-manager.ts +4 -16
- package/src/index.ts +34 -31
- package/src/permission-events.ts +7 -103
- package/src/permission-prompter.ts +1 -1
- package/src/permission-ui-prompt.ts +1 -25
- package/src/prompting-gateway.ts +5 -19
- package/src/service-lifecycle.ts +3 -5
- package/src/service.ts +3 -8
- package/src/session-logger.ts +1 -1
- package/src/permission-event-rpc.ts +0 -227
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,29 @@ 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
|
+
## [20.0.0](https://github.com/gotgenes/pi-packages/compare/pi-permission-system-v19.0.1...pi-permission-system-v20.0.0) (2026-07-07)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### ⚠ BREAKING CHANGES
|
|
12
|
+
|
|
13
|
+
* **pi-permission-system:** The permissions:rpc:check and permissions:rpc:prompt event-bus channels are removed, along with their request/reply types (PermissionsCheckRequest, PermissionsCheckReplyData, PermissionsPromptRequest, PermissionsPromptReplyData), the PermissionsRpcReply envelope, PERMISSIONS_PROTOCOL_VERSION, and the rpc_prompt member of PermissionUiPromptSource. permissions:rpc:check consumers migrate to getPermissionsService().checkPermission(surface, value?, agentName?). permissions:rpc:prompt is removed with no public replacement; prompt forwarding is an internal subagent-to-parent mechanism.
|
|
14
|
+
|
|
15
|
+
### Features
|
|
16
|
+
|
|
17
|
+
* **pi-permission-system:** remove deprecated event-bus RPC channel ([557ea91](https://github.com/gotgenes/pi-packages/commit/557ea913c54f21ef64b0812169bbc7d5224072e2))
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Documentation
|
|
21
|
+
|
|
22
|
+
* **pi-permission-system:** repoint cross-extension docs off the removed RPC channel ([b3d06f7](https://github.com/gotgenes/pi-packages/commit/b3d06f77aea43758a4e820e66d1111608b86879b)), closes [#531](https://github.com/gotgenes/pi-packages/issues/531)
|
|
23
|
+
|
|
24
|
+
## [19.0.1](https://github.com/gotgenes/pi-packages/compare/pi-permission-system-v19.0.0...pi-permission-system-v19.0.1) (2026-07-07)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
### Documentation
|
|
28
|
+
|
|
29
|
+
* **pi-permission-system:** mark Phase 8 Step 6 complete; retarget forwarder docs ([c11d8a2](https://github.com/gotgenes/pi-packages/commit/c11d8a2653edbac3637e45c1e5c5867f0a882afe))
|
|
30
|
+
|
|
8
31
|
## [19.0.0](https://github.com/gotgenes/pi-packages/compare/pi-permission-system-v18.2.0...pi-permission-system-v19.0.0) (2026-07-06)
|
|
9
32
|
|
|
10
33
|
|
|
@@ -3,14 +3,14 @@
|
|
|
3
3
|
The extension provides two cross-extension integration surfaces:
|
|
4
4
|
|
|
5
5
|
1. **Service accessor** (preferred) — a `Symbol.for()`-backed synchronous API on `globalThis` for direct policy queries.
|
|
6
|
-
2. **Event bus** — broadcasts
|
|
6
|
+
2. **Event bus** — broadcasts on `pi.events` for observation.
|
|
7
7
|
|
|
8
8
|
---
|
|
9
9
|
|
|
10
10
|
## Service Accessor
|
|
11
11
|
|
|
12
12
|
The preferred way for other extensions to query the permission policy is the `Symbol.for()`-backed service accessor.
|
|
13
|
-
It provides direct, synchronous, type-safe function calls
|
|
13
|
+
It provides direct, synchronous, type-safe function calls.
|
|
14
14
|
|
|
15
15
|
### Quick Start
|
|
16
16
|
|
|
@@ -286,22 +286,17 @@ The extension also emits events on Pi's `pi.events` bus so other extensions can
|
|
|
286
286
|
|
|
287
287
|
Fields may be added to any payload, but existing fields will not be removed or renamed without a semver-major version bump.
|
|
288
288
|
The broadcast contract is defined by the published TypeScript types plus package semver — broadcast payloads (`permissions:ready`, `permissions:ui_prompt`, `permissions:decision`) carry no `protocolVersion`.
|
|
289
|
-
The `PERMISSIONS_PROTOCOL_VERSION` constant is exported from `src/permission-events.ts` and embedded only in the RPC reply envelope, where per-call request/reply negotiation is load-bearing.
|
|
290
289
|
Consumers should read broadcast payloads defensively (field-presence checks) rather than version-gating — that is robust to any shape skew between independently-versioned sibling extensions.
|
|
291
290
|
|
|
292
291
|
All three broadcasts are best-effort: a throwing listener cannot block permission handling, session startup, or gate resolution.
|
|
293
292
|
|
|
294
293
|
## Channel Reference
|
|
295
294
|
|
|
296
|
-
| Channel
|
|
297
|
-
|
|
|
298
|
-
| `permissions:ready`
|
|
299
|
-
| `permissions:ui_prompt`
|
|
300
|
-
| `permissions:decision`
|
|
301
|
-
| `permissions:rpc:check` | Request | On-demand | `PermissionsCheckRequest` |
|
|
302
|
-
| `permissions:rpc:check:reply:<requestId>` | Reply | After each check request | `PermissionsRpcReply<PermissionsCheckReplyData>` |
|
|
303
|
-
| `permissions:rpc:prompt` | Request | On-demand | `PermissionsPromptRequest` |
|
|
304
|
-
| `permissions:rpc:prompt:reply:<requestId>` | Reply | After prompt is resolved | `PermissionsRpcReply<PermissionsPromptReplyData>` |
|
|
295
|
+
| Channel | Direction | When | Payload type |
|
|
296
|
+
| ----------------------- | --------- | --------------------------------- | ------------------------- |
|
|
297
|
+
| `permissions:ready` | Broadcast | At `session_start`, after publish | `PermissionsReadyEvent` |
|
|
298
|
+
| `permissions:ui_prompt` | Broadcast | Before active UI prompt | `PermissionUiPromptEvent` |
|
|
299
|
+
| `permissions:decision` | Broadcast | After every gate resolution | `PermissionDecisionEvent` |
|
|
305
300
|
|
|
306
301
|
---
|
|
307
302
|
|
|
@@ -333,15 +328,15 @@ pi.events.on("permissions:ui_prompt", (raw) => {
|
|
|
333
328
|
|
|
334
329
|
### Payload Fields
|
|
335
330
|
|
|
336
|
-
| Field | Type | Description
|
|
337
|
-
| ------------ | -------------------------------- |
|
|
338
|
-
| `requestId` | `string` | Unique ID for the permission request being prompted
|
|
339
|
-
| `source` | `PermissionUiPromptSource` | Prompt origin: `"tool_call"`, `"skill_input"`,
|
|
340
|
-
| `surface` | `string \| null` | Normalized display surface (e.g. `"bash"`, `"skill"`), when known
|
|
341
|
-
| `value` | `string \| null` | Normalized display value (command, path, skill name, etc.), when known
|
|
342
|
-
| `agentName` | `string \| null` | Active/requesting agent name, when known
|
|
343
|
-
| `message` | `string` | Message displayed in the permission prompt
|
|
344
|
-
| `forwarding` | `ForwardedPromptContext \| null` | Forwarding context, or `null` for a direct prompt
|
|
331
|
+
| Field | Type | Description |
|
|
332
|
+
| ------------ | -------------------------------- | ---------------------------------------------------------------------- |
|
|
333
|
+
| `requestId` | `string` | Unique ID for the permission request being prompted |
|
|
334
|
+
| `source` | `PermissionUiPromptSource` | Prompt origin: `"tool_call"`, `"skill_input"`, or `"skill_read"` |
|
|
335
|
+
| `surface` | `string \| null` | Normalized display surface (e.g. `"bash"`, `"skill"`), when known |
|
|
336
|
+
| `value` | `string \| null` | Normalized display value (command, path, skill name, etc.), when known |
|
|
337
|
+
| `agentName` | `string \| null` | Active/requesting agent name, when known |
|
|
338
|
+
| `message` | `string` | Message displayed in the permission prompt |
|
|
339
|
+
| `forwarding` | `ForwardedPromptContext \| null` | Forwarding context, or `null` for a direct prompt |
|
|
345
340
|
|
|
346
341
|
Forwarding is orthogonal to origin: a forwarded subagent prompt keeps its original `source` and is identified by a non-null `forwarding` field, not by a dedicated source value.
|
|
347
342
|
|
|
@@ -400,117 +395,13 @@ pi.events.on("permissions:decision", (raw) => {
|
|
|
400
395
|
|
|
401
396
|
---
|
|
402
397
|
|
|
403
|
-
## Policy Query RPC (deprecated)
|
|
404
|
-
|
|
405
|
-
> **Deprecated**: prefer the [Service Accessor](#service-accessor) above.
|
|
406
|
-
> The event-bus RPC remains available as a zero-dependency fallback.
|
|
407
|
-
|
|
408
|
-
Other extensions can evaluate the current permission policy without importing this package.
|
|
409
|
-
The call is synchronous-style: emit a request, listen on a scoped reply channel.
|
|
410
|
-
|
|
411
|
-
```typescript
|
|
412
|
-
const requestId = crypto.randomUUID();
|
|
413
|
-
|
|
414
|
-
// Listen for the reply first
|
|
415
|
-
const unsub = pi.events.on(
|
|
416
|
-
`permissions:rpc:check:reply:${requestId}`,
|
|
417
|
-
(raw) => {
|
|
418
|
-
unsub();
|
|
419
|
-
const reply = raw as import("@gotgenes/pi-permission-system").PermissionsRpcReply<
|
|
420
|
-
import("@gotgenes/pi-permission-system").PermissionsCheckReplyData
|
|
421
|
-
>;
|
|
422
|
-
if (reply.success) {
|
|
423
|
-
console.log(reply.data?.result); // "allow" | "deny" | "ask"
|
|
424
|
-
}
|
|
425
|
-
},
|
|
426
|
-
);
|
|
427
|
-
|
|
428
|
-
// Then emit the request
|
|
429
|
-
pi.events.emit("permissions:rpc:check", {
|
|
430
|
-
requestId,
|
|
431
|
-
surface: "bash",
|
|
432
|
-
value: "git push",
|
|
433
|
-
agentName: "Worker", // optional
|
|
434
|
-
});
|
|
435
|
-
```
|
|
436
|
-
|
|
437
|
-
If the extension is not loaded, no reply arrives.
|
|
438
|
-
Callers should implement a timeout and treat no-reply as `deny` (graceful degradation).
|
|
439
|
-
|
|
440
|
-
### Request Fields
|
|
441
|
-
|
|
442
|
-
| Field | Required | Description |
|
|
443
|
-
| ----------- | -------- | ---------------------------------------------------------- |
|
|
444
|
-
| `requestId` | Yes | Unique string; scopes the reply channel |
|
|
445
|
-
| `surface` | Yes | Permission surface to evaluate |
|
|
446
|
-
| `value` | No | Value to evaluate (command, name, path); defaults to `"*"` |
|
|
447
|
-
| `agentName` | No | Agent name for per-agent policy resolution |
|
|
448
|
-
|
|
449
|
-
As with the `checkPermission` service method, a path-shaped surface (`path`, `external_directory`, or a path-bearing tool) matches the `value` against both the path as given and its canonical (symlink-resolved) form.
|
|
450
|
-
|
|
451
|
-
### Reply Data Fields (`PermissionsCheckReplyData`)
|
|
452
|
-
|
|
453
|
-
| Field | Type | Description |
|
|
454
|
-
| ---------------- | ---------------------------- | ------------------------------------------------ |
|
|
455
|
-
| `result` | `"allow" \| "deny" \| "ask"` | Policy decision (including active session rules) |
|
|
456
|
-
| `matchedPattern` | `string \| null` | Matched rule pattern |
|
|
457
|
-
| `origin` | `string \| null` | Config scope of the winning rule |
|
|
458
|
-
|
|
459
|
-
---
|
|
460
|
-
|
|
461
|
-
## Prompt Forwarding RPC
|
|
462
|
-
|
|
463
|
-
In-process child sessions (e.g. tintinweb/pi-subagents running via `createAgentSession()`) cannot use file-based permission forwarding because no child process is spawned.
|
|
464
|
-
They can instead forward permission prompts to the parent session's UI via this RPC.
|
|
465
|
-
|
|
466
|
-
```typescript
|
|
467
|
-
const requestId = crypto.randomUUID();
|
|
468
|
-
|
|
469
|
-
const unsub = pi.events.on(
|
|
470
|
-
`permissions:rpc:prompt:reply:${requestId}`,
|
|
471
|
-
(raw) => {
|
|
472
|
-
unsub();
|
|
473
|
-
const reply = raw as import("@gotgenes/pi-permission-system").PermissionsRpcReply<
|
|
474
|
-
import("@gotgenes/pi-permission-system").PermissionsPromptReplyData
|
|
475
|
-
>;
|
|
476
|
-
if (reply.success && reply.data?.approved) {
|
|
477
|
-
// proceed
|
|
478
|
-
} else {
|
|
479
|
-
// deny — either user denied or no UI was available (error: "no_ui")
|
|
480
|
-
}
|
|
481
|
-
},
|
|
482
|
-
);
|
|
483
|
-
|
|
484
|
-
pi.events.emit("permissions:rpc:prompt", {
|
|
485
|
-
requestId,
|
|
486
|
-
surface: "bash",
|
|
487
|
-
value: "rm -rf /tmp/build",
|
|
488
|
-
message: "Allow rm -rf /tmp/build?",
|
|
489
|
-
agentName: "Explore", // optional
|
|
490
|
-
sessionLabel: "Allow rm *", // optional — label for the "for this session" option
|
|
491
|
-
});
|
|
492
|
-
```
|
|
493
|
-
|
|
494
|
-
The handler replies with `{ success: false, error: "no_ui" }` when no interactive session is available.
|
|
495
|
-
|
|
496
|
-
### Successful Reply Fields
|
|
497
|
-
|
|
498
|
-
| Field | Type | Description |
|
|
499
|
-
| -------------- | ------------------- | ----------------------------------------------------------------------------- |
|
|
500
|
-
| `approved` | `boolean` | Whether the user approved |
|
|
501
|
-
| `state` | `string` | `"approved"`, `"approved_for_session"`, `"denied"`, or `"denied_with_reason"` |
|
|
502
|
-
| `denialReason` | `string` (optional) | User-provided denial reason |
|
|
503
|
-
|
|
504
|
-
---
|
|
505
|
-
|
|
506
398
|
## Ready Event
|
|
507
399
|
|
|
508
400
|
The extension emits `permissions:ready` at `session_start`, right after the service is published — so a consumer reacting to it can immediately resolve `getPermissionsService()`.
|
|
509
401
|
It fires once per `session_start` (including `/reload`).
|
|
510
|
-
Consumers that start after the extension can check via a ping-style RPC check — the `permissions:rpc:check` handler is active as long as the extension is loaded.
|
|
511
402
|
|
|
512
403
|
The payload is intentionally empty (`Record<string, never>`): the channel is a pure readiness signal.
|
|
513
|
-
It carries no `protocolVersion` —
|
|
404
|
+
It carries no `protocolVersion` — the broadcast contract is defined by the published types plus package semver.
|
|
514
405
|
|
|
515
406
|
```typescript
|
|
516
407
|
pi.events.on("permissions:ready", () => {
|
|
@@ -127,61 +127,29 @@ The permission system handles all evaluation, prompt dialogs, and policy enforce
|
|
|
127
127
|
|
|
128
128
|
## Runtime Integration (Optional)
|
|
129
129
|
|
|
130
|
-
If your extension runs subagents in-process (e.g. via `createAgentSession()`), you can optionally query the permission system's policy at runtime via the
|
|
130
|
+
If your extension runs subagents in-process (e.g. via `createAgentSession()`), you can optionally query the permission system's policy at runtime via the `Symbol.for()`-backed service accessor — no required peer dependency, just a dynamic `import()`.
|
|
131
131
|
|
|
132
132
|
### Querying policy
|
|
133
133
|
|
|
134
134
|
```typescript
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
pi
|
|
138
|
-
|
|
139
|
-
(
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
pi.events.emit("permissions:rpc:check", {
|
|
148
|
-
requestId,
|
|
149
|
-
surface: "bash",
|
|
150
|
-
value: "git push",
|
|
151
|
-
agentName: "Worker",
|
|
152
|
-
});
|
|
135
|
+
try {
|
|
136
|
+
const { getPermissionsService } = await import(
|
|
137
|
+
"@gotgenes/pi-permission-system"
|
|
138
|
+
);
|
|
139
|
+
const permissions = getPermissionsService();
|
|
140
|
+
if (permissions) {
|
|
141
|
+
const result = permissions.checkPermission("bash", "git push", "Worker");
|
|
142
|
+
console.log(result.state); // "allow" | "deny" | "ask"
|
|
143
|
+
}
|
|
144
|
+
} catch {
|
|
145
|
+
// Not installed — graceful degradation
|
|
146
|
+
}
|
|
153
147
|
```
|
|
154
148
|
|
|
155
|
-
|
|
149
|
+
If `pi-permission-system` is not installed, `import()` throws; if it has not published a service yet (or has been unloaded), `getPermissionsService()` returns `undefined`.
|
|
150
|
+
Guard both cases as shown above.
|
|
156
151
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
```typescript
|
|
160
|
-
const requestId = crypto.randomUUID();
|
|
161
|
-
|
|
162
|
-
pi.events.on(
|
|
163
|
-
`permissions:rpc:prompt:reply:${requestId}`,
|
|
164
|
-
(raw) => {
|
|
165
|
-
const reply = raw as { success: boolean; data?: { approved: boolean } };
|
|
166
|
-
if (reply.success && reply.data?.approved) {
|
|
167
|
-
// proceed
|
|
168
|
-
} else {
|
|
169
|
-
// deny
|
|
170
|
-
}
|
|
171
|
-
},
|
|
172
|
-
);
|
|
173
|
-
|
|
174
|
-
pi.events.emit("permissions:rpc:prompt", {
|
|
175
|
-
requestId,
|
|
176
|
-
surface: "bash",
|
|
177
|
-
value: "rm -rf /tmp/build",
|
|
178
|
-
message: "Allow rm -rf /tmp/build?",
|
|
179
|
-
agentName: "Worker",
|
|
180
|
-
});
|
|
181
|
-
```
|
|
182
|
-
|
|
183
|
-
If `pi-permission-system` is not installed, no reply arrives.
|
|
184
|
-
Implement a timeout and treat no-reply as `deny` for graceful degradation.
|
|
152
|
+
Prompt forwarding for headless child agents is an internal subagent-to-parent mechanism, not a public cross-extension operation — there is no service-accessor equivalent to call directly.
|
|
185
153
|
|
|
186
154
|
For full API documentation, see [Cross-extension API](../cross-extension-api.md).
|
|
187
155
|
|
|
@@ -191,11 +159,11 @@ For full API documentation, see [Cross-extension API](../cross-extension-api.md)
|
|
|
191
159
|
2. **Unified config** — one `permission:` block per agent instead of separate restriction keys in multiple extensions.
|
|
192
160
|
3. **Surface coverage** — policy covers bash patterns, MCP tools, skills, external directories, and special operations, not just tool names.
|
|
193
161
|
4. **Forwarding** — permission prompts from headless child agents surface in the parent session's UI.
|
|
194
|
-
5. **Programmatic access** — the
|
|
162
|
+
5. **Programmatic access** — the `Symbol.for()` service accessor lets your extension query policy at runtime with only a dynamic `import()`, no required peer dependency.
|
|
195
163
|
|
|
196
164
|
## Further Reading
|
|
197
165
|
|
|
198
166
|
- [Subagent Integration](../subagent-integration.md) — full coexistence documentation and interaction rules
|
|
199
|
-
- [Cross-extension API](../cross-extension-api.md) — service accessor, event bus reference (decision
|
|
167
|
+
- [Cross-extension API](../cross-extension-api.md) — service accessor, event bus reference (decision and UI-prompt broadcasts)
|
|
200
168
|
- [Configuration](../configuration.md) — full policy reference including merge precedence
|
|
201
169
|
- [Schema](../../schemas/permissions.schema.json) — canonical JSON Schema for the flat permission format
|
|
@@ -31,7 +31,7 @@ This is purely a documentation change — no code dependency on pi-permission-sy
|
|
|
31
31
|
- **Three-state policy**: `allow`, `ask` (prompt the user), or `deny` — richer than binary allow/deny
|
|
32
32
|
- **Multiple surfaces**: tools, bash commands (glob patterns), MCP operations, skills, external directories
|
|
33
33
|
- **Prompt forwarding**: `ask` decisions in headless child agents surface in the parent session's UI
|
|
34
|
-
- **
|
|
34
|
+
- **Service accessor API**: other extensions can query policy at runtime via a `Symbol.for()`-backed accessor, with only a dynamic `import()` and no required peer dependency
|
|
35
35
|
|
|
36
36
|
### Example
|
|
37
37
|
|
|
@@ -99,7 +99,7 @@ No code changes, no new dependency, no schema enforcement.
|
|
|
99
99
|
| `{{your-key}}` | `disallowed_tools` |
|
|
100
100
|
| `{{example-value}}` | `write_file,bash` |
|
|
101
101
|
|
|
102
|
-
Additional note for tintinweb: since this extension runs subagents in-process via `createAgentSession()`, mention the [
|
|
102
|
+
Additional note for tintinweb: since this extension runs subagents in-process via `createAgentSession()`, mention the [service accessor](https://github.com/gotgenes/pi-permission-system/blob/main/docs/cross-extension-api.md#service-accessor) as an optional runtime integration path for querying policy without spawning a subprocess.
|
|
103
103
|
|
|
104
104
|
### HazAT/pi-interactive-subagents
|
|
105
105
|
|
|
@@ -29,7 +29,6 @@ The main interactive session polls for forwarded requests, shows the confirmatio
|
|
|
29
29
|
This keeps `ask` policies usable even when the original permission check happens inside a non-UI execution context.
|
|
30
30
|
|
|
31
31
|
For in-process child sessions, detection and forwarding use the event-driven registration described above.
|
|
32
|
-
The [Prompt Forwarding RPC](cross-extension-api.md#prompt-forwarding-rpc) remains available as an alternative for extensions that cannot use the service accessor.
|
|
33
32
|
|
|
34
33
|
---
|
|
35
34
|
|