@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,137 @@
1
+ // The server's config warnings in the TUI: one toast per distinct entry per
2
+ // TUI session, and a one-line sidebar summary while any remain. The same
3
+ // `status` read also names the server's reasoning reviewer.
4
+ import { asObjectLike } from "../is-record.ts";
5
+
6
+ interface NoticeLists {
7
+ configWarnings?: readonly string[] | undefined;
8
+ configDegraded?: readonly string[] | undefined;
9
+ }
10
+
11
+ export interface ConfigToast {
12
+ variant: "warning" | "error";
13
+ title: string;
14
+ message: string;
15
+ }
16
+
17
+ export interface SidebarLine {
18
+ text: string;
19
+ tone: "warning" | "error";
20
+ }
21
+
22
+ /** Keyed by the exact text `systemOneRoutingWarnings` emits; a reworded
23
+ * warning falls back to its full text. */
24
+ const SHORT_WARNINGS: Readonly<Record<string, string>> = {
25
+ 'systemOneEscalation "reasoning-first" is inactive: no escalationReviewer is configured; Jev escalations still go to you':
26
+ "reasoning-first inactive (no escalationReviewer)",
27
+ 'systemOneEscalation "reasoning-first" is inactive: the reviewer model is not Jev':
28
+ "reasoning-first inactive (model is not Jev)",
29
+ "systemOneDenialReview is inactive: no escalationReviewer is configured; Jev denials stay final":
30
+ "denial review inactive (no escalationReviewer)",
31
+ "systemOneDenialReview is inactive: the reviewer model is not Jev":
32
+ "denial review inactive (model is not Jev)",
33
+ };
34
+
35
+ const strings = (value: unknown): string[] =>
36
+ Array.isArray(value)
37
+ ? value.filter((entry): entry is string => typeof entry === "string")
38
+ : [];
39
+
40
+ const warningToast = (warning: string): ConfigToast => ({
41
+ variant: "warning",
42
+ title: "Permission reviewer config",
43
+ message: warning,
44
+ });
45
+
46
+ const degradedToast = (reason: string): ConfigToast => ({
47
+ variant: "error",
48
+ title: "Permission reviewer config degraded",
49
+ message: `Automatic approval is disabled: ${reason}.`,
50
+ });
51
+
52
+ /** No dedupe here: `ConfigNotices.update` shows each entry once per session. */
53
+ export function configToasts(
54
+ warnings: readonly string[],
55
+ degraded: readonly string[],
56
+ ): ConfigToast[] {
57
+ return [...degraded.map(degradedToast), ...warnings.map(warningToast)];
58
+ }
59
+
60
+ /** The sidebar summary: the only entry, or the count and the first, degraded
61
+ * reasons first; undefined for a healthy config. */
62
+ export function sidebarLine(
63
+ warnings: readonly string[],
64
+ degraded: readonly string[],
65
+ ): SidebarLine | undefined {
66
+ const items = [
67
+ ...degraded.map((reason) => `auto-approval disabled (${reason})`),
68
+ ...warnings.map((warning) => SHORT_WARNINGS[warning] ?? warning),
69
+ ];
70
+ const first = items[0];
71
+ if (first === undefined) return;
72
+ const tone: SidebarLine["tone"] = degraded.length > 0 ? "error" : "warning";
73
+ const icon = tone === "error" ? "✕" : "⚠";
74
+ const body =
75
+ items.length === 1 ? first : `${items.length} config warnings · ${first}`;
76
+ return { text: `${icon} reviewer: ${body}`, tone };
77
+ }
78
+
79
+ export class ConfigNotices {
80
+ private readonly shown = new Set<string>();
81
+ private warnings: readonly string[] = [];
82
+ private degraded: readonly string[] = [];
83
+ private reviewer: string | undefined;
84
+
85
+ constructor(private readonly show: (toast: ConfigToast) => void) {}
86
+
87
+ /** The server's `escalationReviewer` model from the last applied `status`
88
+ * read; undefined before one, after `reset`, or when none is configured. */
89
+ get reasoningModel(): string | undefined {
90
+ return this.reviewer;
91
+ }
92
+
93
+ /** For another directory's server. Keeps `shown`, so an entry already
94
+ * toasted is not toasted again. */
95
+ reset(): void {
96
+ this.reviewer = undefined;
97
+ this.update({});
98
+ }
99
+
100
+ /** Takes the server's current lists (absent means none) and toasts each
101
+ * entry not yet shown in this TUI session. */
102
+ update(lists: NoticeLists): void {
103
+ this.warnings = lists.configWarnings ?? [];
104
+ this.degraded = lists.configDegraded ?? [];
105
+ for (const toast of configToasts(this.warnings, this.degraded)) {
106
+ const key = `${toast.variant}:${toast.message}`;
107
+ if (this.shown.has(key)) continue;
108
+ this.shown.add(key);
109
+ this.show(toast);
110
+ }
111
+ }
112
+
113
+ /** Reads the lists from the reviewer's `status` RPC. True when applied; a
114
+ * failed call, or one whose connection was dropped, changes nothing. */
115
+ async refresh(
116
+ call: () => Promise<unknown>,
117
+ signal: AbortSignal,
118
+ ): Promise<boolean> {
119
+ try {
120
+ const status = asObjectLike(await call());
121
+ if (status === undefined || signal.aborted) return false;
122
+ const model = status.escalationReviewerModel;
123
+ this.reviewer = typeof model === "string" ? model : undefined;
124
+ this.update({
125
+ configWarnings: strings(status.configWarnings),
126
+ configDegraded: strings(status.configDegraded),
127
+ });
128
+ return true;
129
+ } catch {
130
+ return false;
131
+ }
132
+ }
133
+
134
+ sidebar(): SidebarLine | undefined {
135
+ return sidebarLine(this.warnings, this.degraded);
136
+ }
137
+ }
@@ -0,0 +1,76 @@
1
+ // Measuring, slicing and merging fitted action parts.
2
+
3
+ import { LINE_BREAK } from "../ui-text-elide.ts";
4
+ import type { ActionFitPart } from "./action-fit.ts";
5
+
6
+ /** A part as the fit builds it; `whole` marks one a cut may not split. */
7
+ export interface FitPart extends ActionFitPart {
8
+ whole?: boolean;
9
+ }
10
+
11
+ const STANDALONE_BREAK = new RegExp(`(?<!\\\\)${LINE_BREAK}`);
12
+
13
+ /** Columns `text` takes, one per code point. */
14
+ export function textColumns(text: string): number {
15
+ return Array.from(text).length;
16
+ }
17
+
18
+ export function partsColumns(parts: readonly FitPart[]): number {
19
+ return parts.reduce(
20
+ (sum: number, part: ActionFitPart): number => sum + textColumns(part.text),
21
+ 0,
22
+ );
23
+ }
24
+
25
+ export const shown = (parts: readonly ActionFitPart[]): string =>
26
+ parts.map((part: ActionFitPart): string => part.text).join("");
27
+
28
+ function expandPart(part: FitPart): ActionFitPart[] {
29
+ if (part.muted || !STANDALONE_BREAK.test(part.text))
30
+ return [{ text: part.text, muted: part.muted }];
31
+ return part.text
32
+ .split(STANDALONE_BREAK)
33
+ .flatMap((piece, index) => [
34
+ ...(index === 0 ? [] : [{ text: LINE_BREAK, muted: true }]),
35
+ { text: piece, muted: false },
36
+ ]);
37
+ }
38
+
39
+ /** Drops empty parts, mutes line-break markers, and merges neighbours that
40
+ * share `muted`. */
41
+ export function merged(parts: readonly FitPart[]): ActionFitPart[] {
42
+ const out: ActionFitPart[] = [];
43
+ for (const part of parts.flatMap(expandPart)) {
44
+ const last = out.at(-1);
45
+ if (part.text === "") continue;
46
+ if (last !== undefined && last.muted === part.muted)
47
+ out[out.length - 1] = {
48
+ text: `${last.text}${part.text}`,
49
+ muted: part.muted,
50
+ };
51
+ else out.push(part);
52
+ }
53
+ return out;
54
+ }
55
+
56
+ /** The code points `start` to `end` of `parts`. A muted or `whole` part (a
57
+ * heredoc marker or a separator) is kept whole or dropped, never cut. */
58
+ export function sliceParts(
59
+ parts: readonly FitPart[],
60
+ start: number,
61
+ end: number,
62
+ ): FitPart[] {
63
+ const out: FitPart[] = [];
64
+ let offset = 0;
65
+ for (const part of parts) {
66
+ const chars = Array.from(part.text);
67
+ const from = Math.max(start - offset, 0);
68
+ const to = Math.max(0, Math.min(end - offset, chars.length));
69
+ offset += chars.length;
70
+ const text = chars.slice(from, to).join("");
71
+ const cut = text.trim() !== part.text.trim();
72
+ if (text === "" || ((part.muted || part.whole === true) && cut)) continue;
73
+ out.push({ ...part, text });
74
+ }
75
+ return out;
76
+ }
@@ -0,0 +1,87 @@
1
+ // The toast a manual outcome raises: title, variant and lead sentence follow
2
+ // how the review ended, then the reason.
3
+ import { failureKind } from "../failure-kind.ts";
4
+ import type { ReviewUiStatus } from "../ui-protocol.ts";
5
+ import { handoffCause, modelLabel, shortModelName } from "./attribution.ts";
6
+
7
+ export interface ManualToast {
8
+ variant: "warning" | "error";
9
+ title: string;
10
+ message: string;
11
+ }
12
+
13
+ const NO_TIME_LEAD = "No review time left for";
14
+ const GENERIC_REVIEWER = "the reasoning reviewer";
15
+ /** `budgetExhaustedResult`'s reason (`src/system-one/system-one-budget.ts`):
16
+ * "<lead> after <cause>: <budget sentence> <Jev reason>". */
17
+ const BUDGET_REASON =
18
+ /^No review time left for the reasoning reviewer after (.+?): ([\s\S]*)$/;
19
+
20
+ const warning = (message: string): ManualToast => ({
21
+ variant: "warning",
22
+ title: "Manual review required",
23
+ message,
24
+ });
25
+
26
+ const withReason = (lead: string, reason: string | undefined): string =>
27
+ reason ? `${lead} ${reason}` : lead;
28
+
29
+ /** Without a hand-off, `status.model` is the reasoning reviewer on these
30
+ * resolutions. */
31
+ const reasoningModel = (status: ReviewUiStatus): string =>
32
+ modelLabel(status.handoff?.to ?? status.model);
33
+
34
+ function unavailable(status: ReviewUiStatus): ManualToast {
35
+ const kind = failureKind(status.reason ?? "");
36
+ const failed = kind === undefined ? "failed" : `failed (${kind})`;
37
+ return {
38
+ variant: "error",
39
+ title: "Reasoning reviewer unavailable",
40
+ message: withReason(
41
+ `${reasoningModel(status)} ${failed}. This permission needs your approval.`,
42
+ status.reason,
43
+ ),
44
+ };
45
+ }
46
+
47
+ /** The engine's reason repeats the lead, so it is reshaped rather than
48
+ * appended to. */
49
+ function noTimeLeft(
50
+ status: ReviewUiStatus,
51
+ reviewer: string | undefined,
52
+ ): string {
53
+ const { handoff, reason } = status;
54
+ const parts = reason === undefined ? null : BUDGET_REASON.exec(reason);
55
+ if (handoff !== undefined)
56
+ return withReason(
57
+ `${NO_TIME_LEAD} ${shortModelName(handoff.to) || GENERIC_REVIEWER} after Jev (${handoffCause(handoff)}).`,
58
+ parts === null ? reason : parts[2],
59
+ );
60
+ if (reason === undefined)
61
+ return `${NO_TIME_LEAD} ${GENERIC_REVIEWER} after Jev.`;
62
+ if (parts === null) return reason;
63
+ const name = shortModelName(reviewer ?? "") || GENERIC_REVIEWER;
64
+ return `${NO_TIME_LEAD} ${name} after Jev (${parts[1]}). ${parts[2]}`;
65
+ }
66
+
67
+ /** `fallback` stands in for a missing reason on a `reasoning-escalated` or
68
+ * plain manual toast; `reasoningReviewer` names the configured reasoning
69
+ * model for a review that ran out of time before the hand-off. */
70
+ export function manualToast(
71
+ status: ReviewUiStatus,
72
+ fallback: string,
73
+ reasoningReviewer?: string,
74
+ ): ManualToast {
75
+ switch (status.resolution) {
76
+ case "reasoning-escalated":
77
+ return warning(
78
+ `${reasoningModel(status)} reviewed this after Jev; it needs your approval: ${status.reason ?? fallback}`,
79
+ );
80
+ case "reasoning-unavailable":
81
+ return unavailable(status);
82
+ case "budget-exhausted":
83
+ return warning(noTimeLeft(status, reasoningReviewer));
84
+ default:
85
+ return warning(status.reason ?? fallback);
86
+ }
87
+ }
@@ -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,156 @@
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 { ConfigNotices } from "./config-notices.ts";
5
+ import { manualToast } from "./manual-toast.ts";
6
+ import { type Connection, receive, release } from "./review-connection.ts";
7
+ import { isSnapshot, ReviewStore } from "./review-store.ts";
8
+ import { ReviewerRpc } from "./rpc.ts";
9
+
10
+ type Context = Parameters<Plugin.Definition["setup"]>[0];
11
+
12
+ /** The reviewer's status for one directory, kept in sync over the read-only
13
+ * reviewer RPC: a snapshot, then revisioned update events. */
14
+ interface ReviewFeed {
15
+ readonly directory: string | undefined;
16
+ readonly state: ReviewUiState;
17
+ /** The server's config warnings for the current directory. */
18
+ readonly notices: ConfigNotices;
19
+ connect(): Promise<void>;
20
+ /** Switches to another directory with an empty state, and reconnects. */
21
+ retarget(directory: string | undefined): void;
22
+ /** Expires overdue reviews (dropping the connection) and dismisses old results. */
23
+ sweep(): void;
24
+ stop(): void;
25
+ }
26
+
27
+ export function createReviewFeed(
28
+ ctx: Context,
29
+ changed: () => void,
30
+ ): ReviewFeed {
31
+ let directory = ctx.location?.directory;
32
+ const rpc = ctx.client.rpc(ReviewerRpc);
33
+ const notices = new ConfigNotices((toast) => ctx.ui.toast.show(toast));
34
+ const store = new ReviewStore((status) =>
35
+ ctx.ui.toast.show(
36
+ manualToast(
37
+ status,
38
+ "The host requires your decision.",
39
+ notices.reasoningModel,
40
+ ),
41
+ ),
42
+ );
43
+ // Read once per connection; a failed call leaves the notices as they are.
44
+ const refreshNotices = async (connection: Connection): Promise<void> => {
45
+ const { directory: target, controller: owner } = connection;
46
+ const applied = await notices.refresh(
47
+ () =>
48
+ rpc.status(
49
+ {},
50
+ { location: { directory: target }, signal: owner.signal },
51
+ ),
52
+ owner.signal,
53
+ );
54
+ if (applied) changed();
55
+ };
56
+ let stopped = false;
57
+ let controller: AbortController | undefined;
58
+ let reconnect: ReturnType<typeof setTimeout> | undefined;
59
+ const owns = (current: AbortController): boolean =>
60
+ controller === current && !stopped;
61
+ const update = (value: unknown, owner: AbortController): void => {
62
+ if (owner !== controller || owner.signal.aborted) return;
63
+ const outcome = store.accept(value, directory);
64
+ if (outcome === "foreign") owner.abort();
65
+ if (outcome === "applied") changed();
66
+ };
67
+ // Unknown means the UI lacks authoritative state, never human approval.
68
+ const disconnect = (current: AbortController): void => {
69
+ if (!owns(current)) return;
70
+ store.markDisconnected();
71
+ changed();
72
+ };
73
+ const listen = async (connection: Connection): Promise<void> => {
74
+ for await (const event of rpc.events.subscribe("review.updated", {
75
+ signal: connection.controller.signal,
76
+ }))
77
+ receive(event, connection, update);
78
+ };
79
+ // Applies the snapshot; false when the connection was dropped meanwhile.
80
+ const applySnapshot = (value: unknown, connection: Connection): boolean => {
81
+ const snapshot = asObjectLike(value);
82
+ if (!isSnapshot(snapshot, connection.directory))
83
+ throw new Error("Invalid reviewer snapshot");
84
+ if (connection.controller.signal.aborted) return false;
85
+ store.load(snapshot);
86
+ release(connection, update);
87
+ changed();
88
+ return true;
89
+ };
90
+ // Drops the current connection and opens a new one when there is a directory.
91
+ const open = (): Connection | undefined => {
92
+ controller?.abort();
93
+ clearTimeout(reconnect);
94
+ if (!directory || stopped) return;
95
+ controller = new AbortController();
96
+ return { controller, directory, loading: true, buffered: [] };
97
+ };
98
+ const retry = (): void => {
99
+ void connect();
100
+ };
101
+ const connect = async (): Promise<void> => {
102
+ const connection = open();
103
+ if (!connection) return;
104
+ const current = connection.controller;
105
+ const stream = listen(connection);
106
+ void stream.catch(() => {});
107
+ void refreshNotices(connection);
108
+ try {
109
+ const snapshot = await rpc.snapshot(
110
+ {},
111
+ {
112
+ location: { directory: connection.directory },
113
+ signal: current.signal,
114
+ },
115
+ );
116
+ if (!applySnapshot(snapshot, connection)) return;
117
+ await stream;
118
+ disconnect(current);
119
+ } catch {
120
+ disconnect(current);
121
+ } finally {
122
+ current.abort();
123
+ await stream.catch(() => {});
124
+ if (owns(current)) reconnect = setTimeout(retry, 1000);
125
+ }
126
+ };
127
+ return {
128
+ get directory(): string | undefined {
129
+ return directory;
130
+ },
131
+ get state(): ReviewUiState {
132
+ return store.state;
133
+ },
134
+ get notices(): ConfigNotices {
135
+ return notices;
136
+ },
137
+ connect,
138
+ retarget: (next: string | undefined): void => {
139
+ directory = next;
140
+ store.reset();
141
+ notices.reset();
142
+ changed();
143
+ void connect();
144
+ },
145
+ sweep: (): void => {
146
+ const expired = store.state.expire();
147
+ if (expired.length) controller?.abort();
148
+ if (expired.length || store.state.dismissResults().length) changed();
149
+ },
150
+ stop: (): void => {
151
+ stopped = true;
152
+ controller?.abort();
153
+ clearTimeout(reconnect);
154
+ },
155
+ };
156
+ }
@@ -0,0 +1,111 @@
1
+ /** @jsxImportSource @opentui/solid */
2
+
3
+ import type { MouseEvent } from "@opentui/core";
4
+ import { useTerminalDimensions } from "@opentui/solid";
5
+ import type { JSX } from "solid-js";
6
+ import { Show } from "solid-js";
7
+ import type { ReviewUiStatus } from "../ui-protocol.ts";
8
+ import { type ActionFitPart, fitAction } from "./action-fit.ts";
9
+ import { ActionSpans, overlayActionColumns } from "./action-spans.tsx";
10
+ import { handoffPhrase, modelLabel } from "./attribution.ts";
11
+ import { type ReviewTheme, SPINNER } from "./components.tsx";
12
+
13
+ export function ReviewOverlay(props: {
14
+ theme: () => ReviewTheme;
15
+ status: ReviewUiStatus;
16
+ /** Spinner signal, read inside text children so only those update per tick. */
17
+ frame: () => number;
18
+ }): JSX.Element {
19
+ const theme = props.theme;
20
+ const elapsed = (): string => {
21
+ // Reading the tick signal inside the text child is what re-renders it every
22
+ // 250ms: Date.now() and status.emittedAt are plain values, so a text that
23
+ // reads no signal is evaluated once at mount and freezes.
24
+ props.frame();
25
+ const elapsedMs = Math.max(0, Date.now() - props.status.emittedAt);
26
+ return `${(elapsedMs / 1_000).toFixed(1)}s`;
27
+ };
28
+ const terminal = useTerminalDimensions();
29
+ const action = (): ActionFitPart[] =>
30
+ fitAction(
31
+ props.status,
32
+ overlayActionColumns(
33
+ terminal().width,
34
+ props.status.permission,
35
+ props.status.actorName,
36
+ ),
37
+ );
38
+
39
+ return (
40
+ // biome-ignore lint/a11y/noStaticElementInteractions: <box> is an OpenTUI terminal renderable, not a DOM element, so the ARIA role rule does not apply
41
+ <box
42
+ position="absolute"
43
+ left={0}
44
+ right={0}
45
+ bottom={0}
46
+ height="auto"
47
+ maxHeight={12}
48
+ overflow="hidden"
49
+ backgroundColor={theme().backgroundPanel}
50
+ border={["left"]}
51
+ borderColor={theme().info}
52
+ flexDirection="column"
53
+ onMouseDown={(event: MouseEvent): void => {
54
+ event.preventDefault();
55
+ event.stopPropagation();
56
+ }}
57
+ onMouseUp={(event: MouseEvent): void => {
58
+ event.preventDefault();
59
+ event.stopPropagation();
60
+ }}
61
+ >
62
+ <box
63
+ flexDirection="column"
64
+ gap={1}
65
+ paddingTop={1}
66
+ paddingBottom={1}
67
+ paddingLeft={2}
68
+ paddingRight={3}
69
+ >
70
+ <box flexDirection="row" gap={1}>
71
+ <text fg={theme().info}>
72
+ {SPINNER[props.frame() % SPINNER.length] ?? "◐"}
73
+ </text>
74
+ <text fg={theme().text}>Reviewing this permission</text>
75
+ <box flexGrow={1} />
76
+ <text fg={theme().textMuted}>{elapsed()}</text>
77
+ </box>
78
+ <box flexDirection="row" gap={1} paddingLeft={2}>
79
+ <text fg={theme().textMuted} flexShrink={0}>
80
+ {props.status.permission}
81
+ </text>
82
+ <text fg={theme().text} wrapMode="char" flexShrink={1} minWidth={0}>
83
+ <ActionSpans
84
+ parts={action()}
85
+ color={theme().text}
86
+ muted={theme().textMuted}
87
+ />
88
+ </text>
89
+ <Show when={props.status.actorName}>
90
+ <text fg={theme().textMuted} flexShrink={0}>
91
+ · actor {props.status.actorName}
92
+ </text>
93
+ </Show>
94
+ </box>
95
+ <box paddingLeft={2} flexDirection="row" gap={1}>
96
+ <text fg={theme().textMuted}>
97
+ {modelLabel(props.status.handoff?.to ?? props.status.model)} ·
98
+ reasoning {props.status.variant}
99
+ <Show when={handoffPhrase(props.status)} keyed>
100
+ {(phrase: string) => (
101
+ <span style={{ fg: theme().info }}> · {phrase}</span>
102
+ )}
103
+ </Show>
104
+ </text>
105
+ <box flexGrow={1} />
106
+ <text fg={theme().textMuted}>No action needed</text>
107
+ </box>
108
+ </box>
109
+ </box>
110
+ );
111
+ }
@@ -0,0 +1,74 @@
1
+ /** @jsxImportSource @opentui/solid */
2
+
3
+ import type { ColorInput } from "@opentui/core";
4
+ import { useTerminalDimensions } from "@opentui/solid";
5
+ import type { JSX } from "solid-js";
6
+ import { Show } from "solid-js";
7
+ import type { ReviewUiStatus } from "../ui-protocol.ts";
8
+ import { type ActionFitPart, fitAction, singleLine } from "./action-fit.ts";
9
+ import { ActionSpans, stripActionColumns } from "./action-spans.tsx";
10
+ import { resultDetail } from "./attribution.ts";
11
+ import type { ReviewTheme } from "./components.tsx";
12
+
13
+ export function ReviewResult(props: {
14
+ theme: () => ReviewTheme;
15
+ status: ReviewUiStatus;
16
+ }): JSX.Element {
17
+ const theme = props.theme;
18
+ const appearance = (): { color: ColorInput; icon: string; title: string } => {
19
+ if (props.status.phase === "unknown") {
20
+ return {
21
+ color: theme().textMuted,
22
+ icon: "?",
23
+ title: "Review status unavailable",
24
+ };
25
+ }
26
+ if (props.status.phase === "approved") {
27
+ return { color: theme().success, icon: "✓", title: "Review approved" };
28
+ }
29
+ // Fail-closed escalate→deny is distinct from an explicit reviewer/policy deny.
30
+ if (props.status.escalationDisposition === "deny") {
31
+ return {
32
+ color: theme().error,
33
+ icon: "✕",
34
+ title: "Review blocked (fail-closed)",
35
+ };
36
+ }
37
+ return { color: theme().error, icon: "✕", title: "Review blocked" };
38
+ };
39
+ const terminal = useTerminalDimensions();
40
+ const action = (): ActionFitPart[] =>
41
+ fitAction(
42
+ props.status,
43
+ stripActionColumns(
44
+ terminal().width,
45
+ `${appearance().icon} ${appearance().title} · ${props.status.permission} · `,
46
+ ),
47
+ );
48
+ const detail = (): string | undefined => resultDetail(props.status);
49
+ return (
50
+ <box
51
+ height={detail() ? 2 : 1}
52
+ flexShrink={0}
53
+ overflow="hidden"
54
+ backgroundColor={theme().backgroundPanel}
55
+ flexDirection="column"
56
+ paddingLeft={1}
57
+ paddingRight={1}
58
+ >
59
+ <text fg={appearance().color} wrapMode="none" truncate>
60
+ {appearance().icon} {appearance().title} · {props.status.permission} ·{" "}
61
+ <ActionSpans
62
+ parts={action()}
63
+ color={appearance().color}
64
+ muted={theme().textMuted}
65
+ />
66
+ </text>
67
+ <Show when={detail()}>
68
+ <text fg={theme().textMuted} wrapMode="none" truncate>
69
+ {singleLine(detail() ?? "")}
70
+ </text>
71
+ </Show>
72
+ </box>
73
+ );
74
+ }