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

environment.ts

232 lines11.4 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;
61export type ExecutionEnvironmentPlatform = typeof ExecutionEnvironmentPlatform.Type;
62​
63/** How a server can replace itself with another version when asked over RPC.
64 New servers only advertise the stable launcher-backed "boot-service" path;
65 "respawn" remains decodable for compatibility with older servers.
66 "desktop-app" means the supervising desktop app updated and relaunched
67 itself, bringing the server back with it. */
68export const ServerSelfUpdateMethod = Schema.Literals(["boot-service", "respawn", "desktop-app"]);
69export type ServerSelfUpdateMethod = typeof ServerSelfUpdateMethod.Type;
70​
71/** What update path a client should offer for a server: one of the RPC
72 self-update methods above, or "desktop-managed" when the backend's
73 version belongs to the T3 Code desktop app supervising it — updating the
74 app on that machine is the only way to update the server. */
75export const ServerSelfUpdateCapability = Schema.Literals([
76 "boot-service",
77 "respawn",
78 "desktop-managed",
79]);
80export type ServerSelfUpdateCapability = typeof ServerSelfUpdateCapability.Type;
81​
82export const ExecutionEnvironmentCapabilities = Schema.Struct({
83 repositoryIdentity: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),
84 connectionProbe: Schema.optionalKey(Schema.Boolean),
85 /** Missing on older servers, which still accept inline image attachments. */
86 attachmentUploads: Schema.optionalKey(Schema.Boolean),
87 /** Uploaded files may accompany question answers. */
88 questionAttachments: Schema.optionalKey(Schema.Boolean),
89 /** Missing on servers that only accept image attachments. */
90 fileAttachments: Schema.optionalKey(
91 Schema.Struct({
92 maxUploadBytes: Schema.Int.check(Schema.isGreaterThanOrEqualTo(1)),
93 }),
94 ),
95 /** Server exposes the pull-request list, detail, activity, diff, and mutation APIs. Absent on
96 servers from before the pull-request workspace shipped, so clients must not probe them. */
97 pullRequests: Schema.optionalKey(Schema.Boolean),
98 /** Server understands canonical inline context links plus their message context records.
99 Absent on servers from before inline context shipped, which drop the records and forward
100 the links as literal text -- so a client must serialize context the legacy way for them. */
101 inlineMessageContext: Schema.optionalKey(Schema.Boolean),
102 /** Server understands thread.settle / thread.unsettle commands. Absent on
103 pre-settlement servers, so clients treat missing as unsupported and
104 never send the commands under version skew. */
105 threadSettlement: Schema.optionalKey(Schema.Boolean),
106 /** Server evaluates merge and inactivity settlement without a client. */
107 threadAutoSettlement: Schema.optionalKey(Schema.Boolean),
108 /** Server persists the opt-in for continuing interrupted threads after restarts. */
109 threadRestartContinuation: Schema.optionalKey(Schema.Boolean),
110 /** Server resolves `projectSettingsOverrides`; older servers ignore the key. */
111 projectSettingsOverrides: Schema.optionalKey(Schema.Boolean),
112 /** Server understands thread.snooze / thread.unsnooze commands. Same
113 version-skew contract as threadSettlement. */
114 threadSnooze: Schema.optionalKey(Schema.Boolean),
115 /** Server streams themes an environment publishes. Absent on servers from
116 before environment themes shipped, which never emit the events -- so a
117 client reconnecting to one must drop published themes rather than keep
118 showing a set nothing will ever update. */
119 environmentThemes: Schema.optionalKey(Schema.Boolean),
120 /** Server streams quota from configured usage-limit sources. Same
121 version-skew contract as environmentThemes. */
122 usageLimitSources: Schema.optionalKey(Schema.Boolean),
123 /** Server persists custom model rates and applies them to usage summaries. */
124 usagePriceOverrides: Schema.optionalKey(Schema.Boolean),
125 /** Server understands thread.pin / thread.unpin commands. Same
126 version-skew contract as threadSettlement. */
127 threadPinning: Schema.optionalKey(Schema.Boolean),
128 /** Server understands thread.pin.reorder (and orderKey on thread.pin).
129 Same version-skew contract as threadSettlement. */
130 threadPinReorder: Schema.optionalKey(Schema.Boolean),
131 /** Server persists manual Active order through thread.active.reorder. */
132 threadActiveReorder: Schema.optionalKey(Schema.Boolean),
133 /** Server understands regenerateTitle on thread.meta.update. Absent on
134 older servers, so clients hide the action instead of sending it. */
135 threadTitleRegeneration: Schema.optionalKey(Schema.Boolean),
136 /** Server supports legacy linkedPullRequest updates through thread.meta.update.
137 Independent of threadPullRequests; servers supporting both advertise both. */
138 threadPullRequestLinking: Schema.optionalKey(Schema.Boolean),
139 /** Server understands thread.pull-request.link / .unlink, exposes `pullRequests` on
140 threads, and routes PullRequestRef.host across projects on the same host. Same
141 version-skew contract as threadSettlement. */
142 threadPullRequests: Schema.optionalKey(Schema.Boolean),
143 pullRequestStackActions: Schema.optionalKey(Schema.Boolean),
144 /** The update path clients should offer for this server. Absent on
145 servers that must be relaunched manually (dev checkouts, Windows
146 foreground runs, pre-update servers). */
147 serverSelfUpdate: Schema.optionalKey(ServerSelfUpdateCapability),
148 /** Server can stream self-update progress before acknowledging the
149 restart. Clients fall back to server.updateServer when absent. */
150 serverSelfUpdateProgress: Schema.optionalKey(Schema.Boolean),
151 /** Server can durably mark running provider turns before a self-update and
152 continue them after the replacement process starts. */
153 serverUpdateThreadContinuation: Schema.optionalKey(Schema.Boolean),
154 /** Agent-activity publishes (push notifications and Live Activities)
155 currently leave this environment: the publish opt-in is enabled and the
156 relay link credentials exist. Clients skip seeding a Live Activity when
157 this is false — no update would ever repaint it. Absent on older
158 servers, which may still publish, so only an explicit false skips. */
159 agentActivityPublishing: Schema.optionalKey(Schema.Boolean),
160 /** Server runs repository clones for new projects in the background and
161 streams their progress (`projectClone.*`, `subscribeProjectClones`).
162 Absent on older servers, where clients must clone with the blocking
163 `sourceControl.cloneRepository` call instead. */
164 projectCloneTracking: Schema.optionalKey(Schema.Boolean),
165 /** Server detects `platform.machine` and persists the `environmentIcon`
166 setting. Older servers drop the key on write, so clients show the
167 picker inert rather than offering a choice that would never stick. */
168 environmentIcon: Schema.optionalKey(Schema.Boolean),
169 /** The desktop app supervising this server can be driven over RPC:
170 server.updateServer runs its check -> download -> relaunch. Absent on
171 desktop servers whose app predates the remote trigger, where clients
172 must keep telling the user to update the app on that machine. */
173 desktopAppUpdate: Schema.optionalKey(Schema.Boolean),
174});
175export type ExecutionEnvironmentCapabilities = typeof ExecutionEnvironmentCapabilities.Type;
176​
177export const ExecutionEnvironmentDescriptor = Schema.Struct({
178 environmentId: EnvironmentId,
179 label: TrimmedNonEmptyString,
180 platform: ExecutionEnvironmentPlatform,
181 serverVersion: TrimmedNonEmptyString,
182 /** Missing metadata denotes protocol 1. Bump this for breaking wire changes. */
183 orchestrationProtocolVersion: Schema.optionalKey(Schema.Int),
184 capabilities: ExecutionEnvironmentCapabilities,
185});
186export type ExecutionEnvironmentDescriptor = typeof ExecutionEnvironmentDescriptor.Type;
187​
188export const EnvironmentConnectionState = Schema.Literals([
189 "connecting",
190 "connected",
191 "disconnected",
192 "error",
193]);
194export type EnvironmentConnectionState = typeof EnvironmentConnectionState.Type;
195​
196export const RepositoryIdentityLocator = Schema.Struct({
197 source: Schema.Literal("git-remote"),
198 remoteName: TrimmedNonEmptyString,
199 remoteUrl: TrimmedNonEmptyString,
200});
201export type RepositoryIdentityLocator = typeof RepositoryIdentityLocator.Type;
202​
203export const RepositoryIdentity = Schema.Struct({
204 canonicalKey: TrimmedNonEmptyString,
205 locator: RepositoryIdentityLocator,
206 /** Repository browser URL resolved from the server's configured hosting account. */
207 webUrl: Schema.optionalKey(TrimmedNonEmptyString),
208 rootPath: Schema.optionalKey(TrimmedNonEmptyString),
209 displayName: Schema.optionalKey(TrimmedNonEmptyString),
210 provider: Schema.optionalKey(TrimmedNonEmptyString),
211 owner: Schema.optionalKey(TrimmedNonEmptyString),
212 name: Schema.optionalKey(TrimmedNonEmptyString),
213});
214export type RepositoryIdentity = typeof RepositoryIdentity.Type;
215​
216export const ScopedProjectRef = Schema.Struct({
217 environmentId: EnvironmentId,
218 projectId: ProjectId,
219});
220export type ScopedProjectRef = typeof ScopedProjectRef.Type;
221​
222export const ScopedThreadRef = Schema.Struct({
223 environmentId: EnvironmentId,
224 threadId: ThreadId,
225});
226export type ScopedThreadRef = typeof ScopedThreadRef.Type;
227​
228export const ScopedThreadSessionRef = Schema.Struct({
229 environmentId: EnvironmentId,
230 threadId: ThreadId,
231});
232export type ScopedThreadSessionRef = typeof ScopedThreadSessionRef.Type;