The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import { canCreateProjectInEnvironment } from "@t3tools/client-runtime/operations/projects"; |
| 2 | import type { EnvironmentConnectionPhase } from "@t3tools/client-runtime/connection"; |
| 3 | import { type EnvironmentId, FilesystemBrowseError } from "@t3tools/contracts"; |
| 4 | import * as Schema from "effect/Schema"; |
| 5 | |
| 6 | const isFilesystemBrowseError = Schema.is(FilesystemBrowseError); |
| 7 | |
| 8 | /** Clone destinations may name folders that do not exist yet; cloning creates them. */ |
| 9 | export function isMissingCloneParentBrowseFailure(input: { |
| 10 | readonly cloning: boolean; |
| 11 | readonly failure: unknown; |
| 12 | }): boolean { |
| 13 | return ( |
| 14 | input.cloning && |
| 15 | isFilesystemBrowseError(input.failure) && |
| 16 | input.failure.failure === "read_directory_failed" && |
| 17 | input.failure.pathMissing === true |
| 18 | ); |
| 19 | } |
| 20 | |
| 21 | export function resolveAddProjectEnvironment< |
| 22 | T extends { |
| 23 | readonly environmentId: EnvironmentId; |
| 24 | readonly connectionState: EnvironmentConnectionPhase; |
| 25 | }, |
| 26 | >(environmentOptions: ReadonlyArray<T>, requestedEnvironmentId: EnvironmentId | null): T | null { |
| 27 | if (requestedEnvironmentId !== null) { |
| 28 | return ( |
| 29 | environmentOptions.find( |
| 30 | (environment) => |
| 31 | environment.environmentId === requestedEnvironmentId && |
| 32 | canCreateProjectInEnvironment(environment.connectionState), |
| 33 | ) ?? null |
| 34 | ); |
| 35 | } |
| 36 | |
| 37 | return ( |
| 38 | environmentOptions.find((environment) => |
| 39 | canCreateProjectInEnvironment(environment.connectionState), |
| 40 | ) ?? null |
| 41 | ); |
| 42 | } |