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