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";
11import { SourceControlProviderKind } from "./sourceControl.ts";
12
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
29export const ENVIRONMENT_MACHINE_KINDS = [
30 "server",
31 "cloud",
32 "linux",
33 "desktop",
34 "laptop",
35 "mac-mini",
36 "mac-studio",
37] as const;
38export const EnvironmentMachineKind = Schema.Literals(ENVIRONMENT_MACHINE_KINDS);
39export type EnvironmentMachineKind = typeof EnvironmentMachineKind.Type;
40export const isEnvironmentMachineKind = Schema.is(EnvironmentMachineKind);
41
42export const ExecutionEnvironmentPlatform = Schema.Struct({
43 os: ExecutionEnvironmentPlatformOs,
44 arch: ExecutionEnvironmentPlatformArch,
45 machine: ForwardCompatibleOptional(EnvironmentMachineKind),
46});
47
48// Kept outside settings.ts to avoid an orchestration import cycle.
49export const ThreadEnvMode = Schema.Literals(["local", "worktree"]);
50export type ThreadEnvMode = typeof ThreadEnvMode.Type;
51
52export const WorktreeSubmodules = Schema.Literals(["recursive", "top-level", "none"]);
53export type WorktreeSubmodules = typeof WorktreeSubmodules.Type;
54export type ExecutionEnvironmentPlatform = typeof ExecutionEnvironmentPlatform.Type;
55
56export const ServerSelfUpdateMethod = Schema.Literals(["boot-service", "respawn", "desktop-app"]);
57export type ServerSelfUpdateMethod = typeof ServerSelfUpdateMethod.Type;
58
59export const ServerInstallation = Schema.Union([
60 Schema.Struct({ kind: Schema.Literals(["npx", "pnpm-dlx", "bunx"]) }),
61 Schema.Struct({ kind: Schema.Literal("npm-global"), prefix: TrimmedNonEmptyString }),
62]);
63export type ServerInstallation = typeof ServerInstallation.Type;
64
65export const ServerSelfUpdateCapability = Schema.Literals([
66 "boot-service",
67 "respawn",
68 "desktop-managed",
69]);
70export type ServerSelfUpdateCapability = typeof ServerSelfUpdateCapability.Type;
71
72export const ExecutionEnvironmentCapabilities = Schema.Struct({
73 repositoryIdentity: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),
74 connectionProbe: Schema.optionalKey(Schema.Boolean),
75 attachmentUploads: Schema.optionalKey(Schema.Boolean),
76 questionAttachments: Schema.optionalKey(Schema.Boolean),
77 fileAttachments: Schema.optionalKey(
78 Schema.Struct({
79 maxUploadBytes: Schema.Int.check(Schema.isGreaterThanOrEqualTo(1)),
80 }),
81 ),
82 pullRequests: Schema.optionalKey(Schema.Boolean),
83 pullRequestChecks: Schema.optionalKey(Schema.Boolean),
84 /** Side chats: hidden `lineage.sideChat` forks. Older servers ignore the fork flag. */
85 sideChats: Schema.optionalKey(Schema.Boolean),
86 /** Every protocol-2 server sends this; older mobile builds still read it. */
87 inlineMessageContext: Schema.optionalKey(Schema.Boolean),
88 requiredWorktreeBootstrap: Schema.optionalKey(Schema.Boolean),
89 threadSettlement: Schema.optionalKey(Schema.Boolean),
90 threadAutoSettlement: Schema.optionalKey(Schema.Boolean),
91 storageCleanup: Schema.optionalKey(Schema.Boolean),
92 storageCleanupRun: Schema.optionalKey(Schema.Boolean),
93 databaseStorage: Schema.optionalKey(Schema.Boolean),
94 otlpEndpointCheck: Schema.optionalKey(Schema.Boolean),
95 projectWorktreeCleanup: Schema.optionalKey(Schema.Boolean),
96 settledWorktreeCleanup: Schema.optionalKey(Schema.Boolean),
97 worktreesDirectory: Schema.optionalKey(Schema.Boolean),
98 threadAutoSettlementScope: Schema.optionalKey(Schema.Boolean),
99 threadRestartContinuation: Schema.optionalKey(Schema.Boolean),
100 projectSettingsOverrides: Schema.optionalKey(Schema.Boolean),
101 /** Hide the switch when absent; older servers silently drop per-project provider patches. */
102 projectProviderInstanceOverrides: Schema.optionalKey(Schema.Boolean),
103 threadSnooze: Schema.optionalKey(Schema.Boolean),
104 /** Serves `orchestration.forceStopThread`; hide Force stop where it is absent. */
105 threadForceStop: Schema.optionalKey(Schema.Boolean),
106 /** Every protocol-2 server sends this; older mobile builds still read it. */
107 environmentThemes: Schema.optionalKey(Schema.Boolean),
108 usageLimitSources: Schema.optionalKey(Schema.Boolean),
109 /** Honors `workspaceSnapshotsOnDemand`; older servers send every snapshot and drop them in the stream. */
110 providerWorkspaceSnapshotsOnDemand: Schema.optionalKey(Schema.Boolean),
111 usagePriceOverrides: Schema.optionalKey(Schema.Boolean),
112 usageModelAliases: Schema.optionalKey(Schema.Boolean),
113 threadPinning: Schema.optionalKey(Schema.Boolean),
114 threadPinReorder: Schema.optionalKey(Schema.Boolean),
115 threadActiveReorder: Schema.optionalKey(Schema.Boolean),
116 threadAutoSettleOptOut: Schema.optionalKey(Schema.Boolean),
117 threadProjectFromScratch: Schema.optionalKey(Schema.Boolean),
118 threadTitleRegeneration: Schema.optionalKey(Schema.Boolean),
119 threadVisitedTracking: Schema.optionalKey(Schema.Boolean),
120 threadPullRequestLinking: Schema.optionalKey(Schema.Boolean),
121 serverResolvedCommandContext: Schema.optionalKey(Schema.Boolean),
122 threadStop: Schema.optionalKey(Schema.Boolean),
123 /** Absent on older servers and on Windows hosts, which cannot stop a discovered server. */
124 localServerStop: Schema.optionalKey(Schema.Boolean),
125 threadPullRequests: Schema.optionalKey(Schema.Boolean),
126 threadPullRequestWatch: Schema.optionalKey(Schema.Boolean),
127 pullRequestStackActions: Schema.optionalKey(Schema.Boolean),
128 serverSelfUpdate: Schema.optionalKey(ServerSelfUpdateCapability),
129 /** Server answers server.getNpmRelease using its configured npm registry. */
130 npmReleaseLookup: Schema.optionalKey(Schema.Boolean),
131 /** Manual commands must update this install, not the host's default global prefix. */
132 serverInstallation: ForwardCompatibleOptional(ServerInstallation),
133 serverSelfUpdateProgress: Schema.optionalKey(Schema.Boolean),
134 serverUpdateThreadContinuation: Schema.optionalKey(Schema.Boolean),
135 /** Only explicit false skips Live Activity seeding; older servers may still publish. */
136 agentActivityPublishing: Schema.optionalKey(Schema.Boolean),
137 projectCloneTracking: Schema.optionalKey(Schema.Boolean),
138 /** Server keeps `pinned` and `archived` from project.update. Older servers drop them. */
139 projectOrganization: Schema.optionalKey(Schema.Boolean),
140 /** Server answers projects.listIgnoredFiles. */
141 ignoredFileListing: Schema.optionalKey(Schema.Boolean),
142 environmentIcon: Schema.optionalKey(Schema.Boolean),
143 desktopAppUpdate: Schema.optionalKey(Schema.Boolean),
144 /** The desktop app switches update tracks when a server update request names one. */
145 desktopAppChannelSwitch: Schema.optionalKey(Schema.Boolean),
146 /** Subscribe to command output only when advertised; older servers never send it. */
147 commandOutputStreaming: Schema.optionalKey(Schema.Boolean),
148 /** Hosts headless Chromium tabs streamed over /api/preview-stream for clients without a local runtime. */
149 serverBrowser: Schema.optionalKey(Schema.Boolean),
150 /** Server links to other environments (`PeerLink`) and its agents can work
151 in them. Absent on servers from before linking, which clients must not
152 offer linking for. */
153 peerLinks: Schema.optionalKey(Schema.Boolean),
154 /** Server's `/mcp` narrows an OAuth client's modes from `T3-Mode-Limit`, so
155 a linked environment's calls keep its agent's limits. Another environment
156 links to this one only when it is set. */
157 mcpModeLimitHeader: Schema.optionalKey(Schema.Boolean),
158 /** Work a linked environment starts here stays within its link
159 (`linkOrigin`). Another environment links to this one only when it is
160 set, since without it that work could change the user's own threads. */
161 linkFence: Schema.optionalKey(Schema.Boolean),
162 /** Server answers server.prepareTriage. */
163 triage: Schema.optionalKey(Schema.Boolean),
164 /** Server accepts `{ type: "once" }` scheduled tasks; older servers reject them on save. */
165 oneTimeSchedules: Schema.optionalKey(Schema.Boolean),
166});
167export type ExecutionEnvironmentCapabilities = typeof ExecutionEnvironmentCapabilities.Type;
168
169export const ExecutionEnvironmentDescriptor = Schema.Struct({
170 environmentId: EnvironmentId,
171 label: TrimmedNonEmptyString,
172 platform: ExecutionEnvironmentPlatform,
173 serverVersion: TrimmedNonEmptyString,
174 orchestrationProtocolVersion: Schema.optionalKey(Schema.Int),
175 /** Highest migration this server's database holds; absent on older servers. */
176 databaseMigration: Schema.optionalKey(Schema.Int),
177 capabilities: ExecutionEnvironmentCapabilities,
178});
179export type ExecutionEnvironmentDescriptor = typeof ExecutionEnvironmentDescriptor.Type;
180
181export const RepositoryIdentityLocator = Schema.Struct({
182 source: Schema.Literal("git-remote"),
183 remoteName: TrimmedNonEmptyString,
184 remoteUrl: TrimmedNonEmptyString,
185});
186export type RepositoryIdentityLocator = typeof RepositoryIdentityLocator.Type;
187
188export const RepositoryOrigin = Schema.Struct({
189 canonicalKey: TrimmedNonEmptyString,
190 remoteUrl: Schema.optionalKey(TrimmedNonEmptyString),
191 displayName: Schema.optionalKey(TrimmedNonEmptyString),
192});
193export type RepositoryOrigin = typeof RepositoryOrigin.Type;
194
195export const RepositoryIdentity = Schema.Struct({
196 canonicalKey: TrimmedNonEmptyString,
197 locator: RepositoryIdentityLocator,
198 webUrl: Schema.optionalKey(TrimmedNonEmptyString),
199 /** Work tree root, or the git dir for a bare repository. */
200 rootPath: Schema.optionalKey(TrimmedNonEmptyString),
201 displayName: Schema.optionalKey(TrimmedNonEmptyString),
202 provider: Schema.optionalKey(SourceControlProviderKind),
203 owner: Schema.optionalKey(TrimmedNonEmptyString),
204 name: Schema.optionalKey(TrimmedNonEmptyString),
205 origin: Schema.optionalKey(RepositoryOrigin),
206});
207export type RepositoryIdentity = typeof RepositoryIdentity.Type;
208
209export function repositoryGroupingKeyOf(identity: RepositoryIdentity): string {
210 return identity.origin?.canonicalKey ?? identity.canonicalKey;
211}
212
213export function repositoryGroupingDisplayNameOf(identity: RepositoryIdentity): string | undefined {
214 return identity.origin
215 ? (identity.origin.displayName ?? identity.origin.canonicalKey)
216 : identity.displayName;
217}
218
219export const ScopedProjectRef = Schema.Struct({
220 environmentId: EnvironmentId,
221 projectId: ProjectId,
222});
223export type ScopedProjectRef = typeof ScopedProjectRef.Type;
224
225export const ScopedThreadRef = Schema.Struct({
226 environmentId: EnvironmentId,
227 threadId: ThreadId,
228});
229export type ScopedThreadRef = typeof ScopedThreadRef.Type;