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

environment.ts

239 lines11.8 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 /** Server understands canonical inline context links plus their message context records.
101 Absent on servers from before inline context shipped, which drop the records and forward
102 the links as literal text -- so a client must serialize context the legacy way for them. */
103 inlineMessageContext: Schema.optionalKey(Schema.Boolean),
104 /** Server understands thread.settle / thread.unsettle commands. Absent on
105 pre-settlement servers, so clients treat missing as unsupported and
106 never send the commands under version skew. */
107 threadSettlement: Schema.optionalKey(Schema.Boolean),
108 /** Server evaluates merge and inactivity settlement without a client. */
109 threadAutoSettlement: Schema.optionalKey(Schema.Boolean),
110 /** Server persists the opt-in for continuing interrupted threads after restarts. */
111 threadRestartContinuation: Schema.optionalKey(Schema.Boolean),
112 /** Server resolves `projectSettingsOverrides`; older servers ignore the key. */
113 projectSettingsOverrides: Schema.optionalKey(Schema.Boolean),
114 /** Server understands thread.snooze / thread.unsnooze commands. Same
115 version-skew contract as threadSettlement. */
116 threadSnooze: Schema.optionalKey(Schema.Boolean),
117 /** Server streams themes an environment publishes. Absent on servers from
118 before environment themes shipped, which never emit the events -- so a
119 client reconnecting to one must drop published themes rather than keep
120 showing a set nothing will ever update. */
121 environmentThemes: Schema.optionalKey(Schema.Boolean),
122 /** Server streams quota from configured usage-limit sources. Same
123 version-skew contract as environmentThemes. */
124 usageLimitSources: Schema.optionalKey(Schema.Boolean),
125 /** Server persists custom model rates and applies them to usage summaries. */
126 usagePriceOverrides: Schema.optionalKey(Schema.Boolean),
127 /** Server understands thread.pin / thread.unpin commands. Same
128 version-skew contract as threadSettlement. */
129 threadPinning: Schema.optionalKey(Schema.Boolean),
130 /** Server understands thread.pin.reorder (and orderKey on thread.pin).
131 Same version-skew contract as threadSettlement. */
132 threadPinReorder: Schema.optionalKey(Schema.Boolean),
133 /** Server persists manual Active order through thread.active.reorder. */
134 threadActiveReorder: Schema.optionalKey(Schema.Boolean),
135 /** Server understands regenerateTitle on thread.meta.update. Absent on
136 older servers, so clients hide the action instead of sending it. */
137 threadTitleRegeneration: Schema.optionalKey(Schema.Boolean),
138 /** Server understands thread.visit / thread.mark-unread commands and
139 projects lastVisitedAt on thread shells. Same version-skew contract as
140 threadSettlement: clients keep their local visited state against
141 servers that lack this. */
142 threadVisitedTracking: Schema.optionalKey(Schema.Boolean),
143 /** Server persists a pull request reference on thread.meta.update. */
144 threadPullRequestLinking: Schema.optionalKey(Schema.Boolean),
145 /** Server resolves message delivery and model-selection context and validates
146 identified rollback readiness. Clients retain projection-based command
147 shaping and validation when this is absent. */
148 serverResolvedCommandContext: Schema.optionalKey(Schema.Boolean),
149 threadPullRequests: Schema.optionalKey(Schema.Boolean),
150 pullRequestStackActions: Schema.optionalKey(Schema.Boolean),
151 /** The update path clients should offer for this server. Absent on
152 servers that must be relaunched manually (dev checkouts, Windows
153 foreground runs, pre-update servers). */
154 serverSelfUpdate: Schema.optionalKey(ServerSelfUpdateCapability),
155 /** Server can stream self-update progress before acknowledging the
156 restart. Clients fall back to server.updateServer when absent. */
157 serverSelfUpdateProgress: Schema.optionalKey(Schema.Boolean),
158 /** Server can durably mark running provider turns before a self-update and
159 continue them after the replacement process starts. */
160 serverUpdateThreadContinuation: Schema.optionalKey(Schema.Boolean),
161 /** Agent-activity publishes (push notifications and Live Activities)
162 currently leave this environment: the publish opt-in is enabled and the
163 relay link credentials exist. Clients skip seeding a Live Activity when
164 this is false — no update would ever repaint it. Absent on older
165 servers, which may still publish, so only an explicit false skips. */
166 agentActivityPublishing: Schema.optionalKey(Schema.Boolean),
167 /** Server runs repository clones for new projects in the background and
168 streams their progress (`projectClone.*`, `subscribeProjectClones`).
169 Absent on older servers, where clients must clone with the blocking
170 `sourceControl.cloneRepository` call instead. */
171 projectCloneTracking: Schema.optionalKey(Schema.Boolean),
172 /** Server detects `platform.machine` and persists the `environmentIcon`
173 setting. Older servers drop the key on write, so clients show the
174 picker inert rather than offering a choice that would never stick. */
175 environmentIcon: Schema.optionalKey(Schema.Boolean),
176 /** The desktop app supervising this server can be driven over RPC:
177 server.updateServer runs its check -> download -> relaunch. Absent on
178 desktop servers whose app predates the remote trigger, where clients
179 must keep telling the user to update the app on that machine. */
180 desktopAppUpdate: Schema.optionalKey(Schema.Boolean),
181});
182export type ExecutionEnvironmentCapabilities = typeof ExecutionEnvironmentCapabilities.Type;
183​
184export const ExecutionEnvironmentDescriptor = Schema.Struct({
185 environmentId: EnvironmentId,
186 label: TrimmedNonEmptyString,
187 platform: ExecutionEnvironmentPlatform,
188 serverVersion: TrimmedNonEmptyString,
189 /** Absent on hosts from before explicit orchestration protocol negotiation. */
190 orchestrationProtocolVersion: Schema.optionalKey(Schema.Int),
191 capabilities: ExecutionEnvironmentCapabilities,
192});
193export type ExecutionEnvironmentDescriptor = typeof ExecutionEnvironmentDescriptor.Type;
194​
195export const EnvironmentConnectionState = Schema.Literals([
196 "connecting",
197 "connected",
198 "disconnected",
199 "error",
200]);
201export type EnvironmentConnectionState = typeof EnvironmentConnectionState.Type;
202​
203export const RepositoryIdentityLocator = Schema.Struct({
204 source: Schema.Literal("git-remote"),
205 remoteName: TrimmedNonEmptyString,
206 remoteUrl: TrimmedNonEmptyString,
207});
208export type RepositoryIdentityLocator = typeof RepositoryIdentityLocator.Type;
209​
210export const RepositoryIdentity = Schema.Struct({
211 canonicalKey: TrimmedNonEmptyString,
212 locator: RepositoryIdentityLocator,
213 /** Repository browser URL resolved from the server's configured hosting account. */
214 webUrl: Schema.optionalKey(TrimmedNonEmptyString),
215 rootPath: Schema.optionalKey(TrimmedNonEmptyString),
216 displayName: Schema.optionalKey(TrimmedNonEmptyString),
217 provider: Schema.optionalKey(TrimmedNonEmptyString),
218 owner: Schema.optionalKey(TrimmedNonEmptyString),
219 name: Schema.optionalKey(TrimmedNonEmptyString),
220});
221export type RepositoryIdentity = typeof RepositoryIdentity.Type;
222​
223export const ScopedProjectRef = Schema.Struct({
224 environmentId: EnvironmentId,
225 projectId: ProjectId,
226});
227export type ScopedProjectRef = typeof ScopedProjectRef.Type;
228​
229export const ScopedThreadRef = Schema.Struct({
230 environmentId: EnvironmentId,
231 threadId: ThreadId,
232});
233export type ScopedThreadRef = typeof ScopedThreadRef.Type;
234​
235export const ScopedThreadSessionRef = Schema.Struct({
236 environmentId: EnvironmentId,
237 threadId: ThreadId,
238});
239export type ScopedThreadSessionRef = typeof ScopedThreadSessionRef.Type;