@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.
Files changed (59) hide show
  1. package/CHANGELOG.md +174 -1
  2. package/LICENSE +21 -201
  3. package/LICENSE-APACHE +201 -0
  4. package/MIGRATION.md +2 -1
  5. package/NOTICE +14 -6
  6. package/README.md +109 -787
  7. package/SECURITY.md +41 -22
  8. package/dist/explain.d.ts +3 -4
  9. package/dist/explain.js +9708 -4298
  10. package/dist/index.d.ts +1096 -987
  11. package/dist/index.js +18646 -10575
  12. package/dist/rpc.d.ts +38 -38
  13. package/dist/rpc.js +30 -18
  14. package/dist/tui/config/jsonc.ts +71 -63
  15. package/dist/tui/config/layer-read.ts +120 -0
  16. package/dist/tui/config/loader.ts +73 -512
  17. package/dist/tui/config/risk-policy-clamp.ts +80 -0
  18. package/dist/tui/config/trust-boundary-keys.ts +102 -0
  19. package/dist/tui/config/trust-boundary.ts +148 -0
  20. package/dist/tui/config/trusted-degradation.ts +97 -0
  21. package/dist/tui/config-fields.ts +75 -0
  22. package/dist/tui/config-knobs.ts +119 -0
  23. package/dist/tui/config-policy-rules.ts +86 -0
  24. package/dist/tui/config-risk-policy.ts +59 -0
  25. package/dist/tui/config-rule-condition.ts +150 -0
  26. package/dist/tui/config.ts +72 -431
  27. package/dist/tui/descriptor-io.ts +42 -0
  28. package/dist/tui/failure-kind.ts +28 -0
  29. package/dist/tui/is-record.ts +13 -0
  30. package/dist/tui/opencode/event-normalizer.ts +41 -31
  31. package/dist/tui/reviewer-model.ts +87 -0
  32. package/dist/tui/system-one-routing.ts +110 -0
  33. package/dist/tui/tui.tsx +97 -99
  34. package/dist/tui/types.ts +206 -596
  35. package/dist/tui/ui/action-fit.ts +161 -0
  36. package/dist/tui/ui/action-spans.tsx +60 -0
  37. package/dist/tui/ui/attribution.ts +113 -0
  38. package/dist/tui/ui/components.tsx +69 -137
  39. package/dist/tui/ui/config-notices.ts +137 -0
  40. package/dist/tui/ui/fit-parts.ts +76 -0
  41. package/dist/tui/ui/manual-toast.ts +87 -0
  42. package/dist/tui/ui/review-connection.ts +32 -0
  43. package/dist/tui/ui/review-feed.ts +156 -0
  44. package/dist/tui/ui/review-overlay.tsx +111 -0
  45. package/dist/tui/ui/review-result.tsx +74 -0
  46. package/dist/tui/ui/review-store.ts +88 -0
  47. package/dist/tui/ui/review-theme.ts +70 -0
  48. package/dist/tui/ui/rpc.ts +5 -2
  49. package/dist/tui/ui/v1-host.ts +66 -0
  50. package/dist/tui/ui/v2.tsx +82 -220
  51. package/dist/tui/ui-protocol.ts +112 -124
  52. package/dist/tui/ui-state.ts +86 -64
  53. package/dist/tui/ui-status-extras.ts +165 -0
  54. package/dist/tui/ui-status-parse.ts +132 -0
  55. package/dist/tui/ui-text-elide.ts +89 -0
  56. package/package.json +24 -23
  57. package/rpc.js +2 -1
  58. package/server.js +2 -2
  59. package/tui.tsx +2 -1
