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