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 Effect from "effect/Effect"; |
| 2 | import * as Schema from "effect/Schema"; |
| 3 | |
| 4 | import { |
| 5 | EnvironmentId, |
| 6 | ForwardCompatibleOptional, |
| 7 | ProjectId, |
| 8 | ThreadId, |
| 9 | TrimmedNonEmptyString, |
| 10 | } from "./baseSchemas.ts"; |
| 11 | import { SourceControlProviderKind } from "./sourceControl.ts"; |
| 12 | |
| 13 | export const ORCHESTRATION_PROTOCOL_VERSION = 2; |
| 14 | export const ORCHESTRATION_PROTOCOL_VERSION_TEXT = "2"; |
| 15 | export const ORCHESTRATION_PROTOCOL_QUERY_PARAM = "orchestrationProtocol"; |
| 16 | export const ORCHESTRATION_PROTOCOL_HEADER = "x-t3-orchestration-protocol"; |
| 17 | |
| 18 | /** Wire shapes a client understands, comma-separated; a client that omits one gets the older shape. */ |
| 19 | export const CLIENT_CAPABILITIES_QUERY_PARAM = "clientCapabilities"; |
| 20 | /** Secret fields may hold a secret provider reference instead of a string. */ |
| 21 | export const SETTINGS_SECRET_REFERENCES_CAPABILITY = "settingsSecretReferences"; |
| 22 | |
| 23 | export const ExecutionEnvironmentPlatformOs = Schema.Literals([ |
| 24 | "darwin", |
| 25 | "linux", |
| 26 | "windows", |
| 27 | "unknown", |
| 28 | ]); |
| 29 | export type ExecutionEnvironmentPlatformOs = typeof ExecutionEnvironmentPlatformOs.Type; |
| 30 | |
| 31 | export const ExecutionEnvironmentPlatformArch = Schema.Literals(["arm64", "x64", "other"]); |
| 32 | export type ExecutionEnvironmentPlatformArch = typeof ExecutionEnvironmentPlatformArch.Type; |
| 33 | |
| 34 | export const ENVIRONMENT_MACHINE_KINDS = [ |
| 35 | "server", |
| 36 | "cloud", |
| 37 | "linux", |
| 38 | "desktop", |
| 39 | "laptop", |
| 40 | "mac-mini", |
| 41 | "mac-studio", |
| 42 | ] as const; |
| 43 | export const EnvironmentMachineKind = Schema.Literals(ENVIRONMENT_MACHINE_KINDS); |
| 44 | export type EnvironmentMachineKind = typeof EnvironmentMachineKind.Type; |
| 45 | export const isEnvironmentMachineKind = Schema.is(EnvironmentMachineKind); |
| 46 | |
| 47 | export const ExecutionEnvironmentPlatform = Schema.Struct({ |
| 48 | os: ExecutionEnvironmentPlatformOs, |
| 49 | arch: ExecutionEnvironmentPlatformArch, |
| 50 | machine: ForwardCompatibleOptional(EnvironmentMachineKind), |
| 51 | }); |
| 52 | |
| 53 | // Kept outside settings.ts to avoid an orchestration import cycle. |
| 54 | export const ThreadEnvMode = Schema.Literals(["local", "worktree"]); |
| 55 | export type ThreadEnvMode = typeof ThreadEnvMode.Type; |
| 56 | |
| 57 | export const WorktreeSubmodules = Schema.Literals(["recursive", "top-level", "none"]); |
| 58 | export type WorktreeSubmodules = typeof WorktreeSubmodules.Type; |
| 59 | export type ExecutionEnvironmentPlatform = typeof ExecutionEnvironmentPlatform.Type; |
| 60 | |
| 61 | export const ServerSelfUpdateMethod = Schema.Literals(["boot-service", "respawn", "desktop-app"]); |
| 62 | export type ServerSelfUpdateMethod = typeof ServerSelfUpdateMethod.Type; |
| 63 | |
| 64 | // Not trimmed: a path that differs from the installed one would update the wrong home. |
| 65 | const InstalledPath = Schema.String.check(Schema.isNonEmpty()); |
| 66 | |
| 67 | export const ServerInstallation = Schema.Union([ |
| 68 | Schema.Struct({ kind: Schema.Literals(["npx", "pnpm-dlx", "bunx"]) }), |
| 69 | Schema.Struct({ kind: Schema.Literal("npm-global"), prefix: TrimmedNonEmptyString }), |
| 70 | // A launcher (script, or a legacy symlink) into a downloaded runtime, as the install script and `t3 update` leave. |
| 71 | Schema.Struct({ |
| 72 | kind: Schema.Literal("t3-launcher"), |
| 73 | launcher: InstalledPath, |
| 74 | baseDir: InstalledPath, |
| 75 | }), |
| 76 | ]); |
| 77 | export type ServerInstallation = typeof ServerInstallation.Type; |
| 78 | |
| 79 | export const ServerSelfUpdateCapability = Schema.Literals([ |
| 80 | "boot-service", |
| 81 | "respawn", |
| 82 | "desktop-managed", |
| 83 | ]); |
| 84 | export type ServerSelfUpdateCapability = typeof ServerSelfUpdateCapability.Type; |
| 85 | |
| 86 | export const ExecutionEnvironmentCapabilities = Schema.Struct({ |
| 87 | repositoryIdentity: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))), |
| 88 | connectionProbe: Schema.optionalKey(Schema.Boolean), |
| 89 | /** A DPoP session from a pairing link renews at /oauth/token; pair with a bearer where absent. */ |
| 90 | accessTokenRenewal: Schema.optionalKey(Schema.Boolean), |
| 91 | attachmentUploads: Schema.optionalKey(Schema.Boolean), |
| 92 | questionAttachments: Schema.optionalKey(Schema.Boolean), |
| 93 | fileAttachments: Schema.optionalKey( |
| 94 | Schema.Struct({ |
| 95 | maxUploadBytes: Schema.Int.check(Schema.isGreaterThanOrEqualTo(1)), |
| 96 | }), |
| 97 | ), |
| 98 | pullRequests: Schema.optionalKey(Schema.Boolean), |
| 99 | pullRequestChecks: Schema.optionalKey(Schema.Boolean), |
| 100 | issues: Schema.optionalKey(Schema.Boolean), |
| 101 | /** Side chats: hidden `lineage.sideChat` forks. Older servers ignore the fork flag. */ |
| 102 | sideChats: Schema.optionalKey(Schema.Boolean), |
| 103 | vcsBranchStatus: Schema.optionalKey(Schema.Boolean), |
| 104 | /** Every protocol-2 server sends this; older mobile builds still read it. */ |
| 105 | inlineMessageContext: Schema.optionalKey(Schema.Boolean), |
| 106 | requiredWorktreeBootstrap: Schema.optionalKey(Schema.Boolean), |
| 107 | threadSettlement: Schema.optionalKey(Schema.Boolean), |
| 108 | threadAutoSettlement: Schema.optionalKey(Schema.Boolean), |
| 109 | storageCleanup: Schema.optionalKey(Schema.Boolean), |
| 110 | storageCleanupRun: Schema.optionalKey(Schema.Boolean), |
| 111 | databaseStorage: Schema.optionalKey(Schema.Boolean), |
| 112 | otlpEndpointCheck: Schema.optionalKey(Schema.Boolean), |
| 113 | /** Serves `server.checkSecretSource`; hide the secret check where it is absent. */ |
| 114 | secretSourceCheck: Schema.optionalKey(Schema.Boolean), |
| 115 | projectWorktreeCleanup: Schema.optionalKey(Schema.Boolean), |
| 116 | settledWorktreeCleanup: Schema.optionalKey(Schema.Boolean), |
| 117 | worktreesDirectory: Schema.optionalKey(Schema.Boolean), |
| 118 | /** Sent by macOS servers, which honor the fastWorktreeCheckout setting. */ |
| 119 | fastWorktreeCheckout: Schema.optionalKey(Schema.Boolean), |
| 120 | threadAutoSettlementScope: Schema.optionalKey(Schema.Boolean), |
| 121 | threadRestartContinuation: Schema.optionalKey(Schema.Boolean), |
| 122 | projectSettingsOverrides: Schema.optionalKey(Schema.Boolean), |
| 123 | /** Hide the switch when absent; older servers silently drop per-project provider patches. */ |
| 124 | projectProviderInstanceOverrides: Schema.optionalKey(Schema.Boolean), |
| 125 | threadSnooze: Schema.optionalKey(Schema.Boolean), |
| 126 | /** Serves `orchestration.forceStopThread`; hide Force stop where it is absent. */ |
| 127 | threadForceStop: Schema.optionalKey(Schema.Boolean), |
| 128 | /** Every protocol-2 server sends this; older mobile builds still read it. */ |
| 129 | environmentThemes: Schema.optionalKey(Schema.Boolean), |
| 130 | usageLimitSources: Schema.optionalKey(Schema.Boolean), |
| 131 | /** Honors `workspaceSnapshotsOnDemand`; older servers send every snapshot and drop them in the stream. */ |
| 132 | providerWorkspaceSnapshotsOnDemand: Schema.optionalKey(Schema.Boolean), |
| 133 | /** Honors `modelCatalogOnly`; older servers drop the field and probe every provider. */ |
| 134 | modelCatalogRefresh: Schema.optionalKey(Schema.Boolean), |
| 135 | usagePriceOverrides: Schema.optionalKey(Schema.Boolean), |
| 136 | usageModelAliases: Schema.optionalKey(Schema.Boolean), |
| 137 | threadPinning: Schema.optionalKey(Schema.Boolean), |
| 138 | threadPinReorder: Schema.optionalKey(Schema.Boolean), |
| 139 | threadActiveReorder: Schema.optionalKey(Schema.Boolean), |
| 140 | threadAutoSettleOptOut: Schema.optionalKey(Schema.Boolean), |
| 141 | threadProjectFromScratch: Schema.optionalKey(Schema.Boolean), |
| 142 | threadTitleRegeneration: Schema.optionalKey(Schema.Boolean), |
| 143 | threadVisitedTracking: Schema.optionalKey(Schema.Boolean), |
| 144 | threadPullRequestLinking: Schema.optionalKey(Schema.Boolean), |
| 145 | serverResolvedCommandContext: Schema.optionalKey(Schema.Boolean), |
| 146 | threadStop: Schema.optionalKey(Schema.Boolean), |
| 147 | /** Absent on older servers and on Windows hosts, which cannot stop a discovered server. */ |
| 148 | localServerStop: Schema.optionalKey(Schema.Boolean), |
| 149 | /** Honors `enablePreviewTunnel`; hide the switch where absent, since the tunnel stays on there. */ |
| 150 | previewTunnelSetting: Schema.optionalKey(Schema.Boolean), |
| 151 | threadPullRequests: Schema.optionalKey(Schema.Boolean), |
| 152 | threadPullRequestWatch: Schema.optionalKey(Schema.Boolean), |
| 153 | pullRequestStackActions: Schema.optionalKey(Schema.Boolean), |
| 154 | serverSelfUpdate: Schema.optionalKey(ServerSelfUpdateCapability), |
| 155 | /** Server answers server.getNpmRelease using its configured npm registry. */ |
| 156 | npmReleaseLookup: Schema.optionalKey(Schema.Boolean), |
| 157 | /** Manual commands must update this install, not the host's default global prefix. */ |
| 158 | serverInstallation: ForwardCompatibleOptional(ServerInstallation), |
| 159 | serverSelfUpdateProgress: Schema.optionalKey(Schema.Boolean), |
| 160 | serverUpdateStaging: Schema.optionalKey(Schema.Boolean), |
| 161 | serverUpdateThreadContinuation: Schema.optionalKey(Schema.Boolean), |
| 162 | /** Only explicit false skips Live Activity seeding; older servers may still publish. */ |
| 163 | agentActivityPublishing: Schema.optionalKey(Schema.Boolean), |
| 164 | projectCloneTracking: Schema.optionalKey(Schema.Boolean), |
| 165 | /** Server keeps `pinned` and `archived` from project.update. Older servers drop them. */ |
| 166 | projectOrganization: Schema.optionalKey(Schema.Boolean), |
| 167 | /** Server answers projects.listIgnoredFiles. */ |
| 168 | ignoredFileListing: Schema.optionalKey(Schema.Boolean), |
| 169 | /** projects.listIgnoredFiles honors `query`. Older servers ignore it. */ |
| 170 | ignoredFileSearch: Schema.optionalKey(Schema.Boolean), |
| 171 | environmentIcon: Schema.optionalKey(Schema.Boolean), |
| 172 | desktopAppUpdate: Schema.optionalKey(Schema.Boolean), |
| 173 | /** The desktop app switches update tracks when a server update request names one. */ |
| 174 | desktopAppChannelSwitch: Schema.optionalKey(Schema.Boolean), |
| 175 | /** Subscribe to command output only when advertised; older servers never send it. */ |
| 176 | commandOutputStreaming: Schema.optionalKey(Schema.Boolean), |
| 177 | /** Hosts headless Chromium tabs streamed over /api/preview-stream for clients without a local runtime. */ |
| 178 | serverBrowser: Schema.optionalKey(Schema.Boolean), |
| 179 | /** Server links to other environments (`PeerLink`) and its agents can work |
| 180 | in them. Absent on servers from before linking, which clients must not |
| 181 | offer linking for. */ |
| 182 | peerLinks: Schema.optionalKey(Schema.Boolean), |
| 183 | /** Server's `/mcp` narrows an OAuth client's modes from `T3-Mode-Limit`, so |
| 184 | a linked environment's calls keep its agent's limits. Another environment |
| 185 | links to this one only when it is set. */ |
| 186 | mcpModeLimitHeader: Schema.optionalKey(Schema.Boolean), |
| 187 | /** Work a linked environment starts here stays within its link |
| 188 | (`linkOrigin`). Another environment links to this one only when it is |
| 189 | set, since without it that work could change the user's own threads. */ |
| 190 | linkFence: Schema.optionalKey(Schema.Boolean), |
| 191 | /** Serves a thread's stream, history pages and item detail to a link's session |
| 192 | (`PEER_LINK_THREAD_STREAM_ROUTE`), so a client of the linking environment can read it. */ |
| 193 | linkThreadStream: Schema.optionalKey(Schema.Boolean), |
| 194 | /** A full-access link can ask this server for a one-time pairing credential for a client |
| 195 | of the linking environment. Absent on servers from before it. */ |
| 196 | linkClientPairing: Schema.optionalKey(Schema.Boolean), |
| 197 | /** Mints pairing codes that approve one agent sign-in at a set level (`AUTO-…`). */ |
| 198 | mcpApprovalCodes: Schema.optionalKey(Schema.Boolean), |
| 199 | peerLinkPairingCodes: Schema.optionalKey(Schema.Boolean), |
| 200 | /** Agent sign-ins on its T3 Connect address are approved on the hosted app, without a code. */ |
| 201 | mcpHostedApproval: Schema.optionalKey(Schema.Boolean), |
| 202 | /** Server answers server.prepareTriage. */ |
| 203 | triage: Schema.optionalKey(Schema.Boolean), |
| 204 | /** Server accepts `{ type: "once" }` scheduled tasks; older servers reject them on save. */ |
| 205 | oneTimeSchedules: Schema.optionalKey(Schema.Boolean), |
| 206 | /** Server honors `freshContext` on sends; older servers ignore it and keep the old context. */ |
| 207 | freshContext: Schema.optionalKey(Schema.Boolean), |
| 208 | /** Server saves and runs scheduled task `threadMode`; older servers ignore it. */ |
| 209 | scheduledTaskThreadModes: Schema.optionalKey(Schema.Boolean), |
| 210 | /** Server can transcribe 16 kHz mono PCM audio on the environment machine. */ |
| 211 | voiceTranscription: Schema.optionalKey(Schema.Boolean), |
| 212 | cloudVoiceTranscription: Schema.optionalKey(Schema.Boolean), |
| 213 | /** |
| 214 | * The server config's flags of the same names. A server that names them here lets a client |
| 215 | * load the shell snapshot before the socket opens, and answers its `resumeFrom`. |
| 216 | */ |
| 217 | shellThreadFamilies: Schema.optionalKey(Schema.Boolean), |
| 218 | shellOlderSettled: Schema.optionalKey(Schema.Boolean), |
| 219 | /** Publishes a pull request refresh when linked-thread answers change; older servers need polling. */ |
| 220 | linkedThreadRefreshes: Schema.optionalKey(Schema.Boolean), |
| 221 | /** Answers `issues.linkedThreads`, the threads an issue is linked to. */ |
| 222 | issueLinkedThreads: Schema.optionalKey(Schema.Boolean), |
| 223 | }); |
| 224 | export type ExecutionEnvironmentCapabilities = typeof ExecutionEnvironmentCapabilities.Type; |
| 225 | |
| 226 | export const ExecutionEnvironmentDescriptor = Schema.Struct({ |
| 227 | environmentId: EnvironmentId, |
| 228 | label: TrimmedNonEmptyString, |
| 229 | platform: ExecutionEnvironmentPlatform, |
| 230 | serverVersion: TrimmedNonEmptyString, |
| 231 | orchestrationProtocolVersion: Schema.optionalKey(Schema.Int), |
| 232 | /** Highest migration this server's database holds; absent on older servers. */ |
| 233 | databaseMigration: Schema.optionalKey(Schema.Int), |
| 234 | capabilities: ExecutionEnvironmentCapabilities, |
| 235 | }); |
| 236 | export type ExecutionEnvironmentDescriptor = typeof ExecutionEnvironmentDescriptor.Type; |
| 237 | |
| 238 | export const RepositoryIdentityLocator = Schema.Struct({ |
| 239 | source: Schema.Literal("git-remote"), |
| 240 | remoteName: TrimmedNonEmptyString, |
| 241 | remoteUrl: TrimmedNonEmptyString, |
| 242 | }); |
| 243 | export type RepositoryIdentityLocator = typeof RepositoryIdentityLocator.Type; |
| 244 | |
| 245 | export const RepositoryOrigin = Schema.Struct({ |
| 246 | canonicalKey: TrimmedNonEmptyString, |
| 247 | remoteUrl: Schema.optionalKey(TrimmedNonEmptyString), |
| 248 | displayName: Schema.optionalKey(TrimmedNonEmptyString), |
| 249 | }); |
| 250 | export type RepositoryOrigin = typeof RepositoryOrigin.Type; |
| 251 | |
| 252 | export const RepositoryIdentity = Schema.Struct({ |
| 253 | canonicalKey: TrimmedNonEmptyString, |
| 254 | locator: RepositoryIdentityLocator, |
| 255 | webUrl: Schema.optionalKey(TrimmedNonEmptyString), |
| 256 | /** Work tree root, or the git dir for a bare repository. */ |
| 257 | rootPath: Schema.optionalKey(TrimmedNonEmptyString), |
| 258 | displayName: Schema.optionalKey(TrimmedNonEmptyString), |
| 259 | provider: Schema.optionalKey(SourceControlProviderKind), |
| 260 | owner: Schema.optionalKey(TrimmedNonEmptyString), |
| 261 | name: Schema.optionalKey(TrimmedNonEmptyString), |
| 262 | origin: Schema.optionalKey(RepositoryOrigin), |
| 263 | }); |
| 264 | export type RepositoryIdentity = typeof RepositoryIdentity.Type; |
| 265 | |
| 266 | export function repositoryGroupingKeyOf(identity: RepositoryIdentity): string { |
| 267 | return identity.origin?.canonicalKey ?? identity.canonicalKey; |
| 268 | } |
| 269 | |
| 270 | export function repositoryGroupingDisplayNameOf(identity: RepositoryIdentity): string | undefined { |
| 271 | return identity.origin |
| 272 | ? (identity.origin.displayName ?? identity.origin.canonicalKey) |
| 273 | : identity.displayName; |
| 274 | } |
| 275 | |
| 276 | export const ScopedProjectRef = Schema.Struct({ |
| 277 | environmentId: EnvironmentId, |
| 278 | projectId: ProjectId, |
| 279 | }); |
| 280 | export type ScopedProjectRef = typeof ScopedProjectRef.Type; |
| 281 | |
| 282 | export const ScopedThreadRef = Schema.Struct({ |
| 283 | environmentId: EnvironmentId, |
| 284 | threadId: ThreadId, |
| 285 | }); |
| 286 | export type ScopedThreadRef = typeof ScopedThreadRef.Type; |