@noppu-labs/opencode-permission-reviewer 2.4.2 → 3.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/CHANGELOG.md +174 -1
- package/LICENSE +21 -201
- package/LICENSE-APACHE +201 -0
- package/MIGRATION.md +2 -1
- package/NOTICE +14 -6
- package/README.md +109 -787
- package/SECURITY.md +41 -22
- package/dist/explain.d.ts +3 -4
- package/dist/explain.js +9708 -4298
- package/dist/index.d.ts +1096 -987
- package/dist/index.js +18646 -10575
- package/dist/rpc.d.ts +38 -38
- package/dist/rpc.js +30 -18
- package/dist/tui/config/jsonc.ts +71 -63
- package/dist/tui/config/layer-read.ts +120 -0
- package/dist/tui/config/loader.ts +73 -512
- package/dist/tui/config/risk-policy-clamp.ts +80 -0
- package/dist/tui/config/trust-boundary-keys.ts +102 -0
- package/dist/tui/config/trust-boundary.ts +148 -0
- package/dist/tui/config/trusted-degradation.ts +97 -0
- package/dist/tui/config-fields.ts +75 -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 +72 -431
- package/dist/tui/descriptor-io.ts +42 -0
- package/dist/tui/failure-kind.ts +28 -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/system-one-routing.ts +110 -0
- package/dist/tui/tui.tsx +97 -99
- package/dist/tui/types.ts +206 -596
- package/dist/tui/ui/action-fit.ts +161 -0
- package/dist/tui/ui/action-spans.tsx +60 -0
- package/dist/tui/ui/attribution.ts +113 -0
- package/dist/tui/ui/components.tsx +69 -137
- package/dist/tui/ui/config-notices.ts +137 -0
- package/dist/tui/ui/fit-parts.ts +76 -0
- package/dist/tui/ui/manual-toast.ts +87 -0
- package/dist/tui/ui/review-connection.ts +32 -0
- package/dist/tui/ui/review-feed.ts +156 -0
- package/dist/tui/ui/review-overlay.tsx +111 -0
- package/dist/tui/ui/review-result.tsx +74 -0
- package/dist/tui/ui/review-store.ts +88 -0
- package/dist/tui/ui/review-theme.ts +70 -0
- package/dist/tui/ui/rpc.ts +5 -2
- package/dist/tui/ui/v1-host.ts +66 -0
- package/dist/tui/ui/v2.tsx +82 -220
- package/dist/tui/ui-protocol.ts +112 -124
- package/dist/tui/ui-state.ts +86 -64
- package/dist/tui/ui-status-extras.ts +165 -0
- package/dist/tui/ui-status-parse.ts +132 -0
- package/dist/tui/ui-text-elide.ts +89 -0
- package/package.json +24 -23
- package/rpc.js +2 -1
- package/server.js +2 -2
- package/tui.tsx +2 -1
package/dist/rpc.d.ts
CHANGED
|
@@ -1,42 +1,42 @@
|
|
|
1
|
+
//#region src/ui/rpc.d.ts
|
|
1
2
|
/** Portable, read-only protocol. No UI message can approve a permission. */
|
|
2
|
-
declare const ReviewerRpc: {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
};
|
|
3
|
+
export declare const ReviewerRpc: {
|
|
4
|
+
readonly id: "opencode-permission-reviewer";
|
|
5
|
+
readonly methods: {
|
|
6
|
+
readonly identity: {
|
|
7
|
+
readonly input: {
|
|
8
|
+
readonly type: "object";
|
|
9
|
+
readonly additionalProperties: false;
|
|
10
|
+
};
|
|
11
|
+
readonly output: {
|
|
12
|
+
readonly type: "string";
|
|
13
|
+
};
|
|
32
14
|
};
|
|
33
|
-
readonly
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
15
|
+
readonly status: {
|
|
16
|
+
readonly input: {
|
|
17
|
+
readonly type: "object";
|
|
18
|
+
readonly additionalProperties: false;
|
|
19
|
+
};
|
|
20
|
+
readonly output: {
|
|
21
|
+
readonly type: "object";
|
|
22
|
+
};
|
|
39
23
|
};
|
|
24
|
+
readonly snapshot: {
|
|
25
|
+
readonly input: {
|
|
26
|
+
readonly type: "object";
|
|
27
|
+
readonly additionalProperties: false;
|
|
28
|
+
};
|
|
29
|
+
readonly output: {
|
|
30
|
+
readonly type: "object";
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
readonly events: {
|
|
35
|
+
readonly "review.updated": {
|
|
36
|
+
readonly schema: {
|
|
37
|
+
readonly type: "object";
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
};
|
|
40
41
|
};
|
|
41
|
-
|
|
42
|
-
export { ReviewerRpc };
|
|
42
|
+
//#endregion
|
package/dist/rpc.js
CHANGED
|
@@ -1,19 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
1
|
+
//#region src/ui/rpc.ts
|
|
2
|
+
/** Portable, read-only protocol. No UI message can approve a permission. */
|
|
3
|
+
const ReviewerRpc = {
|
|
4
|
+
id: "opencode-permission-reviewer",
|
|
5
|
+
methods: {
|
|
6
|
+
identity: {
|
|
7
|
+
input: {
|
|
8
|
+
type: "object",
|
|
9
|
+
additionalProperties: false
|
|
10
|
+
},
|
|
11
|
+
output: { type: "string" }
|
|
12
|
+
},
|
|
13
|
+
status: {
|
|
14
|
+
input: {
|
|
15
|
+
type: "object",
|
|
16
|
+
additionalProperties: false
|
|
17
|
+
},
|
|
18
|
+
output: { type: "object" }
|
|
19
|
+
},
|
|
20
|
+
snapshot: {
|
|
21
|
+
input: {
|
|
22
|
+
type: "object",
|
|
23
|
+
additionalProperties: false
|
|
24
|
+
},
|
|
25
|
+
output: { type: "object" }
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
events: { "review.updated": { schema: { type: "object" } } }
|
|
19
29
|
};
|
|
30
|
+
//#endregion
|
|
31
|
+
export { ReviewerRpc };
|
package/dist/tui/config/jsonc.ts
CHANGED
|
@@ -11,9 +11,9 @@
|
|
|
11
11
|
*/
|
|
12
12
|
export function parseJsonc(text: string): Record<string, unknown> {
|
|
13
13
|
try {
|
|
14
|
-
return parseJsoncStrict(text)
|
|
14
|
+
return parseJsoncStrict(text);
|
|
15
15
|
} catch {
|
|
16
|
-
return {}
|
|
16
|
+
return {};
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
|
|
@@ -21,80 +21,88 @@ export function parseJsonc(text: string): Record<string, unknown> {
|
|
|
21
21
|
* top-level non-object so callers can distinguish a malformed config file
|
|
22
22
|
* (worth warning about) from a missing one (the common case). */
|
|
23
23
|
export function parseJsoncStrict(text: string): Record<string, unknown> {
|
|
24
|
-
const stripped = stripCommentsAndTrailingCommas(text)
|
|
25
|
-
const parsed: unknown = JSON.parse(stripped)
|
|
24
|
+
const stripped = stripCommentsAndTrailingCommas(text);
|
|
25
|
+
const parsed: unknown = JSON.parse(stripped);
|
|
26
26
|
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
27
|
-
throw new Error("top-level value is not a JSON object")
|
|
27
|
+
throw new Error("top-level value is not a JSON object");
|
|
28
28
|
}
|
|
29
|
-
return parsed as Record<string, unknown
|
|
29
|
+
return parsed as Record<string, unknown>;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** One strip pass: the text kept so far and the last non-whitespace
|
|
33
|
+
* character appended to it. When a `}` or `]` arrives right after a `,`, the
|
|
34
|
+
* comma is a trailing comma and is removed. */
|
|
35
|
+
interface StripState {
|
|
36
|
+
out: string;
|
|
37
|
+
lastReal: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function append(state: StripState, ch: string): void {
|
|
41
|
+
state.out += ch;
|
|
42
|
+
if (ch !== " " && ch !== "\t" && ch !== "\n" && ch !== "\r")
|
|
43
|
+
state.lastReal = ch;
|
|
30
44
|
}
|
|
31
45
|
|
|
32
46
|
/** Strip JSONC comments and trailing commas while preserving string contents.
|
|
33
47
|
* Trailing commas are handled in the same pass as comments (both are
|
|
34
48
|
* string-aware), so a `,}` inside a string value is never corrupted. */
|
|
35
49
|
export function stripCommentsAndTrailingCommas(input: string): string {
|
|
36
|
-
|
|
37
|
-
let i = 0
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
-
}
|
|
50
|
+
const state: StripState = { out: "", lastReal: "" };
|
|
51
|
+
let i = 0;
|
|
52
|
+
while (i < input.length) i = stripAt(input, i, state);
|
|
53
|
+
return state.out;
|
|
54
|
+
}
|
|
69
55
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
56
|
+
/** Handle the token starting at `i` and return the index after it. */
|
|
57
|
+
function stripAt(input: string, i: number, state: StripState): number {
|
|
58
|
+
const ch = input.charAt(i);
|
|
59
|
+
const next = input[i + 1];
|
|
60
|
+
if (ch === '"') return copyString(input, i, state);
|
|
61
|
+
if (ch === "/" && next === "/") return skipLineComment(input, i);
|
|
62
|
+
if (ch === "/" && next === "*") return skipBlockComment(input, i);
|
|
63
|
+
if ((ch === "}" || ch === "]") && state.lastReal === ",") {
|
|
64
|
+
dropTrailingComma(state);
|
|
65
|
+
}
|
|
66
|
+
append(state, ch);
|
|
67
|
+
return i + 1;
|
|
68
|
+
}
|
|
76
69
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
70
|
+
/** Copy a string literal verbatim through its closing quote. */
|
|
71
|
+
function copyString(input: string, start: number, state: StripState): number {
|
|
72
|
+
append(state, input.charAt(start));
|
|
73
|
+
let i = start + 1;
|
|
74
|
+
while (i < input.length) {
|
|
75
|
+
const c = input.charAt(i);
|
|
76
|
+
append(state, c);
|
|
77
|
+
if (c === "\\" && i + 1 < input.length) {
|
|
78
|
+
append(state, input.charAt(i + 1));
|
|
79
|
+
i += 2;
|
|
80
|
+
continue;
|
|
83
81
|
}
|
|
82
|
+
i += 1;
|
|
83
|
+
if (c === '"') break;
|
|
84
|
+
}
|
|
85
|
+
return i;
|
|
86
|
+
}
|
|
84
87
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
while (j >= 0 && out[j] !== ",") j -= 1
|
|
91
|
-
if (j >= 0) out = out.slice(0, j)
|
|
92
|
-
lastReal = ""
|
|
93
|
-
}
|
|
88
|
+
function skipLineComment(input: string, start: number): number {
|
|
89
|
+
let i = start + 2;
|
|
90
|
+
while (i < input.length && input[i] !== "\n") i += 1;
|
|
91
|
+
return i;
|
|
92
|
+
}
|
|
94
93
|
|
|
95
|
-
|
|
96
|
-
|
|
94
|
+
function skipBlockComment(input: string, start: number): number {
|
|
95
|
+
let i = start + 2;
|
|
96
|
+
while (i < input.length && !(input[i] === "*" && input[i + 1] === "/")) {
|
|
97
|
+
i += 1;
|
|
97
98
|
}
|
|
99
|
+
return i + 2;
|
|
100
|
+
}
|
|
98
101
|
|
|
99
|
-
|
|
102
|
+
/** Walk back over the comma (and any whitespace after it in `out`). */
|
|
103
|
+
function dropTrailingComma(state: StripState): void {
|
|
104
|
+
let j = state.out.length - 1;
|
|
105
|
+
while (j >= 0 && state.out[j] !== ",") j -= 1;
|
|
106
|
+
if (j >= 0) state.out = state.out.slice(0, j);
|
|
107
|
+
state.lastReal = "";
|
|
100
108
|
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { fstatSync, openSync } from "node:fs";
|
|
2
|
+
import {
|
|
3
|
+
closeQuietly,
|
|
4
|
+
O_NOFOLLOW,
|
|
5
|
+
O_NONBLOCK,
|
|
6
|
+
O_RDONLY,
|
|
7
|
+
readFully,
|
|
8
|
+
} from "../descriptor-io.ts";
|
|
9
|
+
import { parseJsoncStrict } from "./jsonc.ts";
|
|
10
|
+
|
|
11
|
+
/** Cap on a single config file read: the project layer is repository-controlled
|
|
12
|
+
* and read at startup, so an unbounded read lets a committed symlink to an
|
|
13
|
+
* endless source exhaust memory. A file over the cap is treated like any
|
|
14
|
+
* other unreadable layer (warned about and ignored). */
|
|
15
|
+
const CONFIG_READ_CAP_BYTES = 1024 * 1024;
|
|
16
|
+
|
|
17
|
+
export type ConfigLayer =
|
|
18
|
+
| {
|
|
19
|
+
raw: Record<string, unknown>;
|
|
20
|
+
status: "missing" | "ok";
|
|
21
|
+
warning?: undefined;
|
|
22
|
+
}
|
|
23
|
+
| {
|
|
24
|
+
raw: Record<string, unknown>;
|
|
25
|
+
status: "read-error" | "malformed";
|
|
26
|
+
/** A silently unreadable trusted layer must be visible, not
|
|
27
|
+
* indistinguishable from an absent one. */
|
|
28
|
+
warning: string;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
type LayerText = ConfigLayer | { status: "ok"; text: string };
|
|
32
|
+
|
|
33
|
+
/** Read a JSONC config file. A missing file is the common case (status
|
|
34
|
+
* "missing", no warning). A file that exists but cannot be read or parsed
|
|
35
|
+
* keeps the plugin working with an empty layer, but the status lets the
|
|
36
|
+
* caller treat an unusable TRUSTED layer as a fail-closed condition rather
|
|
37
|
+
* than silently falling back to defaults.
|
|
38
|
+
*
|
|
39
|
+
* The read goes through an explicitly opened descriptor: O_NOFOLLOW rejects
|
|
40
|
+
* a symlinked layer (a committed link to a FIFO would otherwise hang startup
|
|
41
|
+
* and a link to an endless source would exhaust memory), O_NONBLOCK keeps a
|
|
42
|
+
* FIFO from blocking before fstat can reject it, fstat requires a regular
|
|
43
|
+
* file, and the byte cap bounds the read. */
|
|
44
|
+
export function readConfigLayer(path: string): ConfigLayer {
|
|
45
|
+
const read = readLayerText(path);
|
|
46
|
+
if (!("text" in read)) return read;
|
|
47
|
+
try {
|
|
48
|
+
return { raw: parseJsoncStrict(read.text), status: "ok" };
|
|
49
|
+
} catch (error) {
|
|
50
|
+
return {
|
|
51
|
+
raw: {},
|
|
52
|
+
status: "malformed",
|
|
53
|
+
warning: `permission-reviewer config at ${path} is malformed and was ignored (${error instanceof Error ? error.message : String(error)})`,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function readError(warning: string): ConfigLayer {
|
|
59
|
+
return { raw: {}, status: "read-error", warning };
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function unreadable(path: string, error: unknown): ConfigLayer {
|
|
63
|
+
const code = (error as { code?: unknown }).code;
|
|
64
|
+
return readError(
|
|
65
|
+
`permission-reviewer config at ${path} exists but could not be read (${code ?? "unknown error"}); the layer was ignored`,
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Read at most the capped bytes through the open descriptor; anything but a
|
|
70
|
+
* missing file that stops the read becomes a `read-error` layer. Never
|
|
71
|
+
* throws. */
|
|
72
|
+
function readLayerText(path: string): LayerText {
|
|
73
|
+
let fd: number | undefined;
|
|
74
|
+
try {
|
|
75
|
+
const opened = openLayer(path);
|
|
76
|
+
if (typeof opened !== "number") return opened;
|
|
77
|
+
fd = opened;
|
|
78
|
+
return readOpenLayer(fd, path);
|
|
79
|
+
} catch (error) {
|
|
80
|
+
return unreadable(path, error);
|
|
81
|
+
} finally {
|
|
82
|
+
closeQuietly(fd);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function openLayer(path: string): number | ConfigLayer {
|
|
87
|
+
try {
|
|
88
|
+
// Read-only descriptor open of an existing config path; no file is
|
|
89
|
+
// created here and the descriptor must pass the regular-file check below.
|
|
90
|
+
// codeql[js/insecure-temporary-file]
|
|
91
|
+
return openSync(path, O_RDONLY | O_NONBLOCK | O_NOFOLLOW);
|
|
92
|
+
} catch (error) {
|
|
93
|
+
if ((error as { code?: unknown }).code === "ENOENT")
|
|
94
|
+
return { raw: {}, status: "missing" };
|
|
95
|
+
return unreadable(path, error);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function readOpenLayer(fd: number, path: string): LayerText {
|
|
100
|
+
const info = fstatSync(fd);
|
|
101
|
+
if (!info.isFile()) {
|
|
102
|
+
return readError(
|
|
103
|
+
`permission-reviewer config at ${path} is not a regular file and was ignored`,
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
if (info.size > CONFIG_READ_CAP_BYTES) {
|
|
107
|
+
return readError(
|
|
108
|
+
`permission-reviewer config at ${path} exceeds the size limit (${CONFIG_READ_CAP_BYTES} bytes) and was ignored`,
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
return { status: "ok", text: readBytes(fd, info.size) };
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function readBytes(fd: number, length: number): string {
|
|
115
|
+
const buffer = Buffer.alloc(length);
|
|
116
|
+
const read = readFully(fd, buffer, length, 0);
|
|
117
|
+
// A concurrent shrink can end the read early; decode only the bytes
|
|
118
|
+
// actually read so no zero-padding leaks into the parser.
|
|
119
|
+
return (read < length ? buffer.subarray(0, read) : buffer).toString("utf8");
|
|
120
|
+
}
|