Open History to see the last commit
1import * as Effect from "effect/Effect";
2import * as Schema from "effect/Schema";
3
4import {
5 EnvironmentId,
6 ForwardCompatibleOptional,
7 ProjectId,
8 ThreadId,
9 TrimmedNonEmptyString,
10} from "./baseSchemas.ts";
11import { SourceControlProviderKind } from "./sourceControl.ts";
12
13export const ORCHESTRATION_PROTOCOL_VERSION = 2;
14export const ORCHESTRATION_PROTOCOL_VERSION_TEXT = "2";
15export const ORCHESTRATION_PROTOCOL_QUERY_PARAM = "orchestrationProtocol";
16export const ORCHESTRATION_PROTOCOL_HEADER = "x-t3-orchestration-protocol";
17
18export const ExecutionEnvironmentPlatformOs = Schema.Literals([
19 "darwin",
20 "linux",
21 "windows",
22 "unknown",
23]);
24export type ExecutionEnvironmentPlatformOs = typeof ExecutionEnvironmentPlatformOs.Type;
25
26export const ExecutionEnvironmentPlatformArch = Schema.Literals(["arm64", "x64", "other"]);
27export type ExecutionEnvironmentPlatformArch = typeof ExecutionEnvironmentPlatformArch.Type;
28
29export const ENVIRONMENT_MACHINE_KINDS = [
30 "server",
31 "cloud",
32 "linux",
33 "desktop",
34 "laptop",
35 "mac-mini",
36 "mac-studio",
37] as const;
38export const EnvironmentMachineKind = Schema.Literals(ENVIRONMENT_MACHINE_KINDS);
39export type EnvironmentMachineKind = typeof EnvironmentMachineKind.Type;
40export const isEnvironmentMachineKind = Schema.is(EnvironmentMachineKind);
41
42export const ExecutionEnvironmentPlatform = Schema.Struct({
43 os: ExecutionEnvironmentPlatformOs,
44 arch: ExecutionEnvironmentPlatformArch,
45 machine: ForwardCompatibleOptional(EnvironmentMachineKind),
46});
47
48/**
49 * Lives here (not settings.ts) so orchestration contracts can reference it
50 * without an import cycle.
51 */
52export const ThreadEnvMode = Schema.Literals(["local", "worktree"]);
53export type ThreadEnvMode = typeof ThreadEnvMode.Type;
54
55export const WorktreeSubmodules = Schema.Literals(["recursive", "top-level", "none"]);
56export type WorktreeSubmodules = typeof WorktreeSubmodules.Type;
57export type ExecutionEnvironmentPlatform = typeof ExecutionEnvironmentPlatform.Type;
58
59export const ServerSelfUpdateMethod = Schema.Literals(["boot-service", "respawn", "desktop-app"]);
60export type ServerSelfUpdateMethod = typeof ServerSelfUpdateMethod.Type;
61
62export const ServerInstallation = Schema.Union([
63 Schema.Struct({ kind: Schema.Literals(["npx", "pnpm-dlx", "bunx"]) }),
64 Schema.Struct({ kind: Schema.Literal("npm-global"), prefix: TrimmedNonEmptyString }),
65]);
66export type ServerInstallation = typeof ServerInstallation.Type;
67
68export const ServerSelfUpdateCapability = Schema.Literals([
69 "boot-service",
70 "respawn",
71 "desktop-managed",
72]);
73export type ServerSelfUpdateCapability = typeof ServerSelfUpdateCapability.Type;
74
75export const ExecutionEnvironmentCapabilities = Schema.Struct({
76 repositoryIdentity: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),
77 connectionProbe: Schema.optionalKey(Schema.Boolean),
78 attachmentUploads: Schema.optionalKey(Schema.Boolean),
79 questionAttachments: Schema.optionalKey(Schema.Boolean),
80 fileAttachments: Schema.optionalKey(
81 Schema.Struct({
82 maxUploadBytes: Schema.Int.check(Schema.isGreaterThanOrEqualTo(1)),
83 }),
84 ),
85 pullRequests: Schema.optionalKey(Schema.Boolean),
86 pullRequestChecks: Schema.optionalKey(Schema.Boolean),
87 /** Absent on servers from before inline context shipped, which drop the records and forward
88 the links as literal text -- so a client must serialize context the legacy way for them. */
89 inlineMessageContext: Schema.optionalKey(Schema.Boolean),
90 requiredWorktreeBootstrap: Schema.optionalKey(Schema.Boolean),
91 threadSettlement: Schema.optionalKey(Schema.Boolean),
92 threadAutoSettlement: Schema.optionalKey(Schema.Boolean),
93 storageCleanup: Schema.optionalKey(Schema.Boolean),
94 storageCleanupRun: Schema.optionalKey(Schema.Boolean),
95 /** Server streams database size and reclaimable space for the Storage settings notice. */
96 databaseStorage: Schema.optionalKey(Schema.Boolean),
97 /** Server checks OTLP endpoints for the telemetry export settings. */
98 otlpEndpointCheck: Schema.optionalKey(Schema.Boolean),
99 projectWorktreeCleanup: Schema.optionalKey(Schema.Boolean),
100 settledWorktreeCleanup: Schema.optionalKey(Schema.Boolean),
101 worktreesDirectory: Schema.optionalKey(Schema.Boolean),
102 threadAutoSettlementScope: Schema.optionalKey(Schema.Boolean),
103 threadRestartContinuation: Schema.optionalKey(Schema.Boolean),
104 projectSettingsOverrides: Schema.optionalKey(Schema.Boolean),
105 /**
106 * Older
107 servers decode the key away (unknown fields are stripped, not
108 rejected), so the per-project provider switch would silently do
109 nothing; clients hide it instead of sending a patch that goes nowhere.
110 */
111 projectProviderInstanceOverrides: Schema.optionalKey(Schema.Boolean),
112 threadSnooze: Schema.optionalKey(Schema.Boolean),
113 /** Absent on servers from
114 before environment themes shipped, which never emit the events -- so a
115 client reconnecting to one must drop published themes rather than keep
116 showing a set nothing will ever update. */
117 environmentThemes: Schema.optionalKey(Schema.Boolean),
118 usageLimitSources: Schema.optionalKey(Schema.Boolean),
119 usagePriceOverrides: Schema.optionalKey(Schema.Boolean),
120 usageModelAliases: Schema.optionalKey(Schema.Boolean),
121 threadPinning: Schema.optionalKey(Schema.Boolean),
122 threadPinReorder: Schema.optionalKey(Schema.Boolean),
123 threadActiveReorder: Schema.optionalKey(Schema.Boolean),
124 threadAutoSettleOptOut: Schema.optionalKey(Schema.Boolean),
125 threadTitleRegeneration: Schema.optionalKey(Schema.Boolean),
126 threadVisitedTracking: Schema.optionalKey(Schema.Boolean),
127 threadPullRequestLinking: Schema.optionalKey(Schema.Boolean),
128 serverResolvedCommandContext: Schema.optionalKey(Schema.Boolean),
129 threadStop: Schema.optionalKey(Schema.Boolean),
130 threadPullRequests: Schema.optionalKey(Schema.Boolean),
131 threadPullRequestWatch: Schema.optionalKey(Schema.Boolean),
132 pullRequestStackActions: Schema.optionalKey(Schema.Boolean),
133 serverSelfUpdate: Schema.optionalKey(ServerSelfUpdateCapability),
134 /** Manual commands must update this install, not the host's default global prefix. */
135 serverInstallation: ForwardCompatibleOptional(ServerInstallation),
136 serverSelfUpdateProgress: Schema.optionalKey(Schema.Boolean),
137 serverUpdateThreadContinuation: Schema.optionalKey(Schema.Boolean),
138 /**
139 * Clients skip seeding a Live Activity when
140 this is false — no update would ever repaint it. Absent on older
141 servers, which may still publish, so only an explicit false skips.
142 */
143 agentActivityPublishing: Schema.optionalKey(Schema.Boolean),
144 projectCloneTracking: Schema.optionalKey(Schema.Boolean),
145 /** Server answers projects.listIgnoredFiles. */
146 ignoredFileListing: Schema.optionalKey(Schema.Boolean),
147 environmentIcon: Schema.optionalKey(Schema.Boolean),
148 desktopAppUpdate: Schema.optionalKey(Schema.Boolean),
149 /** Server answers orchestration.subscribeCommandOutput. Absent on older servers,
150 which never send command output, so clients must not subscribe. */
151 commandOutputStreaming: Schema.optionalKey(Schema.Boolean),
152 /** Server hosts preview tabs in its own headless Chromium (`runtime:
153 "server"`) and streams them over `/api/preview-stream`. Clients
154 without a local browser runtime open server tabs here. */
155 serverBrowser: Schema.optionalKey(Schema.Boolean),
156});
157export type ExecutionEnvironmentCapabilities = typeof ExecutionEnvironmentCapabilities.Type;
158
159export const ExecutionEnvironmentDescriptor = Schema.Struct({
160 environmentId: EnvironmentId,
161 label: TrimmedNonEmptyString,
162 platform: ExecutionEnvironmentPlatform,
163 serverVersion: TrimmedNonEmptyString,
164 orchestrationProtocolVersion: Schema.optionalKey(Schema.Int),
165 capabilities: ExecutionEnvironmentCapabilities,
166});
167export type ExecutionEnvironmentDescriptor = typeof ExecutionEnvironmentDescriptor.Type;
168
169export const RepositoryIdentityLocator = Schema.Struct({
170 source: Schema.Literal("git-remote"),
171 remoteName: TrimmedNonEmptyString,
172 remoteUrl: TrimmedNonEmptyString,
173});
174export type RepositoryIdentityLocator = typeof RepositoryIdentityLocator.Type;
175
176export const RepositoryOrigin = Schema.Struct({
177 canonicalKey: TrimmedNonEmptyString,
178 remoteUrl: Schema.optionalKey(TrimmedNonEmptyString),
179 displayName: Schema.optionalKey(TrimmedNonEmptyString),
180});
181export type RepositoryOrigin = typeof RepositoryOrigin.Type;
182
183export const RepositoryIdentity = Schema.Struct({
184 canonicalKey: TrimmedNonEmptyString,
185 locator: RepositoryIdentityLocator,
186 webUrl: Schema.optionalKey(TrimmedNonEmptyString),
187 /** Work tree root, or the git dir for a bare repository. */
188 rootPath: Schema.optionalKey(TrimmedNonEmptyString),
189 displayName: Schema.optionalKey(TrimmedNonEmptyString),
190 provider: Schema.optionalKey(SourceControlProviderKind),
191 owner: Schema.optionalKey(TrimmedNonEmptyString),
192 name: Schema.optionalKey(TrimmedNonEmptyString),
193 origin: Schema.optionalKey(RepositoryOrigin),
194});
195export type RepositoryIdentity = typeof RepositoryIdentity.Type;
196
197export function repositoryGroupingKeyOf(identity: RepositoryIdentity): string {
198 return identity.origin?.canonicalKey ?? identity.canonicalKey;
199}
200
201export function repositoryGroupingDisplayNameOf(identity: RepositoryIdentity): string | undefined {
202 return identity.origin
203 ? (identity.origin.displayName ?? identity.origin.canonicalKey)
204 : identity.displayName;
205}
206
207export const ScopedProjectRef = Schema.Struct({
208 environmentId: EnvironmentId,
209 projectId: ProjectId,
210});
211export type ScopedProjectRef = typeof ScopedProjectRef.Type;
212
213export const ScopedThreadRef = Schema.Struct({
214 environmentId: EnvironmentId,
215 threadId: ThreadId,
216});
217export type ScopedThreadRef = typeof ScopedThreadRef.Type;