The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { |
| 2 | isAtomCommandInterrupted, |
| 3 | runAtomCommand, |
| 4 | squashAtomCommandFailure, |
| 5 | } from "@t3tools/client-runtime/state/runtime"; |
| 6 | import { errorDisplayMessage } from "@t3tools/client-runtime/errors"; |
| 7 | import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/shell"; |
| 8 | import { AuthOrchestrationOperateScope } from "@t3tools/contracts"; |
| 9 | import * as Haptics from "expo-haptics"; |
| 10 | import { msg } from "gt-react-native"; |
| 11 | |
| 12 | import * as Dialog from "../../components/ui/Dialog"; |
| 13 | import { m } from "../../i18n/messages"; |
| 14 | import { appAtomRegistry } from "../../state/atom-registry"; |
| 15 | import { environmentProjects, projectEnvironment } from "../../state/projects"; |
| 16 | import { environmentServerConfigsAtom } from "../../state/server"; |
| 17 | import { readEnvironmentScope } from "../../state/session"; |
| 18 | |
| 19 | /** A No project thread that already has its own folder, on a server that can promote it. */ |
| 20 | export function canTurnThreadIntoProject(thread: EnvironmentThreadShell): boolean { |
| 21 | if (thread.worktreePath === null) return false; |
| 22 | const config = appAtomRegistry.get(environmentServerConfigsAtom).get(thread.environmentId); |
| 23 | if (config?.environment.capabilities.threadProjectFromScratch !== true) return false; |
| 24 | const project = appAtomRegistry.get( |
| 25 | environmentProjects.projectAtom({ |
| 26 | environmentId: thread.environmentId, |
| 27 | projectId: thread.projectId, |
| 28 | }), |
| 29 | ); |
| 30 | return project?.isScratch === true; |
| 31 | } |
| 32 | |
| 33 | export async function turnThreadIntoProject(thread: EnvironmentThreadShell): Promise<void> { |
| 34 | const title = m(msg("Could not turn thread into a project")); |
| 35 | if (!readEnvironmentScope(thread.environmentId, AuthOrchestrationOperateScope)) { |
| 36 | Dialog.alert(title, m(msg("This connection cannot change threads."))); |
| 37 | return; |
| 38 | } |
| 39 | void Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Light); |
| 40 | const result = await runAtomCommand( |
| 41 | appAtomRegistry, |
| 42 | projectEnvironment.createFromThread, |
| 43 | { environmentId: thread.environmentId, input: { threadId: thread.id } }, |
| 44 | { reportFailure: false }, |
| 45 | ); |
| 46 | if (result._tag === "Failure" && !isAtomCommandInterrupted(result)) { |
| 47 | const error = squashAtomCommandFailure(result); |
| 48 | Dialog.alert(title, errorDisplayMessage(error, m) ?? m(msg("Try again."))); |
| 49 | } |
| 50 | } |