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