@@ -0,0 +1,132 @@
1
+ import { isRecord } from "./is-record.ts";
2
+ import type { HandoffInfo } from "./system-one/backend.ts";
3
+ import type {
4
+ HandoffTrigger,
5
+ ManualResolution,
6
+ ReviewDecision,
7
+ } from "./types.ts";
8
+ import type { ActionSegment, ReviewUiStatus } from "./ui-protocol.ts";
9
+
10
+ // Structural checks for a decoded UI status payload. A payload passes only
11
+ // when every field holds a value the protocol defines; it is then returned
12
+ // as is, unknown extra fields included.
13
+
14
+ type Check = (value: unknown) => boolean;
15
+
16
+ const oneOf =
17
+ (allowed: readonly unknown[]): Check =>
18
+ (value: unknown): boolean =>
19
+ allowed.includes(value);
20
+ const isString: Check = (value: unknown): boolean => typeof value === "string";
21
+ const isFiniteNumber = (value: unknown): value is number =>
22
+ typeof value === "number" && Number.isFinite(value);
23
+ const optional =
24
+ (check: Check): Check =>
25
+ (value: unknown): boolean =>
26
+ value === undefined || check(value);
27
+
28
+ /** True when every field named in `checks` passes its check. */
29
+ function fieldsPass(
30
+ value: Record<string, unknown>,
31
+ checks: Record<string, Check>,
32
+ ): boolean {
33
+ return Object.entries(checks).every(([key, check]) => check(value[key]));
34
+ }
35
+
36
+ const DECISION_CHECKS: Partial<Record<keyof ReviewDecision, Check>> = {
37
+ outcome: oneOf(["allow", "deny", "escalate"]),
38
+ risk_level: oneOf(["low", "medium", "high", "critical"]),
39
+ user_authorization: oneOf(["high", "medium", "low", "unknown"]),
40
+ rationale: isString,
41
+ confidence: (value: unknown): boolean =>
42
+ isFiniteNumber(value) && value >= 0 && value <= 1,
43
+ };
44
+
45
+ function isDecision(value: unknown): value is ReviewDecision {
46
+ return isRecord(value) && fieldsPass(value, DECISION_CHECKS);
47
+ }
48
+
49
+ // Keyed records, so a trigger or resolution added to the union without a
50
+ // check here fails to compile.
51
+ const HANDOFF_TRIGGERS: Record<HandoffTrigger, true> = {
52
+ "jev-escalate": true,
53
+ "jev-uncertain-allow": true,
54
+ "jev-gate": true,
55
+ "jev-invalid": true,
56
+ "jev-failure": true,
57
+ "jev-uncertain-deny": true,
58
+ };
59
+
60
+ const RESOLUTIONS: Record<ManualResolution, true> = {
61
+ reviewer: true,
62
+ "reasoning-escalated": true,
63
+ "reasoning-unavailable": true,
64
+ "budget-exhausted": true,
65
+ };
66
+
67
+ const isStringList: Check = (value: unknown): boolean =>
68
+ Array.isArray(value) && value.every((entry) => typeof entry === "string");
69
+
70
+ const HANDOFF_CHECKS: Record<keyof HandoffInfo, Check> = {
71
+ from: isString,
72
+ to: isString,
73
+ trigger: oneOf(Object.keys(HANDOFF_TRIGGERS)),
74
+ failureKind: optional(isString),
75
+ };
76
+
77
+ const isHandoff: Check = (value: unknown): boolean =>
78
+ isRecord(value) && fieldsPass(value, HANDOFF_CHECKS);
79
+
80
+ const SEGMENT_CHECKS: Record<keyof ActionSegment, Check> = {
81
+ text: isString,
82
+ separator: optional(oneOf(["|", "||", "&&", ";", "&"])),
83
+ heredocLines: optional(
84
+ (value: unknown): boolean =>
85
+ isFiniteNumber(value) && Number.isInteger(value) && value >= 0,
86
+ ),
87
+ };
88
+
89
+ const isActionSegments: Check = (value: unknown): boolean =>
90
+ Array.isArray(value) &&
91
+ value.every(
92
+ (segment: unknown): boolean =>
93
+ isRecord(segment) && fieldsPass(segment, SEGMENT_CHECKS),
94
+ );
95
+
96
+ const STATUS_CHECKS: Record<keyof ReviewUiStatus, Check> = {
97
+ version: (value: unknown): boolean => value === 1,
98
+ requestID: isString,
99
+ sessionID: isString,
100
+ phase: oneOf(["reviewing", "approved", "denied", "manual", "unknown"]),
101
+ permission: isString,
102
+ action: isString,
103
+ model: isString,
104
+ variant: isString,
105
+ emittedAt: isFiniteNumber,
106
+ timeoutMs: (value: unknown): boolean => isFiniteNumber(value) && value >= 0,
107
+ reason: optional(isString),
108
+ decision: optional(isDecision),
109
+ escalationDisposition: optional(oneOf(["manual", "deny"])),
110
+ actorName: optional(isString),
111
+ actorProfile: optional(
112
+ oneOf([
113
+ "read-only",
114
+ "validation",
115
+ "workspace",
116
+ "operator",
117
+ "reviewer",
118
+ "unknown",
119
+ ]),
120
+ ),
121
+ handoff: optional(isHandoff),
122
+ resolution: optional(oneOf(Object.keys(RESOLUTIONS))),
123
+ decidedBy: optional(isString),
124
+ configWarnings: optional(isStringList),
125
+ configDegraded: optional(isStringList),
126
+ actionSegments: optional(isActionSegments),
127
+ };
128
+
129
+ export function parseUiStatus(value: unknown): ReviewUiStatus | undefined {
130
+ if (!(isRecord(value) && fieldsPass(value, STATUS_CHECKS))) return;
131
+ return value as unknown as ReviewUiStatus;
132
+ }
@@ -0,0 +1,89 @@
1
+ // Ships to the TUI (the action fit) and runs on the server (the bounded action
2
+ // and segment texts), so it must not import a server-only module.
3
+
4
+ export const ELISION: string = " ⋯ ";
5
+ export const LINE_BREAK: string = "⏎";
6
+ const ELISION_COLUMNS: number = Array.from(ELISION).length;
7
+ const ESCAPED =
8
+ // Each member matches one code point on its own, so no adjacent pair
9
+ // should read as a combined character; the combining grapheme joiner is
10
+ // therefore listed first.
11
+ // biome-ignore lint/suspicious/noControlCharactersInRegex: action text renders C0/C1, bidi, format and non-ASCII space code points as visible escapes
12
+ // biome-ignore lint/suspicious/noMisleadingCharacterClass: intentional per-code-point match for variation selectors, joiners and combining grapheme joiner
13
+ /[\u034f\u0000-\u0008\u000b-\u001f\u007f-\u00a0\u00ad\u061c\u1680\u180e\u2000-\u200f\u2028-\u202f\u205f-\u206f\u21b5\u22ef\u23ce\u3000\ud800-\udfff\ufe00-\ufe0f\ufeff\ufff9-\ufffb\u{e0000}-\u{e007f}\u{e0100}-\u{e01ef}]/gu;
14
+
15
+ function escapeChar(char: string): string {
16
+ const code = char.codePointAt(0) ?? 0;
17
+ if (code <= 0xff) return `\\x${code.toString(16).padStart(2, "0")}`;
18
+ if (code <= 0xffff) return `\\u${code.toString(16).padStart(4, "0")}`;
19
+ return `\\u{${code.toString(16)}}`;
20
+ }
21
+
22
+ /** `value` with invisible, directional, control and marker characters escaped,
23
+ * line continuations marked with `\⏎`, line breaks marked with `⏎`, and runs
24
+ * of spaces and tabs collapsed. */
25
+ export function renderActionText(value: string): string {
26
+ return value
27
+ .replace(ESCAPED, escapeChar)
28
+ .replace(/\\\n/g, `\\${LINE_BREAK}`)
29
+ .replace(/\n/g, ` ${LINE_BREAK} `)
30
+ .replace(/[ \t]+/g, " ")
31
+ .trim();
32
+ }
33
+
34
+ /** Whether whole words of `kept` code points use at least half of `max`, so
35
+ * the cut may fall between words rather than inside one. */
36
+ const wordCut = (kept: number, max: number): boolean =>
37
+ kept > 0 && kept * 2 >= max;
38
+
39
+ /** The longest prefix of `text` made of whole words within `max` code
40
+ * points; a hard cut at `max` when those words would use less than half of
41
+ * it. Always a prefix of `text` (trailing spaces trimmed). */
42
+ export function keepHead(text: string, max: number): string {
43
+ const chars = Array.from(text);
44
+ if (chars.length <= max) return text;
45
+ let end = max;
46
+ while (end > 0 && chars[end] !== " ") end -= 1;
47
+ const head = wordCut(end, max)
48
+ ? chars.slice(0, end)
49
+ : chars.slice(0, Math.max(0, max));
50
+ return head.join("").trimEnd();
51
+ }
52
+
53
+ /** The longest suffix of `text` made of whole words within `max` code
54
+ * points; a hard cut at `max` when those words would use less than half of
55
+ * it. Always a suffix of `text` (leading spaces trimmed). */
56
+ export function keepTail(text: string, max: number): string {
57
+ if (max <= 0) return "";
58
+ const chars = Array.from(text);
59
+ if (chars.length <= max) return text;
60
+ let start = chars.length - max;
61
+ while (start < chars.length && chars[start - 1] !== " ") start += 1;
62
+ const tail = wordCut(chars.length - start, max)
63
+ ? chars.slice(start)
64
+ : chars.slice(chars.length - max);
65
+ return tail.join("").trimStart();
66
+ }
67
+
68
+ /** `text` split into a head and a tail that fit `max` code points together
69
+ * with " ⋯ " between them, the head taking at most half; undefined when
70
+ * `text` already fits. */
71
+ export function elideMiddle(
72
+ text: string,
73
+ max: number,
74
+ ): { head: string; tail: string } | undefined {
75
+ if (Array.from(text).length <= max) return undefined;
76
+ const budget = Math.max(0, max - ELISION_COLUMNS);
77
+ const head = keepHead(text, Math.ceil(budget / 2));
78
+ return { head, tail: keepTail(text, budget - Array.from(head).length) };
79
+ }
80
+
81
+ /** `value` on one line with escapes and line-break markers applied and at most
82
+ * `max` code points: its middle elided around " ⋯ " when it is longer. */
83
+ export function boundedHeadTail(value: string, max: number): string {
84
+ const compact = renderActionText(value);
85
+ const elided = elideMiddle(compact, max);
86
+ return elided === undefined
87
+ ? compact
88
+ : `${elided.head}${ELISION}${elided.tail}`;
89
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@noppu-labs/opencode-permission-reviewer",
3
- "version": "2.4.2",
3
+ "version": "3.1.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": "Warc0s",
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,44 +88,44 @@
87
88
  }
