@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
@@ -0,0 +1,39 @@
1
+ import type { TuiPluginApi } from "@opencode-ai/plugin/tui";
2
+ import type { ReviewUiStatus } from "../ui-protocol.ts";
3
+ import type { ReviewUiState } from "../ui-state.ts";
4
+
5
+ function routeSessionID(api: TuiPluginApi): string | undefined {
6
+ const route = api.route.current;
7
+ if (route.name !== "session") return;
8
+ const params = "params" in route ? route.params : undefined;
9
+ const sessionID = params?.sessionID;
10
+ return typeof sessionID === "string" ? sessionID : undefined;
11
+ }
12
+
13
+ function parentSessionID(
14
+ api: TuiPluginApi,
15
+ sessionID: string,
16
+ ): string | undefined {
17
+ return api.state.session.get(sessionID)?.parentID;
18
+ }
19
+
20
+ export function notifyManual(api: TuiPluginApi, status: ReviewUiStatus): void {
21
+ api.ui.toast({
22
+ variant: "warning",
23
+ title: "Manual review required",
24
+ message:
25
+ status.reason ??
26
+ "The reviewer could not decide. This permission now needs your approval.",
27
+ duration: 8_000,
28
+ });
29
+ }
30
+
31
+ /** The status the V1 panel shows for the routed session, if any. */
32
+ export function activeStatus(
33
+ api: TuiPluginApi,
34
+ state: ReviewUiState,
35
+ ): ReviewUiStatus | undefined {
36
+ const sessionID = routeSessionID(api);
37
+ if (!sessionID) return;
38
+ return state.activeFor(sessionID, (id) => parentSessionID(api, id));
39
+ }
@@ -1,261 +1,107 @@
1
1
  /** @jsxImportSource @opentui/solid */
2
- import type { Plugin } from "@opencode/plugin/tui"
3
- import type { ColorInput } from "@opentui/core"
4
- import { createSignal, Show } from "solid-js"
5
- import { ReviewerRpc } from "./rpc.ts"
6
- import { ReviewProgress, ReviewResult, type ReviewTheme } from "./components.tsx"
7
- import { ReviewUiState } from "../ui-state.ts"
8
- import { decodeUiStatus, encodeUiStatus, type ReviewUiStatus } from "../ui-protocol.ts"
2
+ import type { Plugin } from "@opencode/plugin/tui";
3
+ import { createSignal, Show } from "solid-js";
4
+ import type { ReviewUiStatus } from "../ui-protocol.ts";
5
+ import { ReviewProgress, type ReviewTheme } from "./components.tsx";
6
+ import { createReviewFeed } from "./review-feed.ts";
7
+ import { ReviewResult } from "./review-result.tsx";
8
+ import { resolveReviewTheme } from "./review-theme.ts";
9
9
 
10
- type Context = Parameters<Plugin.Definition["setup"]>[0]
11
- const object = (value: unknown): Record<string, unknown> | undefined =>
12
- typeof value === "object" && value !== null ? (value as Record<string, unknown>) : undefined
13
- const color = (value: unknown): ColorInput | undefined => {
14
- if (typeof value === "string") return value
15
- const candidate = object(value)
16
- return candidate && "buffer" in candidate ? (value as ColorInput) : undefined
17
- }
18
- const FALLBACK_THEME = {
19
- backgroundPanel: "#111111",
20
- text: "#eeeeee",
21
- textMuted: "#999999",
22
- info: "#4da3ff",
23
- success: "#48c774",
24
- error: "#ff5c5c",
25
- } satisfies ReviewTheme
26
-
27
- export function resolveReviewTheme(value: unknown): ReviewTheme {
28
- const host = object(value)
29
- if (!host) return FALLBACK_THEME
30
- const background = object(host.background)
31
- const surface = object(background?.surface)
32
- const raised = object(background?.raised)
33
- const text = object(host.text)
34
- const status = object(text?.status)
35
- const feedback = object(text?.feedback)
36
- const infoFeedback = object(feedback?.info)
37
- const successFeedback = object(feedback?.success)
38
- const errorFeedback = object(feedback?.error)
39
- return {
40
- backgroundPanel:
41
- color(surface?.overlay) ??
42
- color(raised?.base) ??
43
- color(host.backgroundPanel) ??
44
- FALLBACK_THEME.backgroundPanel,
45
- text: color(text?.default) ?? color(text?.base) ?? color(host.text) ?? FALLBACK_THEME.text,
46
- textMuted:
47
- color(text?.subdued) ??
48
- color(text?.muted) ??
49
- color(host.textMuted) ??
50
- FALLBACK_THEME.textMuted,
51
- info:
52
- color(status?.running) ??
53
- color(infoFeedback?.base) ??
54
- color(host.info) ??
55
- FALLBACK_THEME.info,
56
- success:
57
- color(successFeedback?.default) ??
58
- color(successFeedback?.base) ??
59
- color(host.success) ??
60
- FALLBACK_THEME.success,
61
- error:
62
- color(errorFeedback?.default) ??
63
- color(errorFeedback?.base) ??
64
- color(host.error) ??
65
- FALLBACK_THEME.error,
66
- }
67
- }
10
+ type Context = Parameters<Plugin.Definition["setup"]>[0];
68
11
 
