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