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

environment.ts

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