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