@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,161 @@
1
+ // Ships to the TUI, so it imports no shell module.
2
+
3
+ import type { ActionSegment, ReviewUiStatus } from "../ui-protocol.ts";
4
+ import { ELISION, elideMiddle, keepHead, keepTail } from "../ui-text-elide.ts";
5
+ import {
6
+ type FitPart,
7
+ merged,
8
+ partsColumns,
9
+ shown,
10
+ sliceParts,
11
+ textColumns,
12
+ } from "./fit-parts.ts";
13
+
14
+ export interface ActionFitPart {
15
+ text: string;
16
+ muted: boolean;
17
+ }
18
+
19
+ const ELLIPSIS = "⋯";
20
+ /** Narrowest width that still shows a character on each side of " ⋯ ". */
21
+ const MIN_ELIDED_COLUMNS = 5;
22
+
23
+ /** Collapses line breaks and tabs so a value renders on one row. */
24
+ export const singleLine = (value: string): string =>
25
+ value.replace(/[\r\n\t]+/g, " ");
26
+
27
+ function separatorText(separator: string | undefined): string {
28
+ if (separator === undefined) return "";
29
+ return separator === ";" ? ";" : ` ${separator}`;
30
+ }
31
+
32
+ function segmentParts(segment: ActionSegment): FitPart[] {
33
+ const parts: FitPart[] = [{ text: singleLine(segment.text), muted: false }];
34
+ if (segment.heredocLines !== undefined)
35
+ parts.push({
36
+ text: ` ${ELLIPSIS} ${segment.heredocLines}-line heredoc ${ELLIPSIS}`,
37
+ muted: true,
38
+ });
39
+ parts.push({
40
+ text: separatorText(segment.separator),
41
+ muted: false,
42
+ whole: true,
43
+ });
44
+ return parts;
45
+ }
46
+
47
+ function joined(segments: readonly ActionSegment[]): FitPart[] {
48
+ return segments.flatMap(
49
+ (segment: ActionSegment, index: number): FitPart[] => [
50
+ { text: index === 0 ? "" : " ", muted: false },
51
+ ...segmentParts(segment),
52
+ ],
53
+ );
54
+ }
55
+
56
+ const hiddenCount = (hidden: number): string =>
57
+ ` ${ELLIPSIS} ${hidden} more ${ELLIPSIS} `;
58
+
59
+ /** The first segment, a muted count of the hidden ones, and the most
60
+ * trailing segments that fit; undefined when not even the last one fits,
61
+ * or fewer than three segments leave nothing to hide. */
62
+ function elided(
63
+ segments: readonly ActionSegment[],
64
+ columns: number,
65
+ ): FitPart[] | undefined {
66
+ const [first, ...rest] = segments;
67
+ if (first === undefined) return undefined;
68
+ let fitted: FitPart[] | undefined;
69
+ for (let kept = 1; kept < rest.length; kept += 1) {
70
+ const candidate = [
71
+ ...segmentParts(first),
72
+ { text: hiddenCount(rest.length - kept), muted: true },
73
+ ...joined(rest.slice(-kept)),
74
+ ];
75
+ if (partsColumns(candidate) > columns) break;
76
+ fitted = candidate;
77
+ }
78
+ return fitted;
79
+ }
80
+
81
+ /** The muted marker at the cut: a count of the whole segments hidden when it
82
+ * leaves a column for each side, else " ⋯ ". */
83
+ function cutMarker(hidden: number, columns: number): string {
84
+ const counted = hiddenCount(hidden);
85
+ return hidden > 0 && columns - textColumns(counted) >= 2 ? counted : ELISION;
86
+ }
87
+
88
+ const headOf = (parts: readonly FitPart[], max: number): FitPart[] =>
89
+ sliceParts(parts, 0, textColumns(keepHead(shown(parts), max)));
90
+
91
+ function tailOf(parts: readonly FitPart[], max: number): FitPart[] {
92
+ const columns = partsColumns(parts);
93
+ const tail = keepTail(shown(parts), max);
94
+ return sliceParts(parts, columns - textColumns(tail), columns);
95
+ }
96
+
97
+ /** The start of the first segment and the end of the last (the same segment
98
+ * when there is only one) around a muted marker of their own, so a kept
99
+ * heredoc label never stands in for the cut. Heredocs stay collapsed, and
100
+ * the last segment's label is not shown without its command. */
101
+ function firstAndLast(
102
+ segments: readonly ActionSegment[],
103
+ first: ActionSegment,
104
+ last: ActionSegment,
105
+ columns: number,
106
+ ): FitPart[] {
107
+ const marker = cutMarker(Math.max(0, segments.length - 2), columns);
108
+ const headParts = segmentParts(first);
109
+ const tailParts = segmentParts(last);
110
+ const budget = columns - textColumns(marker);
111
+ let kept = headOf(
112
+ headParts,
113
+ Math.max(Math.ceil(budget / 2), budget - partsColumns(tailParts)),
114
+ );
115
+ let ending = tailOf(tailParts, budget - partsColumns(kept));
116
+ if (first !== last && ending[0]?.muted === true) ending = [];
117
+ if (ending.length === 0) kept = headOf(headParts, budget);
118
+ const spaced = ending[0]?.text.startsWith(" ") ?? true;
119
+ return [
120
+ ...kept,
121
+ { text: spaced ? marker.trimEnd() : marker, muted: true },
122
+ ...ending,
123
+ ];
124
+ }
125
+
126
+ function headAndTail(action: string, columns: number): ActionFitPart[] {
127
+ const parts = elideMiddle(singleLine(action), columns);
128
+ if (parts === undefined)
129
+ return merged([{ text: singleLine(action), muted: false }]);
130
+ return merged([
131
+ { text: parts.head, muted: false },
132
+ { text: ELISION, muted: true },
133
+ { text: parts.tail, muted: false },
134
+ ]);
135
+ }
136
+
137
+ /** A fitting `action` is shown as sent unless a segment collapses a heredoc
138
+ * body, which `action` shows flattened. */
139
+ export function fitAction(
140
+ status: Pick<ReviewUiStatus, "action" | "actionSegments">,
141
+ columns: number,
142
+ ): ActionFitPart[] {
143
+ const width = Math.floor(columns);
144
+ if (!(width > 0)) return [];
145
+ const segments = status.actionSegments ?? [];
146
+ const first = segments[0];
147
+ const last = segments.at(-1);
148
+ const asSent = [{ text: singleLine(status.action), muted: false }];
149
+ const collapsesBody = segments.some(
150
+ (segment: ActionSegment): boolean => segment.heredocLines !== undefined,
151
+ );
152
+ if (!collapsesBody && partsColumns(asSent) <= width) return merged(asSent);
153
+ const full = joined(segments);
154
+ if (first !== undefined && partsColumns(full) <= width) return merged(full);
155
+ if (width < MIN_ELIDED_COLUMNS) return [{ text: ELLIPSIS, muted: true }];
156
+ if (first === undefined || last === undefined)
157
+ return headAndTail(status.action, width);
158
+ return merged(
159
+ elided(segments, width) ?? firstAndLast(segments, first, last, width),
160
+ );
161
+ }
@@ -0,0 +1,60 @@
1
+ /** @jsxImportSource @opentui/solid */
2
+
3
+ import type { ColorInput } from "@opentui/core";
4
+ import type { JSX } from "solid-js";
5
+ import { For } from "solid-js";
6
+ import type { ActionFitPart } from "./action-fit.ts";
7
+ import { textColumns } from "./fit-parts.ts";
8
+
9
+ /** Rows the v1 overlay's action may wrap over; with the overlay's six other
10
+ * rows this stays inside its 12-row cap. */
11
+ const OVERLAY_ACTION_ROWS = 3;
12
+ /** Overlay action-row columns that are not the permission, the action or the
13
+ * actor: the left border, the panel's side padding (2 + 3), the row's indent
14
+ * (2) and the gap after the permission. */
15
+ const OVERLAY_ACTION_INSET = 9;
16
+
17
+ const less = (columns: number, fixed: readonly string[]): number =>
18
+ fixed.reduce(
19
+ (left: number, text: string): number => left - textColumns(text),
20
+ columns,
21
+ );
22
+
23
+ /** Columns a strip row leaves for the action: the terminal width less the
24
+ * strip's one-column side padding and the fixed text sharing the row. */
25
+ export function stripActionColumns(
26
+ columns: number,
27
+ ...fixed: string[]
28
+ ): number {
29
+ return less(columns - 2, fixed);
30
+ }
31
+
32
+ export function overlayActionColumns(
33
+ columns: number,
34
+ permission: string,
35
+ actorName: string | undefined,
36
+ ): number {
37
+ const actor = actorName ? ` · actor ${actorName}` : "";
38
+ return (
39
+ OVERLAY_ACTION_ROWS *
40
+ less(columns - OVERLAY_ACTION_INSET, [permission, actor])
41
+ );
42
+ }
43
+
44
+ /** A fitted action as inline spans: muted parts in `muted`, the rest in
45
+ * `color`. */
46
+ export function ActionSpans(props: {
47
+ parts: ActionFitPart[];
48
+ color: ColorInput;
49
+ muted: ColorInput;
50
+ }): JSX.Element {
51
+ return (
52
+ <For each={props.parts}>
53
+ {(part: ActionFitPart): JSX.Element => (
54
+ <span style={{ fg: part.muted ? props.muted : props.color }}>
55
+ {part.text}
56
+ </span>
57
+ )}
58
+ </For>
59
+ );
60
+ }
@@ -0,0 +1,113 @@
1
+ // Who decided, and why the reasoning reviewer ran, as the TUI shows it.
2
+ import type { HandoffInfo } from "../system-one/backend.ts";
3
+ import type { HandoffTrigger } from "../types.ts";
4
+ import type { ReviewUiStatus } from "../ui-protocol.ts";
5
+
6
+ type PhraseSource = Pick<
7
+ ReviewUiStatus,
8
+ "handoff" | "phase" | "resolution" | "escalationDisposition"
9
+ >;
10
+
11
+ const AFTER: Record<
12
+ Exclude<HandoffTrigger, "jev-failure" | "jev-uncertain-deny">,
13
+ string
14
+ > = {
15
+ "jev-escalate": "after Jev's escalation",
16
+ "jev-uncertain-allow": "after Jev's uncertain approval",
17
+ "jev-gate": "after a safety gate stopped Jev's approval",
18
+ "jev-invalid": "after Jev's invalid response",
19
+ };
20
+
21
+ const CAUSE: Record<Exclude<HandoffTrigger, "jev-failure">, string> = {
22
+ "jev-escalate": "Jev escalated",
23
+ "jev-uncertain-allow": "Jev's approval was uncertain",
24
+ "jev-gate": "a safety gate stopped Jev's approval",
25
+ "jev-invalid": "Jev's response was invalid",
26
+ "jev-uncertain-deny": "Jev's denial was uncertain",
27
+ };
28
+
29
+ /** Last path segment of a provider model id: "omniroute/auto/gpt-6-luna" -> "gpt-6-luna". */
30
+ export function shortModelName(model: string): string {
31
+ const segments = model
32
+ .split("/")
33
+ .map((segment) => segment.trim())
34
+ .filter((segment) => segment.length > 0);
35
+ return segments.at(-1) ?? "";
36
+ }
37
+
38
+ /** The last non-blank path segment, or the whole id when there is none ("///"). */
39
+ export function modelLabel(model: string): string {
40
+ return shortModelName(model) || model;
41
+ }
42
+
43
+ const jevFailed = (kind: string | undefined): string =>
44
+ kind === undefined ? "Jev failed" : `Jev failed (${kind})`;
45
+
46
+ /** A "denied" phase with `escalationDisposition: "deny"` is a fail-closed
47
+ * escalation, not the reasoning reviewer's own block, so it does not confirm
48
+ * Jev's denial. */
49
+ function denialVerdict(status: PhraseSource): string {
50
+ if (status.phase === "approved") return "overturned Jev's denial";
51
+ if (status.phase === "denied" && status.escalationDisposition !== "deny")
52
+ return "confirmed Jev's denial";
53
+ return "after Jev's uncertain denial";
54
+ }
55
+
56
+ /** Undefined on `budget-exhausted` (the reasoning reviewer never ran) and on
57
+ * `reasoning-unavailable` (it made no decision). */
58
+ export function handoffPhrase(status: PhraseSource): string | undefined {
59
+ const { handoff } = status;
60
+ if (
61
+ handoff === undefined ||
62
+ status.resolution === "budget-exhausted" ||
63
+ status.resolution === "reasoning-unavailable"
64
+ )
65
+ return;
66
+ if (handoff.trigger === "jev-failure")
67
+ return `after ${jevFailed(handoff.failureKind)}`;
68
+ if (handoff.trigger === "jev-uncertain-deny") return denialVerdict(status);
69
+ return AFTER[handoff.trigger];
70
+ }
71
+
72
+ /** `decidedBy`, except a `budget-exhausted` status that carries a hand-off,
73
+ * which credits `status.model`: the reasoning reviewer never ran. */
74
+ function creditedModel(status: ReviewUiStatus): string | undefined {
75
+ if (status.handoff !== undefined && status.resolution === "budget-exhausted")
76
+ return status.model;
77
+ return status.decidedBy;
78
+ }
79
+
80
+ /** Line 2's attribution; undefined when no model is credited. */
81
+ export function attributionText(status: ReviewUiStatus): string | undefined {
82
+ const phrase = handoffPhrase(status);
83
+ if (phrase !== undefined && status.handoff !== undefined)
84
+ return `${modelLabel(status.handoff.to)} ${phrase}`;
85
+ const model = modelLabel(creditedModel(status) ?? "");
86
+ return model === "" ? undefined : model;
87
+ }
88
+
89
+ /** Why Jev handed off, for the budget toast ("Jev timed out"). */
90
+ export function handoffCause(handoff: HandoffInfo): string {
91
+ if (handoff.trigger !== "jev-failure") return CAUSE[handoff.trigger];
92
+ return handoff.failureKind === "timeout"
93
+ ? "Jev timed out"
94
+ : jevFailed(handoff.failureKind);
95
+ }
96
+
97
+ /** The progress strip's reviewer: the hand-off while the reasoning reviewer
98
+ * runs, else the model's label. */
99
+ export function reviewerLabel(status: ReviewUiStatus): string {
100
+ if (status.handoff === undefined) return modelLabel(status.model);
101
+ return attributionText(status) ?? modelLabel(status.model);
102
+ }
103
+
104
+ /** Result strip line 2: "<attribution> — <reason>". The reason alone when no
105
+ * model decided or the status is unknown; undefined without a reason. */
106
+ export function resultDetail(status: ReviewUiStatus): string | undefined {
107
+ if (!status.reason) return;
108
+ const attribution =
109
+ status.phase === "unknown" ? undefined : attributionText(status);
110
+ return attribution === undefined
111
+ ? status.reason
112
+ : `${attribution} — ${status.reason}`;
113
+ }
@@ -1,29 +1,66 @@
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 { 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 { reviewerLabel } from "./attribution.ts";
11
+ import type { SidebarLine } from "./config-notices.ts";
5
12
 
6
13
  export interface ReviewTheme {
7
- backgroundPanel: ColorInput
8
- text: ColorInput
9
- textMuted: ColorInput
10
- info: ColorInput
11
- success: ColorInput
12
- error: ColorInput
14
+ backgroundPanel: ColorInput;
15
+ text: ColorInput;
16
+ textMuted: ColorInput;
17
+ info: ColorInput;
18
+ success: ColorInput;
19
+ error: ColorInput;
20
+ warning: ColorInput;
21
+ }
22
+ export const SPINNER = ["◐", "◓", "◑", "◒"] as const;
23
+
24
+ /** The reviewer's config line in the host sidebar; nothing when healthy. */
25
+ export function ConfigNoticeSlot(props: {
26
+ theme: () => ReviewTheme;
27
+ line: SidebarLine | undefined;
28
+ }): JSX.Element {
29
+ return (
30
+ <Show when={props.line} keyed>
31
+ {(line: SidebarLine) => (
32
+ <text fg={props.theme()[line.tone]} wrapMode="none" truncate>
33
+ {singleLine(line.text)}
34
+ </text>
35
+ )}
36
+ </Show>
37
+ );
13
38
  }
14
- export const SPINNER = ["◐", "◓", "◑", "◒"] as const
15
39
 
16
40
  /** Compact, non-modal progress strip for hosts with an editable composer. */
17
41
  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
- }
42
+ theme: () => ReviewTheme;
43
+ status: ReviewUiStatus;
44
+ frame: () => number;
45
+ }): JSX.Element {
46
+ const elapsed = (): string => {
47
+ props.frame();
48
+ return `${(Math.max(0, Date.now() - props.status.emittedAt) / 1_000).toFixed(1)}s`;
49
+ };
50
+ const terminal = useTerminalDimensions();
51
+ const actor = (): string =>
52
+ props.status.actorName
53
+ ? ` · actor ${singleLine(props.status.actorName)}`
54
+ : "";
55
+ const action = (): ActionFitPart[] =>
56
+ fitAction(
57
+ props.status,
58
+ stripActionColumns(
59
+ terminal().width,
60
+ `${props.status.permission} · `,
61
+ actor(),
62
+ ),
63
+ );
27
64
  return (
28
65
  <box
29
66
  height={2}
@@ -43,10 +80,12 @@ export function ReviewProgress(props: {
43
80
  wrapMode="none"
44
81
  truncate
45
82
  >
46
- {SPINNER[props.frame() % SPINNER.length] ?? "◐"} Reviewing this permission
83
+ {SPINNER[props.frame() % SPINNER.length] ?? "◐"} Reviewing this
84
+ permission
47
85
  <span style={{ fg: props.theme().textMuted }}>
48
86
  {" "}
49
- · {singleLine(props.status.model)} · {singleLine(props.status.variant)}
87
+ · {singleLine(reviewerLabel(props.status))} ·{" "}
88
+ {singleLine(props.status.variant)}
50
89
  </span>
51
90
  </text>
52
91
  <text fg={props.theme().textMuted} flexShrink={0} wrapMode="none">
@@ -54,8 +93,14 @@ export function ReviewProgress(props: {
54
93
  </text>
55
94
  </box>
56
95
  <text fg={props.theme().text} wrapMode="none" truncate>
57
- <span style={{ fg: props.theme().textMuted }}>{props.status.permission} · </span>
58
- {singleLine(props.status.action)}
96
+ <span style={{ fg: props.theme().textMuted }}>
97
+ {props.status.permission} ·{" "}
98
+ </span>
99
+ <ActionSpans
100
+ parts={action()}
101
+ color={props.theme().text}
102
+ muted={props.theme().textMuted}
103
+ />
59
104
  <Show when={props.status.actorName}>
60
105
  <span style={{ fg: props.theme().textMuted }}>
61
106
  {" "}
@@ -64,118 +109,5 @@ export function ReviewProgress(props: {
64
109
  </Show>
65
110
  </text>
66
111
  </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
- )
112
+ );
181
113
  }