The best way to control Claude Code, Codex and more from any computer or phone

main
ts 87 lines 2.66 KB
Raw
1 import type { PullRequestReviewGuideResult } from "@t3tools/contracts";
2 import { msg } from "gt-react-native";
3
4 import { m, type MessageResolver } from "../../../i18n/messages";
5
6 export function reviewGuideState(data: PullRequestReviewGuideResult | null) {
7 const guide = data?.guide ?? null;
8 return {
9 guide,
10 running: data?.run?._tag === "Running",
11 stale: guide !== null && data?.currentHeadSha != null && guide.headSha !== data.currentHeadSha,
12 failure:
13 data?.run?._tag === "Failed" && data.run.headSha === data.currentHeadSha
14 ? data.run.detail
15 : null,
16 };
17 }
18
19 export function guideNoticeState(
20 state: {
21 readonly data: PullRequestReviewGuideResult | null;
22 readonly isPending: boolean;
23 readonly running: boolean;
24 readonly startError: string | null;
25 readonly error: string | null;
26 },
27 resolve: MessageResolver = m,
28 ) {
29 const { guide, stale, failure } = reviewGuideState(state.data);
30 if (state.running) {
31 return {
32 kind: "writing" as const,
33 title: resolve(msg("Rewriting guide")),
34 description: guide
35 ? resolve(msg("You can keep reading this guide while the agent writes the update."))
36 : resolve(
37 msg(
38 "An agent is reading the change and writing the tour. You can leave and come back when it’s ready.",
39 ),
40 ),
41 action: guide ? resolve(msg("Rewriting…")) : resolve(msg("Writing guide…")),
42 };
43 }
44 const error = state.startError ?? failure;
45 if (error) {
46 return {
47 kind: "failed" as const,
48 title: resolve(msg("Could not write guide")),
49 description: error,
50 action: resolve(msg("Try again")),
51 };
52 }
53 if (state.error) {
54 return {
55 kind: "unavailable" as const,
56 title: resolve(msg("Could not refresh guide")),
57 description: state.error,
58 action: resolve(msg("Try again")),
59 };
60 }
61 if (!state.data) {
62 return {
63 kind: "loading" as const,
64 title: resolve(msg("Review guide")),
65 description: resolve(msg("Checking for a saved guide…")),
66 action: resolve(msg("Loading guide…")),
67 };
68 }
69 if (stale) {
70 return {
71 kind: "stale" as const,
72 title: resolve(msg("New changes since this guide")),
73 description: resolve(
74 msg("You can read the previous guide, or rewrite it for the latest changes."),
75 ),
76 action: resolve(msg("Rewrite guide")),
77 };
78 }
79 return {
80 kind: guide ? ("ready" as const) : ("empty" as const),
81 title: resolve(msg("Review guide")),
82 description: resolve(
83 msg("Get a tour of the change, with code excerpts and notes on what needs a closer look."),
84 ),
85 action: resolve(msg("Write guide")),
86 };
87 }