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