@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.
Files changed (46) hide show
  1. package/CHANGELOG.md +64 -1
  2. package/LICENSE +21 -201
  3. package/LICENSE-APACHE +201 -0
  4. package/NOTICE +14 -6
  5. package/README.md +100 -750
  6. package/SECURITY.md +41 -22
  7. package/dist/explain.js +4932 -3522
  8. package/dist/index.d.ts +520 -513
  9. package/dist/index.js +12595 -9115
  10. package/dist/rpc.js +4 -1
  11. package/dist/tui/config/jsonc.ts +71 -63
  12. package/dist/tui/config/layer-read.ts +120 -0
  13. package/dist/tui/config/loader.ts +61 -513
  14. package/dist/tui/config/risk-policy-clamp.ts +80 -0
  15. package/dist/tui/config/trust-boundary-keys.ts +100 -0
  16. package/dist/tui/config/trust-boundary.ts +135 -0
  17. package/dist/tui/config/trusted-degradation.ts +97 -0
  18. package/dist/tui/config-fields.ts +55 -0
  19. package/dist/tui/config-knobs.ts +119 -0
  20. package/dist/tui/config-policy-rules.ts +86 -0
  21. package/dist/tui/config-risk-policy.ts +59 -0
  22. package/dist/tui/config-rule-condition.ts +150 -0
  23. package/dist/tui/config.ts +61 -430
  24. package/dist/tui/descriptor-io.ts +42 -0
  25. package/dist/tui/is-record.ts +13 -0
  26. package/dist/tui/opencode/event-normalizer.ts +41 -31
  27. package/dist/tui/reviewer-model.ts +87 -0
  28. package/dist/tui/tui.tsx +87 -99
  29. package/dist/tui/types.ts +171 -538
  30. package/dist/tui/ui/components.tsx +32 -136
  31. package/dist/tui/ui/review-connection.ts +32 -0
  32. package/dist/tui/ui/review-feed.ts +131 -0
  33. package/dist/tui/ui/review-overlay.tsx +83 -0
  34. package/dist/tui/ui/review-result.tsx +56 -0
  35. package/dist/tui/ui/review-store.ts +88 -0
  36. package/dist/tui/ui/review-theme.ts +63 -0
  37. package/dist/tui/ui/rpc.ts +5 -2
  38. package/dist/tui/ui/v1-host.ts +39 -0
  39. package/dist/tui/ui/v2.tsx +66 -220
  40. package/dist/tui/ui-protocol.ts +63 -118
  41. package/dist/tui/ui-state.ts +71 -64
  42. package/dist/tui/ui-status-parse.ts +74 -0
  43. package/package.json +18 -17
  44. package/rpc.js +2 -1
  45. package/server.js +2 -2
  46. package/tui.tsx +2 -1
@@ -1,29 +1,34 @@
1
1
  /** @jsxImportSource @opentui/solid */
2
- import { Show } from "solid-js"
3
- import type { ColorInput } from "@opentui/core"
4
- import type { ReviewUiStatus } from "../ui-protocol.ts"
2
+
3
+ import type { ColorInput } from "@opentui/core";
4
+ import type { JSX } from "solid-js";
5
+ import { Show } from "solid-js";
6
+ import type { ReviewUiStatus } from "../ui-protocol.ts";
5
7
 
6
8
  export interface ReviewTheme {
7
- backgroundPanel: ColorInput
8
- text: ColorInput
9
- textMuted: ColorInput
10
- info: ColorInput
11
- success: ColorInput
12
- error: ColorInput
9
+ backgroundPanel: ColorInput;
10
+ text: ColorInput;
11
+ textMuted: ColorInput;
12
+ info: ColorInput;
13
+ success: ColorInput;
14
+ error: ColorInput;
13
15
  }
14
- export const SPINNER = ["◐", "◓", "◑", "◒"] as const
16
+ export const SPINNER = ["◐", "◓", "◑", "◒"] as const;
17
+
18
+ /** Collapses line breaks and tabs so a value renders on one row. */
19
+ export const singleLine = (value: string): string =>
20
+ value.replace(/[\r\n\t]+/g, " ");
15
21
 
16
22
  /** Compact, non-modal progress strip for hosts with an editable composer. */