69
12
  export async function setupTuiV2(ctx: Context): Promise<() => void> {
70
- let directory = ctx.location?.directory
71
- const rpc = ctx.client.rpc(ReviewerRpc)
72
- const [revision, touch] = createSignal(0)
73
- const [frame, tick] = createSignal(0)
74
- let state = new ReviewUiState({ model: "", variant: "", timeoutMs: 180_000 })
75
- let generation: string | undefined
76
- let sequence = -1
77
- let stopped = false
78
- let controller: AbortController | undefined
79
- let reconnect: ReturnType<typeof setTimeout> | undefined
80
- let popMode: (() => void) | undefined
81
- let routeSession: string | undefined
82
- const active = () => {
83
- revision()
84
- const route = ctx.ui.router.current()
13
+ const [revision, touch] = createSignal(0);
14
+ const [frame, tick] = createSignal(0);
15
+ let popMode: (() => void) | undefined;
16
+ let routeSession: string | undefined;
17
+ const feed = createReviewFeed(ctx, () => refresh());
18
+ const active = (): ReviewUiStatus | undefined => {
19
+ revision();
20
+ const route = ctx.ui.router.current();
85
21
  return route.type === "session"
86
- ? state.activeFor(route.sessionID, (id) => ctx.data.session.get(id)?.parentID)
87
- : undefined
88
- }
89
- const theme = (): ReviewTheme => resolveReviewTheme((ctx as unknown as { theme?: unknown }).theme)
90
- const refresh = () => {
91
- touch((value) => value + 1)
92
- const reviewing = active()?.phase === "reviewing"
22
+ ? feed.state.activeFor(
23
+ route.sessionID,
24
+ (id) => ctx.data.session.get(id)?.parentID,
25
+ )
26
+ : undefined;
27
+ };
28
+ const theme = (): ReviewTheme =>
29
+ resolveReviewTheme((ctx as unknown as { theme?: unknown }).theme);
30
+ const refresh = (): void => {
31
+ touch((value) => value + 1);
32
+ const reviewing = active()?.phase === "reviewing";
93
33
  if (reviewing && !popMode) {
94
34
  try {
95
- popMode = ctx.keymap.mode.push("permission-reviewer")
35
+ popMode = ctx.keymap.mode.push("permission-reviewer");
96
36
  } catch {
97
37
  /* The panel remains useful without a host mode. */
98
38
  }
99
39
  }
100
40
  if (!reviewing && popMode) {
101
- popMode()
102
- popMode = undefined
103
- }
104
- }
105
- const applyStatus = (value: unknown) => {
106
- const status = decodeUiStatus(encodeUiStatus(value as ReviewUiStatus))
107
- if (!status) return
108
- state.apply(status)
109
- if (status.phase === "manual")
110
- ctx.ui.toast.show({
111
- variant: "warning",
112
- title: "Manual review required",
113
- message: status.reason ?? "The host requires your decision.",
114
- })
115
- }
116
- const update = (value: unknown, owner: AbortController) => {
117
- if (owner !== controller || owner.signal.aborted) return
118
- const event = object(value)
119
- if (!event || event.directory !== directory) return
120
- if (typeof event.generation !== "string") return
121
- if (event.generation !== generation) {
122
- owner.abort()
123
- return
124
- }
125
- if (typeof event.revision !== "number" || event.revision <= sequence) return
126
- sequence = event.revision
127
- applyStatus(event.status)
128
- refresh()
129
- }
130
- const markDisconnected = () => {
131
- for (const status of state.all())
132
- if (status.phase === "reviewing")
133
- state.apply({
134
- ...status,
135
- phase: "unknown",
136
- emittedAt: Date.now(),
137
- reason: "Reconnecting to reviewer status",
138
- })
139
- refresh()
140
- }
141
- const connect = async () => {
142
- controller?.abort()
143
- clearTimeout(reconnect)
144
- if (!directory || stopped) return
145
- const scopeDirectory = directory
146
- const current = new AbortController()
147
- controller = current
148
- const buffered: unknown[] = []
149
- let loading = true
150
- const stream = (async () => {
151
- for await (const event of rpc.events.subscribe("review.updated", {
152
- signal: current.signal,
153
- })) {
154
- if (event.location.directory !== scopeDirectory) continue
155
- if (loading) {
156
- if (buffered.length >= 512) throw new Error("Reviewer event buffer overflow")
157
- buffered.push(event.data)
158
- } else update(event.data, current)
159
- }
160
- })()
161
- void stream.catch(() => {})
162
- try {
163
- const snapshot = object(
164
- await rpc.snapshot({}, { location: { directory: scopeDirectory }, signal: current.signal }),
165
- )
166
- if (
167
- !snapshot ||
168
- snapshot.directory !== scopeDirectory ||
169
- typeof snapshot.generation !== "string" ||
170
- typeof snapshot.revision !== "number" ||
171
- !Array.isArray(snapshot.reviews)
172
- )
173
- throw new Error("Invalid reviewer snapshot")
174
- if (current.signal.aborted) return
175
- state = new ReviewUiState({ model: "", variant: "", timeoutMs: 180_000 })
176
- generation = snapshot.generation
177
- sequence = snapshot.revision
178
- for (const status of snapshot.reviews) applyStatus(status)
179
- loading = false
180
- for (const event of buffered) update(event, current)
181
- refresh()
182
- await stream
183
- if (controller === current && !stopped) markDisconnected()
184
- } catch {
185
- if (controller !== current || stopped) return
186
- // Unknown means the UI lacks authoritative state, never human approval.
187
- markDisconnected()
188
- } finally {
189
- current.abort()
190
- await stream.catch(() => {})
191
- if (!stopped && controller === current)
192
- reconnect = setTimeout(() => {
193
- void connect()
194
- }, 1000)
41
+ popMode();
42
+ popMode = undefined;
195
43
  }
196
- }
197
- void connect()
44
+ };
45
+ void feed.connect();
198
46
  const slot = ctx.ui.slot({
199
47
  append: "app",
200
48
  render: () => {
201
49
  const reviewing = () => {
202
- const status = active()
203
- return status?.phase === "reviewing" ? status : undefined
204
- }
50
+ const status = active();
51
+ return status?.phase === "reviewing" ? status : undefined;
52
+ };
205
53
  const terminal = () => {
206
- const status = active()
207
- return status && status.phase !== "reviewing" && status.phase !== "manual"
54
+ const status = active();
55
+ return status &&
56
+ status.phase !== "reviewing" &&
57
+ status.phase !== "manual"
208
58
  ? status
209
- : undefined
210
- }
59
+ : undefined;
60
+ };
211
61
  return (
212
62
  <>
213
63
  <Show when={reviewing()} keyed>
214
- {(current) => (
64
+ {(current: ReviewUiStatus) => (
215
65
  <box position="absolute" bottom={0} left={0} right={0}>
216
66
  <ReviewProgress theme={theme} status={current} frame={frame} />
217
67
  </box>
218
68
  )}
219
69
  </Show>
220
70
  <Show when={terminal()} keyed>
221
- {(current) => (
71
+ {(current: ReviewUiStatus) => (
222
72
  <box position="absolute" bottom={0} left={0} right={0}>
223
73
  <ReviewResult theme={theme} status={current} />
224
74
  </box>
225
75
  )}
226
76
  </Show>
227
77
  </>
228
- )
78
+ );
229
79
  },
230
- })
231
- const timer = setInterval(() => {
232
- tick((value) => value + 1)
233
- const route = ctx.ui.router.current()
234
- const nextSession = route.type === "session" ? route.sessionID : undefined
80
+ });
81
+ // Refreshes on a session switch, and follows the routed session's directory.
82
+ const followRoute = (): void => {
83
+ const route = ctx.ui.router.current();
84
+ const nextSession = route.type === "session" ? route.sessionID : undefined;
235
85
  if (nextSession !== routeSession) {
236
- routeSession = nextSession
237
- refresh()
86
+ routeSession = nextSession;
87
+ refresh();
238
88
  }
239
89
  const nextDirectory =
240
90
  route.type === "session"
241
- ? (ctx.data.session.get(route.sessionID)?.location.directory ?? ctx.location?.directory)
242
- : ctx.location?.directory
243
- if (nextDirectory !== directory) {
244
- directory = nextDirectory
245
- state = new ReviewUiState({ model: "", variant: "", timeoutMs: 180_000 })
246
- refresh()
247
- void connect()
248
- }
249
- const expired = state.expire()
250
- if (expired.length) controller?.abort()
251
- if (expired.length || state.dismissResults().length) refresh()
252
- }, 250)
91
+ ? (ctx.data.session.get(route.sessionID)?.location.directory ??
92
+ ctx.location?.directory)
93
+ : ctx.location?.directory;
94
+ if (nextDirectory !== feed.directory) feed.retarget(nextDirectory);
95
+ };
96
+ const timer = setInterval(() => {
97
+ tick((value) => value + 1);
98
+ followRoute();
99
+ feed.sweep();
100
+ }, 250);
253
101
  return () => {
254
- stopped = true
255
- controller?.abort()
256
- clearTimeout(reconnect)
257
- clearInterval(timer)
258
- popMode?.()
259
- slot()
260
- }
102
+ feed.stop();
103
+ clearInterval(timer);
104
+ popMode?.();
105
+ slot();
106
+ };
261
107
  }
