@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
package/dist/rpc.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/** Portable, read-only protocol. No UI message can approve a permission. */
|
|
2
|
+
declare const ReviewerRpc: {
|
|
3
|
+
readonly id: "opencode-permission-reviewer";
|
|
4
|
+
readonly methods: {
|
|
5
|
+
readonly identity: {
|
|
6
|
+
readonly input: {
|
|
7
|
+
readonly type: "object";
|
|
8
|
+
readonly additionalProperties: false;
|
|
9
|
+
};
|
|
10
|
+
readonly output: {
|
|
11
|
+
readonly type: "string";
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
readonly status: {
|
|
15
|
+
readonly input: {
|
|
16
|
+
readonly type: "object";
|
|
17
|
+
readonly additionalProperties: false;
|
|
18
|
+
};
|
|
19
|
+
readonly output: {
|
|
20
|
+
readonly type: "object";
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
readonly snapshot: {
|
|
24
|
+
readonly input: {
|
|
25
|
+
readonly type: "object";
|
|
26
|
+
readonly additionalProperties: false;
|
|
27
|
+
};
|
|
28
|
+
readonly output: {
|
|
29
|
+
readonly type: "object";
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
readonly events: {
|
|
34
|
+
readonly "review.updated": {
|
|
35
|
+
readonly schema: {
|
|
36
|
+
readonly type: "object";
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export { ReviewerRpc };
|
package/dist/rpc.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// src/ui/rpc.ts
|
|
2
|
+
var ReviewerRpc = {
|
|
3
|
+
id: "opencode-permission-reviewer",
|
|
4
|
+
methods: {
|
|
5
|
+
identity: {
|
|
6
|
+
input: { type: "object", additionalProperties: false },
|
|
7
|
+
output: { type: "string" }
|
|
8
|
+
},
|
|
9
|
+
status: { input: { type: "object", additionalProperties: false }, output: { type: "object" } },
|
|
10
|
+
snapshot: {
|
|
11
|
+
input: { type: "object", additionalProperties: false },
|
|
12
|
+
output: { type: "object" }
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
events: { "review.updated": { schema: { type: "object" } } }
|
|
16
|
+
};
|
|
17
|
+
export {
|
|
18
|
+
ReviewerRpc
|
|
19
|
+
};
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/** Minimal JSONC (JSON with comments) parser with zero dependencies.
|
|
2
|
+
*
|
|
3
|
+
* Strips line comments, block comments, and trailing commas (all in a single
|
|
4
|
+
* string-aware pass), then delegates to `JSON.parse`. String contents are
|
|
5
|
+
* preserved verbatim — comment markers and trailing-comma patterns inside
|
|
6
|
+
* strings are NOT stripped.
|
|
7
|
+
*
|
|
8
|
+
* Used by the config loader to read `~/.config/opencode/permission-reviewer.jsonc`
|
|
9
|
+
* and `.opencode/permission-reviewer.jsonc`. Returns `{}` on parse failure so
|
|
10
|
+
* a malformed config file degrades to defaults rather than crashing the plugin.
|
|
11
|
+
*/
|
|
12
|
+
export function parseJsonc(text: string): Record<string, unknown> {
|
|
13
|
+
try {
|
|
14
|
+
return parseJsoncStrict(text)
|
|
15
|
+
} catch {
|
|
16
|
+
return {}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** Strict variant used by the config loader: throws on a syntax error or on a
|
|
21
|
+
* top-level non-object so callers can distinguish a malformed config file
|
|
22
|
+
* (worth warning about) from a missing one (the common case). */
|
|
23
|
+
export function parseJsoncStrict(text: string): Record<string, unknown> {
|
|
24
|
+
const stripped = stripCommentsAndTrailingCommas(text)
|
|
25
|
+
const parsed: unknown = JSON.parse(stripped)
|
|
26
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
27
|
+
throw new Error("top-level value is not a JSON object")
|
|
28
|
+
}
|
|
29
|
+
return parsed as Record<string, unknown>
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Strip JSONC comments and trailing commas while preserving string contents.
|
|
33
|
+
* Trailing commas are handled in the same pass as comments (both are
|
|
34
|
+
* string-aware), so a `,}` inside a string value is never corrupted. */
|
|
35
|
+
export function stripCommentsAndTrailingCommas(input: string): string {
|
|
36
|
+
let out = ""
|
|
37
|
+
let i = 0
|
|
38
|
+
const len = input.length
|
|
39
|
+
// Tracks the last non-whitespace character appended to `out`. Used to detect
|
|
40
|
+
// trailing commas: when we encounter `}` or `]`, we check if the last real
|
|
41
|
+
// character was `,` and remove it.
|
|
42
|
+
let lastReal = ""
|
|
43
|
+
const append = (ch: string) => {
|
|
44
|
+
out += ch
|
|
45
|
+
if (ch !== " " && ch !== "\t" && ch !== "\n" && ch !== "\r") lastReal = ch
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
while (i < len) {
|
|
49
|
+
const ch = input[i]!
|
|
50
|
+
const next = input[i + 1]
|
|
51
|
+
|
|
52
|
+
// String literal — copy verbatim until the closing quote.
|
|
53
|
+
if (ch === '"') {
|
|
54
|
+
append(ch)
|
|
55
|
+
i += 1
|
|
56
|
+
while (i < len) {
|
|
57
|
+
const c = input[i]!
|
|
58
|
+
append(c)
|
|
59
|
+
if (c === "\\" && i + 1 < len) {
|
|
60
|
+
append(input[i + 1]!)
|
|
61
|
+
i += 2
|
|
62
|
+
continue
|
|
63
|
+
}
|
|
64
|
+
i += 1
|
|
65
|
+
if (c === '"') break
|
|
66
|
+
}
|
|
67
|
+
continue
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Line comment.
|
|
71
|
+
if (ch === "/" && next === "/") {
|
|
72
|
+
i += 2
|
|
73
|
+
while (i < len && input[i] !== "\n") i += 1
|
|
74
|
+
continue
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Block comment.
|
|
78
|
+
if (ch === "/" && next === "*") {
|
|
79
|
+
i += 2
|
|
80
|
+
while (i < len && !(input[i] === "*" && input[i + 1] === "/")) i += 1
|
|
81
|
+
i += 2
|
|
82
|
+
continue
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Structural close: if the last real character was a trailing comma,
|
|
86
|
+
// remove it before appending the closing brace/bracket.
|
|
87
|
+
if ((ch === "}" || ch === "]") && lastReal === ",") {
|
|
88
|
+
// Walk back over the comma (and any whitespace after it in `out`).
|
|
89
|
+
let j = out.length - 1
|
|
90
|
+
while (j >= 0 && out[j] !== ",") j -= 1
|
|
91
|
+
if (j >= 0) out = out.slice(0, j)
|
|
92
|
+
lastReal = ""
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
append(ch)
|
|
96
|
+
i += 1
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return out
|
|
100
|
+
}
|