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