@@ -3,49 +3,55 @@ import type {
3
3
  EscalationDisposition,
4
4
  PermissionRequest,
5
5
  ReviewDecision,
6
- } from "./types.ts"
6
+ } from "./types.ts";
7
+ import { parseUiStatus } from "./ui-status-parse.ts";
7
8
 
8
- export const UI_COMMAND_PREFIX = "opencode-permission-reviewer.status."
9
+ export const UI_COMMAND_PREFIX = "opencode-permission-reviewer.status.";
9
10
  // Time to wait for the server's first "reviewing" ack after permission.asked.
10
11
  // Short enough to surface a broken publish path, long enough to survive a busy
11
12
  // event bus without flipping the panel to "manual" before the review starts.
12
- export const UI_START_GRACE_MS = 15_000
13
- export const UI_WATCHDOG_GRACE_MS = 5_000
13
+ export const UI_START_GRACE_MS = 15_000;
14
+ export const UI_WATCHDOG_GRACE_MS = 5_000;
14
15
 
15
- export type ReviewUiPhase = "reviewing" | "approved" | "denied" | "manual" | "unknown"
16
+ export type ReviewUiPhase =
17
+ | "reviewing"
18
+ | "approved"
19
+ | "denied"
20
+ | "manual"
21
+ | "unknown";
16
22
 