88
89
  },
89
90
  "devDependencies": {
90
- "@eslint/js": "^10.0.0",
91
- "@opencode-ai/plugin": "1.18.35",
92
- "@opencode/plugin": "2.0.26",
91
+ "@biomejs/biome": "2.5.15",
92
+ "@opencode-ai/plugin": "1.19.3",
93
+ "@opencode-ai/sdk": "1.19.3",
94
+ "@opencode/plugin": "2.1.1",
93
95
  "@types/bun": "^1.3.0",
94
96
  "@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"
97
+ "fta-cli": "3.1.0",
98
+ "knip": "6.41.0",
99
+ "tsdown": "0.23.1",
100
+ "typescript": "7.0.2"
103
101
  },
104
102
  "overrides": {
105
- "@babel/core": "7.29.7",
106
- "esbuild": "^0.28.2"
103
+ "@babel/core": "7.29.7"
107
104
  },
108
105
  "scripts": {
109
- "format": "prettier --write .",
110
- "format:check": "prettier --check .",
111
- "lint": "eslint . --max-warnings=0",
106
+ "lint": "biome check --error-on-warnings .",
107
+ "lint:fix": "biome check --write .",
108
+ "format": "biome format --write .",
112
109
  "typecheck": "tsc --noEmit",
113
- "build": "tsup && bun scripts/copy-tui.ts",
110
+ "fta": "fta .",
111
+ "knip": "knip",
112
+ "audit": "bun audit --ignore GHSA-ch52-4w7c-c8xp --ignore GHSA-p6vx-979v-rg4c --ignore GHSA-jp82-f5mq-hwhp",
113
+ "build": "rm -rf dist && tsdown && bun scripts/copy-tui.ts",
114
114
  "test": "bun test",
115
115
  "test:stress": "bun test tests/stress.test.ts --timeout 30000",
116
116
  "test:package": "bun test tests/package-smoke.test.ts --timeout 120000",
117
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"
118
+ "docs:screens": "bun scripts/capture-tui.ts --all",
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.26",
123
+ "@opencode/client": "2.1.1",
123
124
  "jsonc-parser": "3.3.1",
124
125
  "semver": "7.8.5",
125
126
  "@opentui/core": "0.5.11",
126
127
  "@opentui/solid": "0.5.11",
127
128
  "solid-js": "1.9.12",
128
- "zod": "4.6.5"
129
+ "zod": "4.6.7"
129
130
  }
130
131
  }
package/rpc.js CHANGED
@@ -1 +1,2 @@
1
- export { ReviewerRpc, ReviewerRpc as default } from "./dist/rpc.js"
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
- // Directory entrypoint for hosts that resolve local plugins by filename.
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
- export { default } from "./dist/tui/tui.tsx"
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";