Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

environment.ts

234 lines11.9 KB

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 stages worktree removal and restores it if thread deletion fails. */
116 recoverableThreadDeletion: Schema.optionalKey(Schema.Boolean),
117 /** Server evaluates merge and inactivity settlement without a client. */
118 threadAutoSettlement: Schema.optionalKey(Schema.Boolean),
119 storageCleanup: Schema.optionalKey(Schema.Boolean),
120 projectWorktreeCleanup: Schema.optionalKey(Schema.Boolean),
121 /** Server persists the opt-in for continuing interrupted threads after restarts. */
122 threadRestartContinuation: Schema.optionalKey(Schema.Boolean),
123 /** Server resolves `projectSettingsOverrides`; older servers ignore the key. */
124 projectSettingsOverrides: Schema.optionalKey(Schema.Boolean),
125 /** Server understands thread.snooze / thread.unsnooze commands. Same
126 version-skew contract as threadSettlement. */
127 threadSnooze: Schema.optionalKey(Schema.Boolean),
128 /** Server streams themes an environment publishes. Absent on servers from
129 before environment themes shipped, which never emit the events -- so a
130 client reconnecting to one must drop published themes rather than keep
131 showing a set nothing will ever update. */
132 environmentThemes: Schema.optionalKey(Schema.Boolean),
133 /** Server streams quota from configured usage-limit sources. Same
134 version-skew contract as environmentThemes. */
135 usageLimitSources: Schema.optionalKey(Schema.Boolean),
136 /** Server persists custom model rates and applies them to usage summaries. */
137 usagePriceOverrides: Schema.optionalKey(Schema.Boolean),
138 /** Server understands thread.pin / thread.unpin commands. Same
139 version-skew contract as threadSettlement. */
140 threadPinning: Schema.optionalKey(Schema.Boolean),
141 /** Server understands thread.pin.reorder (and orderKey on thread.pin).
142 Same version-skew contract as threadSettlement. */
143 threadPinReorder: Schema.optionalKey(Schema.Boolean),
144 /** Server persists manual Active order through thread.active.reorder. */
145 threadActiveReorder: Schema.optionalKey(Schema.Boolean),
146 /** Server understands thread.auto-settle.set (per-thread auto-settle off).
147 Same version-skew contract as threadSettlement. */
148 threadAutoSettleOptOut: Schema.optionalKey(Schema.Boolean),
149 /** Server understands regenerateTitle on thread.meta.update. Absent on
150 older servers, so clients hide the action instead of sending it. */
151 threadTitleRegeneration: Schema.optionalKey(Schema.Boolean),
152 /** Server supports legacy linkedPullRequest updates through thread.meta.update.
153 Independent of threadPullRequests; servers supporting both advertise both. */
154 threadPullRequestLinking: Schema.optionalKey(Schema.Boolean),
155 /** Server understands thread.pull-request.link / .unlink, exposes `pullRequests` on
156 threads, and routes PullRequestRef.host across projects on the same host. Same
157 version-skew contract as threadSettlement. */
158 threadPullRequests: Schema.optionalKey(Schema.Boolean),
159 pullRequestStackActions: Schema.optionalKey(Schema.Boolean),
160 /** The update path clients should offer for this server. Absent on
161 servers that must be relaunched manually (dev checkouts, Windows
162 foreground runs, pre-update servers). */
163 serverSelfUpdate: Schema.optionalKey(ServerSelfUpdateCapability),
164 /** Server can stream self-update progress before acknowledging the
165 restart. Clients fall back to server.updateServer when absent. */
166 serverSelfUpdateProgress: Schema.optionalKey(Schema.Boolean),
167 /** Server can durably mark running provider turns before a self-update and
168 continue them after the replacement process starts. */
169 serverUpdateThreadContinuation: Schema.optionalKey(Schema.Boolean),
170 /** Agent-activity publishes (push notifications and Live Activities)
171 currently leave this environment: the publish opt-in is enabled and the
172 relay link credentials exist. Clients skip seeding a Live Activity when
173 this is false — no update would ever repaint it. Absent on older
174 servers, which may still publish, so only an explicit false skips. */
175 agentActivityPublishing: Schema.optionalKey(Schema.Boolean),
176 /** Server runs repository clones for new projects in the background and
177 streams their progress (`projectClone.*`, `subscribeProjectClones`).
178 Absent on older servers, where clients must clone with the blocking
179 `sourceControl.cloneRepository` call instead. */
180 projectCloneTracking: Schema.optionalKey(Schema.Boolean),
181 /** Server detects `platform.machine` and persists the `environmentIcon`
182 setting. Older servers drop the key on write, so clients show the
183 picker inert rather than offering a choice that would never stick. */
184 environmentIcon: Schema.optionalKey(Schema.Boolean),
185 /** The desktop app supervising this server can be driven over RPC:
186 server.updateServer runs its check -> download -> relaunch. Absent on
187 desktop servers whose app predates the remote trigger, where clients
188 must keep telling the user to update the app on that machine. */
189 desktopAppUpdate: Schema.optionalKey(Schema.Boolean),
190});
191export type ExecutionEnvironmentCapabilities = typeof ExecutionEnvironmentCapabilities.Type;
192​
193export const ExecutionEnvironmentDescriptor = Schema.Struct({
194 environmentId: EnvironmentId,
195 label: TrimmedNonEmptyString,
196 platform: ExecutionEnvironmentPlatform,
197 serverVersion: TrimmedNonEmptyString,
198 /** Missing metadata denotes protocol 1. Bump this for breaking wire changes. */
199 orchestrationProtocolVersion: Schema.optionalKey(Schema.Int),
200 capabilities: ExecutionEnvironmentCapabilities,
201});
202export type ExecutionEnvironmentDescriptor = typeof ExecutionEnvironmentDescriptor.Type;
203​
204export const RepositoryIdentityLocator = Schema.Struct({
205 source: Schema.Literal("git-remote"),
206 remoteName: TrimmedNonEmptyString,
207 remoteUrl: TrimmedNonEmptyString,
208});
209export type RepositoryIdentityLocator = typeof RepositoryIdentityLocator.Type;
210​
211export const RepositoryIdentity = Schema.Struct({
212 canonicalKey: TrimmedNonEmptyString,
213 locator: RepositoryIdentityLocator,
214 /** Repository browser URL resolved from the server's configured hosting account. */
215 webUrl: Schema.optionalKey(TrimmedNonEmptyString),
216 rootPath: Schema.optionalKey(TrimmedNonEmptyString),
217 displayName: Schema.optionalKey(TrimmedNonEmptyString),
218 provider: Schema.optionalKey(TrimmedNonEmptyString),
219 owner: Schema.optionalKey(TrimmedNonEmptyString),
220 name: Schema.optionalKey(TrimmedNonEmptyString),
221});
222export type RepositoryIdentity = typeof RepositoryIdentity.Type;
223​
224export const ScopedProjectRef = Schema.Struct({
225 environmentId: EnvironmentId,
226 projectId: ProjectId,
227});
228export type ScopedProjectRef = typeof ScopedProjectRef.Type;
229​
230export const ScopedThreadRef = Schema.Struct({
231 environmentId: EnvironmentId,
232 threadId: ThreadId,
233});
234export type ScopedThreadRef = typeof ScopedThreadRef.Type;