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
18/** Wire shapes a client understands, comma-separated; a client that omits one gets the older shape. */
19export const CLIENT_CAPABILITIES_QUERY_PARAM = "clientCapabilities";
20/** Secret fields may hold a secret provider reference instead of a string. */
21export const SETTINGS_SECRET_REFERENCES_CAPABILITY = "settingsSecretReferences";
22/** Usage limit sources may be of kind "http", not only "cliproxy". */
23export const HTTP_USAGE_LIMIT_SOURCES_CAPABILITY = "httpUsageLimitSources";
24
25export const ExecutionEnvironmentPlatformOs = Schema.Literals([
26 "darwin",
27 "linux",
28 "windows",
29 "unknown",
30]);
31export type ExecutionEnvironmentPlatformOs = typeof ExecutionEnvironmentPlatformOs.Type;
32
33export const ExecutionEnvironmentPlatformArch = Schema.Literals(["arm64", "x64", "other"]);
34export type ExecutionEnvironmentPlatformArch = typeof ExecutionEnvironmentPlatformArch.Type;
35
36export const ENVIRONMENT_MACHINE_KINDS = [
37 "server",
38 "cloud",
39 "linux",
40 "desktop",
41 "laptop",
42 "mac-mini",
43 "mac-studio",
44] as const;
45export const EnvironmentMachineKind = Schema.Literals(ENVIRONMENT_MACHINE_KINDS);
46export type EnvironmentMachineKind = typeof EnvironmentMachineKind.Type;
47export const isEnvironmentMachineKind = Schema.is(EnvironmentMachineKind);
48
49export const ExecutionEnvironmentPlatform = Schema.Struct({
50 os: ExecutionEnvironmentPlatformOs,
51 arch: ExecutionEnvironmentPlatformArch,
52 machine: ForwardCompatibleOptional(EnvironmentMachineKind),
53});
54
55// Kept outside settings.ts to avoid an orchestration import cycle.
56export const ThreadEnvMode = Schema.Literals(["local", "worktree"]);
57export type ThreadEnvMode = typeof ThreadEnvMode.Type;
58
59export const WorktreeSubmodules = Schema.Literals(["recursive", "top-level", "none"]);
60export type WorktreeSubmodules = typeof WorktreeSubmodules.Type;
61export type ExecutionEnvironmentPlatform = typeof ExecutionEnvironmentPlatform.Type;
62
63export const ServerSelfUpdateMethod = Schema.Literals(["boot-service", "respawn", "desktop-app"]);
64export type ServerSelfUpdateMethod = typeof ServerSelfUpdateMethod.Type;
65
66// Not trimmed: a path that differs from the installed one would update the wrong home.
67const InstalledPath = Schema.String.check(Schema.isNonEmpty());
68
69export const ServerInstallation = Schema.Union([
70 Schema.Struct({ kind: Schema.Literals(["npx", "pnpm-dlx", "bunx"]) }),
71 Schema.Struct({ kind: Schema.Literal("npm-global"), prefix: TrimmedNonEmptyString }),
72 // A launcher (script, or a legacy symlink) into a downloaded runtime, as the install script and `t3 update` leave.
73 Schema.Struct({
74 kind: Schema.Literal("t3-launcher"),
75 launcher: InstalledPath,
76 baseDir: InstalledPath,
77 }),
78]);
79export type ServerInstallation = typeof ServerInstallation.Type;
80
81export const ServerSelfUpdateCapability = Schema.Literals([
82 "boot-service",
83 "respawn",
84 "desktop-managed",
85]);
86export type ServerSelfUpdateCapability = typeof ServerSelfUpdateCapability.Type;
87
88export const ExecutionEnvironmentCapabilities = Schema.Struct({
89 repositoryIdentity: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),
90 connectionProbe: Schema.optionalKey(Schema.Boolean),
91 /** A DPoP session from a pairing link renews at /oauth/token; pair with a bearer where absent. */
92 accessTokenRenewal: Schema.optionalKey(Schema.Boolean),
93 attachmentUploads: Schema.optionalKey(Schema.Boolean),
94 questionAttachments: Schema.optionalKey(Schema.Boolean),
95 fileAttachments: Schema.optionalKey(
96 Schema.Struct({
97 maxUploadBytes: Schema.Int.check(Schema.isGreaterThanOrEqualTo(1)),
98 }),
99 ),
100 pullRequests: Schema.optionalKey(Schema.Boolean),
101 pullRequestChecks: Schema.optionalKey(Schema.Boolean),
102 issues: Schema.optionalKey(Schema.Boolean),
103 /** Side chats: hidden `lineage.sideChat` forks. Older servers ignore the fork flag. */
104 sideChats: Schema.optionalKey(Schema.Boolean),
105 vcsBranchStatus: Schema.optionalKey(Schema.Boolean),
106 /** Every protocol-2 server sends this; older mobile builds still read it. */
107 inlineMessageContext: Schema.optionalKey(Schema.Boolean),
108 requiredWorktreeBootstrap: Schema.optionalKey(Schema.Boolean),
109 threadSettlement: Schema.optionalKey(Schema.Boolean),
110 threadAutoSettlement: Schema.optionalKey(Schema.Boolean),
111 storageCleanup: Schema.optionalKey(Schema.Boolean),
112 storageCleanupRun: Schema.optionalKey(Schema.Boolean),
113 databaseStorage: Schema.optionalKey(Schema.Boolean),
114 otlpEndpointCheck: Schema.optionalKey(Schema.Boolean),
115 /** Serves `server.checkSecretSource`; hide the secret check where it is absent. */
116 secretSourceCheck: Schema.optionalKey(Schema.Boolean),
117 projectWorktreeCleanup: Schema.optionalKey(Schema.Boolean),
118 settledWorktreeCleanup: Schema.optionalKey(Schema.Boolean),
119 worktreesDirectory: Schema.optionalKey(Schema.Boolean),
120 /** Sent by macOS servers, which honor the fastWorktreeCheckout setting. */
121 fastWorktreeCheckout: Schema.optionalKey(Schema.Boolean),
122 threadAutoSettlementScope: Schema.optionalKey(Schema.Boolean),
123 threadRestartContinuation: Schema.optionalKey(Schema.Boolean),
124 projectSettingsOverrides: Schema.optionalKey(Schema.Boolean),
125 /** Hide the switch when absent; older servers silently drop per-project provider patches. */
126 projectProviderInstanceOverrides: Schema.optionalKey(Schema.Boolean),
127 threadSnooze: Schema.optionalKey(Schema.Boolean),
128 /** Serves `orchestration.forceStopThread`; hide Force stop where it is absent. */
129 threadForceStop: Schema.optionalKey(Schema.Boolean),
130 /** Every protocol-2 server sends this; older mobile builds still read it. */
131 environmentThemes: Schema.optionalKey(Schema.Boolean),
132 usageLimitSources: Schema.optionalKey(Schema.Boolean),
133 /** Honors `workspaceSnapshotsOnDemand`; older servers send every snapshot and drop them in the stream. */
134 providerWorkspaceSnapshotsOnDemand: Schema.optionalKey(Schema.Boolean),
135 /** Honors `modelCatalogOnly`; older servers drop the field and probe every provider. */
136 modelCatalogRefresh: Schema.optionalKey(Schema.Boolean),
137 usagePriceOverrides: Schema.optionalKey(Schema.Boolean),
138 usageModelAliases: Schema.optionalKey(Schema.Boolean),
139 threadPinning: Schema.optionalKey(Schema.Boolean),
140 threadPinReorder: Schema.optionalKey(Schema.Boolean),
141 threadActiveReorder: Schema.optionalKey(Schema.Boolean),
142 threadAutoSettleOptOut: Schema.optionalKey(Schema.Boolean),
143 threadProjectFromScratch: Schema.optionalKey(Schema.Boolean),
144 threadTitleRegeneration: Schema.optionalKey(Schema.Boolean),
145 threadVisitedTracking: Schema.optionalKey(Schema.Boolean),
146 threadPullRequestLinking: Schema.optionalKey(Schema.Boolean),
147 serverResolvedCommandContext: Schema.optionalKey(Schema.Boolean),
148 threadStop: Schema.optionalKey(Schema.Boolean),
149 /** Absent on older servers and on Windows hosts, which cannot stop a discovered server. */
150 localServerStop: Schema.optionalKey(Schema.Boolean),
151 /** Honors `enablePreviewTunnel`; hide the switch where absent, since the tunnel stays on there. */
152 previewTunnelSetting: Schema.optionalKey(Schema.Boolean),
153 threadPullRequests: Schema.optionalKey(Schema.Boolean),
154 threadPullRequestWatch: Schema.optionalKey(Schema.Boolean),
155 pullRequestStackActions: Schema.optionalKey(Schema.Boolean),
156 serverSelfUpdate: Schema.optionalKey(ServerSelfUpdateCapability),
157 /** Server answers server.getNpmRelease using its configured npm registry. */
158 npmReleaseLookup: Schema.optionalKey(Schema.Boolean),
159 /** Manual commands must update this install, not the host's default global prefix. */
160 serverInstallation: ForwardCompatibleOptional(ServerInstallation),
161 serverSelfUpdateProgress: Schema.optionalKey(Schema.Boolean),
162 serverUpdateStaging: Schema.optionalKey(Schema.Boolean),
163 serverUpdateThreadContinuation: Schema.optionalKey(Schema.Boolean),
164 /** Only explicit false skips Live Activity seeding; older servers may still publish. */
165 agentActivityPublishing: Schema.optionalKey(Schema.Boolean),
166 projectCloneTracking: Schema.optionalKey(Schema.Boolean),
167 /** Server keeps `pinned` and `archived` from project.update. Older servers drop them. */
168 projectOrganization: Schema.optionalKey(Schema.Boolean),
169 /** Server answers projects.listIgnoredFiles. */
170 ignoredFileListing: Schema.optionalKey(Schema.Boolean),
171 /** projects.listIgnoredFiles honors `query`. Older servers ignore it. */
172 ignoredFileSearch: Schema.optionalKey(Schema.Boolean),
173 environmentIcon: Schema.optionalKey(Schema.Boolean),
174 desktopAppUpdate: Schema.optionalKey(Schema.Boolean),
175 /** The desktop app switches update tracks when a server update request names one. */
176 desktopAppChannelSwitch: Schema.optionalKey(Schema.Boolean),
177 /** Subscribe to command output only when advertised; older servers never send it. */
178 commandOutputStreaming: Schema.optionalKey(Schema.Boolean),
179 /** Hosts headless Chromium tabs streamed over /api/preview-stream for clients without a local runtime. */
180 serverBrowser: Schema.optionalKey(Schema.Boolean),
181 /** Server links to other environments (`PeerLink`) and its agents can work
182 in them. Absent on servers from before linking, which clients must not
183 offer linking for. */
184 peerLinks: Schema.optionalKey(Schema.Boolean),
185 /** Server's `/mcp` narrows an OAuth client's modes from `T3-Mode-Limit`, so
186 a linked environment's calls keep its agent's limits. Another environment
187 links to this one only when it is set. */
188 mcpModeLimitHeader: Schema.optionalKey(Schema.Boolean),
189 /** Work a linked environment starts here stays within its link
190 (`linkOrigin`). Another environment links to this one only when it is
191 set, since without it that work could change the user's own threads. */
192 linkFence: Schema.optionalKey(Schema.Boolean),
193 /** Serves a thread's stream, history pages and item detail to a link's session
194 (`PEER_LINK_THREAD_STREAM_ROUTE`), so a client of the linking environment can read it. */
195 linkThreadStream: Schema.optionalKey(Schema.Boolean),
196 /** A full-access link can ask this server for a one-time pairing credential for a client
197 of the linking environment. Absent on servers from before it. */
198 linkClientPairing: Schema.optionalKey(Schema.Boolean),
199 /** The same route also mints a pairing code for a link from another environment. */
200 linkPairingForLink: Schema.optionalKey(Schema.Boolean),
201 /** Mints pairing codes that approve one agent sign-in at a set level (`AUTO-…`). */
202 mcpApprovalCodes: Schema.optionalKey(Schema.Boolean),
203 peerLinkPairingCodes: Schema.optionalKey(Schema.Boolean),
204 /** Agent sign-ins on its T3 Connect address are approved on the hosted app, without a code. */
205 mcpHostedApproval: Schema.optionalKey(Schema.Boolean),
206 /** Server answers server.prepareTriage. */
207 triage: Schema.optionalKey(Schema.Boolean),
208 /** Server accepts `{ type: "once" }` scheduled tasks; older servers reject them on save. */
209 oneTimeSchedules: Schema.optionalKey(Schema.Boolean),
210 /** Server honors `freshContext` on sends; older servers ignore it and keep the old context. */
211 freshContext: Schema.optionalKey(Schema.Boolean),
212 /** Server saves and runs scheduled task `threadMode`; older servers ignore it. */
213 scheduledTaskThreadModes: Schema.optionalKey(Schema.Boolean),
214 /** Server can transcribe 16 kHz mono PCM audio on the environment machine. */
215 voiceTranscription: Schema.optionalKey(Schema.Boolean),
216 cloudVoiceTranscription: Schema.optionalKey(Schema.Boolean),
217 /**
218 * The server config's flags of the same names. A server that names them here lets a client
219 * load the shell snapshot before the socket opens, and answers its `resumeFrom`.
220 */
221 shellThreadFamilies: Schema.optionalKey(Schema.Boolean),
222 shellOlderSettled: Schema.optionalKey(Schema.Boolean),
223 /** Publishes a pull request refresh when linked-thread answers change; older servers need polling. */
224 linkedThreadRefreshes: Schema.optionalKey(Schema.Boolean),
225 /** Honors the `agentFeedback` setting; older servers drop it, so hide its switch where absent. */
226 agentFeedback: Schema.optionalKey(Schema.Boolean),
227 /** Answers `issues.linkedThreads`, the threads an issue is linked to. */
228 issueLinkedThreads: Schema.optionalKey(Schema.Boolean),
229 /** Keeps more than one account per standalone issue tracker; older servers keep one. */
230 issueTrackerAccounts: Schema.optionalKey(Schema.Boolean),
231});
232export type ExecutionEnvironmentCapabilities = typeof ExecutionEnvironmentCapabilities.Type;
233
234export const ExecutionEnvironmentDescriptor = Schema.Struct({
235 environmentId: EnvironmentId,
236 label: TrimmedNonEmptyString,
237 platform: ExecutionEnvironmentPlatform,
238 serverVersion: TrimmedNonEmptyString,
239 orchestrationProtocolVersion: Schema.optionalKey(Schema.Int),
240 /** Highest migration this server's database holds; absent on older servers. */
241 databaseMigration: Schema.optionalKey(Schema.Int),
242 capabilities: ExecutionEnvironmentCapabilities,
243});
244export type ExecutionEnvironmentDescriptor = typeof ExecutionEnvironmentDescriptor.Type;
245
246export const RepositoryIdentityLocator = Schema.Struct({
247 source: Schema.Literal("git-remote"),
248 remoteName: TrimmedNonEmptyString,
249 remoteUrl: TrimmedNonEmptyString,
250});
251export type RepositoryIdentityLocator = typeof RepositoryIdentityLocator.Type;
252
253export const RepositoryOrigin = Schema.Struct({
254 canonicalKey: TrimmedNonEmptyString,
255 remoteUrl: Schema.optionalKey(TrimmedNonEmptyString),
256 displayName: Schema.optionalKey(TrimmedNonEmptyString),
257});
258export type RepositoryOrigin = typeof RepositoryOrigin.Type;
259
260export const RepositoryIdentity = Schema.Struct({
261 canonicalKey: TrimmedNonEmptyString,
262 locator: RepositoryIdentityLocator,
263 webUrl: Schema.optionalKey(TrimmedNonEmptyString),
264 /** Work tree root, or the git dir for a bare repository. */
265 rootPath: Schema.optionalKey(TrimmedNonEmptyString),
266 displayName: Schema.optionalKey(TrimmedNonEmptyString),
267 provider: Schema.optionalKey(SourceControlProviderKind),
268 owner: Schema.optionalKey(TrimmedNonEmptyString),
269 name: Schema.optionalKey(TrimmedNonEmptyString),
270 origin: Schema.optionalKey(RepositoryOrigin),
271});
272export type RepositoryIdentity = typeof RepositoryIdentity.Type;
273
274export function repositoryGroupingKeyOf(identity: RepositoryIdentity): string {
275 return identity.origin?.canonicalKey ?? identity.canonicalKey;
276}
277
278export function repositoryGroupingDisplayNameOf(identity: RepositoryIdentity): string | undefined {
279 return identity.origin
280 ? (identity.origin.displayName ?? identity.origin.canonicalKey)
281 : identity.displayName;
282}
283
284export const ScopedProjectRef = Schema.Struct({
285 environmentId: EnvironmentId,
286 projectId: ProjectId,
287});
288export type ScopedProjectRef = typeof ScopedProjectRef.Type;
289
290export const ScopedThreadRef = Schema.Struct({
291 environmentId: EnvironmentId,
292 threadId: ThreadId,
293});
294export type ScopedThreadRef = typeof ScopedThreadRef.Type;