The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { createReviewEnvironmentAtoms } from "@t3tools/client-runtime/state/review"; |
| 2 | import type { EnvironmentId, ReviewDiffPreviewSource } from "@t3tools/contracts"; |
| 3 | import * as Effect from "effect/Effect"; |
| 4 | import { Atom } from "effect/reactivity"; |
| 5 | |
| 6 | import { connectionAtomRuntime } from "../connection/runtime"; |
| 7 | |
| 8 | const EMPTY_GIT_SECTIONS = Object.freeze<ReadonlyArray<ReviewDiffPreviewSource>>([]); |
| 9 | |
| 10 | // The last answered preview per worktree, so review keeps showing git sections while the live |
| 11 | // query is not mounted. useReviewSections still hides them unless the session grants file reads. |
| 12 | const lastGitSectionsFamily = Atom.family((key: string) => |
| 13 | Atom.make(EMPTY_GIT_SECTIONS).pipe( |
| 14 | Atom.keepAlive, |
| 15 | Atom.withLabel(`mobile:review:git-sections:${key}`), |
| 16 | ), |
| 17 | ); |
| 18 | |
| 19 | export function lastReviewGitSectionsAtom(environmentId: EnvironmentId, cwd: string) { |
| 20 | return lastGitSectionsFamily(JSON.stringify([environmentId, cwd])); |
| 21 | } |
| 22 | |
| 23 | export const reviewEnvironment = createReviewEnvironmentAtoms(connectionAtomRuntime, { |
| 24 | onDiffPreviewAnswer: (target, value, registry) => |
| 25 | Effect.sync(() => |
| 26 | registry.set( |
| 27 | lastReviewGitSectionsAtom(target.environmentId, target.input.cwd), |
| 28 | value.sources, |
| 29 | ), |
| 30 | ), |
| 31 | }); |