@mzwing/pi-permission-auto-review 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Lockinwize Lolite
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is furnished
10
+ to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,88 @@
1
+ # @mzwing/pi-permission-auto-review
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@mzwing/pi-permission-auto-review?style=flat&logo=npm&logoColor=white)](https://www.npmjs.com/package/@mzwing/pi-permission-auto-review) [![CI](https://img.shields.io/github/actions/workflow/status/mzwing/pi-packages/ci.yml?style=flat&logo=github&label=CI)](https://github.com/mzwing/pi-packages/actions/workflows/release.yml) [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg?style=flat)](https://opensource.org/licenses/MIT) [![TypeScript](https://img.shields.io/badge/TypeScript-7.x-3178C6?style=flat&logo=typescript&logoColor=white)](https://www.typescriptlang.org/) [![Pi Package](https://img.shields.io/badge/Pi-Package-6366F1?style=flat)](https://github.com/earendil-works/pi)
4
+
5
+ A [Pi](https://github.com/earendil-works/pi) extension that adds Codex-style automatic permission reviews to [`@gotgenes/pi-permission-system`](https://github.com/gotgenes/pi-packages/tree/main/packages/pi-permission-system).
6
+
7
+ ## Differences betweem `@gotgenes/pi-permission-model-judge`
8
+
9
+ [@gotgenes/pi-permission-model-judge](https://github.com/gotgenes/pi-packages/tree/main/packages/pi-permission-model-judge) is a general-purpose model-based authorizer that can be used to evaluate any permission request.
10
+
11
+ Ours is mostly specialized for OpenAI's `codex-auto-review` model, which is trained to evaluate permission requests in the context of a coding assistant. Our extension aims at providing Codex-style automatic permission reviews for Pi's coding agent.
12
+
13
+ ## Install
14
+
15
+ ```bash
16
+ pi install npm:@gotgenes/pi-permission-system # dependency
17
+ pi install npm:@mzwing/pi-permission-auto-review
18
+ ```
19
+
20
+ ## Enable
21
+
22
+ Add `"auto-review"` to pi-permission-system's config:
23
+
24
+ ```json
25
+ {
26
+ "authorizerChain": ["auto-review"]
27
+ }
28
+ ```
29
+
30
+ The config is normally located at `~/.pi/agent/extensions/pi-permission-system/config.json`.
31
+
32
+ Extension config can be omitted. The defaults are:
33
+
34
+ ```json
35
+ {
36
+ "provider": "openai-codex",
37
+ "model": "codex-auto-review",
38
+ "reasoning": "low",
39
+ "timeoutMs": 90000,
40
+ "includeBaselinePolicy": true
41
+ }
42
+ ```
43
+
44
+ `codex-auto-review` is an official hidden model. The extension derives it from Pi's `openai-codex` provider and reuses the existing Codex login.
45
+
46
+ ## Configuration
47
+
48
+ | Scope | Path |
49
+ | ------- | -------------------------------------------------------------- |
50
+ | Global | `~/.pi/agent/extensions/pi-permission-auto-review/config.json` |
51
+ | Project | `<cwd>/.pi/extensions/pi-permission-auto-review/config.json` |
52
+
53
+ Project fields override global fields. `PI_CODING_AGENT_DIR` replaces `~/.pi/agent` when set.
54
+
55
+ | Field | Default | Description |
56
+ | ----------------------- | ------------------- | -------------------------------------------- |
57
+ | `provider` | `openai-codex` | Pi model-registry provider id |
58
+ | `model` | `codex-auto-review` | Model id within the selected provider |
59
+ | `reasoning` | `low` | Reasoning level for reviewer calls |
60
+ | `timeoutMs` | `90000` | Total budget across all retry attempts |
61
+ | `includeBaselinePolicy` | `true` | Include the built-in Codex-style risk policy |
62
+ | `additionalPolicy` | omitted | Trusted operator policy appended to it |
63
+
64
+ See the [example config](config/config.example.json) and bundled [JSON Schema](schemas/config.schema.json). Unknown or invalid fields disable automatic decisions and fall through to the normal prompt.
65
+
66
+ Use `/permission-auto-review` in Pi's interactive TUI to edit and apply global or project config without reloading the session. Available subcommands:
67
+
68
+ ```text
69
+ /permission-auto-review show
70
+ /permission-auto-review path
71
+ /permission-auto-review reset [global|project]
72
+ /permission-auto-review help
73
+ ```
74
+
75
+ Custom providers and models must be defined in Pi's `~/.pi/agent/models.json`, then selected with this extension's `provider` and `model` fields. To replace the built-in risk policy completely, set `includeBaselinePolicy` to `false` and provide a non-empty `additionalPolicy`.
76
+
77
+ ## Behavior and Limits
78
+
79
+ - Only direct user transcript entries can establish authorization; assistant, tool, summary, and permission-request content is untrusted.
80
+ - Reviewer calls have no tools and cannot recursively request permission.
81
+ - Model, authentication, timeout, provider, or response-format failures defer to the normal human prompt.
82
+ - Three consecutive denials, or ten denials in the latest fifty reviews, open a circuit breaker until the next Pi turn.
83
+ - pi-permission-system prevents authorizers from auto-approving `path` and `external_directory` requests.
84
+ - The compact transcript and permission request are sent to the selected provider. Audit metadata is written through pi-permission-system's shared logger without credentials, model rationales, or the complete transcript.
85
+
86
+ ## License
87
+
88
+ [MIT](LICENSE)
@@ -0,0 +1,8 @@
1
+ {
2
+ "$schema": "../schemas/config.schema.json",
3
+ "provider": "openai-codex",
4
+ "model": "codex-auto-review",
5
+ "reasoning": "low",
6
+ "timeoutMs": 90000,
7
+ "includeBaselinePolicy": true
8
+ }
@@ -0,0 +1,78 @@
1
+ import { Authorizer, PermissionsService } from "@gotgenes/pi-permission-system";
2
+ import { z } from "zod";
3
+ import { ExtensionAPI, ModelRegistry, SessionManager } from "@earendil-works/pi-coding-agent";
4
+ //#region src/config.d.ts
5
+ declare const EXTENSION_ID = "pi-permission-auto-review";
6
+ declare const AUTHORIZER_NAME = "auto-review";
7
+ declare const DEFAULT_PROVIDER = "openai-codex";
8
+ declare const DEFAULT_MODEL = "codex-auto-review";
9
+ declare const DEFAULT_TIMEOUT_MS = 9e4;
10
+ declare const CONFIG_SCHEMA_URL = "https://raw.githubusercontent.com/mzwing/pi-packages/main/packages/pi-permission-auto-review/schemas/config.schema.json";
11
+ type AutoReviewConfigSchema = z.ZodObject<{
12
+ $schema: z.ZodOptional<z.ZodString>;
13
+ additionalPolicy: z.ZodOptional<z.ZodString>;
14
+ provider: z.ZodDefault<z.ZodString>;
15
+ model: z.ZodDefault<z.ZodString>;
16
+ reasoning: z.ZodDefault<z.ZodEnum<{
17
+ off: "off";
18
+ minimal: "minimal";
19
+ low: "low";
20
+ medium: "medium";
21
+ high: "high";
22
+ xhigh: "xhigh";
23
+ max: "max";
24
+ }>>;
25
+ timeoutMs: z.ZodDefault<z.ZodNumber>;
26
+ includeBaselinePolicy: z.ZodDefault<z.ZodBoolean>;
27
+ }, z.core.$strict>;
28
+ declare const autoReviewConfigSchema: AutoReviewConfigSchema;
29
+ type AutoReviewConfig = z.infer<typeof autoReviewConfigSchema>;
30
+ interface ConfigIssue {
31
+ sourcePath: string;
32
+ message: string;
33
+ }
34
+ interface LoadConfigResult {
35
+ config: AutoReviewConfig | undefined;
36
+ issues: ConfigIssue[];
37
+ globalPath: string;
38
+ projectPath: string;
39
+ }
40
+ interface LoadConfigOptions {
41
+ cwd: string;
42
+ agentDir?: string;
43
+ readFile?: (path: string) => string | undefined;
44
+ }
45
+ declare function loadAutoReviewConfig(options: LoadConfigOptions): LoadConfigResult;
46
+ declare function buildAutoReviewJsonSchema(): Record<string, unknown>;
47
+ //#endregion
48
+ //#region src/circuit-breaker.d.ts
49
+ declare class DenialCircuitBreaker {
50
+ private consecutiveDenials;
51
+ private recentDenials;
52
+ isOpen(): boolean;
53
+ recordDenied(): void;
54
+ recordNonDenial(): void;
55
+ resetTurn(): void;
56
+ private recordRecent;
57
+ }
58
+ //#endregion
59
+ //#region src/extension.d.ts
60
+ interface ReviewerFactoryOptions {
61
+ config: AutoReviewConfig;
62
+ registry: ModelRegistry;
63
+ sessionManager: Pick<SessionManager, "buildContextEntries">;
64
+ circuitBreaker: DenialCircuitBreaker;
65
+ sessionSignal: AbortSignal;
66
+ }
67
+ interface AutoReviewExtensionDependencies {
68
+ loadConfig?: (cwd: string) => LoadConfigResult;
69
+ getPermissionsService?: () => PermissionsService | undefined;
70
+ createReviewer?: (options: ReviewerFactoryOptions) => Authorizer["authorize"];
71
+ }
72
+ declare function createAutoReviewExtension(pi: ExtensionAPI, dependencies?: AutoReviewExtensionDependencies): void;
73
+ //#endregion
74
+ //#region src/index.d.ts
75
+ declare function permissionAutoReviewExtension(pi: ExtensionAPI): void;
76
+ //#endregion
77
+ export { AUTHORIZER_NAME, type AutoReviewConfig, type AutoReviewExtensionDependencies, CONFIG_SCHEMA_URL, type ConfigIssue, DEFAULT_MODEL, DEFAULT_PROVIDER, DEFAULT_TIMEOUT_MS, EXTENSION_ID, type LoadConfigOptions, type LoadConfigResult, autoReviewConfigSchema, buildAutoReviewJsonSchema, createAutoReviewExtension, permissionAutoReviewExtension as default, loadAutoReviewConfig };
78
+ //# sourceMappingURL=index.d.ts.map