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