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