@noppu-labs/opencode-permission-reviewer 3.0.0 → 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.
@@ -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
+ }
@@ -1,6 +1,8 @@
1
1
  import type { Plugin } from "@opencode/plugin/tui";
2
2
  import { asObjectLike } from "../is-record.ts";
3
3
  import type { ReviewUiState } from "../ui-state.ts";
4
+ import { ConfigNotices } from "./config-notices.ts";
5
+ import { manualToast } from "./manual-toast.ts";
4
6
  import { type Connection, receive, release } from "./review-connection.ts";
5
7
  import { isSnapshot, ReviewStore } from "./review-store.ts";
6
8
  import { ReviewerRpc } from "./rpc.ts";
@@ -12,6 +14,8 @@ type Context = Parameters<Plugin.Definition["setup"]>[0];
12
14
  interface ReviewFeed {
13
15
  readonly directory: string | undefined;
14
16
  readonly state: ReviewUiState;
17
+ /** The server's config warnings for the current directory. */
18
+ readonly notices: ConfigNotices;
15
19
  connect(): Promise<void>;
16
20
  /** Switches to another directory with an empty state, and reconnects. */
17
21
  retarget(directory: string | undefined): void;
@@ -26,13 +30,29 @@ export function createReviewFeed(
26
30
  ): ReviewFeed {
27
31
  let directory = ctx.location?.directory;
28
32
  const rpc = ctx.client.rpc(ReviewerRpc);
33
+ const notices = new ConfigNotices((toast) => ctx.ui.toast.show(toast));
29
34
  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
+ ctx.ui.toast.show(
36
+ manualToast(
37
+ status,
38
+ "The host requires your decision.",
39
+ notices.reasoningModel,
40
+ ),
41
+ ),
35
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
+ };
36
56
  let stopped = false;
37
57
  let controller: AbortController | undefined;
38
58
  let reconnect: ReturnType<typeof setTimeout> | undefined;
@@ -84,6 +104,7 @@ export function createReviewFeed(
84
104
  const current = connection.controller;
85
105
  const stream = listen(connection);
86
106
  void stream.catch(() => {});
107
+ void refreshNotices(connection);
87
108
  try {
88
109
  const snapshot = await rpc.snapshot(
89
110
  {},
@@ -110,10 +131,14 @@ export function createReviewFeed(
110
131
  get state(): ReviewUiState {
111
132
  return store.state;
112
133
  },
134
+ get notices(): ConfigNotices {
135
+ return notices;
136
+ },
113
137
  connect,
114
138
  retarget: (next: string | undefined): void => {
115
139
  directory = next;
116
140
  store.reset();
141
+ notices.reset();
117
142
  changed();
118
143
  void connect();
119
144
  },
@@ -1,9 +1,13 @@
1
1
  /** @jsxImportSource @opentui/solid */
2
2
 
3
3
  import type { MouseEvent } from "@opentui/core";
4
+ import { useTerminalDimensions } from "@opentui/solid";
4
5
  import type { JSX } from "solid-js";
5
6
  import { Show } from "solid-js";
6
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";
7
11
  import { type ReviewTheme, SPINNER } from "./components.tsx";
8
12
 
9
13
  export function ReviewOverlay(props: {
@@ -21,6 +25,16 @@ export function ReviewOverlay(props: {
21
25
  const elapsedMs = Math.max(0, Date.now() - props.status.emittedAt);
22
26
  return `${(elapsedMs / 1_000).toFixed(1)}s`;
23
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
+ );
24
38
 
25
39
  return (
26
40
  // biome-ignore lint/a11y/noStaticElementInteractions: <box> is an OpenTUI terminal renderable, not a DOM element, so the ARIA role rule does not apply
@@ -62,17 +76,31 @@ export function ReviewOverlay(props: {
62
76
  <text fg={theme().textMuted}>{elapsed()}</text>
63
77
  </box>
64
78
  <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}
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
+ />
68
88
  </text>
69
89
  <Show when={props.status.actorName}>
70
- <text fg={theme().textMuted}>· actor {props.status.actorName}</text>
90
+ <text fg={theme().textMuted} flexShrink={0}>
91
+ · actor {props.status.actorName}
92
+ </text>
71
93
  </Show>
72
94
  </box>
73
95
  <box paddingLeft={2} flexDirection="row" gap={1}>
74
96
  <text fg={theme().textMuted}>
75
- {props.status.model} · reasoning {props.status.variant}
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>
76
104
  </text>
77
105
  <box flexGrow={1} />
78
106
  <text fg={theme().textMuted}>No action needed</text>
@@ -1,10 +1,14 @@
1
1
  /** @jsxImportSource @opentui/solid */
2
2
 
3
3
  import type { ColorInput } from "@opentui/core";
4
+ import { useTerminalDimensions } from "@opentui/solid";
4
5
  import type { JSX } from "solid-js";
5
6
  import { Show } from "solid-js";
6
7
  import type { ReviewUiStatus } from "../ui-protocol.ts";
7
- import { type ReviewTheme, singleLine } from "./components.tsx";
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";
8
12
 
9
13
  export function ReviewResult(props: {
10
14
  theme: () => ReviewTheme;
@@ -32,9 +36,19 @@ export function ReviewResult(props: {
32
36
  }
33
37
  return { color: theme().error, icon: "✕", title: "Review blocked" };
34
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);
35
49
  return (
36
50
  <box
37
- height={props.status.reason ? 2 : 1}
51
+ height={detail() ? 2 : 1}
38
52
  flexShrink={0}
39
53
  overflow="hidden"
40
54
  backgroundColor={theme().backgroundPanel}
@@ -44,11 +58,15 @@ export function ReviewResult(props: {
44
58
  >
45
59
  <text fg={appearance().color} wrapMode="none" truncate>
46
60
  {appearance().icon} {appearance().title} · {props.status.permission} ·{" "}
47
- {singleLine(props.status.action)}
61
+ <ActionSpans
62
+ parts={action()}
63
+ color={appearance().color}
64
+ muted={theme().textMuted}
65
+ />
48
66
  </text>
49
- <Show when={props.status.reason}>
67
+ <Show when={detail()}>
50
68
  <text fg={theme().textMuted} wrapMode="none" truncate>
51
- {singleLine(props.status.reason ?? "")}
69
+ {singleLine(detail() ?? "")}
52
70
  </text>
53
71
  </Show>
54
72
  </box>
@@ -14,11 +14,12 @@ const FALLBACK_THEME: Record<keyof ReviewTheme, string> = {
14
14
  info: "#4da3ff",
15
15
  success: "#48c774",
16
16
  error: "#ff5c5c",
17
+ warning: "#f5a742",
17
18
  };
18
19
 
19
20
  export function resolveReviewTheme(value: unknown): ReviewTheme {
20
21
  const host = asObjectLike(value);
21
- if (!host) return FALLBACK_THEME;
22
+ if (!host) return { ...FALLBACK_THEME };
22
23
  const background = asObjectLike(host.background);
23
24
  const surface = asObjectLike(background?.surface);
24
25
  const raised = asObjectLike(background?.raised);
@@ -28,6 +29,7 @@ export function resolveReviewTheme(value: unknown): ReviewTheme {
28
29
  const infoFeedback = asObjectLike(feedback?.info);
29
30
  const successFeedback = asObjectLike(feedback?.success);
30
31
  const errorFeedback = asObjectLike(feedback?.error);
32
+ const warningFeedback = asObjectLike(feedback?.warning);
31
33
  return {
32
34
  backgroundPanel:
33
35
  color(surface?.overlay) ??
@@ -59,5 +61,10 @@ export function resolveReviewTheme(value: unknown): ReviewTheme {
59
61
  color(errorFeedback?.base) ??
60
62
  color(host.error) ??
61
63
  FALLBACK_THEME.error,
64
+ warning:
65
+ color(warningFeedback?.default) ??
66
+ color(warningFeedback?.base) ??
67
+ color(host.warning) ??
68
+ FALLBACK_THEME.warning,
62
69
  };
63
70
  }
@@ -1,6 +1,11 @@
1
1
  import type { TuiPluginApi } from "@opencode-ai/plugin/tui";
2
- import type { ReviewUiStatus } from "../ui-protocol.ts";
2
+ import { decodeUiStatus, type ReviewUiStatus } from "../ui-protocol.ts";
3
3
  import type { ReviewUiState } from "../ui-state.ts";
4
+ import { ConfigNotices, type SidebarLine } from "./config-notices.ts";
5
+ import { manualToast } from "./manual-toast.ts";
6
+
7
+ const MANUAL_FALLBACK =
8
+ "The reviewer could not decide. This permission now needs your approval.";
4
9
 
5
10
  function routeSessionID(api: TuiPluginApi): string | undefined {
6
11
  const route = api.route.current;
@@ -17,15 +22,37 @@ function parentSessionID(
17
22
  return api.state.session.get(sessionID)?.parentID;
18
23
  }
19
24
 
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
- });
25
+ const TOAST_MS = 8_000;
26
+
27
+ export interface V1Host {
28
+ /** True when the state changed. A stale or undecodable command applies
29
+ * nothing, config notices included. */
30
+ apply(command: string): boolean;
31
+ sidebar(): SidebarLine | undefined;
32
+ }
33
+
34
+ export function createV1Host(
35
+ api: TuiPluginApi,
36
+ state: ReviewUiState,
37
+ reasoningModel?: string,
38
+ ): V1Host {
39
+ const notices = new ConfigNotices((toast) =>
40
+ api.ui.toast({ ...toast, duration: TOAST_MS }),
41
+ );
42
+ return {
43
+ apply(command: string): boolean {
44
+ const status = decodeUiStatus(command);
45
+ if (!status || !state.apply(status)) return false;
46
+ if (status.phase === "manual")
47
+ api.ui.toast({
48
+ ...manualToast(status, MANUAL_FALLBACK, reasoningModel),
49
+ duration: TOAST_MS,
50
+ });
51
+ notices.update(status);
52
+ return true;
53
+ },
54
+ sidebar: (): SidebarLine | undefined => notices.sidebar(),
55
+ };
29
56
  }
30
57
 
31
58
  /** The status the V1 panel shows for the routed session, if any. */
@@ -2,7 +2,12 @@
2
2
  import type { Plugin } from "@opencode/plugin/tui";
3
3
  import { createSignal, Show } from "solid-js";
4
4
  import type { ReviewUiStatus } from "../ui-protocol.ts";
5
- import { ReviewProgress, type ReviewTheme } from "./components.tsx";
5
+ import {
6
+ ConfigNoticeSlot,
7
+ ReviewProgress,
8
+ type ReviewTheme,
9
+ } from "./components.tsx";
10
+ import type { SidebarLine } from "./config-notices.ts";
6
11
  import { createReviewFeed } from "./review-feed.ts";
7
12
  import { ReviewResult } from "./review-result.tsx";
8
13
  import { resolveReviewTheme } from "./review-theme.ts";
@@ -78,6 +83,16 @@ export async function setupTuiV2(ctx: Context): Promise<() => void> {
78
83
  );
79
84
  },
80
85
  });
86
+ const sidebar = ctx.ui.slot({
87
+ append: "sidebar.content",
88
+ render: () => {
89
+ const line = (): SidebarLine | undefined => {
90
+ revision();
91
+ return feed.notices.sidebar();
92
+ };
93
+ return <ConfigNoticeSlot theme={theme} line={line()} />;
94
+ },
95
+ });
81
96
  // Refreshes on a session switch, and follows the routed session's directory.
82
97
  const followRoute = (): void => {
83
98
  const route = ctx.ui.router.current();
@@ -103,5 +118,6 @@ export async function setupTuiV2(ctx: Context): Promise<() => void> {
103
118
  clearInterval(timer);
104
119
  popMode?.();
105
120
  slot();
121
+ sidebar();
106
122
  };
107
123
  }
@@ -1,10 +1,19 @@
1
+ import type { HandoffInfo } from "./system-one/backend.ts";
1
2
  import type {
2
3
  ActorProfile,
3
4
  EscalationDisposition,
5
+ ManualResolution,
4
6
  PermissionRequest,
5
7
  ReviewDecision,
6
8
  } from "./types.ts";
9
+ import {
10
+ boundedText,
11
+ fitStatus,
12
+ type StatusExtrasOptions,
13
+ statusExtras,
14
+ } from "./ui-status-extras.ts";
7
15
  import { parseUiStatus } from "./ui-status-parse.ts";
16
+ import { boundedHeadTail } from "./ui-text-elide.ts";
8
17
 
9
18
  export const UI_COMMAND_PREFIX = "opencode-permission-reviewer.status.";
10
19
  // Time to wait for the server's first "reviewing" ack after permission.asked.
@@ -20,6 +29,19 @@ export type ReviewUiPhase =
20
29
  | "manual"
21
30
  | "unknown";
22
31
 
32
+ /** One command of a shell action as the server split it, for the TUI to fit
33
+ * to its width. Built by `src/ui-action-segments.ts`. */
34
+ export interface ActionSegment {
35
+ /** The segment as typed in the command, heredoc bodies left out,
36
+ * whitespace collapsed, at most 200 code points. */
37
+ text: string;
38
+ /** The operator that ends this segment: "|", "||", "&&", ";", "&". */
39
+ separator?: string;
40
+ /** Total body lines of the segment's heredocs, whose bodies are not
41
+ * shown. */
42
+ heredocLines?: number;
43
+ }
44
+
23
45
  export interface ReviewUiStatus {
24
46
  version: 1;
25
47
  requestID: string;
@@ -42,12 +64,22 @@ export interface ReviewUiStatus {
42
64
  * collection completes). */
43
65
  actorName?: string;
44
66
  actorProfile?: ActorProfile;
45
- }
46
-
47
- function boundedText(value: string, max: number): string {
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))}…`;
67
+ /** Jev's hand-off to the reasoning reviewer, on the second "reviewing"
68
+ * status and on the result of a handed-off review. */
69
+ handoff?: HandoffInfo;
70
+ /** How a manual outcome came about; chooses the manual-review toast. */
71
+ resolution?: ManualResolution;
72
+ /** The model that made the decision, on a final status a reviewer model
73
+ * decided; absent on a brake, policy or failure-safe result. */
74
+ decidedBy?: string;
75
+ /** The server's config warnings and degraded-config reasons. V1 carries them
76
+ * on every status; V2 reads them from the `status` RPC. */
77
+ configWarnings?: string[];
78
+ configDegraded?: string[];
79
+ /** The action split at its top-level shell operators. Absent when the
80
+ * server did not segment it or left the segments off to fit the status
81
+ * cap, and from a server that predates segments. */
82
+ actionSegments?: ActionSegment[];
51
83
  }
52
84
 
53
85
  export function permissionAction(request: PermissionRequest): string {
@@ -65,25 +97,32 @@ export function permissionAction(request: PermissionRequest): string {
65
97
  typeof value === "string" && value.trim().length > 0,
66
98
  );
67
99
  const prefix = request.permission === "bash" && detail ? "$ " : "";
68
- return boundedText(`${prefix}${detail ?? request.permission}`, 500);
100
+ const text = `${prefix}${detail ?? request.permission}`;
101
+ // 500 UTF-16 units at most, as the status size budget assumes: 250 code
102
+ // points always fit.
103
+ const bounded = boundedHeadTail(text, 500);
104
+ return bounded.length <= 500 ? bounded : boundedHeadTail(text, 250);
69
105
  }
70
106
 
107
+ export type UiStatusOptions = {
108
+ model: string;
109
+ variant: string;
110
+ timeoutMs: number;
111
+ reason?: string;
112
+ decision?: ReviewDecision;
113
+ escalationDisposition?: EscalationDisposition;
114
+ emittedAt?: number;
115
+ actorName?: string;
116
+ actorProfile?: ActorProfile;
117
+ actionSegments?: ActionSegment[];
118
+ } & StatusExtrasOptions;
119
+
71
120
  export function createUiStatus(
72
121
  request: PermissionRequest,
73
122
  phase: ReviewUiPhase,
74
- options: {
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;
84
- },
123
+ options: UiStatusOptions,
85
124
  ): ReviewUiStatus {
86
- return {
125
+ return fitStatus({
87
126
  version: 1,
88
127
  requestID: request.id,
89
128
  sessionID: request.sessionID,
@@ -107,7 +146,11 @@ export function createUiStatus(
107
146
  ...(options.actorProfile === undefined
108
147
  ? {}
109
148
  : { actorProfile: options.actorProfile }),
110
- };
149
+ ...(options.actionSegments === undefined
150
+ ? {}
151
+ : { actionSegments: options.actionSegments }),
152
+ ...statusExtras(options),
153
+ });
111
154
  }
112
155
 
113
156
  export function encodeUiStatus(status: ReviewUiStatus): string {
@@ -17,6 +17,19 @@ const RESULT_DISPLAY_MS = {
17
17
  denied: 5_000,
18
18
  } as const;
19
19
 
20
+ /** A "reviewing" status after another keeps the first `emittedAt`, so elapsed
21
+ * time is the total across a hand-off; a plain one after a hand-off, or any
22
+ * "reviewing" status after a final one, is stale and dropped. */
23
+ function successor(
24
+ current: ReviewUiStatus,
25
+ status: ReviewUiStatus,
26
+ ): ReviewUiStatus | undefined {
27
+ if (status.phase !== "reviewing") return status;
28
+ if (current.phase !== "reviewing") return;
29
+ if (current.handoff !== undefined && status.handoff === undefined) return;
30
+ return { ...status, emittedAt: current.emittedAt };
31
+ }
32
+
20
33
  export class ReviewUiState {
21
34
  private readonly requests = new Map<string, ReviewUiStatus>();
22
35
  private readonly acknowledged = new Set<string>();
@@ -47,7 +60,9 @@ export class ReviewUiState {
47
60
  return true;
48
61
  }
49
62
  if (current && status.emittedAt < current.emittedAt) return false;
50
- this.requests.set(status.requestID, status);
63
+ const next = current ? successor(current, status) : status;
64
+ if (!next) return false;
65
+ this.requests.set(status.requestID, next);
51
66
  this.acknowledged.add(status.requestID);
52
67
  return true;
53
68
  }