@stim-cli/server 1.10.1 → 1.11.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"];
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"];
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,151 @@ 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
+ /** Predicts the next `ios` or `android` build of `workspace` in `slot` (`default` when absent). */
175
+ interface BuildPlanParams {
176
+ workspace: string;
177
+ platform: Platform;
178
+ slot?: string;
179
+ }
180
+ /** `stim ios|android --plan --json`. It builds, boots and installs nothing, and writes no Stim state. */
181
+ type BuildPlanResult = BuildPlanPayload;
182
+ type MemoryPressure = "normal" | "warning" | "critical";
183
+ /** A volume that holds Stim workspaces, Stim home, or the simulators. */
184
+ interface MachineVolume {
185
+ /** `/`, or `/Volumes/<name>` for an external volume. */
186
+ mount: string;
187
+ /** What Stim keeps there: `Workspaces`, `Stim home`, `Simulators`. */
188
+ holds: string[];
189
+ /** Free space without purgeable space, which is what Stim's disk budget measures. */
190
+ freeBytes: number;
191
+ totalBytes: number;
192
+ }
193
+ /** Cheap machine usage, read in the server process without running `stim`. */
194
+ interface MachineUsage {
195
+ volumes: MachineVolume[];
196
+ /**
197
+ * `usedBytes` is the Mac's memory in use, as Activity Monitor's "Memory Used" counts it: app memory, wired and
198
+ * compressed. `pressure` is the macOS memory pressure level. Both are null on other systems or when they cannot
199
+ * be read.
200
+ */
201
+ memory: {
202
+ totalBytes: number;
203
+ usedBytes: number | null;
204
+ pressure: MemoryPressure | null;
205
+ };
206
+ load: {
207
+ avg1: number;
208
+ avg5: number;
209
+ avg15: number;
210
+ cpus: number;
211
+ };
212
+ /**
213
+ * `usage` is the Mac's overall CPU busy fraction (0..1), from the tick delta between this call and the
214
+ * previous one. Null on the first call of a server process, since there is no previous sample yet.
215
+ */
216
+ cpu: {
217
+ usage: number | null;
218
+ cores: number;
219
+ };
220
+ sampledAt: string;
221
+ }
222
+ /**
223
+ * One `machine.history` sample. `at` is epoch milliseconds. `cpu` is the busy fraction (0..1) since the previous
224
+ * sample. `memoryPressure` is 0 (normal), 1 (warning) or 2 (critical). `diskFreeBytes` is the free space of the
225
+ * startup volume, `/`. A field is null when it could not be read.
226
+ */
227
+ interface UsageSample {
228
+ at: number;
229
+ cpu: number | null;
230
+ memoryUsedBytes: number | null;
231
+ memoryPressure: 0 | 1 | 2 | null;
232
+ diskFreeBytes: number | null;
233
+ }
234
+ /** Returns only the samples taken after `sinceMs`, epoch milliseconds. */
235
+ interface MachineHistoryParams {
236
+ sinceMs?: number;
237
+ }
238
+ interface MachineHistory {
239
+ intervalMs: number;
240
+ samples: UsageSample[];
97
241
  }
98
242
  interface Methods {
99
243
  hello: {
@@ -122,12 +266,32 @@ interface Methods {
122
266
  };
123
267
  "frames.subscribe": {
124
268
  params: FrameTarget;
125
- result: SubscribeResult;
269
+ result: FramesSubscribeResult;
270
+ };
271
+ "frames.keyframe": {
272
+ params: KeyframeParams;
273
+ result: Record<string, never>;
274
+ };
275
+ "build.plan": {
276
+ params: BuildPlanParams;
277
+ result: BuildPlanResult;
278
+ };
279
+ "machine.get": {
280
+ params?: Record<string, never>;
281
+ result: MachineUsage;
282
+ };
283
+ "machine.history": {
284
+ params?: MachineHistoryParams;
285
+ result: MachineHistory;
126
286
  };
127
287
  unsubscribe: {
128
288
  params: UnsubscribeParams;
129
289
  result: Record<string, never>;
130
290
  };
291
+ action: {
292
+ params: ActionParams;
293
+ result: ActionResult;
294
+ };
131
295
  }
132
296
  type ClientRequest = { [M in Method]: {
133
297
  id: RequestId;
@@ -165,7 +329,7 @@ interface ErrorEvent {
165
329
  subscription: string;
166
330
  error: ProtocolError;
167
331
  }
168
- /** A screenshot of the device, sent when the screen changed, at most 5 times a second. */
332
+ /** A frame of the device's screen, sent when the screen changed, at most `fps` times a second. */
169
333
  interface FrameEvent {
170
334
  event: "frame";
171
335
  subscription: string;
@@ -177,6 +341,12 @@ interface FrameEvent {
177
341
  capturedAt: string;
178
342
  /** Base64-encoded image bytes. */
179
343
  data: string;
344
+ /**
345
+ * An iPhone Duo's or Android foldable emulator's posture. A Duo reports the panel it lit: the cover when
346
+ * folded, the inner panel when unfolded. An emulator with a hinge reports `folded` while it shows only its
347
+ * outer display, and `unfolded` otherwise, including half open.
348
+ */
349
+ posture?: "folded" | "unfolded";
180
350
  }
181
351
  /**
182
352
  * Captures for a `frames.subscribe` subscription are slow or a timed-out capture is being retried; the
@@ -193,4 +363,4 @@ type JsonSchema = Record<string, unknown>;
193
363
  /** The JSON Schema of every message on the wire, written to `dist/protocol.schema.json` at build time. */
194
364
  declare function protocolJsonSchema(): JsonSchema;
195
365
  //#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 };
366
+ export { ACTIONS, ActionName, ActionParams, ActionResult, BuildPlanParams, BuildPlanResult, CAPABILITIES, Capability, ClientRequest, DeviceAuth, ERROR_CODES, ErrorCode, ErrorEvent, FRAME_EDGE, FRAME_FPS, FrameDelayedEvent, FrameEvent, FrameTarget, FramesSubscribeResult, HelloParams, HelloResult, KeyframeParams, LOG_LEVELS, LOG_SOURCES, LogFilter, LogLevel, LogRecord, LogSource, LogsEvent, LogsQueryResult, MAX_LOG_TAIL, METHODS, MachineHistory, MachineHistoryParams, MachineUsage, MachineVolume, MemoryPressure, Method, Methods, PROTOCOL_SCHEMA_FILE, PROTOCOL_VERSION, PairingAuth, Platform, ProtocolError, RequestId, ServerEvent, ServerMessage, ServerResponse, SettingsResult, StatsResult, StatusEvent, SubscribeResult, 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 { a as FRAME_FPS, c as MAX_LOG_TAIL, d as PROTOCOL_VERSION, f as VIDEO_CODECS, h as protocolJsonSchema, i as FRAME_EDGE, l as METHODS, m as VIDEO_KEYFRAME, n as CAPABILITIES, o as LOG_LEVELS, p as VIDEO_HEADER_VERSION, r as ERROR_CODES, s as LOG_SOURCES, t as ACTIONS, u as PROTOCOL_SCHEMA_FILE } from "./protocol-CmlG7X7_.mjs";
2
+ export { ACTIONS, CAPABILITIES, ERROR_CODES, FRAME_EDGE, FRAME_FPS, LOG_LEVELS, LOG_SOURCES, MAX_LOG_TAIL, METHODS, PROTOCOL_SCHEMA_FILE, PROTOCOL_VERSION, VIDEO_CODECS, VIDEO_HEADER_VERSION, VIDEO_KEYFRAME, protocolJsonSchema };