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

environment.ts

165 lines7.7 KB

1import * as Effect from "effect/Effect";
2import * as Schema from "effect/Schema";
3​
4import { EnvironmentId, ProjectId, ThreadId, TrimmedNonEmptyString } from "./baseSchemas.ts";
5​
6/** Wire version for orchestration snapshots, streams, commands, and RPC payloads. */
7export const ORCHESTRATION_PROTOCOL_VERSION = 2;
8export const ORCHESTRATION_PROTOCOL_VERSION_TEXT = "2";
9export const ORCHESTRATION_PROTOCOL_QUERY_PARAM = "orchestrationProtocol";
10export const ORCHESTRATION_PROTOCOL_HEADER = "x-t3-orchestration-protocol";
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​
23export const ExecutionEnvironmentPlatform = Schema.Struct({
24 os: ExecutionEnvironmentPlatformOs,
25 arch: ExecutionEnvironmentPlatformArch,
26});
27​
28/**
29 * Where a new thread runs: the project's current checkout ("local") or a
30 * fresh git worktree ("worktree"). Lives here (not settings.ts) so
31 * orchestration contracts can reference it without an import cycle.
32 */
33export const ThreadEnvMode = Schema.Literals(["local", "worktree"]);
34export type ThreadEnvMode = typeof ThreadEnvMode.Type;
35export type ExecutionEnvironmentPlatform = typeof ExecutionEnvironmentPlatform.Type;
36​
37/** How a server can replace itself with another version when asked over RPC.
38 New servers only advertise the stable launcher-backed "boot-service" path;
39 "respawn" remains decodable for compatibility with older servers. */
40export const ServerSelfUpdateMethod = Schema.Literals(["boot-service", "respawn"]);
41export type ServerSelfUpdateMethod = typeof ServerSelfUpdateMethod.Type;
42​
43/** What update path a client should offer for a server: one of the RPC
44 self-update methods above, or "desktop-managed" when the backend's
45 version belongs to the T3 Code desktop app supervising it — updating the
46 app on that machine is the only way to update the server. */
47export const ServerSelfUpdateCapability = Schema.Literals([
48 "boot-service",
49 "respawn",
50 "desktop-managed",
51]);
52export type ServerSelfUpdateCapability = typeof ServerSelfUpdateCapability.Type;
53​
54export const ExecutionEnvironmentCapabilities = Schema.Struct({
55 repositoryIdentity: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),
56 connectionProbe: Schema.optionalKey(Schema.Boolean),
57 /** Missing on older servers, which still accept inline image attachments. */
58 attachmentUploads: Schema.optionalKey(Schema.Boolean),
59 /** Missing on servers that only accept image attachments. */
60 fileAttachments: Schema.optionalKey(
61 Schema.Struct({
62 maxUploadBytes: Schema.Int.check(Schema.isGreaterThanOrEqualTo(1)),
63 }),
64 ),
65 /** Server exposes the pull-request list, detail, activity, diff, and mutation APIs. Absent on
66 servers from before the pull-request workspace shipped, so clients must not probe them. */
67 pullRequests: Schema.optionalKey(Schema.Boolean),
68 /** Server understands thread.settle / thread.unsettle commands. Absent on
69 pre-settlement servers, so clients treat missing as unsupported and
70 never send the commands under version skew. */
71 threadSettlement: Schema.optionalKey(Schema.Boolean),
72 /** Server understands thread.snooze / thread.unsnooze commands. Same
73 version-skew contract as threadSettlement. */
74 threadSnooze: Schema.optionalKey(Schema.Boolean),
75 /** Server streams themes an environment publishes. Absent on servers from
76 before environment themes shipped, which never emit the events -- so a
77 client reconnecting to one must drop published themes rather than keep
78 showing a set nothing will ever update. */
79 environmentThemes: Schema.optionalKey(Schema.Boolean),
80 /** Server understands thread.pin / thread.unpin commands. Same
81 version-skew contract as threadSettlement. */
82 threadPinning: Schema.optionalKey(Schema.Boolean),
83 /** Server understands thread.pin.reorder (and orderKey on thread.pin).
84 Same version-skew contract as threadSettlement. */
85 threadPinReorder: Schema.optionalKey(Schema.Boolean),
86 /** Server understands regenerateTitle on thread.meta.update. Absent on
87 older servers, so clients hide the action instead of sending it. */
88 threadTitleRegeneration: Schema.optionalKey(Schema.Boolean),
89 /** Server understands thread.visit / thread.mark-unread commands and
90 projects lastVisitedAt on thread shells. Same version-skew contract as
91 threadSettlement: clients keep their local visited state against
92 servers that lack this. */
93 threadVisitedTracking: Schema.optionalKey(Schema.Boolean),
94 /** Server persists a pull request reference on thread.meta.update. */
95 threadPullRequestLinking: Schema.optionalKey(Schema.Boolean),
96 /** The update path clients should offer for this server. Absent on
97 servers that must be relaunched manually (dev checkouts, Windows
98 foreground runs, pre-update servers). */
99 serverSelfUpdate: Schema.optionalKey(ServerSelfUpdateCapability),
100 /** Server can stream self-update progress before acknowledging the
101 restart. Clients fall back to server.updateServer when absent. */
102 serverSelfUpdateProgress: Schema.optionalKey(Schema.Boolean),
103 /** Agent-activity publishes (push notifications and Live Activities)
104 currently leave this environment: the publish opt-in is enabled and the
105 relay link credentials exist. Clients skip seeding a Live Activity when
106 this is false — no update would ever repaint it. Absent on older
107 servers, which may still publish, so only an explicit false skips. */
108 agentActivityPublishing: Schema.optionalKey(Schema.Boolean),
109});
110export type ExecutionEnvironmentCapabilities = typeof ExecutionEnvironmentCapabilities.Type;
111​
112export const ExecutionEnvironmentDescriptor = Schema.Struct({
113 environmentId: EnvironmentId,
114 label: TrimmedNonEmptyString,
115 platform: ExecutionEnvironmentPlatform,
116 serverVersion: TrimmedNonEmptyString,
117 /** Absent on hosts from before explicit orchestration protocol negotiation. */
118 orchestrationProtocolVersion: Schema.optionalKey(Schema.Int),
119 capabilities: ExecutionEnvironmentCapabilities,
120});
121export type ExecutionEnvironmentDescriptor = typeof ExecutionEnvironmentDescriptor.Type;
122​
123export const EnvironmentConnectionState = Schema.Literals([
124 "connecting",
125 "connected",
126 "disconnected",
127 "error",
128]);
129export type EnvironmentConnectionState = typeof EnvironmentConnectionState.Type;
130​
131export const RepositoryIdentityLocator = Schema.Struct({
132 source: Schema.Literal("git-remote"),
133 remoteName: TrimmedNonEmptyString,
134 remoteUrl: TrimmedNonEmptyString,
135});
136export type RepositoryIdentityLocator = typeof RepositoryIdentityLocator.Type;
137​
138export const RepositoryIdentity = Schema.Struct({
139 canonicalKey: TrimmedNonEmptyString,
140 locator: RepositoryIdentityLocator,
141 rootPath: Schema.optionalKey(TrimmedNonEmptyString),
142 displayName: Schema.optionalKey(TrimmedNonEmptyString),
143 provider: Schema.optionalKey(TrimmedNonEmptyString),
144 owner: Schema.optionalKey(TrimmedNonEmptyString),
145 name: Schema.optionalKey(TrimmedNonEmptyString),
146});
147export type RepositoryIdentity = typeof RepositoryIdentity.Type;
148​
149export const ScopedProjectRef = Schema.Struct({
150 environmentId: EnvironmentId,
151 projectId: ProjectId,
152});
153export type ScopedProjectRef = typeof ScopedProjectRef.Type;
154​
155export const ScopedThreadRef = Schema.Struct({
156 environmentId: EnvironmentId,
157 threadId: ThreadId,
158});
159export type ScopedThreadRef = typeof ScopedThreadRef.Type;
160​
161export const ScopedThreadSessionRef = Schema.Struct({
162 environmentId: EnvironmentId,
163 threadId: ThreadId,
164});
165export type ScopedThreadSessionRef = typeof ScopedThreadSessionRef.Type;