@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.
- package/CHANGELOG.md +174 -1
- package/LICENSE +21 -201
- package/LICENSE-APACHE +201 -0
- package/MIGRATION.md +2 -1
- package/NOTICE +14 -6
- package/README.md +109 -787
- package/SECURITY.md +41 -22
- package/dist/explain.d.ts +3 -4
- package/dist/explain.js +9708 -4298
- package/dist/index.d.ts +1096 -987
- package/dist/index.js +18646 -10575
- package/dist/rpc.d.ts +38 -38
- package/dist/rpc.js +30 -18
- package/dist/tui/config/jsonc.ts +71 -63
- package/dist/tui/config/layer-read.ts +120 -0
- package/dist/tui/config/loader.ts +73 -512
- package/dist/tui/config/risk-policy-clamp.ts +80 -0
- package/dist/tui/config/trust-boundary-keys.ts +102 -0
- package/dist/tui/config/trust-boundary.ts +148 -0
- package/dist/tui/config/trusted-degradation.ts +97 -0
- package/dist/tui/config-fields.ts +75 -0
- package/dist/tui/config-knobs.ts +119 -0
- package/dist/tui/config-policy-rules.ts +86 -0
- package/dist/tui/config-risk-policy.ts +59 -0
- package/dist/tui/config-rule-condition.ts +150 -0
- package/dist/tui/config.ts +72 -431
- package/dist/tui/descriptor-io.ts +42 -0
- package/dist/tui/failure-kind.ts +28 -0
- package/dist/tui/is-record.ts +13 -0
- package/dist/tui/opencode/event-normalizer.ts +41 -31
- package/dist/tui/reviewer-model.ts +87 -0
- package/dist/tui/system-one-routing.ts +110 -0
- package/dist/tui/tui.tsx +97 -99
- package/dist/tui/types.ts +206 -596
- package/dist/tui/ui/action-fit.ts +161 -0
- package/dist/tui/ui/action-spans.tsx +60 -0
- package/dist/tui/ui/attribution.ts +113 -0
- package/dist/tui/ui/components.tsx +69 -137
- package/dist/tui/ui/config-notices.ts +137 -0
- package/dist/tui/ui/fit-parts.ts +76 -0
- package/dist/tui/ui/manual-toast.ts +87 -0
- package/dist/tui/ui/review-connection.ts +32 -0
- package/dist/tui/ui/review-feed.ts +156 -0
- package/dist/tui/ui/review-overlay.tsx +111 -0
- package/dist/tui/ui/review-result.tsx +74 -0
- package/dist/tui/ui/review-store.ts +88 -0
- package/dist/tui/ui/review-theme.ts +70 -0
- package/dist/tui/ui/rpc.ts +5 -2
- package/dist/tui/ui/v1-host.ts +66 -0
- package/dist/tui/ui/v2.tsx +82 -220
- package/dist/tui/ui-protocol.ts +112 -124
- package/dist/tui/ui-state.ts +86 -64
- package/dist/tui/ui-status-extras.ts +165 -0
- package/dist/tui/ui-status-parse.ts +132 -0
- package/dist/tui/ui-text-elide.ts +89 -0
- package/package.json +24 -23
- package/rpc.js +2 -1
- package/server.js +2 -2
- package/tui.tsx +2 -1
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { asObjectLike } from "../is-record.ts";
|
|
2
|
+
import {
|
|
3
|
+
decodeUiStatus,
|
|
4
|
+
encodeUiStatus,
|
|
5
|
+
type ReviewUiStatus,
|
|
6
|
+
} from "../ui-protocol.ts";
|
|
7
|
+
import { ReviewUiState } from "../ui-state.ts";
|
|
8
|
+
|
|
9
|
+
interface ReviewSnapshot extends Record<string, unknown> {
|
|
10
|
+
generation: string;
|
|
11
|
+
revision: number;
|
|
12
|
+
reviews: unknown[];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function isSnapshot(
|
|
16
|
+
value: Record<string, unknown> | undefined,
|
|
17
|
+
directory: string,
|
|
18
|
+
): value is ReviewSnapshot {
|
|
19
|
+
return (
|
|
20
|
+
value !== undefined &&
|
|
21
|
+
value.directory === directory &&
|
|
22
|
+
typeof value.generation === "string" &&
|
|
23
|
+
typeof value.revision === "number" &&
|
|
24
|
+
Array.isArray(value.reviews)
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const emptyState = (): ReviewUiState =>
|
|
29
|
+
new ReviewUiState({ model: "", variant: "", timeoutMs: 180_000 });
|
|
30
|
+
|
|
31
|
+
/** The review statuses of one reviewer generation, applied in revision order. */
|
|
32
|
+
export class ReviewStore {
|
|
33
|
+
state: ReviewUiState = emptyState();
|
|
34
|
+
private generation: string | undefined;
|
|
35
|
+
private sequence = -1;
|
|
36
|
+
|
|
37
|
+
constructor(
|
|
38
|
+
private readonly notifyManual: (status: ReviewUiStatus) => void,
|
|
39
|
+
) {}
|
|
40
|
+
|
|
41
|
+
reset(): void {
|
|
42
|
+
this.state = emptyState();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
load(snapshot: ReviewSnapshot): void {
|
|
46
|
+
this.state = emptyState();
|
|
47
|
+
this.generation = snapshot.generation;
|
|
48
|
+
this.sequence = snapshot.revision;
|
|
49
|
+
for (const status of snapshot.reviews) this.apply(status);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Applies an update event for `directory` when it belongs to the loaded
|
|
54
|
+
* generation and its revision is newer. "foreign" names another generation.
|
|
55
|
+
*/
|
|
56
|
+
accept(
|
|
57
|
+
value: unknown,
|
|
58
|
+
directory: string | undefined,
|
|
59
|
+
): "ignored" | "foreign" | "applied" {
|
|
60
|
+
const event = asObjectLike(value);
|
|
61
|
+
if (!event || event.directory !== directory) return "ignored";
|
|
62
|
+
if (typeof event.generation !== "string") return "ignored";
|
|
63
|
+
if (event.generation !== this.generation) return "foreign";
|
|
64
|
+
if (typeof event.revision !== "number" || event.revision <= this.sequence)
|
|
65
|
+
return "ignored";
|
|
66
|
+
this.sequence = event.revision;
|
|
67
|
+
this.apply(event.status);
|
|
68
|
+
return "applied";
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
markDisconnected(): void {
|
|
72
|
+
for (const status of this.state.all())
|
|
73
|
+
if (status.phase === "reviewing")
|
|
74
|
+
this.state.apply({
|
|
75
|
+
...status,
|
|
76
|
+
phase: "unknown",
|
|
77
|
+
emittedAt: Date.now(),
|
|
78
|
+
reason: "Reconnecting to reviewer status",
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
private apply(value: unknown): void {
|
|
83
|
+
const status = decodeUiStatus(encodeUiStatus(value as ReviewUiStatus));
|
|
84
|
+
if (!status) return;
|
|
85
|
+
this.state.apply(status);
|
|
86
|
+
if (status.phase === "manual") this.notifyManual(status);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { ColorInput } from "@opentui/core";
|
|
2
|
+
import { asObjectLike } from "../is-record.ts";
|
|
3
|
+
import type { ReviewTheme } from "./components.tsx";
|
|
4
|
+
|
|
5
|
+
const color = (value: unknown): ColorInput | undefined => {
|
|
6
|
+
if (typeof value === "string") return value;
|
|
7
|
+
const candidate = asObjectLike(value);
|
|
8
|
+
return candidate && "buffer" in candidate ? (value as ColorInput) : undefined;
|
|
9
|
+
};
|
|
10
|
+
const FALLBACK_THEME: Record<keyof ReviewTheme, string> = {
|
|
11
|
+
backgroundPanel: "#111111",
|
|
12
|
+
text: "#eeeeee",
|
|
13
|
+
textMuted: "#999999",
|
|
14
|
+
info: "#4da3ff",
|
|
15
|
+
success: "#48c774",
|
|
16
|
+
error: "#ff5c5c",
|
|
17
|
+
warning: "#f5a742",
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export function resolveReviewTheme(value: unknown): ReviewTheme {
|
|
21
|
+
const host = asObjectLike(value);
|
|
22
|
+
if (!host) return { ...FALLBACK_THEME };
|
|
23
|
+
const background = asObjectLike(host.background);
|
|
24
|
+
const surface = asObjectLike(background?.surface);
|
|
25
|
+
const raised = asObjectLike(background?.raised);
|
|
26
|
+
const text = asObjectLike(host.text);
|
|
27
|
+
const status = asObjectLike(text?.status);
|
|
28
|
+
const feedback = asObjectLike(text?.feedback);
|
|
29
|
+
const infoFeedback = asObjectLike(feedback?.info);
|
|
30
|
+
const successFeedback = asObjectLike(feedback?.success);
|
|
31
|
+
const errorFeedback = asObjectLike(feedback?.error);
|
|
32
|
+
const warningFeedback = asObjectLike(feedback?.warning);
|
|
33
|
+
return {
|
|
34
|
+
backgroundPanel:
|
|
35
|
+
color(surface?.overlay) ??
|
|
36
|
+
color(raised?.base) ??
|
|
37
|
+
color(host.backgroundPanel) ??
|
|
38
|
+
FALLBACK_THEME.backgroundPanel,
|
|
39
|
+
text:
|
|
40
|
+
color(text?.default) ??
|
|
41
|
+
color(text?.base) ??
|
|
42
|
+
color(host.text) ??
|
|
43
|
+
FALLBACK_THEME.text,
|
|
44
|
+
textMuted:
|
|
45
|
+
color(text?.subdued) ??
|
|
46
|
+
color(text?.muted) ??
|
|
47
|
+
color(host.textMuted) ??
|
|
48
|
+
FALLBACK_THEME.textMuted,
|
|
49
|
+
info:
|
|
50
|
+
color(status?.running) ??
|
|
51
|
+
color(infoFeedback?.base) ??
|
|
52
|
+
color(host.info) ??
|
|
53
|
+
FALLBACK_THEME.info,
|
|
54
|
+
success:
|
|
55
|
+
color(successFeedback?.default) ??
|
|
56
|
+
color(successFeedback?.base) ??
|
|
57
|
+
color(host.success) ??
|
|
58
|
+
FALLBACK_THEME.success,
|
|
59
|
+
error:
|
|
60
|
+
color(errorFeedback?.default) ??
|
|
61
|
+
color(errorFeedback?.base) ??
|
|
62
|
+
color(host.error) ??
|
|
63
|
+
FALLBACK_THEME.error,
|
|
64
|
+
warning:
|
|
65
|
+
color(warningFeedback?.default) ??
|
|
66
|
+
color(warningFeedback?.base) ??
|
|
67
|
+
color(host.warning) ??
|
|
68
|
+
FALLBACK_THEME.warning,
|
|
69
|
+
};
|
|
70
|
+
}
|
package/dist/tui/ui/rpc.ts
CHANGED
|
@@ -6,11 +6,14 @@ export const ReviewerRpc = {
|
|
|
6
6
|
input: { type: "object", additionalProperties: false },
|
|
7
7
|
output: { type: "string" },
|
|
8
8
|
},
|
|
9
|
-
status: {
|
|
9
|
+
status: {
|
|
10
|
+
input: { type: "object", additionalProperties: false },
|
|
11
|
+
output: { type: "object" },
|
|
12
|
+
},
|
|
10
13
|
snapshot: {
|
|
11
14
|
input: { type: "object", additionalProperties: false },
|
|
12
15
|
output: { type: "object" },
|
|
13
16
|
},
|
|
14
17
|
},
|
|
15
18
|
events: { "review.updated": { schema: { type: "object" } } },
|
|
16
|
-
} as const
|
|
19
|
+
} as const;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { TuiPluginApi } from "@opencode-ai/plugin/tui";
|
|
2
|
+
import { decodeUiStatus, type ReviewUiStatus } from "../ui-protocol.ts";
|
|
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.";
|
|
9
|
+
|
|
10
|
+
function routeSessionID(api: TuiPluginApi): string | undefined {
|
|
11
|
+
const route = api.route.current;
|
|
12
|
+
if (route.name !== "session") return;
|
|
13
|
+
const params = "params" in route ? route.params : undefined;
|
|
14
|
+
const sessionID = params?.sessionID;
|
|
15
|
+
return typeof sessionID === "string" ? sessionID : undefined;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function parentSessionID(
|
|
19
|
+
api: TuiPluginApi,
|
|
20
|
+
sessionID: string,
|
|
21
|
+
): string | undefined {
|
|
22
|
+
return api.state.session.get(sessionID)?.parentID;
|
|
23
|
+
}
|
|
24
|
+
|
|
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
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** The status the V1 panel shows for the routed session, if any. */
|
|
59
|
+
export function activeStatus(
|
|
60
|
+
api: TuiPluginApi,
|
|
61
|
+
state: ReviewUiState,
|
|
62
|
+
): ReviewUiStatus | undefined {
|
|
63
|
+
const sessionID = routeSessionID(api);
|
|
64
|
+
if (!sessionID) return;
|
|
65
|
+
return state.activeFor(sessionID, (id) => parentSessionID(api, id));
|
|
66
|
+
}
|
package/dist/tui/ui/v2.tsx
CHANGED
|
@@ -1,261 +1,123 @@
|
|
|
1
1
|
/** @jsxImportSource @opentui/solid */
|
|
2
|
-
import type { Plugin } from "@opencode/plugin/tui"
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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 {
|
|
6
|
+
ConfigNoticeSlot,
|
|
7
|
+
ReviewProgress,
|
|
8
|
+
type ReviewTheme,
|
|
9
|
+
} from "./components.tsx";
|
|
10
|
+
import type { SidebarLine } from "./config-notices.ts";
|
|
11
|
+
import { createReviewFeed } from "./review-feed.ts";
|
|
12
|
+
import { ReviewResult } from "./review-result.tsx";
|
|
13
|
+
import { resolveReviewTheme } from "./review-theme.ts";
|
|
9
14
|
|
|
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
|
-
}
|
|
15
|
+
type Context = Parameters<Plugin.Definition["setup"]>[0];
|
|
68
16
|
|
|
69
17
|
export async function setupTuiV2(ctx: Context): Promise<() => void> {
|
|
70
|
-
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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()
|
|
18
|
+
const [revision, touch] = createSignal(0);
|
|
19
|
+
const [frame, tick] = createSignal(0);
|
|
20
|
+
let popMode: (() => void) | undefined;
|
|
21
|
+
let routeSession: string | undefined;
|
|
22
|
+
const feed = createReviewFeed(ctx, () => refresh());
|
|
23
|
+
const active = (): ReviewUiStatus | undefined => {
|
|
24
|
+
revision();
|
|
25
|
+
const route = ctx.ui.router.current();
|
|
85
26
|
return route.type === "session"
|
|
86
|
-
? state.activeFor(
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
27
|
+
? feed.state.activeFor(
|
|
28
|
+
route.sessionID,
|
|
29
|
+
(id) => ctx.data.session.get(id)?.parentID,
|
|
30
|
+
)
|
|
31
|
+
: undefined;
|
|
32
|
+
};
|
|
33
|
+
const theme = (): ReviewTheme =>
|
|
34
|
+
resolveReviewTheme((ctx as unknown as { theme?: unknown }).theme);
|
|
35
|
+
const refresh = (): void => {
|
|
36
|
+
touch((value) => value + 1);
|
|
37
|
+
const reviewing = active()?.phase === "reviewing";
|
|
93
38
|
if (reviewing && !popMode) {
|
|
94
39
|
try {
|
|
95
|
-
popMode = ctx.keymap.mode.push("permission-reviewer")
|
|
40
|
+
popMode = ctx.keymap.mode.push("permission-reviewer");
|
|
96
41
|
} catch {
|
|
97
42
|
/* The panel remains useful without a host mode. */
|
|
98
43
|
}
|
|
99
44
|
}
|
|
100
45
|
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
|
|
46
|
+
popMode();
|
|
47
|
+
popMode = undefined;
|
|
124
48
|
}
|
|
125
|
-
|
|
126
|
-
|
|
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)
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
void connect()
|
|
49
|
+
};
|
|
50
|
+
void feed.connect();
|
|
198
51
|
const slot = ctx.ui.slot({
|
|
199
52
|
append: "app",
|
|
200
53
|
render: () => {
|
|
201
54
|
const reviewing = () => {
|
|
202
|
-
const status = active()
|
|
203
|
-
return status?.phase === "reviewing" ? status : undefined
|
|
204
|
-
}
|
|
55
|
+
const status = active();
|
|
56
|
+
return status?.phase === "reviewing" ? status : undefined;
|
|
57
|
+
};
|
|
205
58
|
const terminal = () => {
|
|
206
|
-
const status = active()
|
|
207
|
-
return status &&
|
|
59
|
+
const status = active();
|
|
60
|
+
return status &&
|
|
61
|
+
status.phase !== "reviewing" &&
|
|
62
|
+
status.phase !== "manual"
|
|
208
63
|
? status
|
|
209
|
-
: undefined
|
|
210
|
-
}
|
|
64
|
+
: undefined;
|
|
65
|
+
};
|
|
211
66
|
return (
|
|
212
67
|
<>
|
|
213
68
|
<Show when={reviewing()} keyed>
|
|
214
|
-
{(current) => (
|
|
69
|
+
{(current: ReviewUiStatus) => (
|
|
215
70
|
<box position="absolute" bottom={0} left={0} right={0}>
|
|
216
71
|
<ReviewProgress theme={theme} status={current} frame={frame} />
|
|
217
72
|
</box>
|
|
218
73
|
)}
|
|
219
74
|
</Show>
|
|
220
75
|
<Show when={terminal()} keyed>
|
|
221
|
-
{(current) => (
|
|
76
|
+
{(current: ReviewUiStatus) => (
|
|
222
77
|
<box position="absolute" bottom={0} left={0} right={0}>
|
|
223
78
|
<ReviewResult theme={theme} status={current} />
|
|
224
79
|
</box>
|
|
225
80
|
)}
|
|
226
81
|
</Show>
|
|
227
82
|
</>
|
|
228
|
-
)
|
|
83
|
+
);
|
|
229
84
|
},
|
|
230
|
-
})
|
|
231
|
-
const
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
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
|
+
});
|
|
96
|
+
// Refreshes on a session switch, and follows the routed session's directory.
|
|
97
|
+
const followRoute = (): void => {
|
|
98
|
+
const route = ctx.ui.router.current();
|
|
99
|
+
const nextSession = route.type === "session" ? route.sessionID : undefined;
|
|
235
100
|
if (nextSession !== routeSession) {
|
|
236
|
-
routeSession = nextSession
|
|
237
|
-
refresh()
|
|
101
|
+
routeSession = nextSession;
|
|
102
|
+
refresh();
|
|
238
103
|
}
|
|
239
104
|
const nextDirectory =
|
|
240
105
|
route.type === "session"
|
|
241
|
-
? (ctx.data.session.get(route.sessionID)?.location.directory ??
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
if (expired.length || state.dismissResults().length) refresh()
|
|
252
|
-
}, 250)
|
|
106
|
+
? (ctx.data.session.get(route.sessionID)?.location.directory ??
|
|
107
|
+
ctx.location?.directory)
|
|
108
|
+
: ctx.location?.directory;
|
|
109
|
+
if (nextDirectory !== feed.directory) feed.retarget(nextDirectory);
|
|
110
|
+
};
|
|
111
|
+
const timer = setInterval(() => {
|
|
112
|
+
tick((value) => value + 1);
|
|
113
|
+
followRoute();
|
|
114
|
+
feed.sweep();
|
|
115
|
+
}, 250);
|
|
253
116
|
return () => {
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
}
|
|
117
|
+
feed.stop();
|
|
118
|
+
clearInterval(timer);
|
|
119
|
+
popMode?.();
|
|
120
|
+
slot();
|
|
121
|
+
sidebar();
|
|
122
|
+
};
|
|
261
123
|
}
|