17
23
  export interface ReviewUiStatus {
18
- version: 1
19
- requestID: string
20
- sessionID: string
21
- phase: ReviewUiPhase
22
- permission: string
23
- action: string
24
- model: string
25
- variant: string
26
- emittedAt: number
27
- timeoutMs: number
28
- reason?: string
29
- decision?: ReviewDecision
24
+ version: 1;
25
+ requestID: string;
26
+ sessionID: string;
27
+ phase: ReviewUiPhase;
28
+ permission: string;
29
+ action: string;
30
+ model: string;
31
+ variant: string;
32
+ emittedAt: number;
33
+ timeoutMs: number;
34
+ reason?: string;
35
+ decision?: ReviewDecision;
30
36
  /**
31
37
  * When phase is `denied` and this is `"deny"`, the block came from fail-closed
32
38
  * escalation disposition rather than an explicit reviewer/policy deny.
33
39
  */
34
- escalationDisposition?: EscalationDisposition
40
+ escalationDisposition?: EscalationDisposition;
35
41
  /** Resolved actor (absent on the initial "reviewing" phase, before context
36
42
  * collection completes). */
37
- actorName?: string
38
- actorProfile?: ActorProfile
43
+ actorName?: string;
44
+ actorProfile?: ActorProfile;
39
45
  }
