@noppu-labs/opencode-permission-reviewer 0.0.0-stage → 2.4.2
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 +652 -0
- package/LICENSE +201 -0
- package/MIGRATION.md +111 -0
- package/NOTICE +13 -0
- package/README.md +842 -2
- package/SECURITY.md +31 -0
- package/dist/explain.d.ts +4 -0
- package/dist/explain.js +4422 -0
- package/dist/index.d.ts +1179 -0
- package/dist/index.js +10770 -0
- package/dist/rpc.d.ts +42 -0
- package/dist/rpc.js +19 -0
- package/dist/tui/config/jsonc.ts +100 -0
- package/dist/tui/config/loader.ts +573 -0
- package/dist/tui/config.ts +479 -0
- package/dist/tui/opencode/event-normalizer.ts +52 -0
- package/dist/tui/tui.tsx +162 -0
- package/dist/tui/types.ts +747 -0
- package/dist/tui/ui/components.tsx +181 -0
- package/dist/tui/ui/rpc.ts +16 -0
- package/dist/tui/ui/v2.tsx +261 -0
- package/dist/tui/ui-protocol.ts +183 -0
- package/dist/tui/ui-state.ts +139 -0
- package/package.json +128 -4
- package/rpc.js +1 -0
- package/server.js +2 -0
- package/tui.tsx +1 -0
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import type { PermissionRequest } from "./types.ts"
|
|
2
|
+
import {
|
|
3
|
+
UI_START_GRACE_MS,
|
|
4
|
+
UI_WATCHDOG_GRACE_MS,
|
|
5
|
+
createUiStatus,
|
|
6
|
+
type ReviewUiStatus,
|
|
7
|
+
} from "./ui-protocol.ts"
|
|
8
|
+
|
|
9
|
+
export interface UiStateOptions {
|
|
10
|
+
model: string
|
|
11
|
+
variant: string
|
|
12
|
+
timeoutMs: number
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const RESULT_DISPLAY_MS = {
|
|
16
|
+
approved: 5_000,
|
|
17
|
+
denied: 5_000,
|
|
18
|
+
} as const
|
|
19
|
+
|
|
20
|
+
export class ReviewUiState {
|
|
21
|
+
private readonly requests = new Map<string, ReviewUiStatus>()
|
|
22
|
+
private readonly acknowledged = new Set<string>()
|
|
23
|
+
|
|
24
|
+
constructor(private readonly options: UiStateOptions) {}
|
|
25
|
+
|
|
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", { ...this.options, emittedAt: now })
|
|
30
|
+
this.requests.set(request.id, status)
|
|
31
|
+
return status
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
apply(status: ReviewUiStatus): boolean {
|
|
35
|
+
const current = this.requests.get(status.requestID)
|
|
36
|
+
if (current && !this.acknowledged.has(status.requestID)) {
|
|
37
|
+
this.requests.set(
|
|
38
|
+
status.requestID,
|
|
39
|
+
status.phase === "reviewing" ? { ...status, emittedAt: current.emittedAt } : status,
|
|
40
|
+
)
|
|
41
|
+
this.acknowledged.add(status.requestID)
|
|
42
|
+
return true
|
|
43
|
+
}
|
|
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
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
replied(requestID: string): void {
|
|
51
|
+
const current = this.requests.get(requestID)
|
|
52
|
+
if (!current || current.phase === "approved" || current.phase === "denied") return
|
|
53
|
+
this.requests.delete(requestID)
|
|
54
|
+
this.acknowledged.delete(requestID)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
remove(requestID: string): void {
|
|
58
|
+
this.requests.delete(requestID)
|
|
59
|
+
this.acknowledged.delete(requestID)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
get(requestID: string): ReviewUiStatus | undefined {
|
|
63
|
+
return this.requests.get(requestID)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
all(): ReviewUiStatus[] {
|
|
67
|
+
return [...this.requests.values()].sort(
|
|
68
|
+
(left, right) =>
|
|
69
|
+
left.emittedAt - right.emittedAt || left.requestID.localeCompare(right.requestID),
|
|
70
|
+
)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
activeFor(
|
|
74
|
+
sessionID: string,
|
|
75
|
+
parentOf: (sessionID: string) => string | undefined,
|
|
76
|
+
): ReviewUiStatus | undefined {
|
|
77
|
+
// Manual entries only drive toasts; they must not occupy the panel slot or
|
|
78
|
+
// they hide later reviews. Prefer an in-flight review over a terminal
|
|
79
|
+
// result, and within each class pick the newest request.
|
|
80
|
+
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>()
|
|
85
|
+
while (current && !visited.has(current)) {
|
|
86
|
+
if (current === sessionID) return true
|
|
87
|
+
visited.add(current)
|
|
88
|
+
current = parentOf(current)
|
|
89
|
+
}
|
|
90
|
+
return false
|
|
91
|
+
})
|
|
92
|
+
if (matches.length === 0) return undefined
|
|
93
|
+
const rank = (phase: ReviewUiStatus["phase"]): number => {
|
|
94
|
+
if (phase === "reviewing") return 2
|
|
95
|
+
if (phase === "approved" || phase === "denied") return 1
|
|
96
|
+
return 0
|
|
97
|
+
}
|
|
98
|
+
return matches.sort(
|
|
99
|
+
(left, right) =>
|
|
100
|
+
rank(right.phase) - rank(left.phase) ||
|
|
101
|
+
right.emittedAt - left.emittedAt ||
|
|
102
|
+
right.requestID.localeCompare(left.requestID),
|
|
103
|
+
)[0]
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
expire(now = Date.now()): ReviewUiStatus[] {
|
|
107
|
+
const expired: ReviewUiStatus[] = []
|
|
108
|
+
for (const [requestID, status] of this.requests) {
|
|
109
|
+
if (status.phase !== "reviewing") continue
|
|
110
|
+
const acknowledged = this.acknowledged.has(requestID)
|
|
111
|
+
const deadline = acknowledged
|
|
112
|
+
? status.emittedAt + status.timeoutMs + UI_WATCHDOG_GRACE_MS
|
|
113
|
+
: status.emittedAt + UI_START_GRACE_MS
|
|
114
|
+
if (now < deadline) continue
|
|
115
|
+
const unknown: ReviewUiStatus = {
|
|
116
|
+
...status,
|
|
117
|
+
phase: "unknown",
|
|
118
|
+
emittedAt: now,
|
|
119
|
+
reason: acknowledged
|
|
120
|
+
? "The reviewer did not return a result within the expected time."
|
|
121
|
+
: "The reviewer did not acknowledge the start of the review.",
|
|
122
|
+
}
|
|
123
|
+
this.requests.set(requestID, unknown)
|
|
124
|
+
expired.push(unknown)
|
|
125
|
+
}
|
|
126
|
+
return expired
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
dismissResults(now = Date.now()): string[] {
|
|
130
|
+
const removed: string[] = []
|
|
131
|
+
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)
|
|
136
|
+
}
|
|
137
|
+
return removed
|
|
138
|
+
}
|
|
139
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,130 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@noppu-labs/opencode-permission-reviewer",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "2.4.2",
|
|
4
|
+
"description": "Policy-aware permission reviewer for OpenCode V1 and V2",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./server": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"import": "./dist/index.js",
|
|
17
|
+
"default": "./dist/index.js"
|
|
18
|
+
},
|
|
19
|
+
"./tui": "./dist/tui/tui.tsx",
|
|
20
|
+
"./rpc": {
|
|
21
|
+
"types": "./dist/rpc.d.ts",
|
|
22
|
+
"import": "./dist/rpc.js",
|
|
23
|
+
"default": "./dist/rpc.js"
|
|
24
|
+
},
|
|
25
|
+
"./cli": {
|
|
26
|
+
"types": "./dist/explain.d.ts",
|
|
27
|
+
"import": "./dist/explain.js",
|
|
28
|
+
"default": "./dist/explain.js"
|
|
29
|
+
},
|
|
30
|
+
"./package.json": "./package.json"
|
|
31
|
+
},
|
|
32
|
+
"bin": {
|
|
33
|
+
"opencode-permission-reviewer": "dist/explain.js"
|
|
34
|
+
},
|
|
35
|
+
"files": [
|
|
36
|
+
"server.js",
|
|
37
|
+
"rpc.js",
|
|
38
|
+
"tui.tsx",
|
|
39
|
+
"dist/",
|
|
40
|
+
"README.md",
|
|
41
|
+
"MIGRATION.md",
|
|
42
|
+
"CHANGELOG.md",
|
|
43
|
+
"NOTICE",
|
|
44
|
+
"LICENSE",
|
|
45
|
+
"SECURITY.md"
|
|
46
|
+
],
|
|
47
|
+
"license": "Apache-2.0",
|
|
48
|
+
"author": "Warc0s",
|
|
49
|
+
"homepage": "https://github.com/noppu-labs/opencode-permission-reviewer",
|
|
50
|
+
"repository": {
|
|
51
|
+
"type": "git",
|
|
52
|
+
"url": "git+https://github.com/noppu-labs/opencode-permission-reviewer.git"
|
|
53
|
+
},
|
|
54
|
+
"bugs": {
|
|
55
|
+
"url": "https://github.com/noppu-labs/opencode-permission-reviewer/issues"
|
|
56
|
+
},
|
|
57
|
+
"publishConfig": {
|
|
58
|
+
"access": "public"
|
|
59
|
+
},
|
|
60
|
+
"keywords": [
|
|
61
|
+
"opencode",
|
|
62
|
+
"opencode-plugin",
|
|
63
|
+
"ai-agent",
|
|
64
|
+
"agent-safety",
|
|
65
|
+
"auto-approval",
|
|
66
|
+
"permission-management",
|
|
67
|
+
"llm",
|
|
68
|
+
"codex-guardian",
|
|
69
|
+
"policy-as-code",
|
|
70
|
+
"typescript",
|
|
71
|
+
"bun"
|
|
72
|
+
],
|
|
73
|
+
"engines": {
|
|
74
|
+
"bun": ">=1.3.0",
|
|
75
|
+
"opencode": ">=1.18.29 <2 || >=2.0.3 <3"
|
|
76
|
+
},
|
|
77
|
+
"peerDependencies": {
|
|
78
|
+
"@opencode-ai/plugin": ">=1.18.29 <2",
|
|
79
|
+
"@opencode/plugin": ">=2.0.3 <3"
|
|
80
|
+
},
|
|
81
|
+
"peerDependenciesMeta": {
|
|
82
|
+
"@opencode-ai/plugin": {
|
|
83
|
+
"optional": true
|
|
84
|
+
},
|
|
85
|
+
"@opencode/plugin": {
|
|
86
|
+
"optional": true
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
"devDependencies": {
|
|
90
|
+
"@eslint/js": "^10.0.0",
|
|
91
|
+
"@opencode-ai/plugin": "1.18.35",
|
|
92
|
+
"@opencode/plugin": "2.0.26",
|
|
93
|
+
"@types/bun": "^1.3.0",
|
|
94
|
+
"@types/semver": "7.8.0",
|
|
95
|
+
"eslint": "^10.8.0",
|
|
96
|
+
"eslint-config-prettier": "^10.0.0",
|
|
97
|
+
"globals": "^17.9.0",
|
|
98
|
+
"jiti": "^2.7.0",
|
|
99
|
+
"prettier": "^3.0.0",
|
|
100
|
+
"tsup": "^8.0.0",
|
|
101
|
+
"typescript": "6.0.3",
|
|
102
|
+
"typescript-eslint": "^8.0.0"
|
|
103
|
+
},
|
|
104
|
+
"overrides": {
|
|
105
|
+
"@babel/core": "7.29.7",
|
|
106
|
+
"esbuild": "^0.28.2"
|
|
107
|
+
},
|
|
108
|
+
"scripts": {
|
|
109
|
+
"format": "prettier --write .",
|
|
110
|
+
"format:check": "prettier --check .",
|
|
111
|
+
"lint": "eslint . --max-warnings=0",
|
|
112
|
+
"typecheck": "tsc --noEmit",
|
|
113
|
+
"build": "tsup && bun scripts/copy-tui.ts",
|
|
114
|
+
"test": "bun test",
|
|
115
|
+
"test:stress": "bun test tests/stress.test.ts --timeout 30000",
|
|
116
|
+
"test:package": "bun test tests/package-smoke.test.ts --timeout 120000",
|
|
117
|
+
"test:coverage": "bun test --coverage --coverage-reporter lcov --coverage-dir ./coverage && bun scripts/check-coverage.ts",
|
|
118
|
+
"check": "bun run format:check && bun run lint && bun run build && bun run typecheck && bun run test"
|
|
119
|
+
},
|
|
120
|
+
"dependencies": {
|
|
121
|
+
"@typesafe-ai/sdk": "0.6.0",
|
|
122
|
+
"@opencode/client": "2.0.26",
|
|
123
|
+
"jsonc-parser": "3.3.1",
|
|
124
|
+
"semver": "7.8.5",
|
|
125
|
+
"@opentui/core": "0.5.11",
|
|
126
|
+
"@opentui/solid": "0.5.11",
|
|
127
|
+
"solid-js": "1.9.12",
|
|
128
|
+
"zod": "4.6.5"
|
|
129
|
+
}
|
|
130
|
+
}
|
package/rpc.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ReviewerRpc, ReviewerRpc as default } from "./dist/rpc.js"
|
package/server.js
ADDED
package/tui.tsx
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./dist/tui/tui.tsx"
|