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 scratchWorkspaceRoot: Schema.optionalKey(TrimmedNonEmptyString),
644 newProjectsRoot: Schema.optionalKey(TrimmedNonEmptyString),
645 /**
646 * The latest stall long enough to notice, sent only for a few minutes after
647 * it. A client that reconnects reads it to say why the host stopped
648 * answering. Clients do not cache it, since it describes the host at connect.
649 */
650 lastEventLoopStall: Schema.optionalKey(ServerEventLoopStall),
651 /**
652 * Never sent in a config snapshot: the theme stream emits the current set
653 * before any change, so a snapshot carrying it too would hand every
654 * subscriber the same array twice per connect.
655 */
656 environmentThemes: Schema.optional(Schema.Array(EnvironmentTheme)),
657 /** Stream-only and opt-in; the source stream emits the current set on subscribe. */
658 usageLimitSources: Schema.optional(UsageLimitSourceSnapshots),
659});
660export type ServerConfig = typeof ServerConfig.Type;
661
662export function resolveEnvironmentMachineKind(
663 config: {
664 readonly environment: Pick<ExecutionEnvironmentDescriptor, "platform">;
665 readonly settings?: Pick<ServerSettings, "environmentIcon">;
666 } | null,
667): EnvironmentMachineKind {
668 return config?.settings?.environmentIcon ?? config?.environment.platform.machine ?? "server";
669}
670
671const ServerUpsertKeybindingReplaceTarget = Schema.Struct({
672 key: KeybindingValue,
673 command: KeybindingCommand,
674 when: Schema.optional(KeybindingWhen),
675});
676
677export const ServerUpsertKeybindingInput = Schema.Struct({
678 key: KeybindingValue,
679 command: KeybindingCommand,
680 when: Schema.optional(KeybindingWhen),
681 replace: Schema.optional(ServerUpsertKeybindingReplaceTarget),
682});
683export type ServerUpsertKeybindingInput = typeof ServerUpsertKeybindingInput.Type;
684
685export const ServerRemoveKeybindingInput = ServerUpsertKeybindingReplaceTarget;
686export type ServerRemoveKeybindingInput = typeof ServerRemoveKeybindingInput.Type;
687
688export const ServerUpsertKeybindingResult = Schema.Struct({
689 keybindings: ResolvedKeybindingsConfig,
690 issues: ServerConfigIssues,
691});
692export type ServerUpsertKeybindingResult = typeof ServerUpsertKeybindingResult.Type;
693
694export const ServerRemoveKeybindingResult = ServerUpsertKeybindingResult;
695export type ServerRemoveKeybindingResult = typeof ServerRemoveKeybindingResult.Type;
696
697export const ServerConfigUpdatedPayload = Schema.Struct({
698 issues: ServerConfigIssues,
699 providers: ServerProviders,
700 settings: Schema.optional(ServerSettings),
701});
702export type ServerConfigUpdatedPayload = typeof ServerConfigUpdatedPayload.Type;
703
704export const ServerConfigKeybindingsUpdatedPayload = Schema.Struct({
705 keybindings: ResolvedKeybindingsConfig,
706 issues: ServerConfigIssues,
707});
708export type ServerConfigKeybindingsUpdatedPayload =
709 typeof ServerConfigKeybindingsUpdatedPayload.Type;
710
711export const ServerConfigProviderStatusesPayload = Schema.Struct({
712 providers: ServerProviders,
713});
714export type ServerConfigProviderStatusesPayload = typeof ServerConfigProviderStatusesPayload.Type;
715
716export const ServerConfigSettingsUpdatedPayload = Schema.Struct({
717 settings: ServerSettings,
718});
719export type ServerConfigSettingsUpdatedPayload = typeof ServerConfigSettingsUpdatedPayload.Type;
720
721export const ServerConfigStreamSnapshotEvent = Schema.Struct({
722 version: Schema.Literal(1),
723 type: Schema.Literal("snapshot"),
724 config: ServerConfig,
725});
726export type ServerConfigStreamSnapshotEvent = typeof ServerConfigStreamSnapshotEvent.Type;
727
728export const ServerConfigStreamKeybindingsUpdatedEvent = Schema.Struct({
729 version: Schema.Literal(1),
730 type: Schema.Literal("keybindingsUpdated"),
731 payload: ServerConfigKeybindingsUpdatedPayload,
732});
733export type ServerConfigStreamKeybindingsUpdatedEvent =
734 typeof ServerConfigStreamKeybindingsUpdatedEvent.Type;
735
736export const ServerConfigStreamProviderStatusesEvent = Schema.Struct({
737 version: Schema.Literal(1),
738 type: Schema.Literal("providerStatuses"),
739 payload: ServerConfigProviderStatusesPayload,
740});
741export type ServerConfigStreamProviderStatusesEvent =
742 typeof ServerConfigStreamProviderStatusesEvent.Type;
743
744export const ServerConfigStreamSettingsUpdatedEvent = Schema.Struct({
745 version: Schema.Literal(1),
746 type: Schema.Literal("settingsUpdated"),
747 payload: ServerConfigSettingsUpdatedPayload,
748});
749export type ServerConfigStreamSettingsUpdatedEvent =
750 typeof ServerConfigStreamSettingsUpdatedEvent.Type;
751
752export const ServerConfigEnvironmentThemesUpdatedPayload = Schema.Struct({
753 themes: Schema.Array(EnvironmentTheme),
754});
755export type ServerConfigEnvironmentThemesUpdatedPayload =
756 typeof ServerConfigEnvironmentThemesUpdatedPayload.Type;
757
758export const ServerConfigStreamEnvironmentThemesUpdatedEvent = Schema.Struct({
759 version: Schema.Literal(1),
760 type: Schema.Literal("environmentThemesUpdated"),
761 payload: ServerConfigEnvironmentThemesUpdatedPayload,
762});
763export type ServerConfigStreamEnvironmentThemesUpdatedEvent =
764 typeof ServerConfigStreamEnvironmentThemesUpdatedEvent.Type;
765
766export const ServerConfigUsageLimitSourcesUpdatedPayload = Schema.Struct({
767 sources: UsageLimitSourceSnapshots,
768});
769export type ServerConfigUsageLimitSourcesUpdatedPayload =
770 typeof ServerConfigUsageLimitSourcesUpdatedPayload.Type;
771
772export const ServerConfigStreamUsageLimitSourcesUpdatedEvent = Schema.Struct({
773 version: Schema.Literal(1),
774 type: Schema.Literal("usageLimitSourcesUpdated"),
775 payload: ServerConfigUsageLimitSourcesUpdatedPayload,
776});
777export type ServerConfigStreamUsageLimitSourcesUpdatedEvent =
778 typeof ServerConfigStreamUsageLimitSourcesUpdatedEvent.Type;
779
780export const ServerConfigStreamEvent = Schema.Union([
781 ServerConfigStreamSnapshotEvent,
782 ServerConfigStreamKeybindingsUpdatedEvent,
783 ServerConfigStreamProviderStatusesEvent,
784 ServerConfigStreamSettingsUpdatedEvent,
785 ServerConfigStreamEnvironmentThemesUpdatedEvent,
786 ServerConfigStreamUsageLimitSourcesUpdatedEvent,
787]);
788export type ServerConfigStreamEvent = typeof ServerConfigStreamEvent.Type;
789
790export const ServerSelfUpdateOutcome = Schema.Struct({
791 id: TrimmedNonEmptyString,
792 fromVersion: TrimmedNonEmptyString,
793 targetVersion: TrimmedNonEmptyString,
794 status: Schema.Literals(["committed", "rolled-back", "failed"]),
795 reason: Schema.optionalKey(TrimmedNonEmptyString),
796});
797export type ServerSelfUpdateOutcome = typeof ServerSelfUpdateOutcome.Type;
798
799export const ServerLifecycleReadyPayload = Schema.Struct({
800 at: IsoDateTime,
801 environment: ExecutionEnvironmentDescriptor,
802 updateOutcome: Schema.optionalKey(ServerSelfUpdateOutcome),
803});
804export type ServerLifecycleReadyPayload = typeof ServerLifecycleReadyPayload.Type;
805
806export const ServerLifecycleWelcomePayload = Schema.Struct({
807 environment: ExecutionEnvironmentDescriptor,
808 cwd: TrimmedNonEmptyString,
809 projectName: TrimmedNonEmptyString,
810 bootstrapStatus: Schema.optional(Schema.Literals(["pending", "complete"])),
811 bootstrapProjectId: Schema.optional(ProjectId),
812 bootstrapThreadId: Schema.optional(ThreadId),
813 bootstrapProjectCreated: Schema.optional(Schema.Boolean),
814 bootstrapThreadCreated: Schema.optional(Schema.Boolean),
815});
816export type ServerLifecycleWelcomePayload = typeof ServerLifecycleWelcomePayload.Type;
817
818export const ServerLifecycleLegacyThreadMigrationPayload = Schema.Struct({
819 status: Schema.Union([Schema.Literal("running"), Schema.Literal("complete")]),
820 totalThreadCount: NonNegativeInt,
821});
822export type ServerLifecycleLegacyThreadMigrationPayload =
823 typeof ServerLifecycleLegacyThreadMigrationPayload.Type;
824
825export const ServerLifecycleStreamWelcomeEvent = Schema.Struct({
826 version: Schema.Literal(1),
827 sequence: NonNegativeInt,
828 type: Schema.Literal("welcome"),
829 payload: ServerLifecycleWelcomePayload,
830});
831export type ServerLifecycleStreamWelcomeEvent = typeof ServerLifecycleStreamWelcomeEvent.Type;
832
833export const ServerLifecycleStreamReadyEvent = Schema.Struct({
834 version: Schema.Literal(1),
835 sequence: NonNegativeInt,
836 type: Schema.Literal("ready"),
837 payload: ServerLifecycleReadyPayload,
838});
839export type ServerLifecycleStreamReadyEvent = typeof ServerLifecycleStreamReadyEvent.Type;
840
841export const ServerLifecycleStreamLegacyThreadMigrationEvent = Schema.Struct({
842 version: Schema.Literal(1),
843 sequence: NonNegativeInt,
844 type: Schema.Literal("legacyThreadMigration"),
845 payload: ServerLifecycleLegacyThreadMigrationPayload,
846});
847export type ServerLifecycleStreamLegacyThreadMigrationEvent =
848 typeof ServerLifecycleStreamLegacyThreadMigrationEvent.Type;
849
850export const ServerLifecycleStreamEvent = Schema.Union([
851 ServerLifecycleStreamWelcomeEvent,
852 ServerLifecycleStreamReadyEvent,
853 ServerLifecycleStreamLegacyThreadMigrationEvent,
854]);
855export type ServerLifecycleStreamEvent = typeof ServerLifecycleStreamEvent.Type;
856
857export const ServerProviderUpdatedPayload = Schema.Struct({
858 providers: ServerProviders,
859});
860export type ServerProviderUpdatedPayload = typeof ServerProviderUpdatedPayload.Type;
861
862export const ServerProviderUpdateInput = Schema.Struct({
863 provider: ProviderDriverKind,
864 targetVersion: Schema.optionalKey(TrimmedNonEmptyString),
865 instanceId: Schema.optionalKey(ProviderInstanceId),
866});
867export type ServerProviderUpdateInput = typeof ServerProviderUpdateInput.Type;
868
869export class ServerProviderUpdateError extends Schema.TaggedError<ServerProviderUpdateError>()(
870 "ServerProviderUpdateError",
871 {
872 provider: ProviderDriverKind,
873 reason: TrimmedNonEmptyString,
874 cause: Schema.optional(Schema.Defect()),
875 },
876) {
877 override get message(): string {
878 return `Provider update failed for ${this.provider}: ${this.reason}`;
879 }
880}
881
882export const ServerSelfUpdateInput = Schema.Struct({
883 /** Exact npm version, never a dist-tag, so server and client agree on the request. */
884 targetVersion: TrimmedNonEmptyString,
885 /** Desktop-managed hosts move their app to this update track first. Sent only for a track switch. */
886 channel: Schema.optionalKey(DesktopUpdateChannelSchema),
887 /** The target release's highest migration; the host refuses to leave Nightly without it. */
888 targetDatabaseMigration: Schema.optionalKey(Schema.Int),
889});
890export type ServerSelfUpdateInput = typeof ServerSelfUpdateInput.Type;
891
892export const ServerSelfUpdateResult = Schema.Struct({
893 targetVersion: TrimmedNonEmptyString,
894 method: ServerSelfUpdateMethod,
895 updateId: Schema.optionalKey(TrimmedNonEmptyString),
896 desktopUpdateToken: Schema.optionalKey(TrimmedNonEmptyString),
897});
898export type ServerSelfUpdateResult = typeof ServerSelfUpdateResult.Type;
899
900export const DesktopUpdateCommitInput = Schema.Struct({
901 requestId: TrimmedNonEmptyString,
902});
903export type DesktopUpdateCommitInput = typeof DesktopUpdateCommitInput.Type;
904
905export const ServerSelfUpdateProgressStage = Schema.Literals(["downloading", "installing"]);
906export type ServerSelfUpdateProgressStage = typeof ServerSelfUpdateProgressStage.Type;
907
908export const ServerSelfUpdateProgressEvent = Schema.Union([
909 Schema.Struct({
910 type: Schema.Literal("progress"),
911 stage: ServerSelfUpdateProgressStage,
912 }),
913 Schema.Struct({
914 type: Schema.Literal("complete"),
915 result: ServerSelfUpdateResult,
916 }),
917]);
918export type ServerSelfUpdateProgressEvent = typeof ServerSelfUpdateProgressEvent.Type;
919
920export class ServerSelfUpdateError extends Schema.TaggedError<ServerSelfUpdateError>()(
921 "ServerSelfUpdateError",
922 {
923 reason: TrimmedNonEmptyString,
924 cause: Schema.optional(Schema.Defect()),
925 },
926) {
927 override get message(): string {
928 return `Server update failed: ${this.reason}`;
929 }
930}