40
46
 
41
47
  function boundedText(value: string, max: number): string {
42
- const compact = value.replace(/\s+/g, " ").trim()
43
- if (compact.length <= max) return compact
44
- return `${compact.slice(0, Math.max(0, max - 1))}…`
48
+ const compact = value.replace(/\s+/g, " ").trim();
49
+ if (compact.length <= max) return compact;
50
+ return `${compact.slice(0, Math.max(0, max - 1))}…`;
45
51
  }
46
52
 
47
53
  export function permissionAction(request: PermissionRequest): string {
48
- const metadata = request.metadata
54
+ const metadata = request.metadata;
49
55
  const candidates = [
50
56
  metadata.command,
51
57
  metadata.filepath,
@@ -53,27 +59,28 @@ export function permissionAction(request: PermissionRequest): string {
53
59
  metadata.query,
54
60
  metadata.path,
55
61
  request.patterns.join(", "),
56
- ]
62
+ ];
57
63
  const detail = candidates.find(
58
- (value): value is string => typeof value === "string" && value.trim().length > 0,
59
- )
60
- const prefix = request.permission === "bash" && detail ? "$ " : ""
61
- return boundedText(`${prefix}${detail ?? request.permission}`, 500)
64
+ (value): value is string =>
65
+ typeof value === "string" && value.trim().length > 0,
66
+ );
67
+ const prefix = request.permission === "bash" && detail ? "$ " : "";
68
+ return boundedText(`${prefix}${detail ?? request.permission}`, 500);
62
69
  }
63
70
 
