@stim-cli/server 1.10.1 → 1.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,16 +1,17 @@
1
- import { NdjsonRecord, StatusPayload } from "@stim-cli/core/state";
1
+ import { BuildPlanPayload, NdjsonRecord, StatusPayload } from "@stim-cli/core/state";
2
2
  //#region src/protocol.d.ts
3
3
  declare const PROTOCOL_VERSION = 1;
4
4
  declare const PROTOCOL_SCHEMA_FILE = "protocol.schema.json";
5
- declare const CAPABILITIES: readonly ["read"];
5
+ /** `read` serves state. `control` also runs {@link ACTIONS}; only the Mac grants it. */
6
+ declare const CAPABILITIES: readonly ["read", "control"];
6
7
  type Capability = (typeof CAPABILITIES)[number];
7
- declare const METHODS: readonly ["hello", "status.subscribe", "logs.query", "logs.subscribe", "stats.get", "settings.get", "frames.subscribe", "unsubscribe"];
8
+ declare const METHODS: readonly ["hello", "status.subscribe", "logs.query", "logs.subscribe", "stats.get", "settings.get", "frames.subscribe", "frames.keyframe", "build.plan", "machine.get", "machine.history", "unsubscribe", "action", "control.begin", "control.end", "input.touch", "input.text", "input.button", "input.rotate", "input.posture"];
8
9
  type Method = (typeof METHODS)[number];
9
10
  /**
10
11
  * `unauthorized`, `pairing-expired` and `protocol-unsupported` refuse the client until it pairs again or
11
12
  * updates; clients retry the others.
12
13
  */
13
- declare const ERROR_CODES: readonly ["unauthorized", "pairing-expired", "protocol-unsupported", "identity-unavailable", "bad-request", "unknown-method", "already-authenticated", "unknown-subscription", "unknown-workspace", "limit-exceeded", "slow-client", "status-failed", "logs-failed", "stim-failed", "frames-failed"];
14
+ declare const ERROR_CODES: readonly ["unauthorized", "pairing-expired", "protocol-unsupported", "identity-unavailable", "bad-request", "unknown-method", "already-authenticated", "unknown-subscription", "unknown-workspace", "limit-exceeded", "slow-client", "status-failed", "logs-failed", "stim-failed", "frames-failed", "forbidden", "unknown-action", "action-busy", "action-failed", "device-busy", "unknown-session"];
14
15
  type ErrorCode = (typeof ERROR_CODES)[number];
15
16
  type RequestId = number | string;
16
17
  /** Spends a single-use pairing token; the result carries the new device token. */
@@ -32,13 +33,19 @@ interface HelloParams {
32
33
  }
