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 regenerateTitle on thread.meta.update. Absent on
145 older servers, so clients hide the action instead of sending it. */
146 threadTitleRegeneration: Schema.optionalKey(Schema.Boolean),
147 /** Server supports legacy linkedPullRequest updates through thread.meta.update.
148 Independent of threadPullRequests; servers supporting both advertise both. */
149 threadPullRequestLinking: Schema.optionalKey(Schema.Boolean),
150 /** Server understands thread.pull-request.link / .unlink, exposes `pullRequests` on
151 threads, and routes PullRequestRef.host across projects on the same host. Same
152 version-skew contract as threadSettlement. */
153 threadPullRequests: Schema.optionalKey(Schema.Boolean),
154 pullRequestStackActions: Schema.optionalKey(Schema.Boolean),
155 /** The update path clients should offer for this server. Absent on
156 servers that must be relaunched manually (dev checkouts, Windows
157 foreground runs, pre-update servers). */
158 serverSelfUpdate: Schema.optionalKey(ServerSelfUpdateCapability),
159 /** Server can stream self-update progress before acknowledging the
160 restart. Clients fall back to server.updateServer when absent. */
161 serverSelfUpdateProgress: Schema.optionalKey(Schema.Boolean),
162 /** Server can durably mark running provider turns before a self-update and
163 continue them after the replacement process starts. */
164 serverUpdateThreadContinuation: Schema.optionalKey(Schema.Boolean),
165 /** Agent-activity publishes (push notifications and Live Activities)
166 currently leave this environment: the publish opt-in is enabled and the
167 relay link credentials exist. Clients skip seeding a Live Activity when
168 this is false — no update would ever repaint it. Absent on older
169 servers, which may still publish, so only an explicit false skips. */
170 agentActivityPublishing: Schema.optionalKey(Schema.Boolean),
171 /** Server runs repository clones for new projects in the background and
172 streams their progress (`projectClone.*`, `subscribeProjectClones`).
173 Absent on older servers, where clients must clone with the blocking
174 `sourceControl.cloneRepository` call instead. */
175 projectCloneTracking: Schema.optionalKey(Schema.Boolean),
176 /** Server detects `platform.machine` and persists the `environmentIcon`
177 setting. Older servers drop the key on write, so clients show the
178 picker inert rather than offering a choice that would never stick. */
179 environmentIcon: Schema.optionalKey(Schema.Boolean),
180 /** The desktop app supervising this server can be driven over RPC:
181 server.updateServer runs its check -> download -> relaunch. Absent on
182 desktop servers whose app predates the remote trigger, where clients
183 must keep telling the user to update the app on that machine. */
184 desktopAppUpdate: Schema.optionalKey(Schema.Boolean),
185});
186export type ExecutionEnvironmentCapabilities = typeof ExecutionEnvironmentCapabilities.Type;
187
188export const ExecutionEnvironmentDescriptor = Schema.Struct({
189 environmentId: EnvironmentId,
190 label: TrimmedNonEmptyString,
191 platform: ExecutionEnvironmentPlatform,
192 serverVersion: TrimmedNonEmptyString,
193 /** Missing metadata denotes protocol 1. Bump this for breaking wire changes. */
194 orchestrationProtocolVersion: Schema.optionalKey(Schema.Int),
195 capabilities: ExecutionEnvironmentCapabilities,
196});
197export type ExecutionEnvironmentDescriptor = typeof ExecutionEnvironmentDescriptor.Type;
198
199export const RepositoryIdentityLocator = Schema.Struct({
200 source: Schema.Literal("git-remote"),
201 remoteName: TrimmedNonEmptyString,
202 remoteUrl: TrimmedNonEmptyString,
203});
204export type RepositoryIdentityLocator = typeof RepositoryIdentityLocator.Type;
205
206export const RepositoryIdentity = Schema.Struct({
207 canonicalKey: TrimmedNonEmptyString,
208 locator: RepositoryIdentityLocator,
209 /** Repository browser URL resolved from the server's configured hosting account. */
210 webUrl: Schema.optionalKey(TrimmedNonEmptyString),
211 rootPath: Schema.optionalKey(TrimmedNonEmptyString),
212 displayName: Schema.optionalKey(TrimmedNonEmptyString),
213 provider: Schema.optionalKey(TrimmedNonEmptyString),
214 owner: Schema.optionalKey(TrimmedNonEmptyString),
215 name: Schema.optionalKey(TrimmedNonEmptyString),
216});
217export type RepositoryIdentity = typeof RepositoryIdentity.Type;
218
219export const ScopedProjectRef = Schema.Struct({
220 environmentId: EnvironmentId,
221 projectId: ProjectId,
222});
223export type ScopedProjectRef = typeof ScopedProjectRef.Type;
224
225export const ScopedThreadRef = Schema.Struct({
226 environmentId: EnvironmentId,
227 threadId: ThreadId,
228});
229export type ScopedThreadRef = typeof ScopedThreadRef.Type;