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

environment.ts

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