33
34
  interface HelloResult {
34
35
  protocol: number;
35
- /** The Mac's name, this package's version, and the version of the `stim` it runs. */
36
+ /**
37
+ * The Mac's name, this package's version, the version of the `stim` it runs, and the home directory of the
38
+ * user it runs as, so clients can show paths under it as `~/...`.
39
+ */
36
40
  server: {
37
41
  name: string;
38
42
  version: string;
39
43
  stim: string;
44
+ home: string;
40
45
  };
41
46
  capabilities: Capability[];
47
+ /** The actions this device may run: every one of {@link ACTIONS} with `control`, none without. */
48
+ actions: ActionName[];
42
49
  /** The paired device this connection authenticated as, as `stim-server devices` lists it. */
43
50
  device: {
44
51
  id: string;
@@ -53,7 +60,7 @@ interface SubscribeResult {
53
60
  interface UnsubscribeParams {
54
61
  subscription: string;
55
62
  }
56
- declare const LOG_SOURCES: readonly ["metro", "client", "device", "build"];
63
+ declare const LOG_SOURCES: readonly ["metro", "client", "device", "build", "agent"];
57
64
  type LogSource = (typeof LOG_SOURCES)[number];
58
65
  declare const LOG_LEVELS: readonly ["debug", "info", "warn", "error", "fatal"];
59
66
  type LogLevel = (typeof LOG_LEVELS)[number];
@@ -86,14 +93,217 @@ type StatsResult = Record<string, unknown>;
86
93
  /** `stim settings --json`; the CLI masks sensitive values. */
87
94
  type SettingsResult = Record<string, unknown>;
88
95
  type Platform = "ios" | "android";
96
+ declare const FRAME_FPS: {
97
+ readonly default: 5;
98
+ readonly max: 30;
99
+ readonly video: 60;
100
+ };
101
+ declare const FRAME_EDGE: {
102
+ readonly min: 240;
103
+ readonly default: 1280;
104
+ readonly max: 2048;
105
+ };
89
106
  /**
90
107
  * A device `stim status` lists as owned by `workspace`, in `slot` (`default` when absent). Frames come only
91
- * from a booted simulator or a running emulator Stim created.
108
+ * from a booted simulator or a running emulator Stim created. `fps` caps how many frames a second this
109
+ * subscription gets, and `maxEdge` asks for frames scaled to fit that many pixels; the server may send smaller
110
+ * frames, and larger ones while another subscriber of the same device asks for more.
92
111
  */
93
112
  interface FrameTarget {
94
113
  workspace: string;
95
114
  platform: Platform;
96
115
  slot?: string;
116
+ fps?: number;
117
+ maxEdge?: number;
118
+ /** The codecs this client decodes. The server picks one when it can encode video; see {@link FramesSubscribeResult}. */
119
+ video?: VideoCodec[];
120
+ }
121
+ declare const VIDEO_CODECS: readonly ["h264"];
122
+ type VideoCodec = (typeof VIDEO_CODECS)[number];
123
+ /**
124
+ * With `video`, frames arrive as binary WebSocket messages, one H.264 access unit each; see {@link VideoPacket}.
125
+ * A subscription whose device cannot be encoded, such as an iPhone Duo, still sends JSON `frame` events.
126
+ */
127
+ interface FramesSubscribeResult extends SubscribeResult {
128
+ video?: VideoCodec;
129
+ }
130
+ /** Asks for a keyframe on a video subscription, after the client lost its decoder state. */
131
+ interface KeyframeParams {
132
+ subscription: string;
133
+ }
134
+ declare const VIDEO_HEADER_VERSION = 1;
135
+ /** The keyframe bit of a {@link VideoPacket}'s flags. */
136
+ declare const VIDEO_KEYFRAME = 1;
137
+ /**
138
+ * The layout of a binary video message, big-endian: u8 version ({@link VIDEO_HEADER_VERSION}), u8 flags
139
+ * ({@link VIDEO_KEYFRAME}), u16 header length, u32 sequence number of the messages sent on this subscription, f64 capture time in milliseconds since the
140
+ * epoch on the Mac's clock, u16 width, u16 height, u8 subscription id length N, N bytes of ASCII subscription
141
+ * id. After the header comes one Annex-B H.264 access unit; a keyframe carries its SPS and PPS. The stream has
142
+ * no B-frames, so each access unit is shown as it arrives.
143
+ */
144
+ interface VideoPacket {
145
+ subscription: string;
146
+ keyframe: boolean;
147
+ sequence: number;
148
+ capturedAt: number;
149
+ width: number;
150
+ height: number;
151
+ accessUnit: Uint8Array;
152
+ }
153
+ /** Each action runs one fixed `stim` command in the workspace. */
154
+ declare const ACTIONS: readonly ["reload", "stop"];
155
+ type ActionName = (typeof ACTIONS)[number];
156
+ /**
157
+ * `reload` runs `stim reload --json`, with `platform` when both platforms are live; `stop` runs
158
+ * `stim stop --json`. `workspace` is an environment `path` from a status payload. Needs `control`.
159
+ */
160
+ type ActionParams = {
161
+ action: "reload";
162
+ workspace: string;
163
+ platform?: Platform;
164
+ } | {
165
+ action: "stop";
166
+ workspace: string;
167
+ };
168
+ /** `output` is the JSON the command printed. */
169
+ interface ActionResult {
170
+ action: ActionName;
171
+ workspace: string;
172
+ output: Record<string, unknown>;
173
+ }
174
+ /**
175
+ * Starts a control session on the device `stim status` lists as owned by `workspace` in `slot`. Needs
176
+ * `control`. Refused with `device-busy` while an agent, a device lock or another client drives the device,
177
+ * unless `takeOver` is true.
178
+ */
179
+ interface ControlBeginParams {
180
+ workspace: string;
181
+ platform: Platform;
182
+ slot?: string;
183
+ takeOver?: boolean;
184
+ }
185
+ /**
186
+ * `lease` is the `stim device lock` lease the server holds for the session, or null when it holds none, such
187
+ * as after taking over a device another workspace leases. `postures` lists what `input.posture` accepts for
188
+ * the device: `folded` and `unfolded` for an iPhone Duo, all three for an emulator with a hinge, and none
189
+ * otherwise.
190
+ */
191
+ interface ControlBeginResult {
192
+ session: string;
193
+ platform: Platform;
194
+ lease: {
195
+ grantedAt: string | null;
196
+ expiresAt: string;
197
+ } | null;
198
+ postures: DevicePosture[];
199
+ }
200
+ interface ControlEndParams {
201
+ session: string;
202
+ }
203
+ declare const TOUCH_PHASES: readonly ["down", "move", "up"];
204
+ type TouchPhase = (typeof TOUCH_PHASES)[number];
205
+ /** `x` and `y` are fractions of the upright screen, origin top-left. `display` is 0 for the main display. */
206
+ interface InputTouchParams {
207
+ session: string;
208
+ phase: TouchPhase;
209
+ x: number;
210
+ y: number;
211
+ display?: number;
212
+ }
213
+ declare const MAX_INPUT_TEXT = 256;
214
+ /** Printable ASCII, where `\n` presses Return, `\t` Tab and `\b` Delete. */
215
+ interface InputTextParams {
216
+ session: string;
217
+ text: string;
218
+ }
219
+ /** `home` and `lock` on both platforms; `back` and `app-switch` on Android only. */
220
+ declare const INPUT_BUTTONS: readonly ["home", "lock", "back", "app-switch"];
221
+ type InputButton = (typeof INPUT_BUTTONS)[number];
222
+ interface InputButtonParams {
223
+ session: string;
224
+ button: InputButton;
225
+ }
226
+ /** `left` turns the device a quarter turn counterclockwise, `right` clockwise. */
227
+ declare const ROTATE_DIRECTIONS: readonly ["left", "right"];
228
+ type RotateDirection = (typeof ROTATE_DIRECTIONS)[number];
229
+ interface InputRotateParams {
230
+ session: string;
231
+ direction: RotateDirection;
232
+ }
233
+ declare const DEVICE_POSTURES: readonly ["folded", "half-open", "unfolded"];
234
+ type DevicePosture = (typeof DEVICE_POSTURES)[number];
235
+ /** Moves the hinge of a device whose `control.begin` result lists `posture`. */
236
+ interface InputPostureParams {
237
+ session: string;
238
+ posture: DevicePosture;
239
+ }
240
+ /** Predicts the next `ios` or `android` build of `workspace` in `slot` (`default` when absent). */
241
+ interface BuildPlanParams {
242
+ workspace: string;
243
+ platform: Platform;
244
+ slot?: string;
245
+ }
246
+ /** `stim ios|android --plan --json`. It builds, boots and installs nothing, and writes no Stim state. */
247
+ type BuildPlanResult = BuildPlanPayload;
248
+ type MemoryPressure = "normal" | "warning" | "critical";
249
+ /** A volume that holds Stim workspaces, Stim home, or the simulators. */
250
+ interface MachineVolume {
251
+ /** `/`, or `/Volumes/<name>` for an external volume. */
252
+ mount: string;
253
+ /** What Stim keeps there: `Workspaces`, `Stim home`, `Simulators`. */
254
+ holds: string[];
255
+ /** Free space without purgeable space, which is what Stim's disk budget measures. */
256
+ freeBytes: number;
257
+ totalBytes: number;
258
+ }
259
+ /** Cheap machine usage, read in the server process without running `stim`. */
260
+ interface MachineUsage {
261
+ volumes: MachineVolume[];
262
+ /**
263
+ * `usedBytes` is the Mac's memory in use, as Activity Monitor's "Memory Used" counts it: app memory, wired and
264
+ * compressed. `pressure` is the macOS memory pressure level. Both are null on other systems or when they cannot
265
+ * be read.
266
+ */
267
+ memory: {
268
+ totalBytes: number;
269
+ usedBytes: number | null;
270
+ pressure: MemoryPressure | null;
271
+ };
272
+ load: {
273
+ avg1: number;
274
+ avg5: number;
275
+ avg15: number;
276
+ cpus: number;
277
+ };
278
+ /**
279
+ * `usage` is the Mac's overall CPU busy fraction (0..1), from the tick delta between this call and the
280
+ * previous one. Null on the first call of a server process, since there is no previous sample yet.
281
+ */
282
+ cpu: {
283
+ usage: number | null;
284
+ cores: number;
285
+ };
286
+ sampledAt: string;
287
+ }
288
+ /**
289
+ * One `machine.history` sample. `at` is epoch milliseconds. `cpu` is the busy fraction (0..1) since the previous
290
+ * sample. `memoryPressure` is 0 (normal), 1 (warning) or 2 (critical). `diskFreeBytes` is the free space of the
291
+ * startup volume, `/`. A field is null when it could not be read.
292
+ */
293
+ interface UsageSample {
294
+ at: number;
295
+ cpu: number | null;
296
+ memoryUsedBytes: number | null;
297
+ memoryPressure: 0 | 1 | 2 | null;
298
+ diskFreeBytes: number | null;
299
+ }
300
+ /** Returns only the samples taken after `sinceMs`, epoch milliseconds. */
301
+ interface MachineHistoryParams {
302
+ sinceMs?: number;
303
+ }
304
+ interface MachineHistory {
305
+ intervalMs: number;
306
+ samples: UsageSample[];
97
307
  }
98
308
  interface Methods {
99
309
  hello: {
@@ -122,12 +332,60 @@ interface Methods {
122
332
  };
123
333
  "frames.subscribe": {
124
334
  params: FrameTarget;
125
- result: SubscribeResult;
335
+ result: FramesSubscribeResult;
336
+ };
337
+ "frames.keyframe": {
338
+ params: KeyframeParams;
339
+ result: Record<string, never>;
340
+ };
341
+ "build.plan": {
342
+ params: BuildPlanParams;
343
+ result: BuildPlanResult;
344
+ };
345
+ "machine.get": {
346
+ params?: Record<string, never>;
347
+ result: MachineUsage;
348
+ };
349
+ "machine.history": {
350
+ params?: MachineHistoryParams;
351
+ result: MachineHistory;
126
352
  };
127
353
  unsubscribe: {
128
354
  params: UnsubscribeParams;
129
355
  result: Record<string, never>;
130
356
  };
357
+ action: {
358
+ params: ActionParams;
359
+ result: ActionResult;
360
+ };
361
+ "control.begin": {
362
+ params: ControlBeginParams;
363
+ result: ControlBeginResult;
364
+ };
365
+ "control.end": {
366
+ params: ControlEndParams;
367
+ result: Record<string, never>;
368
+ };
369
+ "input.touch": {
370
+ params: InputTouchParams;
371
+ result: Record<string, never>;
372
+ };
373
+ "input.text": {
374
+ params: InputTextParams;
375
+ result: Record<string, never>;
376
+ };
377
+ "input.button": {
378
+ params: InputButtonParams;
379
+ result: Record<string, never>;
380
+ };
381
+ "input.rotate": {
382
+ params: InputRotateParams;
383
+ result: Record<string, never>;
384
+ };
385
+ "input.posture": {
386
+ params: InputPostureParams;
387
+ result: Record<string, never>;
388
+ };
131
389
  }
132
390
  type ClientRequest = { [M in Method]: {
133
391
  id: RequestId;
@@ -165,7 +423,7 @@ interface ErrorEvent {
165
423
  subscription: string;
166
424
  error: ProtocolError;
167
425
  }
168
- /** A screenshot of the device, sent when the screen changed, at most 5 times a second. */
426
+ /** A frame of the device's screen, sent when the screen changed, at most `fps` times a second. */
169
427
  interface FrameEvent {
170
428
  event: "frame";
171
429
  subscription: string;
@@ -177,6 +435,12 @@ interface FrameEvent {
177
435
  capturedAt: string;
178
436
  /** Base64-encoded image bytes. */
179
437
  data: string;
438
+ /**
439
+ * An iPhone Duo's or Android foldable emulator's posture. A Duo reports the panel it lit: the cover when
440
+ * folded, the inner panel when unfolded. An emulator with a hinge reports `folded` while it shows only its
441
+ * outer display, and `unfolded` otherwise, including half open.
442
+ */
443
+ posture?: "folded" | "unfolded";
180
444
  }
181
445
  /**
182
446
  * Captures for a `frames.subscribe` subscription are slow or a timed-out capture is being retried; the
@@ -187,10 +451,21 @@ interface FrameDelayedEvent {
187
451
  subscription: string;
188
452
  delayed: boolean;
189
453
  }
190
- type ServerEvent = StatusEvent | LogsEvent | FrameEvent | FrameDelayedEvent | ErrorEvent;
454
+ declare const CONTROL_END_REASONS: readonly ["idle", "taken-over", "device-gone", "forbidden", "failed"];
455
+ /**
456
+ * The server ended a control session: no input for 5 minutes, another client took the device over, the device
457
+ * stopped or changed owner, the device lost `control`, or input could not reach the device.
458
+ */
459
+ interface ControlEndedEvent {
460
+ event: "control-ended";
461
+ session: string;
462
+ reason: (typeof CONTROL_END_REASONS)[number];
463
+ message: string;
464
+ }
465
+ type ServerEvent = StatusEvent | LogsEvent | FrameEvent | FrameDelayedEvent | ErrorEvent | ControlEndedEvent;
191
466
  type ServerMessage = ServerResponse | ServerEvent;
192
467
  type JsonSchema = Record<string, unknown>;
193
468
  /** The JSON Schema of every message on the wire, written to `dist/protocol.schema.json` at build time. */
194
469
  declare function protocolJsonSchema(): JsonSchema;
195
470
  //#endregion
196
- export { CAPABILITIES, Capability, ClientRequest, DeviceAuth, ERROR_CODES, ErrorCode, ErrorEvent, FrameDelayedEvent, FrameEvent, FrameTarget, HelloParams, HelloResult, LOG_LEVELS, LOG_SOURCES, LogFilter, LogLevel, LogRecord, LogSource, LogsEvent, LogsQueryResult, MAX_LOG_TAIL, METHODS, Method, Methods, PROTOCOL_SCHEMA_FILE, PROTOCOL_VERSION, PairingAuth, Platform, ProtocolError, RequestId, ServerEvent, ServerMessage, ServerResponse, SettingsResult, StatsResult, StatusEvent, SubscribeResult, UnsubscribeParams, WorkspaceParams, protocolJsonSchema };
471
+ export { ACTIONS, ActionName, ActionParams, ActionResult, BuildPlanParams, BuildPlanResult, CAPABILITIES, CONTROL_END_REASONS, Capability, ClientRequest, ControlBeginParams, ControlBeginResult, ControlEndParams, ControlEndedEvent, DEVICE_POSTURES, DeviceAuth, DevicePosture, ERROR_CODES, ErrorCode, ErrorEvent, FRAME_EDGE, FRAME_FPS, FrameDelayedEvent, FrameEvent, FrameTarget, FramesSubscribeResult, HelloParams, HelloResult, INPUT_BUTTONS, InputButton, InputButtonParams, InputPostureParams, InputRotateParams, InputTextParams, InputTouchParams, KeyframeParams, LOG_LEVELS, LOG_SOURCES, LogFilter, LogLevel, LogRecord, LogSource, LogsEvent, LogsQueryResult, MAX_INPUT_TEXT, MAX_LOG_TAIL, METHODS, MachineHistory, MachineHistoryParams, MachineUsage, MachineVolume, MemoryPressure, Method, Methods, PROTOCOL_SCHEMA_FILE, PROTOCOL_VERSION, PairingAuth, Platform, ProtocolError, ROTATE_DIRECTIONS, RequestId, RotateDirection, ServerEvent, ServerMessage, ServerResponse, SettingsResult, StatsResult, StatusEvent, SubscribeResult, TOUCH_PHASES, TouchPhase, UnsubscribeParams, UsageSample, VIDEO_CODECS, VIDEO_HEADER_VERSION, VIDEO_KEYFRAME, VideoCodec, VideoPacket, WorkspaceParams, protocolJsonSchema };
package/dist/protocol.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { a as MAX_LOG_TAIL, c as PROTOCOL_VERSION, i as LOG_SOURCES, l as protocolJsonSchema, n as ERROR_CODES, o as METHODS, r as LOG_LEVELS, s as PROTOCOL_SCHEMA_FILE, t as CAPABILITIES } from "./protocol-B3k9Ykuu.mjs";
2
- export { CAPABILITIES, ERROR_CODES, LOG_LEVELS, LOG_SOURCES, MAX_LOG_TAIL, METHODS, PROTOCOL_SCHEMA_FILE, PROTOCOL_VERSION, protocolJsonSchema };
1
+ import { _ as TOUCH_PHASES, a as ERROR_CODES, b as VIDEO_KEYFRAME, c as INPUT_BUTTONS, d as MAX_INPUT_TEXT, f as MAX_LOG_TAIL, g as ROTATE_DIRECTIONS, h as PROTOCOL_VERSION, i as DEVICE_POSTURES, l as LOG_LEVELS, m as PROTOCOL_SCHEMA_FILE, n as CAPABILITIES, o as FRAME_EDGE, p as METHODS, r as CONTROL_END_REASONS, s as FRAME_FPS, t as ACTIONS, u as LOG_SOURCES, v as VIDEO_CODECS, x as protocolJsonSchema, y as VIDEO_HEADER_VERSION } from "./protocol-BElQc2vm.mjs";
2
+ export { ACTIONS, CAPABILITIES, CONTROL_END_REASONS, DEVICE_POSTURES, ERROR_CODES, FRAME_EDGE, FRAME_FPS, INPUT_BUTTONS, LOG_LEVELS, LOG_SOURCES, MAX_INPUT_TEXT, MAX_LOG_TAIL, METHODS, PROTOCOL_SCHEMA_FILE, PROTOCOL_VERSION, ROTATE_DIRECTIONS, TOUCH_PHASES, VIDEO_CODECS, VIDEO_HEADER_VERSION, VIDEO_KEYFRAME, protocolJsonSchema };