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, 03:37 UTC
| 1 | import * as Schema from "effect/Schema"; |
| 2 | import { PositiveInt, TrimmedNonEmptyString } from "./baseSchemas.ts"; |
| 3 | import { VcsDriverKind } from "./vcs.ts"; |
| 4 | |
| 5 | /** Accept unknown hosts so clients can fall back to generic presentation. */ |
| 6 | export const SourceControlProviderKind = TrimmedNonEmptyString.check( |
| 7 | Schema.isMaxLength(64), |
| 8 | Schema.isPattern(/^[a-z][a-z0-9-]*$/), |
| 9 | ).pipe(Schema.brand("SourceControlProviderKind")); |
| 10 | export type SourceControlProviderKind = typeof SourceControlProviderKind.Type; |
| 11 | |
| 12 | export const SourceControlProviderInfo = Schema.Struct({ |
| 13 | kind: SourceControlProviderKind, |
| 14 | name: TrimmedNonEmptyString, |
| 15 | baseUrl: Schema.String, |
| 16 | }); |
| 17 | export type SourceControlProviderInfo = typeof SourceControlProviderInfo.Type; |
| 18 | |
| 19 | export const ChangeRequestState = Schema.Literals(["open", "closed", "merged"]); |
| 20 | export type ChangeRequestState = typeof ChangeRequestState.Type; |
| 21 | |
| 22 | export const ChangeRequest = Schema.Struct({ |
| 23 | provider: SourceControlProviderKind, |
| 24 | number: PositiveInt, |
| 25 | title: TrimmedNonEmptyString, |
| 26 | url: Schema.String, |
| 27 | baseRefName: TrimmedNonEmptyString, |
| 28 | headRefName: TrimmedNonEmptyString, |
| 29 | headSha: Schema.optional(TrimmedNonEmptyString), |
| 30 | state: ChangeRequestState, |
| 31 | isDraft: Schema.optional(Schema.Boolean), |
| 32 | closedAt: Schema.optional(Schema.NullOr(Schema.String)), |
| 33 | mergedAt: Schema.optional(Schema.NullOr(Schema.String)), |
| 34 | updatedAt: Schema.Option(Schema.DateTimeUtc), |
| 35 | isCrossRepository: Schema.optional(Schema.Boolean), |
| 36 | headRepositoryNameWithOwner: Schema.optional(Schema.NullOr(TrimmedNonEmptyString)), |
| 37 | headRepositoryOwnerLogin: Schema.optional(Schema.NullOr(TrimmedNonEmptyString)), |
| 38 | }); |
| 39 | export type ChangeRequest = typeof ChangeRequest.Type; |
| 40 | |
| 41 | export const SourceControlRepositoryCloneUrls = Schema.Struct({ |
| 42 | nameWithOwner: TrimmedNonEmptyString, |
| 43 | url: TrimmedNonEmptyString, |
| 44 | sshUrl: TrimmedNonEmptyString, |
| 45 | }); |
| 46 | export type SourceControlRepositoryCloneUrls = typeof SourceControlRepositoryCloneUrls.Type; |
| 47 | |
| 48 | export const SourceControlRepositoryVisibility = Schema.Literals(["private", "public"]); |
| 49 | export type SourceControlRepositoryVisibility = typeof SourceControlRepositoryVisibility.Type; |
| 50 | |
| 51 | export const SourceControlCloneProtocol = Schema.Literals(["auto", "ssh", "https"]); |
| 52 | export type SourceControlCloneProtocol = typeof SourceControlCloneProtocol.Type; |
| 53 | |
| 54 | export const SourceControlRepositoryInfo = Schema.Struct({ |
| 55 | provider: SourceControlProviderKind, |
| 56 | nameWithOwner: TrimmedNonEmptyString, |
| 57 | url: TrimmedNonEmptyString, |
| 58 | sshUrl: TrimmedNonEmptyString, |
| 59 | }); |
| 60 | export type SourceControlRepositoryInfo = typeof SourceControlRepositoryInfo.Type; |
| 61 | |
| 62 | export const SourceControlRepositoryLookupInput = Schema.Struct({ |
| 63 | provider: SourceControlProviderKind, |
| 64 | repository: TrimmedNonEmptyString, |
| 65 | cwd: Schema.optional(TrimmedNonEmptyString), |
| 66 | }); |
| 67 | export type SourceControlRepositoryLookupInput = typeof SourceControlRepositoryLookupInput.Type; |
| 68 | |
| 69 | export const SourceControlCloneRepositoryInput = Schema.Struct({ |
| 70 | provider: Schema.optional(SourceControlProviderKind), |
| 71 | repository: Schema.optional(TrimmedNonEmptyString), |
| 72 | remoteUrl: Schema.optional(TrimmedNonEmptyString), |
| 73 | destinationPath: TrimmedNonEmptyString, |
| 74 | protocol: Schema.optional(SourceControlCloneProtocol), |
| 75 | }); |
| 76 | export type SourceControlCloneRepositoryInput = typeof SourceControlCloneRepositoryInput.Type; |
| 77 | |
| 78 | export const SourceControlCloneRepositoryResult = Schema.Struct({ |
| 79 | cwd: TrimmedNonEmptyString, |
| 80 | remoteUrl: TrimmedNonEmptyString, |
| 81 | repository: Schema.NullOr(SourceControlRepositoryInfo), |
| 82 | }); |
| 83 | export type SourceControlCloneRepositoryResult = typeof SourceControlCloneRepositoryResult.Type; |
| 84 | |
| 85 | export const SourceControlPublishRepositoryInput = Schema.Struct({ |
| 86 | cwd: TrimmedNonEmptyString, |
| 87 | provider: SourceControlProviderKind, |
| 88 | repository: TrimmedNonEmptyString, |
| 89 | visibility: SourceControlRepositoryVisibility, |
| 90 | remoteName: Schema.optional(TrimmedNonEmptyString), |
| 91 | protocol: Schema.optional(SourceControlCloneProtocol), |
| 92 | }); |
| 93 | export type SourceControlPublishRepositoryInput = typeof SourceControlPublishRepositoryInput.Type; |
| 94 | |
| 95 | export const SourceControlPublishStatus = Schema.Literals(["pushed", "remote_added"]); |
| 96 | export type SourceControlPublishStatus = typeof SourceControlPublishStatus.Type; |
| 97 | |
| 98 | export const SourceControlPublishRepositoryResult = Schema.Struct({ |
| 99 | repository: SourceControlRepositoryInfo, |
| 100 | remoteName: TrimmedNonEmptyString, |
| 101 | remoteUrl: TrimmedNonEmptyString, |
| 102 | branch: TrimmedNonEmptyString, |
| 103 | status: SourceControlPublishStatus, |
| 104 | }); |
| 105 | export type SourceControlPublishRepositoryResult = typeof SourceControlPublishRepositoryResult.Type; |
| 106 | |
| 107 | export const SourceControlDiscoveryStatus = Schema.Literals(["available", "missing"]); |
| 108 | export type SourceControlDiscoveryStatus = typeof SourceControlDiscoveryStatus.Type; |
| 109 | |
| 110 | export const SourceControlProviderAuthStatus = Schema.Literals([ |
| 111 | "authenticated", |
| 112 | "unauthenticated", |
| 113 | "unknown", |
| 114 | ]); |
| 115 | export type SourceControlProviderAuthStatus = typeof SourceControlProviderAuthStatus.Type; |
| 116 | |
| 117 | export const SourceControlProviderAuth = Schema.Struct({ |
| 118 | status: SourceControlProviderAuthStatus, |
| 119 | account: Schema.Option(TrimmedNonEmptyString), |
| 120 | host: Schema.Option(TrimmedNonEmptyString), |
| 121 | detail: Schema.Option(TrimmedNonEmptyString), |
| 122 | accounts: Schema.optionalKey( |
| 123 | Schema.Array( |
| 124 | Schema.Struct({ |
| 125 | host: TrimmedNonEmptyString, |
| 126 | account: TrimmedNonEmptyString, |
| 127 | active: Schema.Boolean, |
| 128 | authenticated: Schema.Boolean, |
| 129 | error: Schema.optionalKey(TrimmedNonEmptyString), |
| 130 | /** Set when the login comes from a token variable such as `GH_TOKEN`, which wins over Settings. */ |
| 131 | environmentVariable: Schema.optionalKey(TrimmedNonEmptyString), |
| 132 | }), |
| 133 | ), |
| 134 | ), |
| 135 | }); |
| 136 | export type SourceControlProviderAuth = typeof SourceControlProviderAuth.Type; |
| 137 | |
| 138 | const SourceControlDiscoverySharedFields = { |
| 139 | label: TrimmedNonEmptyString, |
| 140 | executable: Schema.optional(TrimmedNonEmptyString), |
| 141 | status: SourceControlDiscoveryStatus, |
| 142 | version: Schema.Option(TrimmedNonEmptyString), |
| 143 | installHint: TrimmedNonEmptyString, |
| 144 | detail: Schema.Option(TrimmedNonEmptyString), |
| 145 | } as const; |
| 146 | |
| 147 | export const VcsDiscoveryItem = Schema.Struct({ |
| 148 | kind: VcsDriverKind, |
| 149 | implemented: Schema.Boolean, |
| 150 | ...SourceControlDiscoverySharedFields, |
| 151 | }); |
| 152 | export type VcsDiscoveryItem = typeof VcsDiscoveryItem.Type; |
| 153 | |
| 154 | export const SourceControlProviderDiscoveryItem = Schema.Struct({ |
| 155 | kind: SourceControlProviderKind, |
| 156 | ...SourceControlDiscoverySharedFields, |
| 157 | auth: SourceControlProviderAuth, |
| 158 | /** The server is configured to sign in through the host's app; clients offer it only then. */ |
| 159 | appSignIn: Schema.optionalKey(Schema.Boolean), |
| 160 | }); |
| 161 | export type SourceControlProviderDiscoveryItem = typeof SourceControlProviderDiscoveryItem.Type; |
| 162 | |
| 163 | export const SourceControlDiscoveryResult = Schema.Struct({ |
| 164 | versionControlSystems: Schema.Array(VcsDiscoveryItem), |
| 165 | sourceControlProviders: Schema.Array(SourceControlProviderDiscoveryItem), |
| 166 | }); |
| 167 | export type SourceControlDiscoveryResult = typeof SourceControlDiscoveryResult.Type; |
| 168 | |
| 169 | export class SourceControlProviderError extends Schema.TaggedError<SourceControlProviderError>()( |
| 170 | "SourceControlProviderError", |
| 171 | { |
| 172 | provider: SourceControlProviderKind, |
| 173 | operation: Schema.String, |
| 174 | cwd: Schema.String, |
| 175 | command: Schema.optional(Schema.String), |
| 176 | repository: Schema.optional(Schema.String), |
| 177 | reference: Schema.optional(Schema.String), |
| 178 | detail: Schema.String, |
| 179 | cause: Schema.optional(Schema.Defect()), |
| 180 | }, |
| 181 | ) { |
| 182 | override get message(): string { |
| 183 | return `Source control provider ${this.provider} failed in ${this.operation}: ${this.detail}`; |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | export const SourceControlSignInInput = Schema.Struct({ |
| 188 | provider: SourceControlProviderKind, |
| 189 | host: TrimmedNonEmptyString, |
| 190 | }); |
| 191 | export type SourceControlSignInInput = typeof SourceControlSignInInput.Type; |
| 192 | |
| 193 | /** A device-flow code the user enters at `verificationUri` in any browser. */ |
| 194 | export const SourceControlSignInPrompt = Schema.Struct({ |
| 195 | userCode: TrimmedNonEmptyString, |
| 196 | verificationUri: TrimmedNonEmptyString, |
| 197 | expiresAt: Schema.Number, |
| 198 | }); |
| 199 | export type SourceControlSignInPrompt = typeof SourceControlSignInPrompt.Type; |
| 200 | |
| 201 | export const SourceControlSignInResult = Schema.Struct({ |
| 202 | account: TrimmedNonEmptyString, |
| 203 | }); |
| 204 | export type SourceControlSignInResult = typeof SourceControlSignInResult.Type; |
| 205 | |
| 206 | export const SourceControlSignInFailure = Schema.Literals([ |
| 207 | "unsupported", |
| 208 | "not-started", |
| 209 | "cancelled", |
| 210 | "denied", |
| 211 | "expired", |
| 212 | "failed", |
| 213 | ]); |
| 214 | export type SourceControlSignInFailure = typeof SourceControlSignInFailure.Type; |
| 215 | |
| 216 | export const SourceControlAppAccessInput = Schema.Struct({ |
| 217 | provider: SourceControlProviderKind, |
| 218 | host: TrimmedNonEmptyString, |
| 219 | repository: TrimmedNonEmptyString, |
| 220 | }); |
| 221 | export type SourceControlAppAccessInput = typeof SourceControlAppAccessInput.Type; |
| 222 | |
| 223 | /** Whether the server's forge app sign-in reaches a repository; `signed-out` when not in use. */ |
| 224 | export const SourceControlAppAccess = Schema.Struct({ |
| 225 | status: Schema.Literals(["covered", "not-covered", "signed-out"]), |
| 226 | }); |
| 227 | export type SourceControlAppAccess = typeof SourceControlAppAccess.Type; |
| 228 | |
| 229 | export const SourceControlStarredInput = Schema.Struct({ |
| 230 | provider: SourceControlProviderKind, |
| 231 | host: TrimmedNonEmptyString, |
| 232 | repository: TrimmedNonEmptyString, |
| 233 | }); |
| 234 | export type SourceControlStarredInput = typeof SourceControlStarredInput.Type; |
| 235 | |
| 236 | export class SourceControlSignInError extends Schema.TaggedError<SourceControlSignInError>()( |
| 237 | "SourceControlSignInError", |
| 238 | { |
| 239 | provider: SourceControlProviderKind, |
| 240 | host: Schema.String, |
| 241 | reason: SourceControlSignInFailure, |
| 242 | detail: Schema.String, |
| 243 | cause: Schema.optional(Schema.Defect()), |
| 244 | }, |
| 245 | ) { |
| 246 | override get message(): string { |
| 247 | return this.detail; |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | export class SourceControlRepositoryError extends Schema.TaggedError<SourceControlRepositoryError>()( |
| 252 | "SourceControlRepositoryError", |
| 253 | { |
| 254 | provider: SourceControlProviderKind, |
| 255 | operation: Schema.String, |
| 256 | detail: Schema.String, |
| 257 | cause: Schema.optional(Schema.Defect()), |
| 258 | }, |
| 259 | ) { |
| 260 | override get message(): string { |
| 261 | return `Source control repository operation ${this.operation} failed for ${this.provider}: ${this.detail}`; |
| 262 | } |
| 263 | } |