Open History to see the last commit
1import * as Effect from "effect/Effect";
2import * as Schema from "effect/Schema";
3import { AcpRegistryUrlAuthAction } from "./acpRegistry.ts";
4import {
5 type EnvironmentMachineKind,
6 ExecutionEnvironmentDescriptor,
7 ServerSelfUpdateMethod,
8} from "./environment.ts";
9import { AuthClientPresentationMetadata, ServerAuthDescriptor } from "./auth.ts";
10import {
11 ForwardCompatibleArray,
12 IsoDateTime,
13 NonNegativeInt,
14 PositiveInt,
15 ProjectId,
16 ThreadId,
17 TrimmedNonEmptyString,
18} from "./baseSchemas.ts";
19import {
20 KeybindingCommand,
21 KeybindingValue,
22 KeybindingWhen,
23 ResolvedKeybindingsConfig,
24} from "./keybindings.ts";
25import { EditorId, FileManagerRevealKind, RemoteOpenTarget } from "./editor.ts";
26import { ModelCapabilities, ProviderOptionDescriptor } from "./model.ts";
27import { RuntimeMode } from "./providerPolicy.ts";
28import { ProviderDriverKind, ProviderInstanceId } from "./providerInstance.ts";
29import { ServerProviderUsageLimits, UsageLimitSourceSnapshots } from "./providerUsageLimits.ts";
30import { ServerSettings } from "./settings.ts";
31import { DesktopUpdateChannelSchema } from "./ipc.ts";
32
33const KeybindingsMalformedConfigIssue = Schema.Struct({
34 kind: Schema.Literal("keybindings.malformed-config"),
35 message: TrimmedNonEmptyString,
36});
37
38const KeybindingsInvalidEntryIssue = Schema.Struct({
39 kind: Schema.Literal("keybindings.invalid-entry"),
40 message: TrimmedNonEmptyString,
41 index: Schema.Number,
42});
43
44export const ServerConfigIssue = Schema.Union([
45 KeybindingsMalformedConfigIssue,
46 KeybindingsInvalidEntryIssue,
47]);
48export type ServerConfigIssue = typeof ServerConfigIssue.Type;
49
50const ServerConfigIssues = ForwardCompatibleArray(ServerConfigIssue);
51
52export const ServerProviderState = Schema.Literals(["ready", "warning", "error", "disabled"]);
53export type ServerProviderState = typeof ServerProviderState.Type;
54
55export const ServerProviderAuthStatus = Schema.Literals([
56 "authenticated",
57 "unauthenticated",
58 "unknown",
59]);
60export type ServerProviderAuthStatus = typeof ServerProviderAuthStatus.Type;
61
62export const ServerProviderAuth = Schema.Struct({
63 status: ServerProviderAuthStatus,
64 type: Schema.optional(TrimmedNonEmptyString),
65 label: Schema.optional(TrimmedNonEmptyString),
66 email: Schema.optional(TrimmedNonEmptyString),
67 action: Schema.optional(AcpRegistryUrlAuthAction),
68 canLogout: Schema.optional(Schema.Boolean),
69 subscriptionSharing: Schema.optional(Schema.Boolean),
70 profileId: Schema.optional(TrimmedNonEmptyString),
71 workspaceId: Schema.optional(TrimmedNonEmptyString),
72});
73export type ServerProviderAuth = typeof ServerProviderAuth.Type;
74
75export const ServerProviderModel = Schema.Struct({
76 slug: TrimmedNonEmptyString,
77 name: TrimmedNonEmptyString,
78 shortName: Schema.optional(TrimmedNonEmptyString),
79 subProvider: Schema.optional(TrimmedNonEmptyString),
80 aliases: Schema.optional(Schema.Array(TrimmedNonEmptyString)),
81 badge: Schema.optional(Schema.Literal("new")),
82 isCustom: Schema.Boolean,
83 isDefault: Schema.optional(Schema.Boolean),
84 isLegacy: Schema.optional(Schema.Boolean),
85 capabilities: Schema.NullOr(ModelCapabilities),
86});
87export type ServerProviderModel = typeof ServerProviderModel.Type;
88
89export const ServerProviderUpdateRequiredModel = Schema.Struct({
90 slug: TrimmedNonEmptyString,
91 name: TrimmedNonEmptyString,
92 badge: Schema.optional(Schema.Literal("new")),
93 minVersion: TrimmedNonEmptyString,
94});
95export type ServerProviderUpdateRequiredModel = typeof ServerProviderUpdateRequiredModel.Type;
96
97export const ServerProviderSlashCommandInput = Schema.Struct({
98 hint: TrimmedNonEmptyString,
99});
100export type ServerProviderSlashCommandInput = typeof ServerProviderSlashCommandInput.Type;
101
102export const ServerProviderSlashCommand = Schema.Struct({
103 name: TrimmedNonEmptyString,
104 description: Schema.optional(TrimmedNonEmptyString),
105 input: Schema.optional(ServerProviderSlashCommandInput),
106});
107export type ServerProviderSlashCommand = typeof ServerProviderSlashCommand.Type;
108
109export const ServerProviderSkill = Schema.Struct({
110 name: TrimmedNonEmptyString,
111 description: Schema.optional(TrimmedNonEmptyString),
112 path: TrimmedNonEmptyString,
113 scope: Schema.optional(TrimmedNonEmptyString),
114 enabled: Schema.Boolean,
115 displayName: Schema.optional(TrimmedNonEmptyString),
116 shortDescription: Schema.optional(TrimmedNonEmptyString),
117 /** Claude disable-model-invocation: only users can invoke; composers must offer a slash command. */
118 userInvocationOnly: Schema.optional(Schema.Boolean),
119 /** Claude user-invocable:false: only agents can invoke; composers must hide the slash command. */
120 userInvocable: Schema.optional(Schema.Boolean),
121});
122export type ServerProviderSkill = typeof ServerProviderSkill.Type;
123
124export const ServerProviderWorkspaceSnapshot = Schema.Struct({
125 cwd: TrimmedNonEmptyString,
126 checkedAt: IsoDateTime,
127 slashCommands: Schema.Array(ServerProviderSlashCommand),
128 slashCommandsPending: Schema.optional(Schema.Boolean),
129 skills: Schema.Array(ServerProviderSkill),
130 optionDescriptors: Schema.optional(Schema.Array(ProviderOptionDescriptor)),
131});
132export type ServerProviderWorkspaceSnapshot = typeof ServerProviderWorkspaceSnapshot.Type;
133
134export const PROVIDER_WORKSPACE_SNAPSHOT_TTL_MS = 5 * 60_000;
135
136export function isProviderWorkspaceSnapshotCurrent(
137 snapshot: Pick<ServerProviderWorkspaceSnapshot, "checkedAt">,
138 nowMs: number,
139): boolean {
140 return nowMs - Date.parse(snapshot.checkedAt) < PROVIDER_WORKSPACE_SNAPSHOT_TTL_MS;
141}
142
143/** Unavailable snapshots must set installed and enabled false. */
144export const ServerProviderAvailability = Schema.Literals(["available", "unavailable"]);
145export type ServerProviderAvailability = typeof ServerProviderAvailability.Type;
146
147export const ServerProviderContinuation = Schema.Struct({
148 groupKey: TrimmedNonEmptyString,
149});
150export type ServerProviderContinuation = typeof ServerProviderContinuation.Type;
151
152export const ServerProviderCompatibilityStatus = Schema.Literals([
153 "unknown",
154 "supported",
155 "graceful",
156 "unsupported",
157 "broken",
158]);
159export const ServerProviderCompatibilityAdvisory = Schema.Struct({
160 status: ServerProviderCompatibilityStatus,
161 latestVersionStatus: Schema.optionalKey(ServerProviderCompatibilityStatus),
162 message: Schema.NullOr(TrimmedNonEmptyString),
163 recommendedVersion: Schema.NullOr(TrimmedNonEmptyString),
164 recommendedRange: Schema.NullOr(TrimmedNonEmptyString),
165});
166export type ServerProviderCompatibilityAdvisory = typeof ServerProviderCompatibilityAdvisory.Type;
167
168export const ServerProviderVersionAdvisoryStatus = Schema.Literals([
169 "unknown",
170 "current",
171 "behind_latest",
172]);
173export type ServerProviderVersionAdvisoryStatus = typeof ServerProviderVersionAdvisoryStatus.Type;
174
175export const ServerProviderVersionAdvisory = Schema.Struct({
176 status: ServerProviderVersionAdvisoryStatus,
177 currentVersion: Schema.NullOr(TrimmedNonEmptyString),
178 latestVersion: Schema.NullOr(TrimmedNonEmptyString),
179 updateCommand: Schema.NullOr(TrimmedNonEmptyString),
180 canUpdate: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),
181 canInstallVersion: Schema.optionalKey(Schema.Boolean),
182 checkedAt: Schema.NullOr(IsoDateTime),
183 message: Schema.NullOr(TrimmedNonEmptyString),
184});
185export type ServerProviderVersionAdvisory = typeof ServerProviderVersionAdvisory.Type;
186
187export const ServerProviderUpdateStatus = Schema.Literals([
188 "idle",
189 "queued",
190 "running",
191 "succeeded",
192 "failed",
193 "unchanged",
194]);
195export type ServerProviderUpdateStatus = typeof ServerProviderUpdateStatus.Type;
196
197export const ServerProviderUpdateState = Schema.Struct({
198 status: ServerProviderUpdateStatus,
199 startedAt: Schema.NullOr(IsoDateTime),
200 finishedAt: Schema.NullOr(IsoDateTime),
201 message: Schema.NullOr(TrimmedNonEmptyString),
202 output: Schema.NullOr(Schema.String.check(Schema.isMaxLength(10_000))),
203});
204export type ServerProviderUpdateState = typeof ServerProviderUpdateState.Type;
205
206export const ServerProvider = Schema.Struct({
207 // Only instanceId is stable enough for provider routing.
208 instanceId: ProviderInstanceId,
209 driver: ProviderDriverKind,
210 displayName: Schema.optional(TrimmedNonEmptyString),
211 accentColor: Schema.optional(TrimmedNonEmptyString),
212 // Validate driver-supplied remote icons against the driver's trusted origin.
213 iconUrl: Schema.optional(TrimmedNonEmptyString.check(Schema.isMaxLength(2_048))),
214 badgeLabel: Schema.optional(TrimmedNonEmptyString),
215 continuation: Schema.optional(ServerProviderContinuation),
216 showInteractionModeToggle: Schema.optional(Schema.Boolean),
217 reportsContextWindow: Schema.optional(Schema.Boolean),
218 supportedRuntimeModes: Schema.optional(ForwardCompatibleArray(RuntimeMode)),
219 supportsConversationRollback: Schema.optional(Schema.Boolean),
220 supportsTextGeneration: Schema.optional(Schema.Boolean),
221 setup: Schema.optional(
222 Schema.Struct({
223 canAuthenticate: Schema.Boolean,
224 canInstall: Schema.Boolean,
225 documentationUrl: Schema.optionalKey(TrimmedNonEmptyString.check(Schema.isMaxLength(2_048))),
226 }),
227 ),
228 nativeSessions: Schema.optional(
229 Schema.Struct({
230 canList: Schema.Boolean,
231 canLoad: Schema.Boolean,
232 canResume: Schema.Boolean,
233 canDelete: Schema.optional(Schema.Boolean),
234 }),
235 ),
236 configurableProviders: Schema.optional(Schema.Boolean),
237 runtimePaths: Schema.optionalKey(
238 Schema.Struct({
239 homePath: TrimmedNonEmptyString,
240 shadowHomePath: Schema.NullOr(TrimmedNonEmptyString),
241 }),
242 ),
243 enabled: Schema.Boolean,
244 installed: Schema.Boolean,
245 version: Schema.NullOr(TrimmedNonEmptyString),
246 // Version reported by the installed CLI for a local provider with a separate
247 // server. Null means unknown; absence keeps legacy snapshots on `version`.
248 installedVersion: Schema.optionalKey(Schema.NullOr(TrimmedNonEmptyString)),
249 status: ServerProviderState,
250 auth: ServerProviderAuth,
251 checkedAt: IsoDateTime,
252 message: Schema.optional(TrimmedNonEmptyString),
253 availability: Schema.optional(ServerProviderAvailability),
254 unavailableReason: Schema.optional(TrimmedNonEmptyString),
255 models: Schema.Array(ServerProviderModel),
256 // Kept apart from `models` so clients that predate it never offer them.
257 updateRequiredModels: Schema.optionalKey(Schema.Array(ServerProviderUpdateRequiredModel)),
258 slashCommands: Schema.Array(ServerProviderSlashCommand).pipe(
259 Schema.withDecodingDefault(Effect.succeed([])),
260 ),
261 skills: Schema.Array(ServerProviderSkill).pipe(Schema.withDecodingDefault(Effect.succeed([]))),
262 workspaceSnapshots: Schema.optionalKey(Schema.Array(ServerProviderWorkspaceSnapshot)),
263 usageLimits: Schema.optional(ServerProviderUsageLimits),
264 versionAdvisory: Schema.optionalKey(ServerProviderVersionAdvisory),
265 compatibilityAdvisory: Schema.optionalKey(ServerProviderCompatibilityAdvisory),
266 updateState: Schema.optionalKey(ServerProviderUpdateState),
267});
268export type ServerProvider = typeof ServerProvider.Type;
269
270export const ServerProviders = ForwardCompatibleArray(ServerProvider);
271export type ServerProviders = typeof ServerProviders.Type;
272
273export const isProviderAvailable = (snapshot: ServerProvider): boolean =>
274 snapshot.availability !== "unavailable";
275
276/** Legacy producers omit this field and support text generation. */
277export const isProviderTextGenerationCapable = (snapshot: ServerProvider): boolean =>
278 snapshot.supportsTextGeneration !== false;
279
280export const OtlpEndpointSource = Schema.Literals(["environment", "bootstrap", "settings"]);
281export type OtlpEndpointSource = typeof OtlpEndpointSource.Type;
282
283export const ServerObservability = Schema.Struct({
284 logsDirectoryPath: TrimmedNonEmptyString,
285 localTracingEnabled: Schema.Boolean,
286 otlpTracesUrl: Schema.optional(TrimmedNonEmptyString),
287 otlpTracesSource: Schema.optional(OtlpEndpointSource),
288 otlpTracesVariable: Schema.optional(TrimmedNonEmptyString),
289 otlpTracesEnabled: Schema.Boolean,
290 otlpMetricsUrl: Schema.optional(TrimmedNonEmptyString),
291 otlpMetricsSource: Schema.optional(OtlpEndpointSource),
292 otlpMetricsVariable: Schema.optional(TrimmedNonEmptyString),
293 otlpMetricsEnabled: Schema.Boolean,
294 otlpLogsUrl: Schema.optional(TrimmedNonEmptyString),
295 otlpLogsSource: Schema.optional(OtlpEndpointSource),
296 otlpLogsVariable: Schema.optional(TrimmedNonEmptyString),
297 otlpLogsEnabled: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),
298});
299export type ServerObservability = typeof ServerObservability.Type;
300
301export const OtlpSignal = Schema.Literals(["traces", "metrics", "logs"]);
302export type OtlpSignal = typeof OtlpSignal.Type;
303
304export const OtlpEndpointCheckInput = Schema.Struct({
305 signal: OtlpSignal,
306 url: TrimmedNonEmptyString.check(Schema.isPattern(/^https?:\/\/./i)),
307});
308export type OtlpEndpointCheckInput = typeof OtlpEndpointCheckInput.Type;
309
310export const OtlpEndpointCheckResult = Schema.Union([
311 Schema.TaggedStruct("Accepted", { latencyMs: Schema.Number }),
312 Schema.TaggedStruct("Rejected", { status: Schema.Number }),
313 Schema.TaggedStruct("Unreachable", { timedOut: Schema.Boolean }),
314]);
315export type OtlpEndpointCheckResult = typeof OtlpEndpointCheckResult.Type;
316
317/** The client tells the server what it is, so the triage context can name it. */
318export const ServerPrepareTriageInput = Schema.Struct({
319 client: AuthClientPresentationMetadata,
320});
321export type ServerPrepareTriageInput = typeof ServerPrepareTriageInput.Type;
322
323export const ServerPrepareTriageResult = Schema.Struct({
324 /** Composer text that links the session's prompt file. */
325 prompt: Schema.String,
326});
327export type ServerPrepareTriageResult = typeof ServerPrepareTriageResult.Type;
328
329/**
330 * The prompt file links as a chip in the user's message; clients spot a triage
331 * draft by it.
332 */
333export const TRIAGE_PROMPT_FILE_NAME = "triage-playbook.md";
334
335export class ServerPrepareTriageError extends Schema.TaggedError<ServerPrepareTriageError>()(
336 "ServerPrepareTriageError",
337 { cause: Schema.optional(Schema.Defect()) },
338) {
339 override get message(): string {
340 return "Could not write the triage session files.";
341 }
342}
343
344export const ServerTraceDiagnosticsErrorKind = Schema.Literals([
345 "trace-file-not-found",
346 "trace-file-read-failed",
347]);
348export type ServerTraceDiagnosticsErrorKind = typeof ServerTraceDiagnosticsErrorKind.Type;
349
350export const ServerTraceDiagnosticsSpanSummary = Schema.Struct({
351 name: TrimmedNonEmptyString,
352 count: NonNegativeInt,
353 failureCount: NonNegativeInt,
354 totalDurationMs: Schema.Number,
355 averageDurationMs: Schema.Number,
356 maxDurationMs: Schema.Number,
357});
358export type ServerTraceDiagnosticsSpanSummary = typeof ServerTraceDiagnosticsSpanSummary.Type;
359
360export const ServerTraceDiagnosticsFailureSummary = Schema.Struct({
361 name: TrimmedNonEmptyString,
362 cause: TrimmedNonEmptyString,
363 count: NonNegativeInt,
364 lastSeenAt: Schema.DateTimeUtc,
365 traceId: TrimmedNonEmptyString,
366 spanId: TrimmedNonEmptyString,
367});
368export type ServerTraceDiagnosticsFailureSummary = typeof ServerTraceDiagnosticsFailureSummary.Type;
369
370export const ServerTraceDiagnosticsRecentFailure = Schema.Struct({
371 name: TrimmedNonEmptyString,
372 cause: TrimmedNonEmptyString,
373 durationMs: Schema.Number,
374 endedAt: Schema.DateTimeUtc,
375 traceId: TrimmedNonEmptyString,
376 spanId: TrimmedNonEmptyString,
377});
378export type ServerTraceDiagnosticsRecentFailure = typeof ServerTraceDiagnosticsRecentFailure.Type;
379
380export const ServerTraceDiagnosticsSpanOccurrence = Schema.Struct({
381 name: TrimmedNonEmptyString,
382 durationMs: Schema.Number,
383 endedAt: Schema.DateTimeUtc,
384 traceId: TrimmedNonEmptyString,
385 spanId: TrimmedNonEmptyString,
386});
387export type ServerTraceDiagnosticsSpanOccurrence = typeof ServerTraceDiagnosticsSpanOccurrence.Type;
388
389export const ServerTraceDiagnosticsLogEvent = Schema.Struct({
390 spanName: TrimmedNonEmptyString,
391 level: TrimmedNonEmptyString,
392 message: TrimmedNonEmptyString,
393 seenAt: Schema.DateTimeUtc,
394 traceId: TrimmedNonEmptyString,
395 spanId: TrimmedNonEmptyString,
396});
397export type ServerTraceDiagnosticsLogEvent = typeof ServerTraceDiagnosticsLogEvent.Type;
398
399export const ServerTraceDiagnosticsResult = Schema.Struct({
400 traceFilePath: TrimmedNonEmptyString,
401 scannedFilePaths: Schema.Array(TrimmedNonEmptyString),
402 readAt: Schema.DateTimeUtc,
403 recordCount: NonNegativeInt,
404 parseErrorCount: NonNegativeInt,
405 firstSpanAt: Schema.Option(Schema.DateTimeUtc),
406 lastSpanAt: Schema.Option(Schema.DateTimeUtc),
407 failureCount: NonNegativeInt,
408 interruptionCount: NonNegativeInt,
409 slowSpanThresholdMs: NonNegativeInt,
410 slowSpanCount: NonNegativeInt,
411 logLevelCounts: Schema.Record(TrimmedNonEmptyString, NonNegativeInt),
412 topSpansByCount: Schema.Array(ServerTraceDiagnosticsSpanSummary),
413 slowestSpans: Schema.Array(ServerTraceDiagnosticsSpanOccurrence),
414 commonFailures: Schema.Array(ServerTraceDiagnosticsFailureSummary),
415 latestFailures: Schema.Array(ServerTraceDiagnosticsRecentFailure),
416 latestWarningAndErrorLogs: Schema.Array(ServerTraceDiagnosticsLogEvent),
417 partialFailure: Schema.Option(Schema.Boolean),
418 error: Schema.Option(
419 Schema.Struct({
420 kind: ServerTraceDiagnosticsErrorKind,
421 message: TrimmedNonEmptyString,
422 }),
423 ),
424});
425export type ServerTraceDiagnosticsResult = typeof ServerTraceDiagnosticsResult.Type;
426
427export const ServerProcessSignal = Schema.Literals(["SIGINT", "SIGKILL"]);
428export type ServerProcessSignal = typeof ServerProcessSignal.Type;
429
430export const ServerProcessDiagnosticsEntry = Schema.Struct({
431 pid: PositiveInt,
432 startTimeMs: NonNegativeInt,
433 ppid: NonNegativeInt,
434 pgid: Schema.Option(Schema.Int),
435 status: TrimmedNonEmptyString,
436 cpuPercent: Schema.Number,
437 rssBytes: NonNegativeInt,
438 elapsed: TrimmedNonEmptyString,
439 command: TrimmedNonEmptyString,
440 depth: NonNegativeInt,
441 childPids: Schema.Array(PositiveInt),
442});
443export type ServerProcessDiagnosticsEntry = typeof ServerProcessDiagnosticsEntry.Type;
444
445export const ServerProcessDiagnosticsResult = Schema.Struct({
446 serverPid: PositiveInt,
447 readAt: Schema.DateTimeUtc,
448 processCount: NonNegativeInt,
449 totalRssBytes: NonNegativeInt,
450 totalCpuPercent: Schema.Number,
451 processes: Schema.Array(ServerProcessDiagnosticsEntry),
452 error: Schema.Option(
453 Schema.Struct({
454 message: TrimmedNonEmptyString,
455 }),
456 ),
457});
458export type ServerProcessDiagnosticsResult = typeof ServerProcessDiagnosticsResult.Type;
459
460export const ServerProcessResourceHistoryInput = Schema.Struct({
461 windowMs: NonNegativeInt,
462 bucketMs: NonNegativeInt,
463});
464export type ServerProcessResourceHistoryInput = typeof ServerProcessResourceHistoryInput.Type;
465
466export const ServerProcessResourceHistoryBucket = Schema.Struct({
467 startedAt: Schema.DateTimeUtc,
468 endedAt: Schema.DateTimeUtc,
469 avgCpuPercent: Schema.Number,
470 maxCpuPercent: Schema.Number,
471 maxRssBytes: NonNegativeInt,
472 maxProcessCount: NonNegativeInt,
473});
474export type ServerProcessResourceHistoryBucket = typeof ServerProcessResourceHistoryBucket.Type;
475
476export const ServerProcessResourceHistorySummary = Schema.Struct({
477 processKey: TrimmedNonEmptyString,
478 pid: PositiveInt,
479 ppid: NonNegativeInt,
480 command: TrimmedNonEmptyString,
481 depth: NonNegativeInt,
482 isServerRoot: Schema.Boolean,
483 firstSeenAt: Schema.DateTimeUtc,
484 lastSeenAt: Schema.DateTimeUtc,
485 currentCpuPercent: Schema.Number,
486 avgCpuPercent: Schema.Number,
487 maxCpuPercent: Schema.Number,
488 cpuSecondsApprox: Schema.Number,
489 currentRssBytes: NonNegativeInt,
490 maxRssBytes: NonNegativeInt,
491 sampleCount: NonNegativeInt,
492});
493export type ServerProcessResourceHistorySummary = typeof ServerProcessResourceHistorySummary.Type;
494
495export const ServerProcessResourceHistoryFailureTag = Schema.Literals([
496 "ProcessDiagnosticsQueryTimeoutError",
497 "ProcessDiagnosticsQueryFailedError",
498 "ProcessDiagnosticsServerProcessSignalError",
499 "ProcessDiagnosticsNotDescendantError",
500 "ProcessDiagnosticsSignalFailedError",
501]);
502export type ServerProcessResourceHistoryFailureTag =
503 typeof ServerProcessResourceHistoryFailureTag.Type;
504
505export const ServerProcessResourceHistoryResult = Schema.Struct({
506 readAt: Schema.DateTimeUtc,
507 windowMs: NonNegativeInt,
508 bucketMs: NonNegativeInt,
509 sampleIntervalMs: NonNegativeInt,
510 retainedSampleCount: NonNegativeInt,
511 totalCpuSecondsApprox: Schema.Number,
512 buckets: Schema.Array(ServerProcessResourceHistoryBucket),
513 topProcesses: Schema.Array(ServerProcessResourceHistorySummary),
514 error: Schema.Option(
515 Schema.Struct({
516 failureTag: ServerProcessResourceHistoryFailureTag,
517 message: TrimmedNonEmptyString,
518 }),
519 ),
520});
521export type ServerProcessResourceHistoryResult = typeof ServerProcessResourceHistoryResult.Type;
522
523export const ServerSignalProcessInput = Schema.Struct({
524 pid: PositiveInt,
525 startTimeMs: NonNegativeInt,
526 signal: ServerProcessSignal,
527});
528export type ServerSignalProcessInput = typeof ServerSignalProcessInput.Type;
529
530export const ServerSignalProcessResult = Schema.Struct({
531 pid: PositiveInt,
532 signal: ServerProcessSignal,
533 signaled: Schema.Boolean,
534 message: Schema.Option(TrimmedNonEmptyString),
535});
536export type ServerSignalProcessResult = typeof ServerSignalProcessResult.Type;
537
538export const EnvironmentThemeColor = Schema.String.check(
539 Schema.isPattern(/^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/),
540);
541export type EnvironmentThemeColor = typeof EnvironmentThemeColor.Type;
542
543/** Reserve appearance keywords so published themes cannot replace stock preferences. */
544export const EnvironmentThemeId = Schema.String.check(
545 Schema.isPattern(/^(?!(?:system|light|dark)$)[a-z0-9](?:[a-z0-9-]{0,47})$/),
546);
547export type EnvironmentThemeId = typeof EnvironmentThemeId.Type;
548
549const EnvironmentThemeColors = Schema.Record(
550 Schema.String.check(Schema.isPattern(/^[a-zA-Z][a-zA-Z0-9]{0,63}$/)),
551 TrimmedNonEmptyString.check(Schema.isMaxLength(64)),
552);
553
554const environmentThemeFields = {
555 version: Schema.optional(Schema.Literal(1)),
556 name: TrimmedNonEmptyString.check(Schema.isMaxLength(48)),
557 appearance: Schema.Literals(["light", "dark"]),
558 /** Derive the palette from canvas/accent, then overlay colors; without them, colors is the palette. */
559 canvas: Schema.optional(EnvironmentThemeColor),
560 accent: Schema.optional(EnvironmentThemeColor),
561 colors: Schema.optional(EnvironmentThemeColors),
562 variants: Schema.optional(
563 Schema.Struct({
564 light: Schema.optional(EnvironmentThemeColors),
565 dark: Schema.optional(EnvironmentThemeColors),
566 }),
567 ),
568};
569
570export const EnvironmentThemeFile = Schema.Struct(environmentThemeFields);
571export type EnvironmentThemeFile = typeof EnvironmentThemeFile.Type;
572
573export const EnvironmentTheme = Schema.Struct({
574 id: EnvironmentThemeId,
575 ...environmentThemeFields,
576});
577export type EnvironmentTheme = typeof EnvironmentTheme.Type;
578
579export function environmentThemeFileHasColors(file: EnvironmentThemeFile): boolean {
580 return (
581 (file.canvas !== undefined && file.accent !== undefined) ||
582 (file.colors !== undefined && Object.keys(file.colors).length > 0)
583 );
584}
585
586/** tailnet means this machine's Tailscale interface; other private addresses are lan. */
587export const ServerDirectEndpointKind = Schema.Literals(["lan", "tailnet"]);
588export type ServerDirectEndpointKind = typeof ServerDirectEndpointKind.Type;
589
590export const ServerDirectEndpoint = Schema.Struct({
591 kind: ServerDirectEndpointKind,
592 httpBaseUrl: TrimmedNonEmptyString,
593});
594export type ServerDirectEndpoint = typeof ServerDirectEndpoint.Type;
595
596/**
597 * A stretch where the server's event loop could not run, so it answered
598 * nothing and clients may have dropped the connection.
599 */
600export const ServerEventLoopStall = Schema.Struct({
601 detectedAt: IsoDateTime,
602 durationMs: NonNegativeInt,
603 /** One-minute load average when the stall was seen. Absent on Windows, which has none. */
604 loadAverage: Schema.optionalKey(Schema.Number),
605 cpuCount: PositiveInt,
606});
607export type ServerEventLoopStall = typeof ServerEventLoopStall.Type;
608
609export const ServerConfig = Schema.Struct({
610 environment: ExecutionEnvironmentDescriptor,
611 auth: ServerAuthDescriptor,
612 cwd: TrimmedNonEmptyString,
613 keybindingsConfigPath: TrimmedNonEmptyString,
614 keybindings: ResolvedKeybindingsConfig,
615 issues: ServerConfigIssues,
616 providers: ServerProviders,
617 availableEditors: ForwardCompatibleArray(EditorId),
618 remoteOpenTargets: Schema.optionalKey(ForwardCompatibleArray(RemoteOpenTarget)),
619 /** Hints only; verify each address answers as this environment. */
620 directEndpoints: Schema.optionalKey(ForwardCompatibleArray(ServerDirectEndpoint)),
621 observability: ServerObservability,
622 settings: ServerSettings,
623 shellResumeCompletionMarker: Schema.optionalKey(Schema.Boolean),
624 /**
625 * The shell can leave idle subagent children out of snapshots (`omitIdleSubagents`), and
626 * `getThreadFamily` and `getWorktreeThreadIds` serve the rows it leaves out.
627 */
628 shellThreadFamilies: Schema.optionalKey(Schema.Boolean),
629 /**
630 * The shell can leave older settled threads out of snapshots (`omitOlderSettled`), and
631 * `getOlderSettledThreads` serves them. Only servers that also advertise `shellThreadFamilies`.
632 */
633 shellOlderSettled: Schema.optionalKey(Schema.Boolean),
634 shellRevealInFileManager: Schema.optionalKey(Schema.Boolean),
635 shellRevealInFileManagerKind: Schema.optionalKey(FileManagerRevealKind),
636 threadResumeCompletionMarker: Schema.optionalKey(Schema.Boolean),
637 /** Send window fields only when advertised. */
638 threadSnapshotPagination: Schema.optionalKey(Schema.Boolean),
639 threadFind: Schema.optionalKey(Schema.Boolean),
640 threadFindProgressive: Schema.optionalKey(Schema.Boolean),
641 /** Settings patches may carry `secretProviders`; older servers drop the key without an error. */
642 secretProviderSettings: Schema.optionalKey(Schema.Boolean),
643 /** Secret settings may point at a secret provider; older servers drop the reference. */
644 secretReferences: Schema.optionalKey(Schema.Boolean),
645 scratchWorkspaceRoot: Schema.optionalKey(TrimmedNonEmptyString),
646 newProjectsRoot: Schema.optionalKey(TrimmedNonEmptyString),
647 /**
648 * The latest stall long enough to notice, sent only for a few minutes after
649 * it. A client that reconnects reads it to say why the host stopped
650 * answering. Clients do not cache it, since it describes the host at connect.
651 */
652 lastEventLoopStall: Schema.optionalKey(ServerEventLoopStall),
653 /**
654 * Never sent in a config snapshot: the theme stream emits the current set
655 * before any change, so a snapshot carrying it too would hand every
656 * subscriber the same array twice per connect.
657 */
658 environmentThemes: Schema.optional(Schema.Array(EnvironmentTheme)),
659 /** Stream-only and opt-in; the source stream emits the current set on subscribe. */
660 usageLimitSources: Schema.optional(UsageLimitSourceSnapshots),
661});
662export type ServerConfig = typeof ServerConfig.Type;
663
664export function resolveEnvironmentMachineKind(
665 config: {
666 readonly environment: Pick<ExecutionEnvironmentDescriptor, "platform">;
667 readonly settings?: Pick<ServerSettings, "environmentIcon">;
668 } | null,
669): EnvironmentMachineKind {
670 return config?.settings?.environmentIcon ?? config?.environment.platform.machine ?? "server";
671}
672
673const ServerUpsertKeybindingReplaceTarget = Schema.Struct({
674 key: KeybindingValue,
675 command: KeybindingCommand,
676 when: Schema.optional(KeybindingWhen),
677});
678
679export const ServerUpsertKeybindingInput = Schema.Struct({
680 key: KeybindingValue,
681 command: KeybindingCommand,
682 when: Schema.optional(KeybindingWhen),
683 replace: Schema.optional(ServerUpsertKeybindingReplaceTarget),
684});
685export type ServerUpsertKeybindingInput = typeof ServerUpsertKeybindingInput.Type;
686
687export const ServerRemoveKeybindingInput = ServerUpsertKeybindingReplaceTarget;
688export type ServerRemoveKeybindingInput = typeof ServerRemoveKeybindingInput.Type;
689
690export const ServerUpsertKeybindingResult = Schema.Struct({
691 keybindings: ResolvedKeybindingsConfig,
692 issues: ServerConfigIssues,
693});
694export type ServerUpsertKeybindingResult = typeof ServerUpsertKeybindingResult.Type;
695
696export const ServerRemoveKeybindingResult = ServerUpsertKeybindingResult;
697export type ServerRemoveKeybindingResult = typeof ServerRemoveKeybindingResult.Type;
698
699export const ServerConfigUpdatedPayload = Schema.Struct({
700 issues: ServerConfigIssues,
701 providers: ServerProviders,
702 settings: Schema.optional(ServerSettings),
703});
704export type ServerConfigUpdatedPayload = typeof ServerConfigUpdatedPayload.Type;
705
706export const ServerConfigKeybindingsUpdatedPayload = Schema.Struct({
707 keybindings: ResolvedKeybindingsConfig,
708 issues: ServerConfigIssues,
709});
710export type ServerConfigKeybindingsUpdatedPayload =
711 typeof ServerConfigKeybindingsUpdatedPayload.Type;
712
713export const ServerConfigProviderStatusesPayload = Schema.Struct({
714 providers: ServerProviders,
715});
716export type ServerConfigProviderStatusesPayload = typeof ServerConfigProviderStatusesPayload.Type;
717
718export const ServerConfigSettingsUpdatedPayload = Schema.Struct({
719 settings: ServerSettings,
720});
721export type ServerConfigSettingsUpdatedPayload = typeof ServerConfigSettingsUpdatedPayload.Type;
722
723export const ServerConfigStreamSnapshotEvent = Schema.Struct({
724 version: Schema.Literal(1),
725 type: Schema.Literal("snapshot"),
726 config: ServerConfig,
727});
728export type ServerConfigStreamSnapshotEvent = typeof ServerConfigStreamSnapshotEvent.Type;
729
730export const ServerConfigStreamKeybindingsUpdatedEvent = Schema.Struct({
731 version: Schema.Literal(1),
732 type: Schema.Literal("keybindingsUpdated"),
733 payload: ServerConfigKeybindingsUpdatedPayload,
734});
735export type ServerConfigStreamKeybindingsUpdatedEvent =
736 typeof ServerConfigStreamKeybindingsUpdatedEvent.Type;
737
738export const ServerConfigStreamProviderStatusesEvent = Schema.Struct({
739 version: Schema.Literal(1),
740 type: Schema.Literal("providerStatuses"),
741 payload: ServerConfigProviderStatusesPayload,
742});
743export type ServerConfigStreamProviderStatusesEvent =
744 typeof ServerConfigStreamProviderStatusesEvent.Type;
745
746export const ServerConfigStreamSettingsUpdatedEvent = Schema.Struct({
747 version: Schema.Literal(1),
748 type: Schema.Literal("settingsUpdated"),
749 payload: ServerConfigSettingsUpdatedPayload,
750});
751export type ServerConfigStreamSettingsUpdatedEvent =
752 typeof ServerConfigStreamSettingsUpdatedEvent.Type;
753
754export const ServerConfigEnvironmentThemesUpdatedPayload = Schema.Struct({
755 themes: Schema.Array(EnvironmentTheme),
756});
757export type ServerConfigEnvironmentThemesUpdatedPayload =
758 typeof ServerConfigEnvironmentThemesUpdatedPayload.Type;
759
760export const ServerConfigStreamEnvironmentThemesUpdatedEvent = Schema.Struct({
761 version: Schema.Literal(1),
762 type: Schema.Literal("environmentThemesUpdated"),
763 payload: ServerConfigEnvironmentThemesUpdatedPayload,
764});
765export type ServerConfigStreamEnvironmentThemesUpdatedEvent =
766 typeof ServerConfigStreamEnvironmentThemesUpdatedEvent.Type;
767
768export const ServerConfigUsageLimitSourcesUpdatedPayload = Schema.Struct({
769 sources: UsageLimitSourceSnapshots,
770});
771export type ServerConfigUsageLimitSourcesUpdatedPayload =
772 typeof ServerConfigUsageLimitSourcesUpdatedPayload.Type;
773
774export const ServerConfigStreamUsageLimitSourcesUpdatedEvent = Schema.Struct({
775 version: Schema.Literal(1),
776 type: Schema.Literal("usageLimitSourcesUpdated"),
777 payload: ServerConfigUsageLimitSourcesUpdatedPayload,
778});
779export type ServerConfigStreamUsageLimitSourcesUpdatedEvent =
780 typeof ServerConfigStreamUsageLimitSourcesUpdatedEvent.Type;
781
782export const ServerConfigStreamEvent = Schema.Union([
783 ServerConfigStreamSnapshotEvent,
784 ServerConfigStreamKeybindingsUpdatedEvent,
785 ServerConfigStreamProviderStatusesEvent,
786 ServerConfigStreamSettingsUpdatedEvent,
787 ServerConfigStreamEnvironmentThemesUpdatedEvent,
788 ServerConfigStreamUsageLimitSourcesUpdatedEvent,
789]);
790export type ServerConfigStreamEvent = typeof ServerConfigStreamEvent.Type;
791
792export const ServerSelfUpdateOutcome = Schema.Struct({
793 id: TrimmedNonEmptyString,
794 fromVersion: TrimmedNonEmptyString,
795 targetVersion: TrimmedNonEmptyString,
796 status: Schema.Literals(["committed", "rolled-back", "failed"]),
797 reason: Schema.optionalKey(TrimmedNonEmptyString),
798});
799export type ServerSelfUpdateOutcome = typeof ServerSelfUpdateOutcome.Type;
800
801export const ServerLifecycleReadyPayload = Schema.Struct({
802 at: IsoDateTime,
803 environment: ExecutionEnvironmentDescriptor,
804 updateOutcome: Schema.optionalKey(ServerSelfUpdateOutcome),
805});
806export type ServerLifecycleReadyPayload = typeof ServerLifecycleReadyPayload.Type;
807
808export const ServerLifecycleWelcomePayload = Schema.Struct({
809 environment: ExecutionEnvironmentDescriptor,
810 cwd: TrimmedNonEmptyString,
811 projectName: TrimmedNonEmptyString,
812 bootstrapStatus: Schema.optional(Schema.Literals(["pending", "complete"])),
813 bootstrapProjectId: Schema.optional(ProjectId),
814 bootstrapThreadId: Schema.optional(ThreadId),
815 bootstrapProjectCreated: Schema.optional(Schema.Boolean),
816 bootstrapThreadCreated: Schema.optional(Schema.Boolean),
817});
818export type ServerLifecycleWelcomePayload = typeof ServerLifecycleWelcomePayload.Type;
819
820export const ServerLifecycleLegacyThreadMigrationPayload = Schema.Struct({
821 status: Schema.Union([Schema.Literal("running"), Schema.Literal("complete")]),
822 totalThreadCount: NonNegativeInt,
823});
824export type ServerLifecycleLegacyThreadMigrationPayload =
825 typeof ServerLifecycleLegacyThreadMigrationPayload.Type;
826
827export const ServerLifecycleStreamWelcomeEvent = Schema.Struct({
828 version: Schema.Literal(1),
829 sequence: NonNegativeInt,
830 type: Schema.Literal("welcome"),
831 payload: ServerLifecycleWelcomePayload,
832});
833export type ServerLifecycleStreamWelcomeEvent = typeof ServerLifecycleStreamWelcomeEvent.Type;
834
835export const ServerLifecycleStreamReadyEvent = Schema.Struct({
836 version: Schema.Literal(1),
837 sequence: NonNegativeInt,
838 type: Schema.Literal("ready"),
839 payload: ServerLifecycleReadyPayload,
840});
841export type ServerLifecycleStreamReadyEvent = typeof ServerLifecycleStreamReadyEvent.Type;
842
843export const ServerLifecycleStreamLegacyThreadMigrationEvent = Schema.Struct({
844 version: Schema.Literal(1),
845 sequence: NonNegativeInt,
846 type: Schema.Literal("legacyThreadMigration"),
847 payload: ServerLifecycleLegacyThreadMigrationPayload,
848});
849export type ServerLifecycleStreamLegacyThreadMigrationEvent =
850 typeof ServerLifecycleStreamLegacyThreadMigrationEvent.Type;
851
852export const ServerLifecycleStreamEvent = Schema.Union([
853 ServerLifecycleStreamWelcomeEvent,
854 ServerLifecycleStreamReadyEvent,
855 ServerLifecycleStreamLegacyThreadMigrationEvent,
856]);
857export type ServerLifecycleStreamEvent = typeof ServerLifecycleStreamEvent.Type;
858
859export const ServerProviderUpdatedPayload = Schema.Struct({
860 providers: ServerProviders,
861});
862export type ServerProviderUpdatedPayload = typeof ServerProviderUpdatedPayload.Type;
863
864export const ServerProviderUpdateInput = Schema.Struct({
865 provider: ProviderDriverKind,
866 targetVersion: Schema.optionalKey(TrimmedNonEmptyString),
867 instanceId: Schema.optionalKey(ProviderInstanceId),
868});
869export type ServerProviderUpdateInput = typeof ServerProviderUpdateInput.Type;
870
871export class ServerProviderUpdateError extends Schema.TaggedError<ServerProviderUpdateError>()(
872 "ServerProviderUpdateError",
873 {
874 provider: ProviderDriverKind,
875 reason: TrimmedNonEmptyString,
876 cause: Schema.optional(Schema.Defect()),
877 },
878) {
879 override get message(): string {
880 return `Provider update failed for ${this.provider}: ${this.reason}`;
881 }
882}
883
884export const ServerSelfUpdateInput = Schema.Struct({
885 /** Exact npm version, never a dist-tag, so server and client agree on the request. */
886 targetVersion: TrimmedNonEmptyString,
887 /** Desktop-managed hosts move their app to this update track first. Sent only for a track switch. */
888 channel: Schema.optionalKey(DesktopUpdateChannelSchema),
889 /** The target release's highest migration; the host refuses to leave Nightly without it. */
890 targetDatabaseMigration: Schema.optionalKey(Schema.Int),
891});
892export type ServerSelfUpdateInput = typeof ServerSelfUpdateInput.Type;
893
894export const ServerSelfUpdateResult = Schema.Struct({
895 targetVersion: TrimmedNonEmptyString,
896 method: ServerSelfUpdateMethod,
897 updateId: Schema.optionalKey(TrimmedNonEmptyString),
898 desktopUpdateToken: Schema.optionalKey(TrimmedNonEmptyString),
899});
900export type ServerSelfUpdateResult = typeof ServerSelfUpdateResult.Type;
901
902export const DesktopUpdateCommitInput = Schema.Struct({
903 requestId: TrimmedNonEmptyString,
904});
905export type DesktopUpdateCommitInput = typeof DesktopUpdateCommitInput.Type;
906
907export const ServerSelfUpdateProgressStage = Schema.Literals(["downloading", "installing"]);
908export type ServerSelfUpdateProgressStage = typeof ServerSelfUpdateProgressStage.Type;
909
910export const ServerSelfUpdateProgressEvent = Schema.Union([
911 Schema.Struct({
912 type: Schema.Literal("progress"),
913 stage: ServerSelfUpdateProgressStage,
914 }),
915 Schema.Struct({
916 type: Schema.Literal("complete"),
917 result: ServerSelfUpdateResult,
918 }),
919]);
920export type ServerSelfUpdateProgressEvent = typeof ServerSelfUpdateProgressEvent.Type;
921
922export class ServerSelfUpdateError extends Schema.TaggedError<ServerSelfUpdateError>()(
923 "ServerSelfUpdateError",
924 {
925 reason: TrimmedNonEmptyString,
926 cause: Schema.optional(Schema.Defect()),
927 },
928) {
929 override get message(): string {
930 return `Server update failed: ${this.reason}`;
931 }
932}