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

environment.ts

198 lines9.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​
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 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 "desktop",
32 "laptop",
33 "mac-mini",
34 "mac-studio",
35] as const;
36export const EnvironmentMachineKind = Schema.Literals(ENVIRONMENT_MACHINE_KINDS);
37export type EnvironmentMachineKind = typeof EnvironmentMachineKind.Type;
38export const isEnvironmentMachineKind = Schema.is(EnvironmentMachineKind);
39​
40export const ExecutionEnvironmentPlatform = Schema.Struct({
41 os: ExecutionEnvironmentPlatformOs,
42 arch: ExecutionEnvironmentPlatformArch,
43 /** Hardware shape detected at startup. Absent when the host gives no usable
44 signal (containers, Windows, unknown DMI), on servers that predate it, or
45 when a newer server names a kind this build cannot draw. */
46 machine: ForwardCompatibleOptional(EnvironmentMachineKind),
47});
48​
49/**
50 * Where a new thread runs: the project's current checkout ("local") or a
51 * fresh git worktree ("worktree"). Lives here (not settings.ts) so
52 * orchestration contracts can reference it without an import cycle.
53 */
54export const ThreadEnvMode = Schema.Literals(["local", "worktree"]);
55export type ThreadEnvMode = typeof ThreadEnvMode.Type;
56export type ExecutionEnvironmentPlatform = typeof ExecutionEnvironmentPlatform.Type;
57​
58/** How a server can replace itself with another version when asked over RPC.
59 New servers only advertise the stable launcher-backed "boot-service" path;
60 "respawn" remains decodable for compatibility with older servers.
61 "desktop-app" means the supervising desktop app updated and relaunched
62 itself, bringing the server back with it. */
63export const ServerSelfUpdateMethod = Schema.Literals(["boot-service", "respawn", "desktop-app"]);
64export type ServerSelfUpdateMethod = typeof ServerSelfUpdateMethod.Type;
65​
66/** What update path a client should offer for a server: one of the RPC
67 self-update methods above, or "desktop-managed" when the backend's
68 version belongs to the T3 Code desktop app supervising it — updating the
69 app on that machine is the only way to update the server. */
70export const ServerSelfUpdateCapability = Schema.Literals([
71 "boot-service",
72 "respawn",
73 "desktop-managed",
74]);
75export type ServerSelfUpdateCapability = typeof ServerSelfUpdateCapability.Type;
76​
77export const ExecutionEnvironmentCapabilities = Schema.Struct({
78 repositoryIdentity: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),
79 connectionProbe: Schema.optionalKey(Schema.Boolean),
80 /** Missing on older servers, which still accept inline image attachments. */
81 attachmentUploads: Schema.optionalKey(Schema.Boolean),
82 /** Missing on servers that only accept image attachments. */
83 fileAttachments: Schema.optionalKey(
84 Schema.Struct({
85 maxUploadBytes: Schema.Int.check(Schema.isGreaterThanOrEqualTo(1)),
86 }),
87 ),
88 /** Server exposes the pull-request list, detail, activity, diff, and mutation APIs. Absent on
89 servers from before the pull-request workspace shipped, so clients must not probe them. */
90 pullRequests: Schema.optionalKey(Schema.Boolean),
91 /** Server understands thread.settle / thread.unsettle commands. Absent on
92 pre-settlement servers, so clients treat missing as unsupported and
93 never send the commands under version skew. */
94 threadSettlement: Schema.optionalKey(Schema.Boolean),
95 /** Server evaluates merge and inactivity settlement without a client. */
96 threadAutoSettlement: Schema.optionalKey(Schema.Boolean),
97 /** Server understands thread.snooze / thread.unsnooze commands. Same
98 version-skew contract as threadSettlement. */
99 threadSnooze: Schema.optionalKey(Schema.Boolean),
100 /** Server streams themes an environment publishes. Absent on servers from
101 before environment themes shipped, which never emit the events -- so a
102 client reconnecting to one must drop published themes rather than keep
103 showing a set nothing will ever update. */
104 environmentThemes: Schema.optionalKey(Schema.Boolean),
105 /** Server streams quota from configured usage-limit sources. Same
106 version-skew contract as environmentThemes. */
107 usageLimitSources: Schema.optionalKey(Schema.Boolean),
108 /** Server understands thread.pin / thread.unpin commands. Same
109 version-skew contract as threadSettlement. */
110 threadPinning: Schema.optionalKey(Schema.Boolean),
111 /** Server understands thread.pin.reorder (and orderKey on thread.pin).
112 Same version-skew contract as threadSettlement. */
113 threadPinReorder: Schema.optionalKey(Schema.Boolean),
114 /** Server understands regenerateTitle on thread.meta.update. Absent on
115 older servers, so clients hide the action instead of sending it. */
116 threadTitleRegeneration: Schema.optionalKey(Schema.Boolean),
117 /** Server persists a pull request reference on thread.meta.update. */
118 threadPullRequestLinking: Schema.optionalKey(Schema.Boolean),
119 /** The update path clients should offer for this server. Absent on
120 servers that must be relaunched manually (dev checkouts, Windows
121 foreground runs, pre-update servers). */
122 serverSelfUpdate: Schema.optionalKey(ServerSelfUpdateCapability),
123 /** Server can stream self-update progress before acknowledging the
124 restart. Clients fall back to server.updateServer when absent. */
125 serverSelfUpdateProgress: Schema.optionalKey(Schema.Boolean),
126 /** Server can durably mark running provider turns before a self-update and
127 continue them after the replacement process starts. */
128 serverUpdateThreadContinuation: Schema.optionalKey(Schema.Boolean),
129 /** Agent-activity publishes (push notifications and Live Activities)
130 currently leave this environment: the publish opt-in is enabled and the
131 relay link credentials exist. Clients skip seeding a Live Activity when
132 this is false — no update would ever repaint it. Absent on older
133 servers, which may still publish, so only an explicit false skips. */
134 agentActivityPublishing: Schema.optionalKey(Schema.Boolean),
135 /** Server detects `platform.machine` and persists the `environmentIcon`
136 setting. Older servers drop the key on write, so clients show the
137 picker inert rather than offering a choice that would never stick. */
138 environmentIcon: Schema.optionalKey(Schema.Boolean),
139 /** The desktop app supervising this server can be driven over RPC:
140 server.updateServer runs its check -> download -> relaunch. Absent on
141 desktop servers whose app predates the remote trigger, where clients
142 must keep telling the user to update the app on that machine. */
143 desktopAppUpdate: Schema.optionalKey(Schema.Boolean),
144});
145export type ExecutionEnvironmentCapabilities = typeof ExecutionEnvironmentCapabilities.Type;
146​
147export const ExecutionEnvironmentDescriptor = Schema.Struct({
148 environmentId: EnvironmentId,
149 label: TrimmedNonEmptyString,
150 platform: ExecutionEnvironmentPlatform,
151 serverVersion: TrimmedNonEmptyString,
152 capabilities: ExecutionEnvironmentCapabilities,
153});
154export type ExecutionEnvironmentDescriptor = typeof ExecutionEnvironmentDescriptor.Type;
155​
156export const EnvironmentConnectionState = Schema.Literals([
157 "connecting",
158 "connected",
159 "disconnected",
160 "error",
161]);
162export type EnvironmentConnectionState = typeof EnvironmentConnectionState.Type;
163​
164export const RepositoryIdentityLocator = Schema.Struct({
165 source: Schema.Literal("git-remote"),
166 remoteName: TrimmedNonEmptyString,
167 remoteUrl: TrimmedNonEmptyString,
168});
169export type RepositoryIdentityLocator = typeof RepositoryIdentityLocator.Type;
170​
171export const RepositoryIdentity = Schema.Struct({
172 canonicalKey: TrimmedNonEmptyString,
173 locator: RepositoryIdentityLocator,
174 rootPath: Schema.optionalKey(TrimmedNonEmptyString),
175 displayName: Schema.optionalKey(TrimmedNonEmptyString),
176 provider: Schema.optionalKey(TrimmedNonEmptyString),
177 owner: Schema.optionalKey(TrimmedNonEmptyString),
178 name: Schema.optionalKey(TrimmedNonEmptyString),
179});
180export type RepositoryIdentity = typeof RepositoryIdentity.Type;
181​
182export const ScopedProjectRef = Schema.Struct({
183 environmentId: EnvironmentId,
184 projectId: ProjectId,
185});
186export type ScopedProjectRef = typeof ScopedProjectRef.Type;
187​
188export const ScopedThreadRef = Schema.Struct({
189 environmentId: EnvironmentId,
190 threadId: ThreadId,
191});
192export type ScopedThreadRef = typeof ScopedThreadRef.Type;
193​
194export const ScopedThreadSessionRef = Schema.Struct({
195 environmentId: EnvironmentId,
196 threadId: ThreadId,
197});
198export type ScopedThreadSessionRef = typeof ScopedThreadSessionRef.Type;