@noppu-labs/opencode-permission-reviewer 2.4.1 → 3.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 +64 -1
- package/LICENSE +21 -201
- package/LICENSE-APACHE +201 -0
- package/NOTICE +14 -6
- package/README.md +100 -750
- package/SECURITY.md +41 -22
- package/dist/explain.js +4932 -3522
- package/dist/index.d.ts +520 -513
- package/dist/index.js +12595 -9115
- package/dist/rpc.js +4 -1
- package/dist/tui/config/jsonc.ts +71 -63
- package/dist/tui/config/layer-read.ts +120 -0
- package/dist/tui/config/loader.ts +61 -513
- package/dist/tui/config/risk-policy-clamp.ts +80 -0
- package/dist/tui/config/trust-boundary-keys.ts +100 -0
- package/dist/tui/config/trust-boundary.ts +135 -0
- package/dist/tui/config/trusted-degradation.ts +97 -0
- package/dist/tui/config-fields.ts +55 -0
- package/dist/tui/config-knobs.ts +119 -0
- package/dist/tui/config-policy-rules.ts +86 -0
- package/dist/tui/config-risk-policy.ts +59 -0
- package/dist/tui/config-rule-condition.ts +150 -0
- package/dist/tui/config.ts +61 -430
- package/dist/tui/descriptor-io.ts +42 -0
- package/dist/tui/is-record.ts +13 -0
- package/dist/tui/opencode/event-normalizer.ts +41 -31
- package/dist/tui/reviewer-model.ts +87 -0
- package/dist/tui/tui.tsx +87 -99
- package/dist/tui/types.ts +171 -538
- package/dist/tui/ui/components.tsx +32 -136
- package/dist/tui/ui/review-connection.ts +32 -0
- package/dist/tui/ui/review-feed.ts +131 -0
- package/dist/tui/ui/review-overlay.tsx +83 -0
- package/dist/tui/ui/review-result.tsx +56 -0
- package/dist/tui/ui/review-store.ts +88 -0
- package/dist/tui/ui/review-theme.ts +63 -0
- package/dist/tui/ui/rpc.ts +5 -2
- package/dist/tui/ui/v1-host.ts +39 -0
- package/dist/tui/ui/v2.tsx +66 -220
- package/dist/tui/ui-protocol.ts +63 -118
- package/dist/tui/ui-state.ts +71 -64
- package/dist/tui/ui-status-parse.ts +74 -0
- package/package.json +18 -17
- package/rpc.js +2 -1
- package/server.js +2 -2
- package/tui.tsx +2 -1
package/dist/tui/ui-state.ts
CHANGED
|
@@ -1,73 +1,80 @@
|
|
|
1
|
-
import type { PermissionRequest } from "./types.ts"
|
|
1
|
+
import type { PermissionRequest } from "./types.ts";
|
|
2
2
|
import {
|
|
3
|
-
UI_START_GRACE_MS,
|
|
4
|
-
UI_WATCHDOG_GRACE_MS,
|
|
5
3
|
createUiStatus,
|
|
6
4
|
type ReviewUiStatus,
|
|
7
|
-
|
|
5
|
+
UI_START_GRACE_MS,
|
|
6
|
+
UI_WATCHDOG_GRACE_MS,
|
|
7
|
+
} from "./ui-protocol.ts";
|
|
8
8
|
|
|
9
9
|
export interface UiStateOptions {
|
|
10
|
-
model: string
|
|
11
|
-
variant: string
|
|
12
|
-
timeoutMs: number
|
|
10
|
+
model: string;
|
|
11
|
+
variant: string;
|
|
12
|
+
timeoutMs: number;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
const RESULT_DISPLAY_MS = {
|
|
16
16
|
approved: 5_000,
|
|
17
17
|
denied: 5_000,
|
|
18
|
-
} as const
|
|
18
|
+
} as const;
|
|
19
19
|
|
|
20
20
|
export class ReviewUiState {
|
|
21
|
-
private readonly requests = new Map<string, ReviewUiStatus>()
|
|
22
|
-
private readonly acknowledged = new Set<string>()
|
|
21
|
+
private readonly requests = new Map<string, ReviewUiStatus>();
|
|
22
|
+
private readonly acknowledged = new Set<string>();
|
|
23
23
|
|
|
24
24
|
constructor(private readonly options: UiStateOptions) {}
|
|
25
25
|
|
|
26
26
|
asked(request: PermissionRequest, now = Date.now()): ReviewUiStatus {
|
|
27
|
-
const existing = this.requests.get(request.id)
|
|
28
|
-
if (existing) return existing
|
|
29
|
-
const status = createUiStatus(request, "reviewing", {
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
const existing = this.requests.get(request.id);
|
|
28
|
+
if (existing) return existing;
|
|
29
|
+
const status = createUiStatus(request, "reviewing", {
|
|
30
|
+
...this.options,
|
|
31
|
+
emittedAt: now,
|
|
32
|
+
});
|
|
33
|
+
this.requests.set(request.id, status);
|
|
34
|
+
return status;
|
|
32
35
|
}
|
|
33
36
|
|
|
34
37
|
apply(status: ReviewUiStatus): boolean {
|
|
35
|
-
const current = this.requests.get(status.requestID)
|
|
38
|
+
const current = this.requests.get(status.requestID);
|
|
36
39
|
if (current && !this.acknowledged.has(status.requestID)) {
|
|
37
40
|
this.requests.set(
|
|
38
41
|
status.requestID,
|
|
39
|
-
status.phase === "reviewing"
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
42
|
+
status.phase === "reviewing"
|
|
43
|
+
? { ...status, emittedAt: current.emittedAt }
|
|
44
|
+
: status,
|
|
45
|
+
);
|
|
46
|
+
this.acknowledged.add(status.requestID);
|
|
47
|
+
return true;
|
|
43
48
|
}
|
|
44
|
-
if (current && status.emittedAt < current.emittedAt) return false
|
|
45
|
-
this.requests.set(status.requestID, status)
|
|
46
|
-
this.acknowledged.add(status.requestID)
|
|
47
|
-
return true
|
|
49
|
+
if (current && status.emittedAt < current.emittedAt) return false;
|
|
50
|
+
this.requests.set(status.requestID, status);
|
|
51
|
+
this.acknowledged.add(status.requestID);
|
|
52
|
+
return true;
|
|
48
53
|
}
|
|
49
54
|
|
|
50
55
|
replied(requestID: string): void {
|
|
51
|
-
const current = this.requests.get(requestID)
|
|
52
|
-
if (!current || current.phase === "approved" || current.phase === "denied")
|
|
53
|
-
|
|
54
|
-
this.
|
|
56
|
+
const current = this.requests.get(requestID);
|
|
57
|
+
if (!current || current.phase === "approved" || current.phase === "denied")
|
|
58
|
+
return;
|
|
59
|
+
this.requests.delete(requestID);
|
|
60
|
+
this.acknowledged.delete(requestID);
|
|
55
61
|
}
|
|
56
62
|
|
|
57
63
|
remove(requestID: string): void {
|
|
58
|
-
this.requests.delete(requestID)
|
|
59
|
-
this.acknowledged.delete(requestID)
|
|
64
|
+
this.requests.delete(requestID);
|
|
65
|
+
this.acknowledged.delete(requestID);
|
|
60
66
|
}
|
|
61
67
|
|
|
62
68
|
get(requestID: string): ReviewUiStatus | undefined {
|
|
63
|
-
return this.requests.get(requestID)
|
|
69
|
+
return this.requests.get(requestID);
|
|
64
70
|
}
|
|
65
71
|
|
|
66
72
|
all(): ReviewUiStatus[] {
|
|
67
73
|
return [...this.requests.values()].sort(
|
|
68
74
|
(left, right) =>
|
|
69
|
-
left.emittedAt - right.emittedAt ||
|
|
70
|
-
|
|
75
|
+
left.emittedAt - right.emittedAt ||
|
|
76
|
+
left.requestID.localeCompare(right.requestID),
|
|
77
|
+
);
|
|
71
78
|
}
|
|
72
79
|
|
|
73
80
|
activeFor(
|
|
@@ -78,40 +85,40 @@ export class ReviewUiState {
|
|
|
78
85
|
// they hide later reviews. Prefer an in-flight review over a terminal
|
|
79
86
|
// result, and within each class pick the newest request.
|
|
80
87
|
const matches = this.all().filter((status) => {
|
|
81
|
-
if (status.phase === "manual") return false
|
|
82
|
-
if (status.sessionID === sessionID) return true
|
|
83
|
-
let current = parentOf(status.sessionID)
|
|
84
|
-
const visited = new Set<string>()
|
|
88
|
+
if (status.phase === "manual") return false;
|
|
89
|
+
if (status.sessionID === sessionID) return true;
|
|
90
|
+
let current = parentOf(status.sessionID);
|
|
91
|
+
const visited = new Set<string>();
|
|
85
92
|
while (current && !visited.has(current)) {
|
|
86
|
-
if (current === sessionID) return true
|
|
87
|
-
visited.add(current)
|
|
88
|
-
current = parentOf(current)
|
|
93
|
+
if (current === sessionID) return true;
|
|
94
|
+
visited.add(current);
|
|
95
|
+
current = parentOf(current);
|
|
89
96
|
}
|
|
90
|
-
return false
|
|
91
|
-
})
|
|
92
|
-
if (matches.length === 0) return undefined
|
|
97
|
+
return false;
|
|
98
|
+
});
|
|
99
|
+
if (matches.length === 0) return undefined;
|
|
93
100
|
const rank = (phase: ReviewUiStatus["phase"]): number => {
|
|
94
|
-
if (phase === "reviewing") return 2
|
|
95
|
-
if (phase === "approved" || phase === "denied") return 1
|
|
96
|
-
return 0
|
|
97
|
-
}
|
|
101
|
+
if (phase === "reviewing") return 2;
|
|
102
|
+
if (phase === "approved" || phase === "denied") return 1;
|
|
103
|
+
return 0;
|
|
104
|
+
};
|
|
98
105
|
return matches.sort(
|
|
99
106
|
(left, right) =>
|
|
100
107
|
rank(right.phase) - rank(left.phase) ||
|
|
101
108
|
right.emittedAt - left.emittedAt ||
|
|
102
109
|
right.requestID.localeCompare(left.requestID),
|
|
103
|
-
)[0]
|
|
110
|
+
)[0];
|
|
104
111
|
}
|
|
105
112
|
|
|
106
113
|
expire(now = Date.now()): ReviewUiStatus[] {
|
|
107
|
-
const expired: ReviewUiStatus[] = []
|
|
114
|
+
const expired: ReviewUiStatus[] = [];
|
|
108
115
|
for (const [requestID, status] of this.requests) {
|
|
109
|
-
if (status.phase !== "reviewing") continue
|
|
110
|
-
const acknowledged = this.acknowledged.has(requestID)
|
|
116
|
+
if (status.phase !== "reviewing") continue;
|
|
117
|
+
const acknowledged = this.acknowledged.has(requestID);
|
|
111
118
|
const deadline = acknowledged
|
|
112
119
|
? status.emittedAt + status.timeoutMs + UI_WATCHDOG_GRACE_MS
|
|
113
|
-
: status.emittedAt + UI_START_GRACE_MS
|
|
114
|
-
if (now < deadline) continue
|
|
120
|
+
: status.emittedAt + UI_START_GRACE_MS;
|
|
121
|
+
if (now < deadline) continue;
|
|
115
122
|
const unknown: ReviewUiStatus = {
|
|
116
123
|
...status,
|
|
117
124
|
phase: "unknown",
|
|
@@ -119,21 +126,21 @@ export class ReviewUiState {
|
|
|
119
126
|
reason: acknowledged
|
|
120
127
|
? "The reviewer did not return a result within the expected time."
|
|
121
128
|
: "The reviewer did not acknowledge the start of the review.",
|
|
122
|
-
}
|
|
123
|
-
this.requests.set(requestID, unknown)
|
|
124
|
-
expired.push(unknown)
|
|
129
|
+
};
|
|
130
|
+
this.requests.set(requestID, unknown);
|
|
131
|
+
expired.push(unknown);
|
|
125
132
|
}
|
|
126
|
-
return expired
|
|
133
|
+
return expired;
|
|
127
134
|
}
|
|
128
135
|
|
|
129
136
|
dismissResults(now = Date.now()): string[] {
|
|
130
|
-
const removed: string[] = []
|
|
137
|
+
const removed: string[] = [];
|
|
131
138
|
for (const [requestID, status] of this.requests) {
|
|
132
|
-
if (status.phase !== "approved" && status.phase !== "denied") continue
|
|
133
|
-
if (now < status.emittedAt + RESULT_DISPLAY_MS[status.phase]) continue
|
|
134
|
-
this.remove(requestID)
|
|
135
|
-
removed.push(requestID)
|
|
139
|
+
if (status.phase !== "approved" && status.phase !== "denied") continue;
|
|
140
|
+
if (now < status.emittedAt + RESULT_DISPLAY_MS[status.phase]) continue;
|
|
141
|
+
this.remove(requestID);
|
|
142
|
+
removed.push(requestID);
|
|
136
143
|
}
|
|
137
|
-
return removed
|
|
144
|
+
return removed;
|
|
138
145
|
}
|
|
139
146
|
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { isRecord } from "./is-record.ts";
|
|
2
|
+
import type { ReviewDecision } from "./types.ts";
|
|
3
|
+
import type { ReviewUiStatus } from "./ui-protocol.ts";
|
|
4
|
+
|
|
5
|
+
// Structural checks for a decoded UI status payload. A payload passes only
|
|
6
|
+
// when every field holds a value the protocol defines; it is then returned
|
|
7
|
+
// as is, unknown extra fields included.
|
|
8
|
+
|
|
9
|
+
type Check = (value: unknown) => boolean;
|
|
10
|
+
|
|
11
|
+
const oneOf =
|
|
12
|
+
(allowed: readonly unknown[]): Check =>
|
|
13
|
+
(value: unknown): boolean =>
|
|
14
|
+
allowed.includes(value);
|
|
15
|
+
const isString: Check = (value: unknown): boolean => typeof value === "string";
|
|
16
|
+
const isFiniteNumber = (value: unknown): value is number =>
|
|
17
|
+
typeof value === "number" && Number.isFinite(value);
|
|
18
|
+
const optional =
|
|
19
|
+
(check: Check): Check =>
|
|
20
|
+
(value: unknown): boolean =>
|
|
21
|
+
value === undefined || check(value);
|
|
22
|
+
|
|
23
|
+
/** True when every field named in `checks` passes its check. */
|
|
24
|
+
function fieldsPass(
|
|
25
|
+
value: Record<string, unknown>,
|
|
26
|
+
checks: Record<string, Check>,
|
|
27
|
+
): boolean {
|
|
28
|
+
return Object.entries(checks).every(([key, check]) => check(value[key]));
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const DECISION_CHECKS: Partial<Record<keyof ReviewDecision, Check>> = {
|
|
32
|
+
outcome: oneOf(["allow", "deny", "escalate"]),
|
|
33
|
+
risk_level: oneOf(["low", "medium", "high", "critical"]),
|
|
34
|
+
user_authorization: oneOf(["high", "medium", "low", "unknown"]),
|
|
35
|
+
rationale: isString,
|
|
36
|
+
confidence: (value: unknown): boolean =>
|
|
37
|
+
isFiniteNumber(value) && value >= 0 && value <= 1,
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
function isDecision(value: unknown): value is ReviewDecision {
|
|
41
|
+
return isRecord(value) && fieldsPass(value, DECISION_CHECKS);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const STATUS_CHECKS: Record<keyof ReviewUiStatus, Check> = {
|
|
45
|
+
version: (value: unknown): boolean => value === 1,
|
|
46
|
+
requestID: isString,
|
|
47
|
+
sessionID: isString,
|
|
48
|
+
phase: oneOf(["reviewing", "approved", "denied", "manual", "unknown"]),
|
|
49
|
+
permission: isString,
|
|
50
|
+
action: isString,
|
|
51
|
+
model: isString,
|
|
52
|
+
variant: isString,
|
|
53
|
+
emittedAt: isFiniteNumber,
|
|
54
|
+
timeoutMs: (value: unknown): boolean => isFiniteNumber(value) && value >= 0,
|
|
55
|
+
reason: optional(isString),
|
|
56
|
+
decision: optional(isDecision),
|
|
57
|
+
escalationDisposition: optional(oneOf(["manual", "deny"])),
|
|
58
|
+
actorName: optional(isString),
|
|
59
|
+
actorProfile: optional(
|
|
60
|
+
oneOf([
|
|
61
|
+
"read-only",
|
|
62
|
+
"validation",
|
|
63
|
+
"workspace",
|
|
64
|
+
"operator",
|
|
65
|
+
"reviewer",
|
|
66
|
+
"unknown",
|
|
67
|
+
]),
|
|
68
|
+
),
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export function parseUiStatus(value: unknown): ReviewUiStatus | undefined {
|
|
72
|
+
if (!(isRecord(value) && fieldsPass(value, STATUS_CHECKS))) return;
|
|
73
|
+
return value as unknown as ReviewUiStatus;
|
|
74
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@noppu-labs/opencode-permission-reviewer",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Policy-aware permission reviewer for OpenCode V1 and V2",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -42,10 +42,11 @@
|
|
|
42
42
|
"CHANGELOG.md",
|
|
43
43
|
"NOTICE",
|
|
44
44
|
"LICENSE",
|
|
45
|
+
"LICENSE-APACHE",
|
|
45
46
|
"SECURITY.md"
|
|
46
47
|
],
|
|
47
|
-
"license": "Apache-2.0",
|
|
48
|
-
"author": "
|
|
48
|
+
"license": "MIT AND Apache-2.0",
|
|
49
|
+
"author": "cris005",
|
|
49
50
|
"homepage": "https://github.com/noppu-labs/opencode-permission-reviewer",
|
|
50
51
|
"repository": {
|
|
51
52
|
"type": "git",
|
|
@@ -87,39 +88,39 @@
|
|
|
87
88
|
}
|
|
88
89
|
},
|
|
89
90
|
"devDependencies": {
|
|
90
|
-
"@
|
|
91
|
+
"@biomejs/biome": "2.5.15",
|
|
91
92
|
"@opencode-ai/plugin": "1.18.35",
|
|
92
|
-
"@opencode/
|
|
93
|
+
"@opencode-ai/sdk": "1.18.35",
|
|
94
|
+
"@opencode/plugin": "2.0.26",
|
|
93
95
|
"@types/bun": "^1.3.0",
|
|
94
96
|
"@types/semver": "7.8.0",
|
|
95
|
-
"
|
|
96
|
-
"
|
|
97
|
-
"globals": "^17.9.0",
|
|
98
|
-
"jiti": "^2.7.0",
|
|
99
|
-
"prettier": "^3.0.0",
|
|
97
|
+
"fta-cli": "3.1.0",
|
|
98
|
+
"knip": "6.41.0",
|
|
100
99
|
"tsup": "^8.0.0",
|
|
101
|
-
"typescript": "6.0.3"
|
|
102
|
-
"typescript-eslint": "^8.0.0"
|
|
100
|
+
"typescript": "6.0.3"
|
|
103
101
|
},
|
|
104
102
|
"overrides": {
|
|
105
103
|
"@babel/core": "7.29.7",
|
|
106
104
|
"esbuild": "^0.28.2"
|
|
107
105
|
},
|
|
108
106
|
"scripts": {
|
|
109
|
-
"
|
|
110
|
-
"
|
|
111
|
-
"
|
|
107
|
+
"lint": "biome check --error-on-warnings .",
|
|
108
|
+
"lint:fix": "biome check --write .",
|
|
109
|
+
"format": "biome format --write .",
|
|
112
110
|
"typecheck": "tsc --noEmit",
|
|
111
|
+
"fta": "fta .",
|
|
112
|
+
"knip": "knip",
|
|
113
|
+
"audit": "bun audit --ignore GHSA-ch52-4w7c-c8xp --ignore GHSA-p6vx-979v-rg4c --ignore GHSA-jp82-f5mq-hwhp",
|
|
113
114
|
"build": "tsup && bun scripts/copy-tui.ts",
|
|
114
115
|
"test": "bun test",
|
|
115
116
|
"test:stress": "bun test tests/stress.test.ts --timeout 30000",
|
|
116
117
|
"test:package": "bun test tests/package-smoke.test.ts --timeout 120000",
|
|
117
118
|
"test:coverage": "bun test --coverage --coverage-reporter lcov --coverage-dir ./coverage && bun scripts/check-coverage.ts",
|
|
118
|
-
"check": "bun run
|
|
119
|
+
"check": "bun run build && bun run typecheck && uv run --frozen pre-commit run --all-files && uv run --frozen pre-commit run --hook-stage manual gitleaks-tree --all-files && bun test"
|
|
119
120
|
},
|
|
120
121
|
"dependencies": {
|
|
121
122
|
"@typesafe-ai/sdk": "0.6.0",
|
|
122
|
-
"@opencode/client": "2.0.
|
|
123
|
+
"@opencode/client": "2.0.26",
|
|
123
124
|
"jsonc-parser": "3.3.1",
|
|
124
125
|
"semver": "7.8.5",
|
|
125
126
|
"@opentui/core": "0.5.11",
|
package/rpc.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
// biome-ignore lint/performance/noBarrelFile: shipped root shim (package.json "files") re-exporting the ReviewerRpc protocol from dist/rpc.js; the re-export is its public API
|
|
2
|
+
export { ReviewerRpc, ReviewerRpc as default } from "./dist/rpc.js";
|
package/server.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
//
|
|
2
|
-
export { default } from "./dist/index.js"
|
|
1
|
+
// biome-ignore lint/performance/noBarrelFile: shipped root shim (package.json "files") re-exporting dist/index.js, for hosts that resolve plugins by filename
|
|
2
|
+
export { default } from "./dist/index.js";
|
package/tui.tsx
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
// biome-ignore lint/performance/noBarrelFile: shipped root shim (package.json "files") re-exporting dist/tui/tui.tsx, for hosts that resolve plugins by filename
|
|
2
|
+
export { default } from "./dist/tui/tui.tsx";
|