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

environment.ts

226 lines10.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 thread.settle / thread.unsettle commands. Absent on
101 pre-settlement servers, so clients treat missing as unsupported and
102 never send the commands under version skew. */
103 threadSettlement: Schema.optionalKey(Schema.Boolean),
104 /** Server evaluates merge and inactivity settlement without a client. */
105 threadAutoSettlement: Schema.optionalKey(Schema.Boolean),
106 /** Server persists the opt-in for continuing interrupted threads after restarts. */
107 threadRestartContinuation: 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 understands thread.visit / thread.mark-unread commands and
133 projects lastVisitedAt on thread shells. Same version-skew contract as
134 threadSettlement: clients keep their local visited state against
135 servers that lack this. */
136 threadVisitedTracking: Schema.optionalKey(Schema.Boolean),
137 /** Server persists a pull request reference on thread.meta.update. */
138 threadPullRequestLinking: Schema.optionalKey(Schema.Boolean),
139 /** Server resolves message delivery and model-selection context and validates
140 identified rollback readiness. Clients retain projection-based command
141 shaping and validation when this is absent. */
142 serverResolvedCommandContext: Schema.optionalKey(Schema.Boolean),
143 threadPullRequests: Schema.optionalKey(Schema.Boolean),
144 pullRequestStackActions: Schema.optionalKey(Schema.Boolean),
145 /** The update path clients should offer for this server. Absent on
146 servers that must be relaunched manually (dev checkouts, Windows
147 foreground runs, pre-update servers). */
148 serverSelfUpdate: Schema.optionalKey(ServerSelfUpdateCapability),
149 /** Server can stream self-update progress before acknowledging the
150 restart. Clients fall back to server.updateServer when absent. */
151 serverSelfUpdateProgress: Schema.optionalKey(Schema.Boolean),
152 /** Server can durably mark running provider turns before a self-update and
153 continue them after the replacement process starts. */
154 serverUpdateThreadContinuation: Schema.optionalKey(Schema.Boolean),
155 /** Agent-activity publishes (push notifications and Live Activities)
156 currently leave this environment: the publish opt-in is enabled and the
157 relay link credentials exist. Clients skip seeding a Live Activity when
158 this is false — no update would ever repaint it. Absent on older
159 servers, which may still publish, so only an explicit false skips. */
160 agentActivityPublishing: 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 /** Absent on hosts from before explicit orchestration protocol negotiation. */
179 orchestrationProtocolVersion: Schema.optionalKey(Schema.Int),
180 capabilities: ExecutionEnvironmentCapabilities,
181});
182export type ExecutionEnvironmentDescriptor = typeof ExecutionEnvironmentDescriptor.Type;
183​
184export const EnvironmentConnectionState = Schema.Literals([
185 "connecting",
186 "connected",
187 "disconnected",
188 "error",
189]);
190export type EnvironmentConnectionState = typeof EnvironmentConnectionState.Type;
191​
192export const RepositoryIdentityLocator = Schema.Struct({
193 source: Schema.Literal("git-remote"),
194 remoteName: TrimmedNonEmptyString,
195 remoteUrl: TrimmedNonEmptyString,
196});
197export type RepositoryIdentityLocator = typeof RepositoryIdentityLocator.Type;
198​
199export const RepositoryIdentity = Schema.Struct({
200 canonicalKey: TrimmedNonEmptyString,
201 locator: RepositoryIdentityLocator,
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;