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