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
12/** Wire version for orchestration snapshots, streams, commands, and RPC payloads. */
13export const ORCHESTRATION_PROTOCOL_VERSION = 1;
14export const ORCHESTRATION_PROTOCOL_QUERY_PARAM = "orchestrationProtocol";
15
16export const ExecutionEnvironmentPlatformOs = Schema.Literals([
17 "darwin",
18 "linux",
19 "windows",
20 "unknown",
21]);
22export type ExecutionEnvironmentPlatformOs = typeof ExecutionEnvironmentPlatformOs.Type;
23
24export const ExecutionEnvironmentPlatformArch = Schema.Literals(["arm64", "x64", "other"]);
25export type ExecutionEnvironmentPlatformArch = typeof ExecutionEnvironmentPlatformArch.Type;
26
27/**
28 * The curated set of machine shapes and OS identities an environment can wear as its icon.
29 * Servers detect one from the hardware they run on (`platform.machine`), and
30 * the `environmentIcon` server setting lets a user pick one instead.
31 */
32export const ENVIRONMENT_MACHINE_KINDS = [
33 "server",
34 "cloud",
35 "linux",
36 "desktop",
37 "laptop",
38 "mac-mini",
39 "mac-studio",
40] as const;
41export const EnvironmentMachineKind = Schema.Literals(ENVIRONMENT_MACHINE_KINDS);
42export type EnvironmentMachineKind = typeof EnvironmentMachineKind.Type;
43export const isEnvironmentMachineKind = Schema.is(EnvironmentMachineKind);
44
45export const ExecutionEnvironmentPlatform = Schema.Struct({
46 os: ExecutionEnvironmentPlatformOs,
47 arch: ExecutionEnvironmentPlatformArch,
48 /** Hardware shape detected at startup. Absent when the host gives no usable
49 signal (containers, Windows, unknown DMI), on servers that predate it, or
50 when a newer server names a kind this build cannot draw. */
51 machine: ForwardCompatibleOptional(EnvironmentMachineKind),
52});
53
54/**
55 * Where a new thread runs: the project's current checkout ("local") or a
56 * fresh git worktree ("worktree"). Lives here (not settings.ts) so
57 * orchestration contracts can reference it without an import cycle.
58 */
59export const ThreadEnvMode = Schema.Literals(["local", "worktree"]);
60export type ThreadEnvMode = typeof ThreadEnvMode.Type;
61
62/**
63 * How a new worktree populates git submodules: every nested level, only the
64 * ones this repository declares, or not at all.
65 */
66export const WorktreeSubmodules = Schema.Literals(["recursive", "top-level", "none"]);
67export type WorktreeSubmodules = typeof WorktreeSubmodules.Type;
68export type ExecutionEnvironmentPlatform = typeof ExecutionEnvironmentPlatform.Type;
69
70/** How a server can replace itself with another version when asked over RPC.
71 New servers only advertise the stable launcher-backed "boot-service" path;
72 "respawn" remains decodable for compatibility with older servers.
73 "desktop-app" means the supervising desktop app updated and relaunched
74 itself, bringing the server back with it. */
75export const ServerSelfUpdateMethod = Schema.Literals(["boot-service", "respawn", "desktop-app"]);
76export type ServerSelfUpdateMethod = typeof ServerSelfUpdateMethod.Type;
77
78/** What update path a client should offer for a server: one of the RPC
79 self-update methods above, or "desktop-managed" when the backend's
80 version belongs to the T3 Code desktop app supervising it — updating the
81 app on that machine is the only way to update the server. */
82export const ServerSelfUpdateCapability = Schema.Literals([
83 "boot-service",
84 "respawn",
85 "desktop-managed",
86]);
87export type ServerSelfUpdateCapability = typeof ServerSelfUpdateCapability.Type;
88
89export const ExecutionEnvironmentCapabilities = Schema.Struct({
90 repositoryIdentity: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),
91 connectionProbe: Schema.optionalKey(Schema.Boolean),
92 /** Missing on older servers, which still accept inline image attachments. */
93 attachmentUploads: Schema.optionalKey(Schema.Boolean),
94 /** Uploaded files may accompany question answers. */
95 questionAttachments: Schema.optionalKey(Schema.Boolean),
96 /** Missing on servers that only accept image attachments. */
97 fileAttachments: Schema.optionalKey(
98 Schema.Struct({
99 maxUploadBytes: Schema.Int.check(Schema.isGreaterThanOrEqualTo(1)),
100 }),
101 ),
102 /** Server exposes the pull-request list, detail, activity, diff, and mutation APIs. Absent on
103 servers from before the pull-request workspace shipped, so clients must not probe them. */
104 pullRequests: Schema.optionalKey(Schema.Boolean),
105 /** Server understands canonical inline context links plus their message context records.
106 Absent on servers from before inline context shipped, which drop the records and forward
107 the links as literal text -- so a client must serialize context the legacy way for them. */
108 inlineMessageContext: Schema.optionalKey(Schema.Boolean),
109 /** Server rejects required worktrees instead of falling back to the project checkout. */
110 requiredWorktreeBootstrap: Schema.optionalKey(Schema.Boolean),
111 /** Server understands thread.settle / thread.unsettle commands. Absent on
112 pre-settlement servers, so clients treat missing as unsupported and
113 never send the commands under version skew. */
114 threadSettlement: Schema.optionalKey(Schema.Boolean),
115 /** Server evaluates merge and inactivity settlement without a client. */
116 threadAutoSettlement: Schema.optionalKey(Schema.Boolean),
117 storageCleanup: Schema.optionalKey(Schema.Boolean),
118 projectWorktreeCleanup: Schema.optionalKey(Schema.Boolean),
119 /** Server persists the opt-in for continuing interrupted threads after restarts. */
120 threadRestartContinuation: Schema.optionalKey(Schema.Boolean),
121 /** Server resolves `projectSettingsOverrides`; older servers ignore the key. */
122 projectSettingsOverrides: Schema.optionalKey(Schema.Boolean),
123 /** Server understands thread.snooze / thread.unsnooze commands. Same
124 version-skew contract as threadSettlement. */
125 threadSnooze: Schema.optionalKey(Schema.Boolean),
126 /** Server streams themes an environment publishes. Absent on servers from
127 before environment themes shipped, which never emit the events -- so a
128 client reconnecting to one must drop published themes rather than keep
129 showing a set nothing will ever update. */
130 environmentThemes: Schema.optionalKey(Schema.Boolean),
131 /** Server streams quota from configured usage-limit sources. Same
132 version-skew contract as environmentThemes. */
133 usageLimitSources: Schema.optionalKey(Schema.Boolean),
134 /** Server persists custom model rates and applies them to usage summaries. */
135 usagePriceOverrides: Schema.optionalKey(Schema.Boolean),
136 /** Server understands thread.pin / thread.unpin commands. Same
137 version-skew contract as threadSettlement. */
138 threadPinning: Schema.optionalKey(Schema.Boolean),
139 /** Server understands thread.pin.reorder (and orderKey on thread.pin).
140 Same version-skew contract as threadSettlement. */
141 threadPinReorder: Schema.optionalKey(Schema.Boolean),
142 /** Server persists manual Active order through thread.active.reorder. */
143 threadActiveReorder: Schema.optionalKey(Schema.Boolean),
144 /** Server understands thread.auto-settle.set (per-thread auto-settle off).
145 Same version-skew contract as threadSettlement. */
146 threadAutoSettleOptOut: Schema.optionalKey(Schema.Boolean),
147 /** Server understands regenerateTitle on thread.meta.update. Absent on
148 older servers, so clients hide the action instead of sending it. */
149 threadTitleRegeneration: Schema.optionalKey(Schema.Boolean),
150 /** Server supports legacy linkedPullRequest updates through thread.meta.update.
151 Independent of threadPullRequests; servers supporting both advertise both. */
152 threadPullRequestLinking: Schema.optionalKey(Schema.Boolean),
153 /** Server understands thread.pull-request.link / .unlink, exposes `pullRequests` on
154 threads, and routes PullRequestRef.host across projects on the same host. Same
155 version-skew contract as threadSettlement. */
156 threadPullRequests: Schema.optionalKey(Schema.Boolean),
157 pullRequestStackActions: Schema.optionalKey(Schema.Boolean),
158 /** The update path clients should offer for this server. Absent on
159 servers that must be relaunched manually (dev checkouts, Windows
160 foreground runs, pre-update servers). */
161 serverSelfUpdate: Schema.optionalKey(ServerSelfUpdateCapability),
162 /** Server can stream self-update progress before acknowledging the
163 restart. Clients fall back to server.updateServer when absent. */
164 serverSelfUpdateProgress: Schema.optionalKey(Schema.Boolean),
165 /** Server can durably mark running provider turns before a self-update and
166 continue them after the replacement process starts. */
167 serverUpdateThreadContinuation: Schema.optionalKey(Schema.Boolean),
168 /** Agent-activity publishes (push notifications and Live Activities)
169 currently leave this environment: the publish opt-in is enabled and the
170 relay link credentials exist. Clients skip seeding a Live Activity when
171 this is false — no update would ever repaint it. Absent on older
172 servers, which may still publish, so only an explicit false skips. */
173 agentActivityPublishing: Schema.optionalKey(Schema.Boolean),
174 /** Server runs repository clones for new projects in the background and
175 streams their progress (`projectClone.*`, `subscribeProjectClones`).
176 Absent on older servers, where clients must clone with the blocking
177 `sourceControl.cloneRepository` call instead. */
178 projectCloneTracking: Schema.optionalKey(Schema.Boolean),
179 /** Server detects `platform.machine` and persists the `environmentIcon`
180 setting. Older servers drop the key on write, so clients show the
181 picker inert rather than offering a choice that would never stick. */
182 environmentIcon: Schema.optionalKey(Schema.Boolean),
183 /** The desktop app supervising this server can be driven over RPC:
184 server.updateServer runs its check -> download -> relaunch. Absent on
185 desktop servers whose app predates the remote trigger, where clients
186 must keep telling the user to update the app on that machine. */
187 desktopAppUpdate: Schema.optionalKey(Schema.Boolean),
188});
189export type ExecutionEnvironmentCapabilities = typeof ExecutionEnvironmentCapabilities.Type;
190
191export const ExecutionEnvironmentDescriptor = Schema.Struct({
192 environmentId: EnvironmentId,
193 label: TrimmedNonEmptyString,
194 platform: ExecutionEnvironmentPlatform,
195 serverVersion: TrimmedNonEmptyString,
196 /** Missing metadata denotes protocol 1. Bump this for breaking wire changes. */
197 orchestrationProtocolVersion: Schema.optionalKey(Schema.Int),
198 capabilities: ExecutionEnvironmentCapabilities,
199});
200export type ExecutionEnvironmentDescriptor = typeof ExecutionEnvironmentDescriptor.Type;
201
202export const RepositoryIdentityLocator = Schema.Struct({
203 source: Schema.Literal("git-remote"),
204 remoteName: TrimmedNonEmptyString,
205 remoteUrl: TrimmedNonEmptyString,
206});
207export type RepositoryIdentityLocator = typeof RepositoryIdentityLocator.Type;
208
209export const RepositoryIdentity = Schema.Struct({
210 canonicalKey: TrimmedNonEmptyString,
211 locator: RepositoryIdentityLocator,
212 /** Repository browser URL resolved from the server's configured hosting account. */
213 webUrl: Schema.optionalKey(TrimmedNonEmptyString),
214 rootPath: Schema.optionalKey(TrimmedNonEmptyString),
215 displayName: Schema.optionalKey(TrimmedNonEmptyString),
216 provider: Schema.optionalKey(TrimmedNonEmptyString),
217 owner: Schema.optionalKey(TrimmedNonEmptyString),
218 name: Schema.optionalKey(TrimmedNonEmptyString),
219});
220export type RepositoryIdentity = typeof RepositoryIdentity.Type;
221
222export const ScopedProjectRef = Schema.Struct({
223 environmentId: EnvironmentId,
224 projectId: ProjectId,
225});
226export type ScopedProjectRef = typeof ScopedProjectRef.Type;
227
228export const ScopedThreadRef = Schema.Struct({
229 environmentId: EnvironmentId,
230 threadId: ThreadId,
231});
232export type ScopedThreadRef = typeof ScopedThreadRef.Type;