Open History to see the last commit
1import * as Schema from "effect/Schema";
2
3import { NonNegativeInt, PositiveInt, ThreadId, TrimmedNonEmptyString } from "./baseSchemas.ts";
4import { HostPowerSnapshot } from "./background.ts";
5import { DesktopUpdateChannelSchema, DesktopUpdateStateSchema } from "./ipc.ts";
6
7export const RESOURCE_MONITOR_PROTOCOL_VERSION = 3 as const;
8
9export const HostPressureLevel = Schema.Literals(["none", "elevated", "severe"]);
10export type HostPressureLevel = typeof HostPressureLevel.Type;
11
12export const HostPressureAgent = Schema.Struct({
13 /** Null for a process several threads share, such as a Codex app-server. */
14 threadId: Schema.NullOr(ThreadId),
15 /** What launched it, such as `claude` or `codex`. */
16 agent: TrimmedNonEmptyString,
17 memoryBytes: NonNegativeInt,
18 /** CPU cores in use, coarsely rounded; null until two samples exist. */
19 cpuCores: Schema.NullOr(Schema.Number),
20});
21export type HostPressureAgent = typeof HostPressureAgent.Type;
22
23export const HOST_PRESSURE_KINDS = ["memory", "disk", "cpu", "io"] as const;
24export const HostPressureKind = Schema.Literals(HOST_PRESSURE_KINDS);
25export type HostPressureKind = typeof HostPressureKind.Type;
26
27/**
28 * When each severe kind became severe, in server epoch milliseconds. A new time means a new
29 * episode, so a client's "hide until it clears" ends when the problem does.
30 */
31export const HostPressureSevereSince = Schema.Struct({
32 memory: Schema.optionalKey(NonNegativeInt),
33 disk: Schema.optionalKey(NonNegativeInt),
34 cpu: Schema.optionalKey(NonNegativeInt),
35 io: Schema.optionalKey(NonNegativeInt),
36});
37export type HostPressureSevereSince = typeof HostPressureSevereSince.Type;
38
39/** Whether work on the machine is stalling, by cause. Busy is not stalling. */
40export const HostPressure = Schema.Struct({
41 memory: HostPressureLevel,
42 /** Runnable work waiting for a CPU. */
43 cpu: HostPressureLevel,
44 /** Work waiting on storage reads and writes. */
45 io: HostPressureLevel,
46 /** Free space where T3 keeps its data and worktrees. */
47 disk: HostPressureLevel,
48 /** Free bytes on the fullest of those volumes, coarsely rounded; null when unreadable. */
49 diskFreeBytes: Schema.NullOr(NonNegativeInt),
50 /** The largest agents by the resource under pressure; empty while memory and CPU are calm. */
51 heaviestAgents: Schema.Array(HostPressureAgent),
52 /** Older servers omit it. */
53 severeSince: Schema.optionalKey(HostPressureSevereSince),
54});
55export type HostPressure = typeof HostPressure.Type;
56
57export const CALM_HOST_PRESSURE: HostPressure = {
58 memory: "none",
59 cpu: "none",
60 io: "none",
61 disk: "none",
62 diskFreeBytes: null,
63 heaviestAgents: [],
64};
65
66const HOST_PRESSURE_RANK = { none: 0, elevated: 1, severe: 2 } as const;
67
68export function worstHostPressureLevel(pressure: HostPressure): HostPressureLevel {
69 return [pressure.memory, pressure.cpu, pressure.io, pressure.disk].reduce((worst, level) =>
70 HOST_PRESSURE_RANK[level] > HOST_PRESSURE_RANK[worst] ? level : worst,
71 );
72}
73
74/** Most actionable first: memory and disk failures end turns, overload only slows them. */
75export function severeHostPressureKinds(pressure: HostPressure): ReadonlyArray<HostPressureKind> {
76 return HOST_PRESSURE_KINDS.filter((kind) => pressure[kind] === "severe");
77}
78
79/** What `heaviestAgents` is ranked by: the more pressured of memory and CPU, memory on a tie. */
80export function hostPressureRanking(pressure: HostPressure): "memory" | "cpu" {
81 return HOST_PRESSURE_RANK[pressure.cpu] > HOST_PRESSURE_RANK[pressure.memory] ? "cpu" : "memory";
82}
83
84/** The thread's agent when it is among the heaviest while memory or CPU is severe. */
85export function hostPressureCulprit(
86 pressure: HostPressure | undefined,
87 threadId: ThreadId,
88): HostPressureAgent | null {
89 if (pressure === undefined || (pressure.memory !== "severe" && pressure.cpu !== "severe")) {
90 return null;
91 }
92 return pressure.heaviestAgents.find((agent) => agent.threadId === threadId) ?? null;
93}
94
95export const HostResourcesSnapshot = Schema.Struct({
96 sampledAt: NonNegativeInt,
97 cpuUtilization: Schema.NullOr(Schema.Number.check(Schema.isBetween({ minimum: 0, maximum: 1 }))),
98 cpuCount: NonNegativeInt,
99 availableMemoryBytes: NonNegativeInt,
100 totalMemoryBytes: NonNegativeInt,
101 /** Absent from older servers. */
102 diskFreeBytes: Schema.optionalKey(Schema.NullOr(NonNegativeInt)),
103 diskTotalBytes: Schema.optionalKey(Schema.NullOr(NonNegativeInt)),
104});
105export type HostResourcesSnapshot = typeof HostResourcesSnapshot.Type;
106
107export const ResourceTelemetryIoSemantics = Schema.Literals([
108 "storage",
109 "logical",
110 "all-io",
111 "unavailable",
112]);
113export type ResourceTelemetryIoSemantics = typeof ResourceTelemetryIoSemantics.Type;
114
115export const ResourceTelemetryProcessCategory = Schema.Literals([
116 "server",
117 "server-child",
118 "provider-root",
119 "terminal-root",
120 "electron-main",
121 "electron-renderer",
122 "electron-gpu",
123 "electron-utility",
124 "resource-monitor",
125 "unknown-t3",
126]);
127export type ResourceTelemetryProcessCategory = typeof ResourceTelemetryProcessCategory.Type;
128
129export const ResourceTelemetrySourceStatus = Schema.Literals([
130 "starting",
131 "healthy",
132 "degraded",
133 "unavailable",
134 "stopped",
135]);
136export type ResourceTelemetrySourceStatus = typeof ResourceTelemetrySourceStatus.Type;
137
138export const ResourceTelemetryProcessIdentity = Schema.Struct({
139 pid: PositiveInt,
140 startTimeMs: NonNegativeInt,
141});
142export type ResourceTelemetryProcessIdentity = typeof ResourceTelemetryProcessIdentity.Type;
143
144export const ResourceMonitorExternalProcess = Schema.Struct({
145 pid: PositiveInt,
146 startTimeMs: Schema.optionalKey(NonNegativeInt),
147});
148export type ResourceMonitorExternalProcess = typeof ResourceMonitorExternalProcess.Type;
149
150export const ResourceMonitorCapabilities = Schema.Struct({
151 cumulativeCpuTime: Schema.Boolean,
152 currentCpuPercent: Schema.Boolean,
153 residentMemory: Schema.Boolean,
154 virtualMemory: Schema.Boolean,
155 ioBytes: Schema.Boolean,
156 processStartTime: Schema.Boolean,
157 processTree: Schema.Boolean,
158 processIdentities: Schema.optionalKey(Schema.Boolean),
159});
160export type ResourceMonitorCapabilities = typeof ResourceMonitorCapabilities.Type;
161
162export const ResourceMonitorProcessSample = Schema.Struct({
163 pid: PositiveInt,
164 ppid: NonNegativeInt,
165 startTimeMs: NonNegativeInt,
166 runTimeMs: NonNegativeInt,
167 name: Schema.String,
168 command: Schema.String,
169 status: Schema.String,
170 cpuPercent: Schema.Number,
171 cpuTimeMs: NonNegativeInt,
172 residentBytes: NonNegativeInt,
173 virtualBytes: NonNegativeInt,
174 ioReadBytes: NonNegativeInt,
175 ioWriteBytes: NonNegativeInt,
176 ioSemantics: Schema.Literals(["storage", "all-io"]),
177});
178export type ResourceMonitorProcessSample = typeof ResourceMonitorProcessSample.Type;
179
180export const ResourceMonitorConfigureCommand = Schema.Struct({
181 version: Schema.Literal(RESOURCE_MONITOR_PROTOCOL_VERSION),
182 type: Schema.Literal("configure"),
183 rootPid: PositiveInt,
184 sampleIntervalMs: NonNegativeInt,
185 externalProcesses: Schema.Array(ResourceMonitorExternalProcess),
186});
187export type ResourceMonitorConfigureCommand = typeof ResourceMonitorConfigureCommand.Type;
188
189export const ResourceMonitorSetExternalProcessesCommand = Schema.Struct({
190 version: Schema.Literal(RESOURCE_MONITOR_PROTOCOL_VERSION),
191 type: Schema.Literal("setExternalProcesses"),
192 processes: Schema.Array(ResourceMonitorExternalProcess),
193});
194export type ResourceMonitorSetExternalProcessesCommand =
195 typeof ResourceMonitorSetExternalProcessesCommand.Type;
196
197export const ResourceMonitorSampleNowCommand = Schema.Struct({
198 version: Schema.Literal(RESOURCE_MONITOR_PROTOCOL_VERSION),
199 type: Schema.Literal("sampleNow"),
200 requestId: TrimmedNonEmptyString,
201});
202export type ResourceMonitorSampleNowCommand = typeof ResourceMonitorSampleNowCommand.Type;
203
204export const ResourceMonitorProcessTableCommand = Schema.Struct({
205 version: Schema.Literal(RESOURCE_MONITOR_PROTOCOL_VERSION),
206 type: Schema.Literal("processTable"),
207 identities: Schema.optionalKey(Schema.Boolean),
208 requestId: TrimmedNonEmptyString,
209});
210export type ResourceMonitorProcessTableCommand = typeof ResourceMonitorProcessTableCommand.Type;
211
212export const ResourceMonitorSetSampleIntervalCommand = Schema.Struct({
213 version: Schema.Literal(RESOURCE_MONITOR_PROTOCOL_VERSION),
214 type: Schema.Literal("setSampleInterval"),
215 sampleIntervalMs: NonNegativeInt,
216});
217export type ResourceMonitorSetSampleIntervalCommand =
218 typeof ResourceMonitorSetSampleIntervalCommand.Type;
219
220export const ResourceMonitorSetStreamingCommand = Schema.Struct({
221 version: Schema.Literal(RESOURCE_MONITOR_PROTOCOL_VERSION),
222 type: Schema.Literal("setStreaming"),
223 enabled: Schema.Boolean,
224});
225export type ResourceMonitorSetStreamingCommand = typeof ResourceMonitorSetStreamingCommand.Type;
226
227export const ResourceMonitorReadHistoryCommand = Schema.Struct({
228 version: Schema.Literal(RESOURCE_MONITOR_PROTOCOL_VERSION),
229 type: Schema.Literal("readHistory"),
230 requestId: TrimmedNonEmptyString,
231 windowMs: NonNegativeInt,
232});
233export type ResourceMonitorReadHistoryCommand = typeof ResourceMonitorReadHistoryCommand.Type;
234
235export const ResourceMonitorMemoryPressureCommand = Schema.Struct({
236 version: Schema.Literal(RESOURCE_MONITOR_PROTOCOL_VERSION),
237 type: Schema.Literal("memoryPressure"),
238 requestId: TrimmedNonEmptyString,
239});
240export type ResourceMonitorMemoryPressureCommand = typeof ResourceMonitorMemoryPressureCommand.Type;
241
242export const ResourceMonitorShutdownCommand = Schema.Struct({
243 version: Schema.Literal(RESOURCE_MONITOR_PROTOCOL_VERSION),
244 type: Schema.Literal("shutdown"),
245});
246export type ResourceMonitorShutdownCommand = typeof ResourceMonitorShutdownCommand.Type;
247
248export const ResourceMonitorCommand = Schema.Union([
249 ResourceMonitorConfigureCommand,
250 ResourceMonitorSetExternalProcessesCommand,
251 ResourceMonitorSetSampleIntervalCommand,
252 ResourceMonitorSetStreamingCommand,
253 ResourceMonitorSampleNowCommand,
254 ResourceMonitorProcessTableCommand,
255 ResourceMonitorReadHistoryCommand,
256 ResourceMonitorMemoryPressureCommand,
257 ResourceMonitorShutdownCommand,
258]);
259export type ResourceMonitorCommand = typeof ResourceMonitorCommand.Type;
260
261export const ResourceMonitorHelloEvent = Schema.Struct({
262 version: Schema.Literal(RESOURCE_MONITOR_PROTOCOL_VERSION),
263 type: Schema.Literal("hello"),
264 sidecarVersion: TrimmedNonEmptyString,
265 sidecarPid: PositiveInt,
266 platform: TrimmedNonEmptyString,
267 arch: TrimmedNonEmptyString,
268 capabilities: ResourceMonitorCapabilities,
269});
270export type ResourceMonitorHelloEvent = typeof ResourceMonitorHelloEvent.Type;
271
272export const ResourceMonitorSnapshotEvent = Schema.Struct({
273 version: Schema.Literal(RESOURCE_MONITOR_PROTOCOL_VERSION),
274 type: Schema.Literal("snapshot"),
275 sequence: NonNegativeInt,
276 sampledAtUnixMs: NonNegativeInt,
277 collectionDurationMicros: NonNegativeInt,
278 scannedProcessCount: NonNegativeInt,
279 retainedProcessCount: NonNegativeInt,
280 inaccessibleProcessCount: NonNegativeInt,
281 requestId: Schema.optionalKey(TrimmedNonEmptyString),
282 externalProcesses: Schema.optionalKey(Schema.Array(ResourceMonitorExternalProcess)),
283 processes: Schema.Array(ResourceMonitorProcessSample),
284});
285export type ResourceMonitorSnapshotEvent = typeof ResourceMonitorSnapshotEvent.Type;
286
287export const ResourceMonitorProcessTableEntry = Schema.Struct({
288 pgid: Schema.optionalKey(NonNegativeInt),
289 startTimeMicros: Schema.optionalKey(NonNegativeInt),
290 pid: PositiveInt,
291 ppid: NonNegativeInt,
292 name: Schema.String,
293});
294export type ResourceMonitorProcessTableEntry = typeof ResourceMonitorProcessTableEntry.Type;
295
296export const ResourceMonitorProcessTableEvent = Schema.Struct({
297 version: Schema.Literal(RESOURCE_MONITOR_PROTOCOL_VERSION),
298 type: Schema.Literal("processTable"),
299 requestId: TrimmedNonEmptyString,
300 processes: Schema.Array(ResourceMonitorProcessTableEntry),
301});
302export type ResourceMonitorProcessTableEvent = typeof ResourceMonitorProcessTableEvent.Type;
303
304export const ResourceMonitorHistoryChunkEvent = Schema.Struct({
305 version: Schema.Literal(RESOURCE_MONITOR_PROTOCOL_VERSION),
306 type: Schema.Literal("historyChunk"),
307 requestId: TrimmedNonEmptyString,
308 done: Schema.Boolean,
309 snapshots: Schema.Array(ResourceMonitorSnapshotEvent),
310});
311export type ResourceMonitorHistoryChunkEvent = typeof ResourceMonitorHistoryChunkEvent.Type;
312
313export const ResourceMonitorMemoryPressureEvent = Schema.Struct({
314 version: Schema.Literal(RESOURCE_MONITOR_PROTOCOL_VERSION),
315 type: Schema.Literal("memoryPressure"),
316 requestId: TrimmedNonEmptyString,
317 /** macOS `kern.memorystatus_vm_pressure_level`: 1 normal, 2 warning, 4 critical. */
318 level: Schema.NullOr(PositiveInt),
319});
320export type ResourceMonitorMemoryPressureEvent = typeof ResourceMonitorMemoryPressureEvent.Type;
321
322export const ResourceMonitorErrorEvent = Schema.Struct({
323 version: Schema.Literal(RESOURCE_MONITOR_PROTOCOL_VERSION),
324 type: Schema.Literal("error"),
325 code: TrimmedNonEmptyString,
326 message: TrimmedNonEmptyString,
327 recoverable: Schema.Boolean,
328});
329export type ResourceMonitorErrorEvent = typeof ResourceMonitorErrorEvent.Type;
330
331export const ResourceMonitorEvent = Schema.Union([
332 ResourceMonitorHelloEvent,
333 ResourceMonitorSnapshotEvent,
334 ResourceMonitorProcessTableEvent,
335 ResourceMonitorHistoryChunkEvent,
336 ResourceMonitorMemoryPressureEvent,
337 ResourceMonitorErrorEvent,
338]);
339export type ResourceMonitorEvent = typeof ResourceMonitorEvent.Type;
340
341export const DesktopElectronProcessType = Schema.Literals([
342 "Browser",
343 "Tab",
344 "Utility",
345 "Zygote",
346 "Sandbox helper",
347 "GPU",
348 "Pepper Plugin",
349 "Pepper Plugin Broker",
350 "Unknown",
351]);
352export type DesktopElectronProcessType = typeof DesktopElectronProcessType.Type;
353
354export const DesktopElectronProcessMetric = Schema.Struct({
355 pid: PositiveInt,
356 creationTimeMs: NonNegativeInt,
357 type: DesktopElectronProcessType,
358 name: Schema.optionalKey(Schema.String),
359 serviceName: Schema.optionalKey(Schema.String),
360 cpuPercent: Schema.Number,
361 cumulativeCpuSeconds: Schema.optionalKey(Schema.Number),
362 idleWakeupsPerSecond: Schema.Number,
363 workingSetBytes: NonNegativeInt,
364 peakWorkingSetBytes: NonNegativeInt,
365});
366export type DesktopElectronProcessMetric = typeof DesktopElectronProcessMetric.Type;
367
368const DesktopHostPowerSnapshot = Schema.Struct({
369 ...HostPowerSnapshot.fields,
370 updatedAt: Schema.DateTimeUtcFromString,
371});
372
373export const DesktopHostTelemetrySnapshot = Schema.Struct({
374 version: Schema.Literal(1),
375 type: Schema.Literal("desktopTelemetry"),
376 sequence: NonNegativeInt,
377 sampledAtUnixMs: NonNegativeInt,
378 electronPid: PositiveInt,
379 power: DesktopHostPowerSnapshot,
380 speedLimitPercent: Schema.OptionFromNullOr(Schema.Number),
381 electronProcesses: Schema.Array(DesktopElectronProcessMetric),
382});
383export type DesktopHostTelemetrySnapshot = typeof DesktopHostTelemetrySnapshot.Type;
384
385export const DesktopHostTelemetryHello = Schema.Struct({
386 version: Schema.Literal(1),
387 type: Schema.Literal("desktopTelemetryHello"),
388 electronPid: PositiveInt,
389});
390export type DesktopHostTelemetryHello = typeof DesktopHostTelemetryHello.Type;
391
392export const DesktopUpdateRemoteOutcome = Schema.Literals([
393 "ready-to-install",
394 "up-to-date",
395 "failed",
396]);
397export type DesktopUpdateRemoteOutcome = typeof DesktopUpdateRemoteOutcome.Type;
398
399export const DesktopUpdateStatusReport = Schema.Struct({
400 version: Schema.Literal(1),
401 type: Schema.Literal("desktopUpdateStatus"),
402 requestId: Schema.optionalKey(TrimmedNonEmptyString),
403 preparedRequestId: Schema.optionalKey(TrimmedNonEmptyString),
404 outcome: Schema.optionalKey(DesktopUpdateRemoteOutcome),
405 reason: Schema.optionalKey(TrimmedNonEmptyString),
406 state: DesktopUpdateStateSchema,
407});
408export type DesktopUpdateStatusReport = typeof DesktopUpdateStatusReport.Type;
409
410export const ShellEnvironmentPatch = Schema.Struct({
411 PATH: Schema.optionalKey(Schema.NullOr(Schema.String)),
412 ANDROID_HOME: Schema.optionalKey(Schema.NullOr(Schema.String)),
413 ANDROID_SDK_ROOT: Schema.optionalKey(Schema.NullOr(Schema.String)),
414 DBUS_SESSION_BUS_ADDRESS: Schema.optionalKey(Schema.NullOr(Schema.String)),
415 DISPLAY: Schema.optionalKey(Schema.NullOr(Schema.String)),
416 LANG: Schema.optionalKey(Schema.NullOr(Schema.String)),
417 LC_ALL: Schema.optionalKey(Schema.NullOr(Schema.String)),
418 LC_CTYPE: Schema.optionalKey(Schema.NullOr(Schema.String)),
419 SSH_AUTH_SOCK: Schema.optionalKey(Schema.NullOr(Schema.String)),
420 HOMEBREW_PREFIX: Schema.optionalKey(Schema.NullOr(Schema.String)),
421 HOMEBREW_CELLAR: Schema.optionalKey(Schema.NullOr(Schema.String)),
422 HOMEBREW_REPOSITORY: Schema.optionalKey(Schema.NullOr(Schema.String)),
423 XDG_CONFIG_HOME: Schema.optionalKey(Schema.NullOr(Schema.String)),
424 XDG_CURRENT_DESKTOP: Schema.optionalKey(Schema.NullOr(Schema.String)),
425 XDG_DATA_HOME: Schema.optionalKey(Schema.NullOr(Schema.String)),
426 XDG_RUNTIME_DIR: Schema.optionalKey(Schema.NullOr(Schema.String)),
427 XDG_SESSION_DESKTOP: Schema.optionalKey(Schema.NullOr(Schema.String)),
428 XDG_SESSION_TYPE: Schema.optionalKey(Schema.NullOr(Schema.String)),
429 WAYLAND_DISPLAY: Schema.optionalKey(Schema.NullOr(Schema.String)),
430 SSL_CERT_FILE: Schema.optionalKey(Schema.NullOr(Schema.String)),
431 SSL_CERT_DIR: Schema.optionalKey(Schema.NullOr(Schema.String)),
432 NODE_EXTRA_CA_CERTS: Schema.optionalKey(Schema.NullOr(Schema.String)),
433 T3CODE_TELEMETRY_ENABLED: Schema.optionalKey(Schema.NullOr(Schema.String)),
434 DO_NOT_TRACK: Schema.optionalKey(Schema.NullOr(Schema.String)),
435 T3CODE_FEATURE_FLAGS: Schema.optionalKey(Schema.NullOr(Schema.String)),
436 T3CODE_RELEASE_BASE_URL: Schema.optionalKey(Schema.NullOr(Schema.String)),
437 __MISE_DIFF: Schema.optionalKey(Schema.NullOr(Schema.String)),
438 JAVA_HOME: Schema.optionalKey(Schema.NullOr(Schema.String)),
439 PNPM_HOME: Schema.optionalKey(Schema.NullOr(Schema.String)),
440 AZURE_CONFIG_DIR: Schema.optionalKey(Schema.NullOr(Schema.String)),
441 GH_CONFIG_DIR: Schema.optionalKey(Schema.NullOr(Schema.String)),
442 GLAB_CONFIG_DIR: Schema.optionalKey(Schema.NullOr(Schema.String)),
443 FNM_DIR: Schema.optionalKey(Schema.NullOr(Schema.String)),
444 FNM_MULTISHELL_PATH: Schema.optionalKey(Schema.NullOr(Schema.String)),
445});
446export type ShellEnvironmentPatch = typeof ShellEnvironmentPatch.Type;
447
448export const DesktopShellEnvironmentSnapshot = Schema.Struct({
449 version: Schema.Literal(1),
450 type: Schema.Literal("shellEnvironment"),
451 discovered: Schema.Boolean,
452 platform: Schema.String,
453 environment: ShellEnvironmentPatch,
454});
455export type DesktopShellEnvironmentSnapshot = typeof DesktopShellEnvironmentSnapshot.Type;
456
457export const DesktopHostTelemetryMessage = Schema.Union([
458 DesktopHostTelemetryHello,
459 DesktopShellEnvironmentSnapshot,
460 DesktopHostTelemetrySnapshot,
461 DesktopUpdateStatusReport,
462]);
463export type DesktopHostTelemetryMessage = typeof DesktopHostTelemetryMessage.Type;
464
465export const DesktopTelemetrySetDiagnosticsDemand = Schema.Struct({
466 version: Schema.Literal(1),
467 type: Schema.Literal("setDiagnosticsDemand"),
468 enabled: Schema.Boolean,
469});
470export type DesktopTelemetrySetDiagnosticsDemand = typeof DesktopTelemetrySetDiagnosticsDemand.Type;
471
472export const DesktopTelemetrySetHostPowerIntervals = Schema.Struct({
473 version: Schema.Literal(1),
474 type: Schema.Literal("setHostPowerIntervals"),
475 activeIntervalMs: PositiveInt,
476 idleIntervalMs: PositiveInt,
477});
478export type DesktopTelemetrySetHostPowerIntervals =
479 typeof DesktopTelemetrySetHostPowerIntervals.Type;
480
481/** Runs check/download/quit-and-install without local confirmation; the remote RPC click supplies consent. */
482export const DesktopTelemetryRequestDesktopUpdate = Schema.Struct({
483 version: Schema.Literal(1),
484 type: Schema.Literal("requestDesktopUpdate"),
485 requestId: TrimmedNonEmptyString,
486 /** A track switch: move to this channel first, and install only `targetVersion`. */
487 channel: Schema.optionalKey(DesktopUpdateChannelSchema),
488 targetVersion: Schema.optionalKey(TrimmedNonEmptyString),
489});
490export type DesktopTelemetryRequestDesktopUpdate = typeof DesktopTelemetryRequestDesktopUpdate.Type;
491
492export const DesktopTelemetryCommitDesktopUpdate = Schema.Struct({
493 version: Schema.Literal(1),
494 type: Schema.Literal("commitDesktopUpdate"),
495 requestId: TrimmedNonEmptyString,
496});
497export type DesktopTelemetryCommitDesktopUpdate = typeof DesktopTelemetryCommitDesktopUpdate.Type;
498
499export const DesktopTelemetryCancelDesktopUpdate = Schema.Struct({
500 version: Schema.Literal(1),
501 type: Schema.Literal("cancelDesktopUpdate"),
502 requestId: TrimmedNonEmptyString,
503});
504export type DesktopTelemetryCancelDesktopUpdate = typeof DesktopTelemetryCancelDesktopUpdate.Type;
505
506/** The server accepts requests; the desktop treats this as backend readiness. */
507export const DesktopTelemetryServerReady = Schema.Struct({
508 version: Schema.Literal(1),
509 type: Schema.Literal("serverReady"),
510});
511export type DesktopTelemetryServerReady = typeof DesktopTelemetryServerReady.Type;
512
513export const DesktopTelemetryControlMessage = Schema.Union([
514 DesktopTelemetryServerReady,
515 DesktopTelemetrySetDiagnosticsDemand,
516 DesktopTelemetrySetHostPowerIntervals,
517 DesktopTelemetryRequestDesktopUpdate,
518 DesktopTelemetryCommitDesktopUpdate,
519 DesktopTelemetryCancelDesktopUpdate,
520]);
521export type DesktopTelemetryControlMessage = typeof DesktopTelemetryControlMessage.Type;
522
523export const ResourceTelemetryProcess = Schema.Struct({
524 identity: ResourceTelemetryProcessIdentity,
525 ppid: NonNegativeInt,
526 childPids: Schema.Array(PositiveInt),
527 depth: NonNegativeInt,
528 name: Schema.String,
529 command: Schema.String,
530 status: Schema.String,
531 category: ResourceTelemetryProcessCategory,
532 electronType: Schema.optionalKey(DesktopElectronProcessType),
533 electronServiceName: Schema.optionalKey(Schema.String),
534 cpuPercent: Schema.Number,
535 cpuTimeMs: NonNegativeInt,
536 residentBytes: NonNegativeInt,
537 peakResidentBytes: NonNegativeInt,
538 virtualBytes: NonNegativeInt,
539 ioReadBytes: NonNegativeInt,
540 ioWriteBytes: NonNegativeInt,
541 ioReadBytesPerSecond: Schema.Number,
542 ioWriteBytesPerSecond: Schema.Number,
543 ioSemantics: ResourceTelemetryIoSemantics,
544 idleWakeupsPerSecond: Schema.optionalKey(Schema.Number),
545 runTimeMs: NonNegativeInt,
546 firstSeenAt: Schema.DateTimeUtc,
547 lastSeenAt: Schema.DateTimeUtc,
548});
549export type ResourceTelemetryProcess = typeof ResourceTelemetryProcess.Type;
550
551export const ResourceTelemetryAggregate = Schema.Struct({
552 processCount: NonNegativeInt,
553 currentCpuPercent: Schema.Number,
554 cpuTimeMs: NonNegativeInt,
555 currentRssBytes: NonNegativeInt,
556 peakRssBytes: NonNegativeInt,
557 ioReadBytes: NonNegativeInt,
558 ioWriteBytes: NonNegativeInt,
559 ioReadBytesPerSecond: Schema.Number,
560 ioWriteBytesPerSecond: Schema.Number,
561 processStarts: NonNegativeInt,
562 processExits: NonNegativeInt,
563});
564export type ResourceTelemetryAggregate = typeof ResourceTelemetryAggregate.Type;
565
566export const ResourceTelemetryGroups = Schema.Struct({
567 backend: ResourceTelemetryAggregate,
568 electron: ResourceTelemetryAggregate,
569 monitor: ResourceTelemetryAggregate,
570 allT3: ResourceTelemetryAggregate,
571});
572export type ResourceTelemetryGroups = typeof ResourceTelemetryGroups.Type;
573
574export const ResourceTelemetrySourceHealth = Schema.Struct({
575 status: ResourceTelemetrySourceStatus,
576 lastSampleAt: Schema.Option(Schema.DateTimeUtc),
577 lastError: Schema.Option(TrimmedNonEmptyString),
578});
579export type ResourceTelemetrySourceHealth = typeof ResourceTelemetrySourceHealth.Type;
580
581export const ResourceTelemetryHealth = Schema.Struct({
582 native: ResourceTelemetrySourceHealth,
583 desktop: ResourceTelemetrySourceHealth,
584 sidecarVersion: Schema.Option(TrimmedNonEmptyString),
585 sidecarPid: Schema.Option(PositiveInt),
586 restartCount: NonNegativeInt,
587 collectionDurationMicros: NonNegativeInt,
588 scannedProcessCount: NonNegativeInt,
589 retainedProcessCount: NonNegativeInt,
590 inaccessibleProcessCount: NonNegativeInt,
591});
592export type ResourceTelemetryHealth = typeof ResourceTelemetryHealth.Type;
593
594export const ResourceAttributionEntry = Schema.Struct({
595 component: TrimmedNonEmptyString,
596 operation: TrimmedNonEmptyString,
597 logicalReadBytes: NonNegativeInt,
598 logicalWriteBytes: NonNegativeInt,
599 count: NonNegativeInt,
600 durationMs: NonNegativeInt,
601});
602export type ResourceAttributionEntry = typeof ResourceAttributionEntry.Type;
603
604export const ResourceAttributionSnapshot = Schema.Struct({
605 readAt: Schema.DateTimeUtc,
606 entries: Schema.Array(ResourceAttributionEntry),
607});
608export type ResourceAttributionSnapshot = typeof ResourceAttributionSnapshot.Type;
609
610export const ResourceTelemetrySnapshot = Schema.Struct({
611 readAt: Schema.DateTimeUtc,
612 sampleIntervalMs: NonNegativeInt,
613 processes: Schema.Array(ResourceTelemetryProcess),
614 groups: ResourceTelemetryGroups,
615 power: HostPowerSnapshot,
616 speedLimitPercent: Schema.Option(Schema.Number),
617 attribution: ResourceAttributionSnapshot,
618 health: ResourceTelemetryHealth,
619});
620export type ResourceTelemetrySnapshot = typeof ResourceTelemetrySnapshot.Type;
621
622export const ResourceTelemetryHistoryInput = Schema.Struct({
623 windowMs: NonNegativeInt,
624 bucketMs: NonNegativeInt,
625});
626export type ResourceTelemetryHistoryInput = typeof ResourceTelemetryHistoryInput.Type;
627
628export const ResourceTelemetryHistoryBucket = Schema.Struct({
629 startedAt: Schema.DateTimeUtc,
630 endedAt: Schema.DateTimeUtc,
631 avgCpuPercent: Schema.Number,
632 maxCpuPercent: Schema.Number,
633 maxRssBytes: NonNegativeInt,
634 ioReadBytes: NonNegativeInt,
635 ioWriteBytes: NonNegativeInt,
636 maxProcessCount: NonNegativeInt,
637});
638export type ResourceTelemetryHistoryBucket = typeof ResourceTelemetryHistoryBucket.Type;
639
640export const ResourceTelemetryProcessSummary = Schema.Struct({
641 identity: ResourceTelemetryProcessIdentity,
642 ppid: NonNegativeInt,
643 depth: NonNegativeInt,
644 name: Schema.String,
645 command: Schema.String,
646 category: ResourceTelemetryProcessCategory,
647 firstSeenAt: Schema.DateTimeUtc,
648 lastSeenAt: Schema.DateTimeUtc,
649 currentCpuPercent: Schema.Number,
650 avgCpuPercent: Schema.Number,
651 maxCpuPercent: Schema.Number,
652 cpuTimeMs: NonNegativeInt,
653 currentRssBytes: NonNegativeInt,
654 peakRssBytes: NonNegativeInt,
655 ioReadBytes: NonNegativeInt,
656 ioWriteBytes: NonNegativeInt,
657 ioSemantics: ResourceTelemetryIoSemantics,
658 sampleCount: NonNegativeInt,
659});
660export type ResourceTelemetryProcessSummary = typeof ResourceTelemetryProcessSummary.Type;
661
662export const ResourceTelemetryHistory = Schema.Struct({
663 readAt: Schema.DateTimeUtc,
664 windowMs: NonNegativeInt,
665 bucketMs: NonNegativeInt,
666 sampleIntervalMs: NonNegativeInt,
667 retainedSampleCount: NonNegativeInt,
668 buckets: Schema.Array(ResourceTelemetryHistoryBucket),
669 topProcesses: Schema.Array(ResourceTelemetryProcessSummary),
670 health: ResourceTelemetryHealth,
671});
672export type ResourceTelemetryHistory = typeof ResourceTelemetryHistory.Type;
673
674export const ResourceTelemetryRetryResult = Schema.Struct({
675 accepted: Schema.Boolean,
676 snapshot: ResourceTelemetrySnapshot,
677});
678export type ResourceTelemetryRetryResult = typeof ResourceTelemetryRetryResult.Type;