17
23
  export function ReviewProgress(props: {
18
- theme: () => ReviewTheme
19
- status: ReviewUiStatus
20
- frame: () => number
21
- }) {
22
- const singleLine = (value: string) => value.replace(/[\r\n\t]+/g, " ")
23
- const elapsed = () => {
24
- props.frame()
25
- return `${(Math.max(0, Date.now() - props.status.emittedAt) / 1_000).toFixed(1)}s`
26
- }
24
+ theme: () => ReviewTheme;
25
+ status: ReviewUiStatus;
26
+ frame: () => number;
27
+ }): JSX.Element {
28
+ const elapsed = (): string => {
29
+ props.frame();
30
+ return `${(Math.max(0, Date.now() - props.status.emittedAt) / 1_000).toFixed(1)}s`;
31
+ };
27
32
  return (
28
33
  <box
29
34
  height={2}
@@ -43,10 +48,12 @@ export function ReviewProgress(props: {
43
48
  wrapMode="none"
44
49
  truncate
45
50
  >
46
- {SPINNER[props.frame() % SPINNER.length] ?? "◐"} Reviewing this permission
51
+ {SPINNER[props.frame() % SPINNER.length] ?? "◐"} Reviewing this
52
+ permission
47
53
  <span style={{ fg: props.theme().textMuted }}>
48
54
  {" "}
49
- · {singleLine(props.status.model)} · {singleLine(props.status.variant)}
55
+ · {singleLine(props.status.model)} ·{" "}
56
+ {singleLine(props.status.variant)}
50
57
  </span>
51
58
  </text>
52
59
  <text fg={props.theme().textMuted} flexShrink={0} wrapMode="none">
@@ -54,7 +61,9 @@ export function ReviewProgress(props: {
54
61
  </text>
55
62
  </box>
56
63
  <text fg={props.theme().text} wrapMode="none" truncate>
57
- <span style={{ fg: props.theme().textMuted }}>{props.status.permission} · </span>
64
+ <span style={{ fg: props.theme().textMuted }}>
65
+ {props.status.permission} ·{" "}
66
+ </span>
58
67
  {singleLine(props.status.action)}
59
68
  <Show when={props.status.actorName}>
60
69
  <span style={{ fg: props.theme().textMuted }}>
@@ -64,118 +73,5 @@ export function ReviewProgress(props: {
64
73
  </Show>
65
74
  </text>
66
75
  </box>
67
- )
68
- }
69
-
70
- export function ReviewOverlay(props: {
71
- theme: () => ReviewTheme
72
- status: ReviewUiStatus
73
- /** Spinner signal, read inside text children so only those update per tick. */
74
- frame: () => number
75
- }) {
76
- const theme = props.theme
77
- const elapsed = () => {
78
- // Reading the tick signal inside the text child is what re-renders it every
79
- // 250ms: Date.now() and status.emittedAt are plain values, so a text that
80
- // reads no signal is evaluated once at mount and freezes.
81
- props.frame()
82
- const elapsedMs = Math.max(0, Date.now() - props.status.emittedAt)
83
- return `${(elapsedMs / 1_000).toFixed(1)}s`
84
- }
85
-
86
- return (
87
- <box
88
- position="absolute"
89
- left={0}
90
- right={0}
91
- bottom={0}
92
- height="auto"
93
- maxHeight={12}
94
- overflow="hidden"
95
- backgroundColor={theme().backgroundPanel}
96
- border={["left"]}
97
- borderColor={theme().info}
98
- flexDirection="column"
99
- onMouseDown={(event) => {
100
- event.preventDefault()
101
- event.stopPropagation()
102
- }}
103
- onMouseUp={(event) => {
104
- event.preventDefault()
105
- event.stopPropagation()
106
- }}
107
- >
108
- <box
109
- flexDirection="column"
110
- gap={1}
111
- paddingTop={1}
112
- paddingBottom={1}
113
- paddingLeft={2}
114
- paddingRight={3}
115
- >
116
- <box flexDirection="row" gap={1}>
117
- <text fg={theme().info}>{SPINNER[props.frame() % SPINNER.length] ?? "◐"}</text>
118
- <text fg={theme().text}>Reviewing this permission</text>
119
- <box flexGrow={1} />
120
- <text fg={theme().textMuted}>{elapsed()}</text>
121
- </box>
122
- <box flexDirection="row" gap={1} paddingLeft={2}>
123
- <text fg={theme().textMuted}>{props.status.permission}</text>
124
- <text fg={theme().text} wrapMode="word">
125
- {props.status.action}
126
- </text>
127
- <Show when={props.status.actorName}>
128
- <text fg={theme().textMuted}>· actor {props.status.actorName}</text>
129
- </Show>
130
- </box>
131
- <box paddingLeft={2} flexDirection="row" gap={1}>
132
- <text fg={theme().textMuted}>
133
- {props.status.model} · reasoning {props.status.variant}
134
- </text>
135
- <box flexGrow={1} />
136
- <text fg={theme().textMuted}>No action needed</text>
137
- </box>
138
- </box>
139
- </box>
140
- )
141
- }
142
-
143
- export function ReviewResult(props: { theme: () => ReviewTheme; status: ReviewUiStatus }) {
144
- const theme = props.theme
145
- const appearance = () => {
146
- if (props.status.phase === "unknown") {
147
- return { color: theme().textMuted, icon: "?", title: "Review status unavailable" }
148
- }
149
- if (props.status.phase === "approved") {
150
- return { color: theme().success, icon: "✓", title: "Review approved" }
151
- }
152
- // Fail-closed escalate→deny is distinct from an explicit reviewer/policy deny.
153
- if (props.status.escalationDisposition === "deny") {
154
- return { color: theme().error, icon: "✕", title: "Review blocked (fail-closed)" }
155
- }
156
- return { color: theme().error, icon: "✕", title: "Review blocked" }
157
- }
158
- const singleLine = (value: string) => value.replace(/[\r\n\t]+/g, " ")
159
-
160
- return (
161
- <box
162
- height={props.status.reason ? 2 : 1}
163
- flexShrink={0}
164
- overflow="hidden"
165
- backgroundColor={theme().backgroundPanel}
166
- flexDirection="column"
167
- paddingLeft={1}
168
- paddingRight={1}
169
- >
170
- <text fg={appearance().color} wrapMode="none" truncate>
171
- {appearance().icon} {appearance().title} · {props.status.permission} ·{" "}
172
- {singleLine(props.status.action)}
173
- </text>
174
- <Show when={props.status.reason}>
175
- <text fg={theme().textMuted} wrapMode="none" truncate>
176
- {singleLine(props.status.reason ?? "")}
177
- </text>
178
- </Show>
179
- </box>
180
- )
76
+ );
181
77
  }
@@ -0,0 +1,32 @@
1
+ type Update = (data: unknown, owner: AbortController) => void;
2
+
3
+ /** One connection: events stay buffered until its snapshot is applied. */
4
+ export interface Connection {
5
+ controller: AbortController;
6
+ directory: string;
7
+ loading: boolean;
8
+ buffered: unknown[];
9
+ }
10
+
11
+ /** Takes one subscription event: ignored for another directory, buffered while
12
+ * the snapshot loads, passed to `update` afterwards. */
13
+ export function receive(
14
+ event: { location: { directory: string }; data: unknown },
15
+ connection: Connection,
16
+ update: Update,
17
+ ): void {
18
+ if (event.location.directory !== connection.directory) return;
19
+ if (!connection.loading) {
20
+ update(event.data, connection.controller);
21
+ return;
22
+ }
23
+ if (connection.buffered.length >= 512)
24
+ throw new Error("Reviewer event buffer overflow");
25
+ connection.buffered.push(event.data);
26
+ }
27
+
28
+ /** Ends loading and replays the buffered events in arrival order. */
29
+ export function release(connection: Connection, update: Update): void {
30
+ connection.loading = false;
31
+ for (const event of connection.buffered) update(event, connection.controller);
32
+ }
@@ -0,0 +1,131 @@
1
+ import type { Plugin } from "@opencode/plugin/tui";
2
+ import { asObjectLike } from "../is-record.ts";
3
+ import type { ReviewUiState } from "../ui-state.ts";
4
+ import { type Connection, receive, release } from "./review-connection.ts";
5
+ import { isSnapshot, ReviewStore } from "./review-store.ts";
6
+ import { ReviewerRpc } from "./rpc.ts";
7
+
8
+ type Context = Parameters<Plugin.Definition["setup"]>[0];
9
+
10
+ /** The reviewer's status for one directory, kept in sync over the read-only
11
+ * reviewer RPC: a snapshot, then revisioned update events. */
12
+ interface ReviewFeed {
13
+ readonly directory: string | undefined;
14
+ readonly state: ReviewUiState;
15
+ connect(): Promise<void>;
16
+ /** Switches to another directory with an empty state, and reconnects. */
17
+ retarget(directory: string | undefined): void;
18
+ /** Expires overdue reviews (dropping the connection) and dismisses old results. */
19
+ sweep(): void;
20
+ stop(): void;
21
+ }
22
+
23
+ export function createReviewFeed(
24
+ ctx: Context,
25
+ changed: () => void,
26
+ ): ReviewFeed {
27
+ let directory = ctx.location?.directory;
28
+ const rpc = ctx.client.rpc(ReviewerRpc);
29
+ const store = new ReviewStore((status) =>
30
+ ctx.ui.toast.show({
31
+ variant: "warning",
32
+ title: "Manual review required",
33
+ message: status.reason ?? "The host requires your decision.",
34
+ }),
35
+ );
36
+ let stopped = false;
37
+ let controller: AbortController | undefined;
38
+ let reconnect: ReturnType<typeof setTimeout> | undefined;
39
+ const owns = (current: AbortController): boolean =>
40
+ controller === current && !stopped;
41
+ const update = (value: unknown, owner: AbortController): void => {
42
+ if (owner !== controller || owner.signal.aborted) return;
43
+ const outcome = store.accept(value, directory);
44
+ if (outcome === "foreign") owner.abort();
45
+ if (outcome === "applied") changed();
46
+ };
47
+ // Unknown means the UI lacks authoritative state, never human approval.
48
+ const disconnect = (current: AbortController): void => {
49
+ if (!owns(current)) return;
50
+ store.markDisconnected();
51
+ changed();
52
+ };
53
+ const listen = async (connection: Connection): Promise<void> => {
54
+ for await (const event of rpc.events.subscribe("review.updated", {
55
+ signal: connection.controller.signal,
56
+ }))
57
+ receive(event, connection, update);
58
+ };
59
+ // Applies the snapshot; false when the connection was dropped meanwhile.
60
+ const applySnapshot = (value: unknown, connection: Connection): boolean => {
61
+ const snapshot = asObjectLike(value);
62
+ if (!isSnapshot(snapshot, connection.directory))
63
+ throw new Error("Invalid reviewer snapshot");
64
+ if (connection.controller.signal.aborted) return false;
65
+ store.load(snapshot);
66
+ release(connection, update);
67
+ changed();
68
+ return true;
69
+ };
70
+ // Drops the current connection and opens a new one when there is a directory.
71
+ const open = (): Connection | undefined => {
72
+ controller?.abort();
73
+ clearTimeout(reconnect);
74
+ if (!directory || stopped) return;
75
+ controller = new AbortController();
76
+ return { controller, directory, loading: true, buffered: [] };
77
+ };
78
+ const retry = (): void => {
79
+ void connect();
80
+ };
81
+ const connect = async (): Promise<void> => {
82
+ const connection = open();
83
+ if (!connection) return;
84
+ const current = connection.controller;
85
+ const stream = listen(connection);
86
+ void stream.catch(() => {});
87
+ try {
88
+ const snapshot = await rpc.snapshot(
89
+ {},
90
+ {
91
+ location: { directory: connection.directory },
92
+ signal: current.signal,
93
+ },
94
+ );
95
+ if (!applySnapshot(snapshot, connection)) return;
96
+ await stream;
97
+ disconnect(current);
98
+ } catch {
99
+ disconnect(current);
100
+ } finally {
101
+ current.abort();
102
+ await stream.catch(() => {});
103
+ if (owns(current)) reconnect = setTimeout(retry, 1000);
104
+ }
105
+ };
106
+ return {
107
+ get directory(): string | undefined {
108
+ return directory;
109
+ },
110
+ get state(): ReviewUiState {
111
+ return store.state;
112
+ },
113
+ connect,
114
+ retarget: (next: string | undefined): void => {
115
+ directory = next;
116
+ store.reset();
117
+ changed();
118
+ void connect();
119
+ },
120
+ sweep: (): void => {
121
+ const expired = store.state.expire();
122
+ if (expired.length) controller?.abort();
123
+ if (expired.length || store.state.dismissResults().length) changed();
124
+ },
125
+ stop: (): void => {
126
+ stopped = true;
127
+ controller?.abort();
128
+ clearTimeout(reconnect);
129
+ },
130
+ };
131
+ }
@@ -0,0 +1,83 @@
1
+ /** @jsxImportSource @opentui/solid */
2
+
3
+ import type { MouseEvent } from "@opentui/core";
4
+ import type { JSX } from "solid-js";
5
+ import { Show } from "solid-js";
6
+ import type { ReviewUiStatus } from "../ui-protocol.ts";
7
+ import { type ReviewTheme, SPINNER } from "./components.tsx";
8
+
9
+ export function ReviewOverlay(props: {
10
+ theme: () => ReviewTheme;
11
+ status: ReviewUiStatus;
12
+ /** Spinner signal, read inside text children so only those update per tick. */
13
+ frame: () => number;
14
+ }): JSX.Element {
15
+ const theme = props.theme;
16
+ const elapsed = (): string => {
17
+ // Reading the tick signal inside the text child is what re-renders it every
18
+ // 250ms: Date.now() and status.emittedAt are plain values, so a text that
19
+ // reads no signal is evaluated once at mount and freezes.
20
+ props.frame();
21
+ const elapsedMs = Math.max(0, Date.now() - props.status.emittedAt);
22
+ return `${(elapsedMs / 1_000).toFixed(1)}s`;
23
+ };
24
+
25
+ return (
26
+ // biome-ignore lint/a11y/noStaticElementInteractions: <box> is an OpenTUI terminal renderable, not a DOM element, so the ARIA role rule does not apply
27
+ <box
28
+ position="absolute"
29
+ left={0}
30
+ right={0}
31
+ bottom={0}
32
+ height="auto"
33
+ maxHeight={12}
34
+ overflow="hidden"
35
+ backgroundColor={theme().backgroundPanel}
36
+ border={["left"]}
37
+ borderColor={theme().info}
38
+ flexDirection="column"
39
+ onMouseDown={(event: MouseEvent): void => {
40
+ event.preventDefault();
41
+ event.stopPropagation();
42
+ }}
43
+ onMouseUp={(event: MouseEvent): void => {
44
+ event.preventDefault();
45
+ event.stopPropagation();
46
+ }}
47
+ >
48
+ <box
49
+ flexDirection="column"
50
+ gap={1}
51
+ paddingTop={1}
52
+ paddingBottom={1}
53
+ paddingLeft={2}
54
+ paddingRight={3}
55
+ >
56
+ <box flexDirection="row" gap={1}>
57
+ <text fg={theme().info}>
58
+ {SPINNER[props.frame() % SPINNER.length] ?? "◐"}
59
+ </text>
60
+ <text fg={theme().text}>Reviewing this permission</text>
61
+ <box flexGrow={1} />
62
+ <text fg={theme().textMuted}>{elapsed()}</text>
63
+ </box>
64
+ <box flexDirection="row" gap={1} paddingLeft={2}>
65
+ <text fg={theme().textMuted}>{props.status.permission}</text>
66
+ <text fg={theme().text} wrapMode="word">
67
+ {props.status.action}
68
+ </text>
69
+ <Show when={props.status.actorName}>
70
+ <text fg={theme().textMuted}>· actor {props.status.actorName}</text>
71
+ </Show>
72
+ </box>
73
+ <box paddingLeft={2} flexDirection="row" gap={1}>
74
+ <text fg={theme().textMuted}>
75
+ {props.status.model} · reasoning {props.status.variant}
76
+ </text>
77
+ <box flexGrow={1} />
78
+ <text fg={theme().textMuted}>No action needed</text>
79
+ </box>
80
+ </box>
81
+ </box>
82
+ );
83
+ }
@@ -0,0 +1,56 @@
1
+ /** @jsxImportSource @opentui/solid */
2
+
3
+ import type { ColorInput } from "@opentui/core";
4
+ import type { JSX } from "solid-js";
5
+ import { Show } from "solid-js";
6
+ import type { ReviewUiStatus } from "../ui-protocol.ts";
7
+ import { type ReviewTheme, singleLine } from "./components.tsx";
8
+
9
+ export function ReviewResult(props: {
10
+ theme: () => ReviewTheme;
11
+ status: ReviewUiStatus;
12
+ }): JSX.Element {
13
+ const theme = props.theme;
14
+ const appearance = (): { color: ColorInput; icon: string; title: string } => {
15
+ if (props.status.phase === "unknown") {
16
+ return {
17
+ color: theme().textMuted,
18
+ icon: "?",
19
+ title: "Review status unavailable",
20
+ };
21
+ }
22
+ if (props.status.phase === "approved") {
23
+ return { color: theme().success, icon: "✓", title: "Review approved" };
24
+ }
25
+ // Fail-closed escalate→deny is distinct from an explicit reviewer/policy deny.
26
+ if (props.status.escalationDisposition === "deny") {
27
+ return {
28
+ color: theme().error,
29
+ icon: "✕",
30
+ title: "Review blocked (fail-closed)",
31
+ };
32
+ }
33
+ return { color: theme().error, icon: "✕", title: "Review blocked" };
34
+ };
35
+ return (
36
+ <box
37
+ height={props.status.reason ? 2 : 1}
38
+ flexShrink={0}
39
+ overflow="hidden"
40
+ backgroundColor={theme().backgroundPanel}
41
+ flexDirection="column"
42
+ paddingLeft={1}
43
+ paddingRight={1}
44
+ >
45
+ <text fg={appearance().color} wrapMode="none" truncate>
46
+ {appearance().icon} {appearance().title} · {props.status.permission} ·{" "}
47
+ {singleLine(props.status.action)}
48
+ </text>
49
+ <Show when={props.status.reason}>
50
+ <text fg={theme().textMuted} wrapMode="none" truncate>
51
+ {singleLine(props.status.reason ?? "")}
52
+ </text>
53
+ </Show>
54
+ </box>
55
+ );
56
+ }
@@ -0,0 +1,88 @@
1
+ import { asObjectLike } from "../is-record.ts";
2
+ import {
3
+ decodeUiStatus,
4
+ encodeUiStatus,
5
+ type ReviewUiStatus,
6
+ } from "../ui-protocol.ts";
7
+ import { ReviewUiState } from "../ui-state.ts";
8
+
9
+ interface ReviewSnapshot extends Record<string, unknown> {
10
+ generation: string;
11
+ revision: number;
12
+ reviews: unknown[];
13
+ }
14
+
15
+ export function isSnapshot(
16
+ value: Record<string, unknown> | undefined,
17
+ directory: string,
18
+ ): value is ReviewSnapshot {
19
+ return (
20
+ value !== undefined &&
21
+ value.directory === directory &&
22
+ typeof value.generation === "string" &&
23
+ typeof value.revision === "number" &&
24
+ Array.isArray(value.reviews)
25
+ );
26
+ }
27
+
28
+ const emptyState = (): ReviewUiState =>
29
+ new ReviewUiState({ model: "", variant: "", timeoutMs: 180_000 });
30
+
31
+ /** The review statuses of one reviewer generation, applied in revision order. */
32
+ export class ReviewStore {
33
+ state: ReviewUiState = emptyState();
34
+ private generation: string | undefined;
35
+ private sequence = -1;
36
+
37
+ constructor(
38
+ private readonly notifyManual: (status: ReviewUiStatus) => void,
39
+ ) {}
40
+
41
+ reset(): void {
42
+ this.state = emptyState();
43
+ }
44
+
45
+ load(snapshot: ReviewSnapshot): void {
46
+ this.state = emptyState();
47
+ this.generation = snapshot.generation;
48
+ this.sequence = snapshot.revision;
49
+ for (const status of snapshot.reviews) this.apply(status);
50
+ }
51
+
52
+ /**
53
+ * Applies an update event for `directory` when it belongs to the loaded
54
+ * generation and its revision is newer. "foreign" names another generation.
55
+ */
56
+ accept(
57
+ value: unknown,
58
+ directory: string | undefined,
59
+ ): "ignored" | "foreign" | "applied" {
60
+ const event = asObjectLike(value);
61
+ if (!event || event.directory !== directory) return "ignored";
62
+ if (typeof event.generation !== "string") return "ignored";
63
+ if (event.generation !== this.generation) return "foreign";
64
+ if (typeof event.revision !== "number" || event.revision <= this.sequence)
65
+ return "ignored";
66
+ this.sequence = event.revision;
67
+ this.apply(event.status);
68
+ return "applied";
69
+ }
70
+
71
+ markDisconnected(): void {
72
+ for (const status of this.state.all())
73
+ if (status.phase === "reviewing")
74
+ this.state.apply({
75
+ ...status,
76
+ phase: "unknown",
77
+ emittedAt: Date.now(),
78
+ reason: "Reconnecting to reviewer status",
79
+ });
80
+ }
81
+
82
+ private apply(value: unknown): void {
83
+ const status = decodeUiStatus(encodeUiStatus(value as ReviewUiStatus));
84
+ if (!status) return;
85
+ this.state.apply(status);
86
+ if (status.phase === "manual") this.notifyManual(status);
87
+ }
88
+ }
@@ -0,0 +1,63 @@
1
+ import type { ColorInput } from "@opentui/core";
2
+ import { asObjectLike } from "../is-record.ts";
3
+ import type { ReviewTheme } from "./components.tsx";
4
+
5
+ const color = (value: unknown): ColorInput | undefined => {
6
+ if (typeof value === "string") return value;
7
+ const candidate = asObjectLike(value);
8
+ return candidate && "buffer" in candidate ? (value as ColorInput) : undefined;
9
+ };
10
+ const FALLBACK_THEME: Record<keyof ReviewTheme, string> = {
11
+ backgroundPanel: "#111111",
12
+ text: "#eeeeee",
13
+ textMuted: "#999999",
14
+ info: "#4da3ff",
15
+ success: "#48c774",
16
+ error: "#ff5c5c",
17
+ };
18
+
19
+ export function resolveReviewTheme(value: unknown): ReviewTheme {
20
+ const host = asObjectLike(value);
21
+ if (!host) return FALLBACK_THEME;
22
+ const background = asObjectLike(host.background);
23
+ const surface = asObjectLike(background?.surface);
24
+ const raised = asObjectLike(background?.raised);
25
+ const text = asObjectLike(host.text);
26
+ const status = asObjectLike(text?.status);
27
+ const feedback = asObjectLike(text?.feedback);
28
+ const infoFeedback = asObjectLike(feedback?.info);
29
+ const successFeedback = asObjectLike(feedback?.success);
30
+ const errorFeedback = asObjectLike(feedback?.error);
31
+ return {
32
+ backgroundPanel:
33
+ color(surface?.overlay) ??
34
+ color(raised?.base) ??
35
+ color(host.backgroundPanel) ??
36
+ FALLBACK_THEME.backgroundPanel,
37
+ text:
38
+ color(text?.default) ??
39
+ color(text?.base) ??
40
+ color(host.text) ??
41
+ FALLBACK_THEME.text,
42
+ textMuted:
43
+ color(text?.subdued) ??
44
+ color(text?.muted) ??
45
+ color(host.textMuted) ??
46
+ FALLBACK_THEME.textMuted,
47
+ info:
48
+ color(status?.running) ??
49
+ color(infoFeedback?.base) ??
50
+ color(host.info) ??
51
+ FALLBACK_THEME.info,
52
+ success:
53
+ color(successFeedback?.default) ??
54
+ color(successFeedback?.base) ??
55
+ color(host.success) ??
56
+ FALLBACK_THEME.success,
57
+ error:
58
+ color(errorFeedback?.default) ??
59
+ color(errorFeedback?.base) ??
60
+ color(host.error) ??
61
+ FALLBACK_THEME.error,
62
+ };
63
+ }
@@ -6,11 +6,14 @@ export const ReviewerRpc = {
6
6
  input: { type: "object", additionalProperties: false },
7
7
  output: { type: "string" },
8
8
  },
9
- status: { input: { type: "object", additionalProperties: false }, output: { type: "object" } },
9
+ status: {
10
+ input: { type: "object", additionalProperties: false },
11
+ output: { type: "object" },
12
+ },
10
13
  snapshot: {
11
14
  input: { type: "object", additionalProperties: false },
12
15
  output: { type: "object" },
13
16
  },
14
17
  },
15
18
  events: { "review.updated": { schema: { type: "object" } } },
16
- } as const
19
+ } as const;