Open History to see the last commit
1import * as Effect from "effect/Effect";
2import * as Schema from "effect/Schema";
3import {
4 type EnvironmentMachineKind,
5 ExecutionEnvironmentDescriptor,
6 ServerSelfUpdateMethod,
7} from "./environment.ts";
8import { ServerAuthDescriptor } from "./auth.ts";
9import {
10 ForwardCompatibleArray,
11 IsoDateTime,
12 NonNegativeInt,
13 PositiveInt,
14 ProjectId,
15 ThreadId,
16 TrimmedNonEmptyString,
17} from "./baseSchemas.ts";
18import {
19 KeybindingCommand,
20 KeybindingValue,
21 KeybindingWhen,
22 ResolvedKeybindingsConfig,
23} from "./keybindings.ts";
24import { EditorId, FileManagerRevealKind, RemoteOpenTarget } from "./editor.ts";
25import { ModelCapabilities } from "./model.ts";
26import { ProviderDriverKind, ProviderInstanceId } from "./providerInstance.ts";
27import { ServerProviderUsageLimits, UsageLimitSourceSnapshots } from "./providerUsageLimits.ts";
28import { ServerSettings } from "./settings.ts";
29
30const KeybindingsMalformedConfigIssue = Schema.Struct({
31 kind: Schema.Literal("keybindings.malformed-config"),
32 message: TrimmedNonEmptyString,
33});
34
35const KeybindingsInvalidEntryIssue = Schema.Struct({
36 kind: Schema.Literal("keybindings.invalid-entry"),
37 message: TrimmedNonEmptyString,
38 index: Schema.Number,
39});
40
41export const ServerConfigIssue = Schema.Union([
42 KeybindingsMalformedConfigIssue,
43 KeybindingsInvalidEntryIssue,
44]);
45export type ServerConfigIssue = typeof ServerConfigIssue.Type;
46
47// Issue kinds grow over time; older clients must not fail the whole config
48// decode over a kind they cannot render.
49const ServerConfigIssues = ForwardCompatibleArray(ServerConfigIssue);
50
51export const ServerProviderState = Schema.Literals(["ready", "warning", "error", "disabled"]);
52export type ServerProviderState = typeof ServerProviderState.Type;
53
54export const ServerProviderAuthStatus = Schema.Literals([
55 "authenticated",
56 "unauthenticated",
57 "unknown",
58]);
59export type ServerProviderAuthStatus = typeof ServerProviderAuthStatus.Type;
60
61export const ServerProviderAuth = Schema.Struct({
62 status: ServerProviderAuthStatus,
63 type: Schema.optional(TrimmedNonEmptyString),
64 label: Schema.optional(TrimmedNonEmptyString),
65 email: Schema.optional(TrimmedNonEmptyString),
66});
67export type ServerProviderAuth = typeof ServerProviderAuth.Type;
68
69export const ServerProviderModel = Schema.Struct({
70 slug: TrimmedNonEmptyString,
71 name: TrimmedNonEmptyString,
72 shortName: Schema.optional(TrimmedNonEmptyString),
73 subProvider: Schema.optional(TrimmedNonEmptyString),
74 aliases: Schema.optional(Schema.Array(TrimmedNonEmptyString)),
75 badge: Schema.optional(Schema.Literal("new")),
76 isCustom: Schema.Boolean,
77 isDefault: Schema.optional(Schema.Boolean),
78 isLegacy: Schema.optional(Schema.Boolean),
79 capabilities: Schema.NullOr(ModelCapabilities),
80});
81export type ServerProviderModel = typeof ServerProviderModel.Type;
82
83export const ServerProviderSlashCommandInput = Schema.Struct({
84 hint: TrimmedNonEmptyString,
85});
86export type ServerProviderSlashCommandInput = typeof ServerProviderSlashCommandInput.Type;
87
88export const ServerProviderSlashCommand = Schema.Struct({
89 name: TrimmedNonEmptyString,
90 description: Schema.optional(TrimmedNonEmptyString),
91 input: Schema.optional(ServerProviderSlashCommandInput),
92});
93export type ServerProviderSlashCommand = typeof ServerProviderSlashCommand.Type;
94
95export const ServerProviderSkill = Schema.Struct({
96 name: TrimmedNonEmptyString,
97 description: Schema.optional(TrimmedNonEmptyString),
98 path: TrimmedNonEmptyString,
99 scope: Schema.optional(TrimmedNonEmptyString),
100 enabled: Schema.Boolean,
101 displayName: Schema.optional(TrimmedNonEmptyString),
102 shortDescription: Schema.optional(TrimmedNonEmptyString),
103 /**
104 * The skill is hidden from the agent's own skill tool, so only the user can
105 * start it — Claude Code's `disable-model-invocation`. Composers must offer
106 * it as a slash command; naming it in prose does nothing.
107 */
108 userInvocationOnly: Schema.optional(Schema.Boolean),
109 /**
110 * The mirror of {@link ServerProviderSkill.userInvocationOnly}: Claude Code's
111 * `user-invocable: false` keeps the skill out of its own slash commands, so
112 * only the agent can start it. Composers must not offer it under `/`.
113 */
114 userInvocable: Schema.optional(Schema.Boolean),
115});
116export type ServerProviderSkill = typeof ServerProviderSkill.Type;
117
118export const ServerProviderWorkspaceSnapshot = Schema.Struct({
119 cwd: TrimmedNonEmptyString,
120 checkedAt: IsoDateTime,
121 slashCommands: Schema.Array(ServerProviderSlashCommand),
122 skills: Schema.Array(ServerProviderSkill),
123});
124export type ServerProviderWorkspaceSnapshot = typeof ServerProviderWorkspaceSnapshot.Type;
125
126/**
127 * Availability of a configured provider instance from the runtime's POV.
128 *
129 * - `available` — the build ships this driver and an instance is wired
130 * up. Default for legacy snapshots produced from the closed
131 * `ServerSettings.providers` map.
132 * - `unavailable` — the user's `ServerSettings.providerInstances` (or a
133 * persisted thread / session binding) references a driver this build
134 * doesn't ship. Common after rolling back from a fork or PR branch
135 * that introduced a new driver. The snapshot is preserved so the UI
136 * can render "missing driver" affordances and so the data round-trips
137 * when the user moves back to the fork.
138 *
139 * Snapshots with `availability: "unavailable"` MUST set
140 * `installed: false` and `enabled: false`; the runtime refuses turn
141 * starts against them with a structured error.
142 */
143export const ServerProviderAvailability = Schema.Literals(["available", "unavailable"]);
144export type ServerProviderAvailability = typeof ServerProviderAvailability.Type;
145
146export const ServerProviderContinuation = Schema.Struct({
147 groupKey: TrimmedNonEmptyString,
148});
149export type ServerProviderContinuation = typeof ServerProviderContinuation.Type;
150
151export const ServerProviderVersionAdvisoryStatus = Schema.Literals([
152 "unknown",
153 "current",
154 "behind_latest",
155]);
156export type ServerProviderVersionAdvisoryStatus = typeof ServerProviderVersionAdvisoryStatus.Type;
157
158export const ServerProviderVersionAdvisory = Schema.Struct({
159 status: ServerProviderVersionAdvisoryStatus,
160 currentVersion: Schema.NullOr(TrimmedNonEmptyString),
161 latestVersion: Schema.NullOr(TrimmedNonEmptyString),
162 updateCommand: Schema.NullOr(TrimmedNonEmptyString),
163 canUpdate: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),
164 checkedAt: Schema.NullOr(IsoDateTime),
165 message: Schema.NullOr(TrimmedNonEmptyString),
166});
167export type ServerProviderVersionAdvisory = typeof ServerProviderVersionAdvisory.Type;
168
169export const ServerProviderUpdateStatus = Schema.Literals([
170 "idle",
171 "queued",
172 "running",
173 "succeeded",
174 "failed",
175 "unchanged",
176]);
177export type ServerProviderUpdateStatus = typeof ServerProviderUpdateStatus.Type;
178
179export const ServerProviderUpdateState = Schema.Struct({
180 status: ServerProviderUpdateStatus,
181 startedAt: Schema.NullOr(IsoDateTime),
182 finishedAt: Schema.NullOr(IsoDateTime),
183 message: Schema.NullOr(TrimmedNonEmptyString),
184 output: Schema.NullOr(Schema.String.check(Schema.isMaxLength(10_000))),
185});
186export type ServerProviderUpdateState = typeof ServerProviderUpdateState.Type;
187
188export const ServerProvider = Schema.Struct({
189 // Routing key for the configured instance this snapshot represents. This
190 // is the only stable identity consumers may use for provider routing.
191 instanceId: ProviderInstanceId,
192 // Open driver kind slug that selects the implementation handling this
193 // instance. It is metadata/capability context, not a routing key.
194 driver: ProviderDriverKind,
195 displayName: Schema.optional(TrimmedNonEmptyString),
196 accentColor: Schema.optional(TrimmedNonEmptyString),
197 badgeLabel: Schema.optional(TrimmedNonEmptyString),
198 continuation: Schema.optional(ServerProviderContinuation),
199 showInteractionModeToggle: Schema.optional(Schema.Boolean),
200 requiresNewThreadForModelChange: Schema.optional(Schema.Boolean),
201 supportsConversationRollback: Schema.optional(Schema.Boolean),
202 supportsTextGeneration: Schema.optional(Schema.Boolean),
203 setup: Schema.optional(
204 Schema.Struct({
205 canAuthenticate: Schema.Boolean,
206 canInstall: Schema.Boolean,
207 }),
208 ),
209 enabled: Schema.Boolean,
210 installed: Schema.Boolean,
211 version: Schema.NullOr(TrimmedNonEmptyString),
212 status: ServerProviderState,
213 auth: ServerProviderAuth,
214 checkedAt: IsoDateTime,
215 message: Schema.optional(TrimmedNonEmptyString),
216 // Optional for back-compat: every legacy producer omits this field and
217 // an absent value is interpreted as `"available"` by consumers (see
218 // `isProviderAvailable`). New `ProviderInstanceRegistry` outputs set it
219 // explicitly so the UI can render unavailable shadows from
220 // `ServerSettings.providerInstances`.
221 availability: Schema.optional(ServerProviderAvailability),
222 // Human-readable reason populated when `availability === "unavailable"`.
223 // Surfaces in the UI alongside the missing-driver affordance.
224 unavailableReason: Schema.optional(TrimmedNonEmptyString),
225 models: Schema.Array(ServerProviderModel),
226 slashCommands: Schema.Array(ServerProviderSlashCommand).pipe(
227 Schema.withDecodingDefault(Effect.succeed([])),
228 ),
229 skills: Schema.Array(ServerProviderSkill).pipe(Schema.withDecodingDefault(Effect.succeed([]))),
230 workspaceSnapshots: Schema.optionalKey(Schema.Array(ServerProviderWorkspaceSnapshot)),
231 // Absent when the driver has no notion of subscription usage.
232 usageLimits: Schema.optional(ServerProviderUsageLimits),
233 versionAdvisory: Schema.optionalKey(ServerProviderVersionAdvisory),
234 updateState: Schema.optionalKey(ServerProviderUpdateState),
235});
236export type ServerProvider = typeof ServerProvider.Type;
237
238// Provider status kinds grow over time (ServerProviderState,
239// ServerProviderAuthStatus, ServerProviderVersionAdvisoryStatus,
240// ServerProviderUpdateStatus); an older client must not fail the whole config
241// decode over one provider it cannot render.
242export const ServerProviders = ForwardCompatibleArray(ServerProvider);
243export type ServerProviders = typeof ServerProviders.Type;
244
245/**
246 * Treat the optional `availability` as "available" when absent. This is
247 * the rule legacy producers (which omit the field) and new producers
248 * (which set it explicitly) agree on so consumers never have to thread
249 * `?? "available"` defaults through their code paths.
250 */
251export const isProviderAvailable = (snapshot: ServerProvider): boolean =>
252 snapshot.availability !== "unavailable";
253
254export const ServerObservability = Schema.Struct({
255 logsDirectoryPath: TrimmedNonEmptyString,
256 localTracingEnabled: Schema.Boolean,
257 otlpTracesUrl: Schema.optional(TrimmedNonEmptyString),
258 otlpTracesEnabled: Schema.Boolean,
259 otlpMetricsUrl: Schema.optional(TrimmedNonEmptyString),
260 otlpMetricsEnabled: Schema.Boolean,
261});
262export type ServerObservability = typeof ServerObservability.Type;
263
264export const ServerTraceDiagnosticsErrorKind = Schema.Literals([
265 "trace-file-not-found",
266 "trace-file-read-failed",
267]);
268export type ServerTraceDiagnosticsErrorKind = typeof ServerTraceDiagnosticsErrorKind.Type;
269
270export const ServerTraceDiagnosticsSpanSummary = Schema.Struct({
271 name: TrimmedNonEmptyString,
272 count: NonNegativeInt,
273 failureCount: NonNegativeInt,
274 totalDurationMs: Schema.Number,
275 averageDurationMs: Schema.Number,
276 maxDurationMs: Schema.Number,
277});
278export type ServerTraceDiagnosticsSpanSummary = typeof ServerTraceDiagnosticsSpanSummary.Type;
279
280export const ServerTraceDiagnosticsFailureSummary = Schema.Struct({
281 name: TrimmedNonEmptyString,
282 cause: TrimmedNonEmptyString,
283 count: NonNegativeInt,
284 lastSeenAt: Schema.DateTimeUtc,
285 traceId: TrimmedNonEmptyString,
286 spanId: TrimmedNonEmptyString,
287});
288export type ServerTraceDiagnosticsFailureSummary = typeof ServerTraceDiagnosticsFailureSummary.Type;
289
290export const ServerTraceDiagnosticsRecentFailure = Schema.Struct({
291 name: TrimmedNonEmptyString,
292 cause: TrimmedNonEmptyString,
293 durationMs: Schema.Number,
294 endedAt: Schema.DateTimeUtc,
295 traceId: TrimmedNonEmptyString,
296 spanId: TrimmedNonEmptyString,
297});
298export type ServerTraceDiagnosticsRecentFailure = typeof ServerTraceDiagnosticsRecentFailure.Type;
299
300export const ServerTraceDiagnosticsSpanOccurrence = Schema.Struct({
301 name: TrimmedNonEmptyString,
302 durationMs: Schema.Number,
303 endedAt: Schema.DateTimeUtc,
304 traceId: TrimmedNonEmptyString,
305 spanId: TrimmedNonEmptyString,
306});
307export type ServerTraceDiagnosticsSpanOccurrence = typeof ServerTraceDiagnosticsSpanOccurrence.Type;
308
309export const ServerTraceDiagnosticsLogEvent = Schema.Struct({
310 spanName: TrimmedNonEmptyString,
311 level: TrimmedNonEmptyString,
312 message: TrimmedNonEmptyString,
313 seenAt: Schema.DateTimeUtc,
314 traceId: TrimmedNonEmptyString,
315 spanId: TrimmedNonEmptyString,
316});
317export type ServerTraceDiagnosticsLogEvent = typeof ServerTraceDiagnosticsLogEvent.Type;
318
319export const ServerTraceDiagnosticsResult = Schema.Struct({
320 traceFilePath: TrimmedNonEmptyString,
321 scannedFilePaths: Schema.Array(TrimmedNonEmptyString),
322 readAt: Schema.DateTimeUtc,
323 recordCount: NonNegativeInt,
324 parseErrorCount: NonNegativeInt,
325 firstSpanAt: Schema.Option(Schema.DateTimeUtc),
326 lastSpanAt: Schema.Option(Schema.DateTimeUtc),
327 failureCount: NonNegativeInt,
328 interruptionCount: NonNegativeInt,
329 slowSpanThresholdMs: NonNegativeInt,
330 slowSpanCount: NonNegativeInt,
331 logLevelCounts: Schema.Record(TrimmedNonEmptyString, NonNegativeInt),
332 topSpansByCount: Schema.Array(ServerTraceDiagnosticsSpanSummary),
333 slowestSpans: Schema.Array(ServerTraceDiagnosticsSpanOccurrence),
334 commonFailures: Schema.Array(ServerTraceDiagnosticsFailureSummary),
335 latestFailures: Schema.Array(ServerTraceDiagnosticsRecentFailure),
336 latestWarningAndErrorLogs: Schema.Array(ServerTraceDiagnosticsLogEvent),
337 partialFailure: Schema.Option(Schema.Boolean),
338 error: Schema.Option(
339 Schema.Struct({
340 kind: ServerTraceDiagnosticsErrorKind,
341 message: TrimmedNonEmptyString,
342 }),
343 ),
344});
345export type ServerTraceDiagnosticsResult = typeof ServerTraceDiagnosticsResult.Type;
346
347export const ServerProcessSignal = Schema.Literals(["SIGINT", "SIGKILL"]);
348export type ServerProcessSignal = typeof ServerProcessSignal.Type;
349
350export const ServerProcessDiagnosticsEntry = Schema.Struct({
351 pid: PositiveInt,
352 startTimeMs: NonNegativeInt,
353 ppid: NonNegativeInt,
354 pgid: Schema.Option(Schema.Int),
355 status: TrimmedNonEmptyString,
356 cpuPercent: Schema.Number,
357 rssBytes: NonNegativeInt,
358 elapsed: TrimmedNonEmptyString,
359 command: TrimmedNonEmptyString,
360 depth: NonNegativeInt,
361 childPids: Schema.Array(PositiveInt),
362});
363export type ServerProcessDiagnosticsEntry = typeof ServerProcessDiagnosticsEntry.Type;
364
365export const ServerProcessDiagnosticsResult = Schema.Struct({
366 serverPid: PositiveInt,
367 readAt: Schema.DateTimeUtc,
368 processCount: NonNegativeInt,
369 totalRssBytes: NonNegativeInt,
370 totalCpuPercent: Schema.Number,
371 processes: Schema.Array(ServerProcessDiagnosticsEntry),
372 error: Schema.Option(
373 Schema.Struct({
374 message: TrimmedNonEmptyString,
375 }),
376 ),
377});
378export type ServerProcessDiagnosticsResult = typeof ServerProcessDiagnosticsResult.Type;
379
380export const ServerProcessResourceHistoryInput = Schema.Struct({
381 windowMs: NonNegativeInt,
382 bucketMs: NonNegativeInt,
383});
384export type ServerProcessResourceHistoryInput = typeof ServerProcessResourceHistoryInput.Type;
385
386export const ServerProcessResourceHistoryBucket = Schema.Struct({
387 startedAt: Schema.DateTimeUtc,
388 endedAt: Schema.DateTimeUtc,
389 avgCpuPercent: Schema.Number,
390 maxCpuPercent: Schema.Number,
391 maxRssBytes: NonNegativeInt,
392 maxProcessCount: NonNegativeInt,
393});
394export type ServerProcessResourceHistoryBucket = typeof ServerProcessResourceHistoryBucket.Type;
395
396export const ServerProcessResourceHistorySummary = Schema.Struct({
397 processKey: TrimmedNonEmptyString,
398 pid: PositiveInt,
399 ppid: NonNegativeInt,
400 command: TrimmedNonEmptyString,
401 depth: NonNegativeInt,
402 isServerRoot: Schema.Boolean,
403 firstSeenAt: Schema.DateTimeUtc,
404 lastSeenAt: Schema.DateTimeUtc,
405 currentCpuPercent: Schema.Number,
406 avgCpuPercent: Schema.Number,
407 maxCpuPercent: Schema.Number,
408 cpuSecondsApprox: Schema.Number,
409 currentRssBytes: NonNegativeInt,
410 maxRssBytes: NonNegativeInt,
411 sampleCount: NonNegativeInt,
412});
413export type ServerProcessResourceHistorySummary = typeof ServerProcessResourceHistorySummary.Type;
414
415export const ServerProcessResourceHistoryFailureTag = Schema.Literals([
416 "ProcessDiagnosticsQueryTimeoutError",
417 "ProcessDiagnosticsQueryFailedError",
418 "ProcessDiagnosticsServerProcessSignalError",
419 "ProcessDiagnosticsNotDescendantError",
420 "ProcessDiagnosticsSignalFailedError",
421]);
422export type ServerProcessResourceHistoryFailureTag =
423 typeof ServerProcessResourceHistoryFailureTag.Type;
424
425export const ServerProcessResourceHistoryResult = Schema.Struct({
426 readAt: Schema.DateTimeUtc,
427 windowMs: NonNegativeInt,
428 bucketMs: NonNegativeInt,
429 sampleIntervalMs: NonNegativeInt,
430 retainedSampleCount: NonNegativeInt,
431 totalCpuSecondsApprox: Schema.Number,
432 buckets: Schema.Array(ServerProcessResourceHistoryBucket),
433 topProcesses: Schema.Array(ServerProcessResourceHistorySummary),
434 error: Schema.Option(
435 Schema.Struct({
436 failureTag: ServerProcessResourceHistoryFailureTag,
437 message: TrimmedNonEmptyString,
438 }),
439 ),
440});
441export type ServerProcessResourceHistoryResult = typeof ServerProcessResourceHistoryResult.Type;
442
443export const ServerSignalProcessInput = Schema.Struct({
444 pid: PositiveInt,
445 startTimeMs: NonNegativeInt,
446 signal: ServerProcessSignal,
447});
448export type ServerSignalProcessInput = typeof ServerSignalProcessInput.Type;
449
450export const ServerSignalProcessResult = Schema.Struct({
451 pid: PositiveInt,
452 signal: ServerProcessSignal,
453 signaled: Schema.Boolean,
454 message: Schema.Option(TrimmedNonEmptyString),
455});
456export type ServerSignalProcessResult = typeof ServerSignalProcessResult.Type;
457
458/**
459 * A palette the environment's machine publishes for T3 Code to follow, read
460 * from a theme file next to the rest of the environment's state. Two seed
461 * colors rather than a full palette: clients derive the remaining roles with
462 * the same generator the guided theme editor uses, so a desktop theme carries
463 * over as a coherent T3 Code palette instead of a foreign one.
464 */
465export const EnvironmentThemeColor = Schema.String.check(
466 Schema.isPattern(/^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/),
467);
468export type EnvironmentThemeColor = typeof EnvironmentThemeColor.Type;
469
470/**
471 * Matches the client-side theme id rule, so a published id is selectable.
472 * The appearance keywords are excluded outright: a published `dark.json`
473 * would otherwise capture every client whose stored preference is the stock
474 * `"dark"`, retinting people who never chose it.
475 */
476export const EnvironmentThemeId = Schema.String.check(
477 Schema.isPattern(/^(?!(?:system|light|dark)$)[a-z0-9](?:[a-z0-9-]{0,47})$/),
478);
479export type EnvironmentThemeId = typeof EnvironmentThemeId.Type;
480
481/**
482 * Role colors as published. Values are any CSS color the client's theme
483 * parser accepts (exported theme files use oklch), canonicalized client-side;
484 * roles a build does not know are dropped there, so a machine may publish
485 * roles a newer client added without breaking an older one. Keys must still
486 * be role-shaped and values color-sized, so the record stays open to future
487 * vocabulary without being an arbitrary-payload channel.
488 */
489const EnvironmentThemeColors = Schema.Record(
490 Schema.String.check(Schema.isPattern(/^[a-zA-Z][a-zA-Z0-9]{0,63}$/)),
491 TrimmedNonEmptyString.check(Schema.isMaxLength(64)),
492);
493
494const environmentThemeFields = {
495 /**
496 * Standard exported theme files (the Download button's output) carry
497 * `version: 1`; the seeded short form a desktop generates has no version.
498 */
499 version: Schema.optional(Schema.Literal(1)),
500 /** Shown on the theme card, e.g. the desktop theme's own name. */
501 name: TrimmedNonEmptyString.check(Schema.isMaxLength(48)),
502 appearance: Schema.Literals(["light", "dark"]),
503 /**
504 * Seed colors. When present, clients derive the full palette from them with
505 * the guided theme editor's generator and layer `colors` on top; when
506 * absent, `colors` is the palette, as in an exported theme file.
507 */
508 canvas: Schema.optional(EnvironmentThemeColor),
509 accent: Schema.optional(EnvironmentThemeColor),
510 colors: Schema.optional(EnvironmentThemeColors),
511 /** The other appearance's palette, as exported theme files carry it. */
512 variants: Schema.optional(
513 Schema.Struct({
514 light: Schema.optional(EnvironmentThemeColors),
515 dark: Schema.optional(EnvironmentThemeColors),
516 }),
517 ),
518};
519
520/** One published theme file. The id is the filename, not part of the content,
521 * so a file cannot claim another file's identity; an embedded `id` is ignored. */
522export const EnvironmentThemeFile = Schema.Struct(environmentThemeFields);
523export type EnvironmentThemeFile = typeof EnvironmentThemeFile.Type;
524
525export const EnvironmentTheme = Schema.Struct({
526 /** The publishing filename without its extension, stable across recolors. */
527 id: EnvironmentThemeId,
528 ...environmentThemeFields,
529});
530export type EnvironmentTheme = typeof EnvironmentTheme.Type;
531
532/**
533 * Whether a theme file carries anything to render. A file with neither seeds
534 * nor colors would show as the stock palette wearing a name, which reads as a
535 * bug rather than a theme — the CLI and the server watcher both reject it,
536 * through this one predicate so they cannot drift.
537 */
538export function environmentThemeFileHasColors(file: EnvironmentThemeFile): boolean {
539 return (
540 (file.canvas !== undefined && file.accent !== undefined) ||
541 (file.colors !== undefined && Object.keys(file.colors).length > 0)
542 );
543}
544
545export const ServerConfig = Schema.Struct({
546 environment: ExecutionEnvironmentDescriptor,
547 auth: ServerAuthDescriptor,
548 cwd: TrimmedNonEmptyString,
549 keybindingsConfigPath: TrimmedNonEmptyString,
550 keybindings: ResolvedKeybindingsConfig,
551 issues: ServerConfigIssues,
552 providers: ServerProviders,
553 // Editor ids grow over time; drop ones this build does not know rather than
554 // failing the whole config decode.
555 availableEditors: ForwardCompatibleArray(EditorId),
556 /**
557 * SSH hosts this environment advertises for remote open-in-editor links.
558 * Absent on servers that predate the feature; empty when the machine has no
559 * sshd or no advertisable name.
560 */
561 remoteOpenTargets: Schema.optionalKey(ForwardCompatibleArray(RemoteOpenTarget)),
562 observability: ServerObservability,
563 settings: ServerSettings,
564 /** Whether shell subscriptions can emit an opt-in catch-up completion marker. */
565 shellResumeCompletionMarker: Schema.optionalKey(Schema.Boolean),
566 /** Whether shell.openInEditor honors `LaunchEditorInput.reveal` for the
567 file-manager editor. */
568 shellRevealInFileManager: Schema.optionalKey(Schema.Boolean),
569 /** File-manager wording clients should use for reveal actions. */
570 shellRevealInFileManagerKind: Schema.optionalKey(FileManagerRevealKind),
571 /** Whether thread subscriptions can emit an opt-in catch-up completion marker. */
572 threadResumeCompletionMarker: Schema.optionalKey(Schema.Boolean),
573 /**
574 * Whether thread detail reads accept a turn window (`turnLimit`/
575 * `beforeCursor`) and return `page` metadata. Clients must not send window
576 * fields to servers that don't advertise this.
577 */
578 threadSnapshotPagination: Schema.optionalKey(Schema.Boolean),
579 /**
580 * Palettes published by this environment's machine. Never sent in a config
581 * snapshot: the theme stream emits the current set before any change, so a
582 * snapshot carrying it too would hand every subscriber the same array twice
583 * per connect. Clients populate this by projecting `environmentThemesUpdated`,
584 * and it stays absent for subscribers that did not opt in.
585 */
586 environmentThemes: Schema.optional(Schema.Array(EnvironmentTheme)),
587 /**
588 * Quota reported by configured `usageLimitSources`. Like themes, never in
589 * a snapshot: the source stream emits the current set on subscribe, and it
590 * stays absent for subscribers that did not opt in.
591 */
592 usageLimitSources: Schema.optional(UsageLimitSourceSnapshots),
593});
594export type ServerConfig = typeof ServerConfig.Type;
595
596/**
597 * The machine an environment should be drawn as: the user's pick, else what
598 * the server detected, else a generic server. A null config (not connected
599 * yet, or an older server) resolves to the same generic so rows never
600 * flicker between glyphs.
601 */
602export function resolveEnvironmentMachineKind(
603 config: Pick<ServerConfig, "environment" | "settings"> | null,
604): EnvironmentMachineKind {
605 return config?.settings.environmentIcon ?? config?.environment.platform.machine ?? "server";
606}
607
608const ServerUpsertKeybindingReplaceTarget = Schema.Struct({
609 key: KeybindingValue,
610 command: KeybindingCommand,
611 when: Schema.optional(KeybindingWhen),
612});
613
614export const ServerUpsertKeybindingInput = Schema.Struct({
615 key: KeybindingValue,
616 command: KeybindingCommand,
617 when: Schema.optional(KeybindingWhen),
618 replace: Schema.optional(ServerUpsertKeybindingReplaceTarget),
619});
620export type ServerUpsertKeybindingInput = typeof ServerUpsertKeybindingInput.Type;
621
622export const ServerRemoveKeybindingInput = ServerUpsertKeybindingReplaceTarget;
623export type ServerRemoveKeybindingInput = typeof ServerRemoveKeybindingInput.Type;
624
625export const ServerUpsertKeybindingResult = Schema.Struct({
626 keybindings: ResolvedKeybindingsConfig,
627 issues: ServerConfigIssues,
628});
629export type ServerUpsertKeybindingResult = typeof ServerUpsertKeybindingResult.Type;
630
631export const ServerRemoveKeybindingResult = ServerUpsertKeybindingResult;
632export type ServerRemoveKeybindingResult = typeof ServerRemoveKeybindingResult.Type;
633
634export const ServerConfigUpdatedPayload = Schema.Struct({
635 issues: ServerConfigIssues,
636 providers: ServerProviders,
637 settings: Schema.optional(ServerSettings),
638});
639export type ServerConfigUpdatedPayload = typeof ServerConfigUpdatedPayload.Type;
640
641export const ServerConfigKeybindingsUpdatedPayload = Schema.Struct({
642 keybindings: ResolvedKeybindingsConfig,
643 issues: ServerConfigIssues,
644});
645export type ServerConfigKeybindingsUpdatedPayload =
646 typeof ServerConfigKeybindingsUpdatedPayload.Type;
647
648export const ServerConfigProviderStatusesPayload = Schema.Struct({
649 providers: ServerProviders,
650});
651export type ServerConfigProviderStatusesPayload = typeof ServerConfigProviderStatusesPayload.Type;
652
653export const ServerConfigSettingsUpdatedPayload = Schema.Struct({
654 settings: ServerSettings,
655});
656export type ServerConfigSettingsUpdatedPayload = typeof ServerConfigSettingsUpdatedPayload.Type;
657
658export const ServerConfigStreamSnapshotEvent = Schema.Struct({
659 version: Schema.Literal(1),
660 type: Schema.Literal("snapshot"),
661 config: ServerConfig,
662});
663export type ServerConfigStreamSnapshotEvent = typeof ServerConfigStreamSnapshotEvent.Type;
664
665export const ServerConfigStreamKeybindingsUpdatedEvent = Schema.Struct({
666 version: Schema.Literal(1),
667 type: Schema.Literal("keybindingsUpdated"),
668 payload: ServerConfigKeybindingsUpdatedPayload,
669});
670export type ServerConfigStreamKeybindingsUpdatedEvent =
671 typeof ServerConfigStreamKeybindingsUpdatedEvent.Type;
672
673export const ServerConfigStreamProviderStatusesEvent = Schema.Struct({
674 version: Schema.Literal(1),
675 type: Schema.Literal("providerStatuses"),
676 payload: ServerConfigProviderStatusesPayload,
677});
678export type ServerConfigStreamProviderStatusesEvent =
679 typeof ServerConfigStreamProviderStatusesEvent.Type;
680
681export const ServerConfigStreamSettingsUpdatedEvent = Schema.Struct({
682 version: Schema.Literal(1),
683 type: Schema.Literal("settingsUpdated"),
684 payload: ServerConfigSettingsUpdatedPayload,
685});
686export type ServerConfigStreamSettingsUpdatedEvent =
687 typeof ServerConfigStreamSettingsUpdatedEvent.Type;
688
689export const ServerConfigEnvironmentThemesUpdatedPayload = Schema.Struct({
690 /** The full published set; empty once the machine publishes none. */
691 themes: Schema.Array(EnvironmentTheme),
692});
693export type ServerConfigEnvironmentThemesUpdatedPayload =
694 typeof ServerConfigEnvironmentThemesUpdatedPayload.Type;
695
696export const ServerConfigStreamEnvironmentThemesUpdatedEvent = Schema.Struct({
697 version: Schema.Literal(1),
698 type: Schema.Literal("environmentThemesUpdated"),
699 payload: ServerConfigEnvironmentThemesUpdatedPayload,
700});
701export type ServerConfigStreamEnvironmentThemesUpdatedEvent =
702 typeof ServerConfigStreamEnvironmentThemesUpdatedEvent.Type;
703
704export const ServerConfigUsageLimitSourcesUpdatedPayload = Schema.Struct({
705 /** The full set; empty once no source is configured. */
706 sources: UsageLimitSourceSnapshots,
707});
708export type ServerConfigUsageLimitSourcesUpdatedPayload =
709 typeof ServerConfigUsageLimitSourcesUpdatedPayload.Type;
710
711export const ServerConfigStreamUsageLimitSourcesUpdatedEvent = Schema.Struct({
712 version: Schema.Literal(1),
713 type: Schema.Literal("usageLimitSourcesUpdated"),
714 payload: ServerConfigUsageLimitSourcesUpdatedPayload,
715});
716export type ServerConfigStreamUsageLimitSourcesUpdatedEvent =
717 typeof ServerConfigStreamUsageLimitSourcesUpdatedEvent.Type;
718
719export const ServerConfigStreamEvent = Schema.Union([
720 ServerConfigStreamSnapshotEvent,
721 ServerConfigStreamKeybindingsUpdatedEvent,
722 ServerConfigStreamProviderStatusesEvent,
723 ServerConfigStreamSettingsUpdatedEvent,
724 ServerConfigStreamEnvironmentThemesUpdatedEvent,
725 ServerConfigStreamUsageLimitSourcesUpdatedEvent,
726]);
727export type ServerConfigStreamEvent = typeof ServerConfigStreamEvent.Type;
728
729/** Terminal selection recorded by the service launcher for one update. */
730export const ServerSelfUpdateOutcome = Schema.Struct({
731 id: TrimmedNonEmptyString,
732 fromVersion: TrimmedNonEmptyString,
733 targetVersion: TrimmedNonEmptyString,
734 status: Schema.Literals(["committed", "rolled-back", "failed"]),
735 reason: Schema.optionalKey(TrimmedNonEmptyString),
736});
737export type ServerSelfUpdateOutcome = typeof ServerSelfUpdateOutcome.Type;
738
739export const ServerLifecycleReadyPayload = Schema.Struct({
740 at: IsoDateTime,
741 environment: ExecutionEnvironmentDescriptor,
742 /** Present when this process resumed a launcher-managed update. */
743 updateOutcome: Schema.optionalKey(ServerSelfUpdateOutcome),
744});
745export type ServerLifecycleReadyPayload = typeof ServerLifecycleReadyPayload.Type;
746
747export const ServerLifecycleWelcomePayload = Schema.Struct({
748 environment: ExecutionEnvironmentDescriptor,
749 cwd: TrimmedNonEmptyString,
750 projectName: TrimmedNonEmptyString,
751 bootstrapProjectId: Schema.optional(ProjectId),
752 bootstrapThreadId: Schema.optional(ThreadId),
753});
754export type ServerLifecycleWelcomePayload = typeof ServerLifecycleWelcomePayload.Type;
755
756export const ServerLifecycleLegacyThreadMigrationPayload = Schema.Struct({
757 status: Schema.Union([Schema.Literal("running"), Schema.Literal("complete")]),
758 totalThreadCount: NonNegativeInt,
759});
760export type ServerLifecycleLegacyThreadMigrationPayload =
761 typeof ServerLifecycleLegacyThreadMigrationPayload.Type;
762
763export const ServerLifecycleStreamWelcomeEvent = Schema.Struct({
764 version: Schema.Literal(1),
765 sequence: NonNegativeInt,
766 type: Schema.Literal("welcome"),
767 payload: ServerLifecycleWelcomePayload,
768});
769export type ServerLifecycleStreamWelcomeEvent = typeof ServerLifecycleStreamWelcomeEvent.Type;
770
771export const ServerLifecycleStreamReadyEvent = Schema.Struct({
772 version: Schema.Literal(1),
773 sequence: NonNegativeInt,
774 type: Schema.Literal("ready"),
775 payload: ServerLifecycleReadyPayload,
776});
777export type ServerLifecycleStreamReadyEvent = typeof ServerLifecycleStreamReadyEvent.Type;
778
779export const ServerLifecycleStreamLegacyThreadMigrationEvent = Schema.Struct({
780 version: Schema.Literal(1),
781 sequence: NonNegativeInt,
782 type: Schema.Literal("legacyThreadMigration"),
783 payload: ServerLifecycleLegacyThreadMigrationPayload,
784});
785export type ServerLifecycleStreamLegacyThreadMigrationEvent =
786 typeof ServerLifecycleStreamLegacyThreadMigrationEvent.Type;
787
788export const ServerLifecycleStreamEvent = Schema.Union([
789 ServerLifecycleStreamWelcomeEvent,
790 ServerLifecycleStreamReadyEvent,
791 ServerLifecycleStreamLegacyThreadMigrationEvent,
792]);
793export type ServerLifecycleStreamEvent = typeof ServerLifecycleStreamEvent.Type;
794
795export const ServerProviderUpdatedPayload = Schema.Struct({
796 providers: ServerProviders,
797});
798export type ServerProviderUpdatedPayload = typeof ServerProviderUpdatedPayload.Type;
799
800export const ServerProviderUpdateInput = Schema.Struct({
801 provider: ProviderDriverKind,
802 instanceId: Schema.optionalKey(ProviderInstanceId),
803});
804export type ServerProviderUpdateInput = typeof ServerProviderUpdateInput.Type;
805
806export class ServerProviderUpdateError extends Schema.TaggedErrorClass<ServerProviderUpdateError>()(
807 "ServerProviderUpdateError",
808 {
809 provider: ProviderDriverKind,
810 reason: TrimmedNonEmptyString,
811 cause: Schema.optional(Schema.Defect()),
812 },
813) {
814 override get message(): string {
815 return `Provider update failed for ${this.provider}: ${this.reason}`;
816 }
817}
818
819export const ServerSelfUpdateInput = Schema.Struct({
820 /** Exact npm version of the `t3` package to install (never a dist-tag, so
821 the server and the acknowledging client agree on what was requested). */
822 targetVersion: TrimmedNonEmptyString,
823 /** Opt-in recovery for provider turns that are running when the server
824 hands off to its replacement. Missing and false keep restart behavior
825 conservative under version skew. */
826 continueRunningThreads: Schema.optionalKey(Schema.Boolean),
827});
828export type ServerSelfUpdateInput = typeof ServerSelfUpdateInput.Type;
829
830/** Acknowledgement that the update artifact is installed and the server is
831 about to restart into it — the connection will drop moments later. */
832export const ServerSelfUpdateResult = Schema.Struct({
833 targetVersion: TrimmedNonEmptyString,
834 method: ServerSelfUpdateMethod,
835 /** Launcher-generated correlation ID. Absent when talking to older servers. */
836 updateId: Schema.optionalKey(TrimmedNonEmptyString),
837 /** Desktop preparation token. Present only for the desktop-app method. */
838 desktopUpdateToken: Schema.optionalKey(TrimmedNonEmptyString),
839});
840export type ServerSelfUpdateResult = typeof ServerSelfUpdateResult.Type;
841
842export const DesktopUpdateCommitInput = Schema.Struct({
843 requestId: TrimmedNonEmptyString,
844});
845export type DesktopUpdateCommitInput = typeof DesktopUpdateCommitInput.Type;
846
847export const ServerSelfUpdateProgressStage = Schema.Literals(["downloading", "installing"]);
848export type ServerSelfUpdateProgressStage = typeof ServerSelfUpdateProgressStage.Type;
849
850export const ServerSelfUpdateProgressEvent = Schema.Union([
851 Schema.Struct({
852 type: Schema.Literal("progress"),
853 stage: ServerSelfUpdateProgressStage,
854 }),
855 Schema.Struct({
856 type: Schema.Literal("complete"),
857 result: ServerSelfUpdateResult,
858 }),
859]);
860export type ServerSelfUpdateProgressEvent = typeof ServerSelfUpdateProgressEvent.Type;
861
862export class ServerSelfUpdateError extends Schema.TaggedErrorClass<ServerSelfUpdateError>()(
863 "ServerSelfUpdateError",
864 {
865 reason: TrimmedNonEmptyString,
866 cause: Schema.optional(Schema.Defect()),
867 },
868) {
869 override get message(): string {
870 return `Server update failed: ${this.reason}`;
871 }
872}