64
71
  export function createUiStatus(
65
72
  request: PermissionRequest,
66
73
  phase: ReviewUiPhase,
67
74
  options: {
68
- model: string
69
- variant: string
70
- timeoutMs: number
71
- reason?: string
72
- decision?: ReviewDecision
73
- escalationDisposition?: EscalationDisposition
74
- emittedAt?: number
75
- actorName?: string
76
- actorProfile?: ActorProfile
75
+ model: string;
76
+ variant: string;
77
+ timeoutMs: number;
78
+ reason?: string;
79
+ decision?: ReviewDecision;
80
+ escalationDisposition?: EscalationDisposition;
81
+ emittedAt?: number;
82
+ actorName?: string;
83
+ actorProfile?: ActorProfile;
77
84
  },
78
85
  ): ReviewUiStatus {
79
86
  return {
@@ -87,97 +94,35 @@ export function createUiStatus(
87
94
  variant: boundedText(options.variant, 100),
88
95
  emittedAt: options.emittedAt ?? Date.now(),
89
96
  timeoutMs: options.timeoutMs,
90
- ...(options.reason === undefined ? {} : { reason: boundedText(options.reason, 2_000) }),
97
+ ...(options.reason === undefined
98
+ ? {}
99
+ : { reason: boundedText(options.reason, 2_000) }),
91
100
  ...(options.decision === undefined ? {} : { decision: options.decision }),
92
101
  ...(options.escalationDisposition === undefined
93
102
  ? {}
94
103
  : { escalationDisposition: options.escalationDisposition }),
95
- ...(options.actorName === undefined ? {} : { actorName: boundedText(options.actorName, 100) }),
96
- ...(options.actorProfile === undefined ? {} : { actorProfile: options.actorProfile }),
97
- }
98
- }
99
-
100
- function isRecord(value: unknown): value is Record<string, unknown> {
101
- return typeof value === "object" && value !== null && !Array.isArray(value)
102
- }
103
-
104
- function isDecision(value: unknown): value is ReviewDecision {
105
- if (!isRecord(value)) return false
106
- return (
107
- (value.outcome === "allow" || value.outcome === "deny" || value.outcome === "escalate") &&
108
- (value.risk_level === "low" ||
109
- value.risk_level === "medium" ||
110
- value.risk_level === "high" ||
111
- value.risk_level === "critical") &&
112
- (value.user_authorization === "high" ||
113
- value.user_authorization === "medium" ||
114
- value.user_authorization === "low" ||
115
- value.user_authorization === "unknown") &&
116
- typeof value.rationale === "string" &&
117
- typeof value.confidence === "number" &&
118
- Number.isFinite(value.confidence) &&
119
- value.confidence >= 0 &&
120
- value.confidence <= 1
121
- )
122
- }
123
-
124
- export function parseUiStatus(value: unknown): ReviewUiStatus | undefined {
125
- if (!isRecord(value) || value.version !== 1) return
126
- if (typeof value.requestID !== "string" || typeof value.sessionID !== "string") return
127
- if (
128
- value.phase !== "reviewing" &&
129
- value.phase !== "approved" &&
130
- value.phase !== "denied" &&
131
- value.phase !== "manual" &&
132
- value.phase !== "unknown"
133
- ) {
134
- return
135
- }
136
- if (typeof value.permission !== "string" || typeof value.action !== "string") return
137
- if (typeof value.model !== "string" || typeof value.variant !== "string") return
138
- if (typeof value.emittedAt !== "number" || !Number.isFinite(value.emittedAt)) return
139
- if (
140
- typeof value.timeoutMs !== "number" ||
141
- !Number.isFinite(value.timeoutMs) ||
142
- value.timeoutMs < 0
143
- )
144
- return
145
- if (value.reason !== undefined && typeof value.reason !== "string") return
146
- if (value.decision !== undefined && !isDecision(value.decision)) return
147
- if (
148
- value.escalationDisposition !== undefined &&
149
- value.escalationDisposition !== "manual" &&
150
- value.escalationDisposition !== "deny"
151
- ) {
152
- return
153
- }
154
- if (value.actorName !== undefined && typeof value.actorName !== "string") return
155
- if (
156
- value.actorProfile !== undefined &&
157
- value.actorProfile !== "read-only" &&
158
- value.actorProfile !== "validation" &&
159
- value.actorProfile !== "workspace" &&
160
- value.actorProfile !== "operator" &&
161
- value.actorProfile !== "reviewer" &&
162
- value.actorProfile !== "unknown"
163
- ) {
164
- return
165
- }
166
-
167
- return value as unknown as ReviewUiStatus
104
+ ...(options.actorName === undefined
105
+ ? {}
106
+ : { actorName: boundedText(options.actorName, 100) }),
107
+ ...(options.actorProfile === undefined
108
+ ? {}
109
+ : { actorProfile: options.actorProfile }),
110
+ };
168
111
  }
169
112
 
170
113
  export function encodeUiStatus(status: ReviewUiStatus): string {
171
- return `${UI_COMMAND_PREFIX}${Buffer.from(JSON.stringify(status), "utf8").toString("base64url")}`
114
+ return `${UI_COMMAND_PREFIX}${Buffer.from(JSON.stringify(status), "utf8").toString("base64url")}`;
172
115
  }
173
116
 
174
117
  export function decodeUiStatus(command: string): ReviewUiStatus | undefined {
175
- if (!command.startsWith(UI_COMMAND_PREFIX)) return
176
- const encoded = command.slice(UI_COMMAND_PREFIX.length)
177
- if (!encoded || encoded.length > 16_000) return
118
+ if (!command.startsWith(UI_COMMAND_PREFIX)) return;
119
+ const encoded = command.slice(UI_COMMAND_PREFIX.length);
120
+ if (!encoded || encoded.length > 16_000) return;
178
121
  try {
179
- return parseUiStatus(JSON.parse(Buffer.from(encoded, "base64url").toString("utf8")))
122
+ return parseUiStatus(
123
+ JSON.parse(Buffer.from(encoded, "base64url").toString("utf8")),
124
+ );
180
125
  } catch {
181
- return
126
+ return;
182
127
  }
183
128
  }