@gjermundgaraba/clankermux 0.4.1 → 0.6.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,74 +1,156 @@
1
1
  export declare const VERSION = 1;
2
- export interface Peer {
3
- name: string;
4
- version: string;
5
- }
6
- export interface Hello {
7
- version: number;
8
- client: Peer;
9
- engine?: string;
10
- capabilities: string[];
11
- }
12
- export interface Limits {
13
- max_frame: number;
14
- control_body: number;
15
- ring: number;
16
- input_queue: number;
17
- scrollback: number;
18
- continuation: number;
19
- label: number;
20
- text: number;
21
- markers: number;
22
- records: number;
23
- commands: number;
24
- page: number;
25
- hello_timeout: number;
26
- remove_grace: number;
27
- events: number;
28
- attachments: number;
29
- }
30
- export interface Welcome {
31
- version: number;
32
- server: Peer;
33
- engine: string;
34
- incarnation: string;
35
- capabilities: string[];
36
- limits: Limits;
2
+ /** Each method's params and result. */
3
+ export interface Methods {
4
+ /** Starts a session: a program on a new PTY. */
5
+ create: {
6
+ params: CreateParams;
7
+ result: Session;
8
+ };
9
+ /** A page of sessions, ordered by id, without their records. */
10
+ list: {
11
+ params: ListParams;
12
+ result: Page;
13
+ };
14
+ /** One session, with its program status records. */
15
+ inspect: {
16
+ params: SessionParams;
17
+ result: Session;
18
+ };
19
+ /** Sends SIGHUP to the session's processes. */
20
+ end: {
21
+ params: SessionParams;
22
+ result: Empty;
23
+ };
24
+ /** Sends a signal, by name, to the session's processes. */
25
+ signal: {
26
+ params: SignalParams;
27
+ result: Empty;
28
+ };
29
+ /** Deletes a session that is not running, with its files. */
30
+ remove: {
31
+ params: SessionParams;
32
+ result: Empty;
33
+ };
34
+ /** Sets the session's label. */
35
+ label: {
36
+ params: LabelParams;
37
+ result: Session;
38
+ };
39
+ /** Sets the session's size, its size policy, or both. */
40
+ resize: {
41
+ params: ResizeParams;
42
+ result: Empty;
43
+ };
44
+ /** The session's screen, history or last command, as text, VT or HTML. */
45
+ read: {
46
+ params: ReadParams;
47
+ result: Read;
48
+ };
49
+ /** The output stream as plain text, from a stream offset. */
50
+ tail: {
51
+ params: TailParams;
52
+ result: Tail;
53
+ };
54
+ /**
55
+ * Writes text, named keys or bytes to the PTY; with `wait`, answers when it
56
+ * ends.
57
+ */
58
+ send: {
59
+ params: SendParams;
60
+ result: Sent;
61
+ };
62
+ /**
63
+ * Answers when the session exits, its output matches, a record is in a state,
64
+ * a prompt shows or output stops.
65
+ */
66
+ wait: {
67
+ params: WaitParams;
68
+ result: Waited;
69
+ };
70
+ /** Ends a pending `wait`, or `send` with `wait`, of this connection. */
71
+ cancel: {
72
+ params: CancelParams;
73
+ result: Cancelled;
74
+ };
75
+ /** Ends an attachment of any connection. */
76
+ detach: {
77
+ params: DetachParams;
78
+ result: Empty;
79
+ };
80
+ /**
81
+ * Starts `EVENT` frames on this connection: from now, or replayed after a
82
+ * `seq`.
83
+ */
84
+ subscribe: {
85
+ params: SubscribeParams;
86
+ result: Subscribed;
87
+ };
88
+ /** Marks `done` and `error` records seen. */
89
+ ack: {
90
+ params: AckParams;
91
+ result: Acked;
92
+ };
93
+ /** This catalog, or one method of it. */
94
+ describe: {
95
+ params: DescribeParams;
96
+ result: Described;
97
+ };
37
98
  }
38
- export interface Request {
39
- id: number;
40
- method: string;
41
- params: unknown;
99
+ export type Method = keyof Methods;
100
+ /** `ack`: every `done` and `error` record when `record_ids` is absent. */
101
+ export interface AckParams {
102
+ /** The session's id. */
103
+ session: string;
104
+ /** Default: every `done` and `error` record. */
105
+ record_ids?: string[];
42
106
  }
43
- export interface Reply {
44
- id: number;
45
- result: unknown;
107
+ /** The `ack` reply: the records it marked seen. */
108
+ export interface Acked {
109
+ record_ids: string[];
46
110
  }
47
- export type ErrorCode = "protocol_error" | "version_mismatch" | "invalid_request" | "limit_exceeded" | "no_such_session" | "not_running" | "running" | "signal_failed" | "engine_mismatch" | "channel_in_use" | "read_only" | "input_overflow" | "too_slow" | "cancelled" | "scope_unavailable" | "internal" | "no_such_attachment";
48
- export interface ErrorMessage {
49
- id?: number;
50
- code: ErrorCode;
51
- message: string;
111
+ export type AttachMode = "snapshot" | "resume";
112
+ export interface Attached {
113
+ mode: AttachMode;
114
+ /** Cursor offset the attachment continues from. */
115
+ offset: number;
116
+ /**
117
+ * Cursor marker: latest `seq` reflected in the snapshot, or in the client's
118
+ * terminal when resuming.
119
+ */
120
+ marker: number;
121
+ cols: number;
122
+ rows: number;
123
+ session: Session;
124
+ /**
125
+ * Required in mode `snapshot`, absent otherwise: the total length of the
126
+ * snapshot that follows (the sum of the `SNAPSHOT` payloads), so a client can
127
+ * size its buffer.
128
+ */
129
+ snapshot_bytes?: number;
52
130
  }
53
- export type OnExit = "remove" | "keep";
54
- export type Status = "running" | "exited" | "restored";
55
- export type Exit = {
56
- code: number;
57
- } | {
58
- signal: string;
59
- };
60
- /** One program status record (OSC 7501). */
61
- export interface StatusRecord {
62
- id: string;
63
- state: string;
64
- kind?: string;
65
- app?: string;
66
- title?: string;
67
- msg?: string;
68
- progress?: number;
69
- updated_at: string;
70
- /** On `done` and `error` records only: false until `ack`. */
71
- seen?: boolean;
131
+ /** One open attachment of a session, as `list` and `inspect` show it. */
132
+ export interface AttachmentInfo {
133
+ /**
134
+ * Assigned by the server at `OPEN`, unique on it and never reused while it
135
+ * runs; not the frame channel, which only its connection knows. `detach`
136
+ * takes it.
137
+ */
138
+ channel: number;
139
+ /**
140
+ * From the connection's `HELLO.client`, each cut to 32 bytes with control
141
+ * characters replaced by `?`.
142
+ */
143
+ client: Peer;
144
+ read_only: boolean;
145
+ /**
146
+ * Its latest viewport report, in `OPEN` or `VIEWPORT`; absent until it makes
147
+ * one.
148
+ */
149
+ viewport?: Cells;
150
+ /** When it opened, RFC 3339. */
151
+ since: string;
152
+ /** When it last sent `INPUT` the server accepted, RFC 3339. */
153
+ last_input?: string;
72
154
  }
73
155
  /** `Session.attention`: the most urgent record that wants the user. */
74
156
  export interface Attention {
@@ -79,10 +161,55 @@ export interface Attention {
79
161
  /** The record's id. */
80
162
  record: string;
81
163
  }
164
+ export interface CancelParams {
165
+ /** The pending request's id on this connection. */
166
+ id: number;
167
+ }
168
+ /** The `cancel` result. */
169
+ export interface Cancelled {
170
+ cancelled: boolean;
171
+ }
172
+ /** The `describe {}` result. */
173
+ export interface Catalog {
174
+ /** The protocol version, as in `WELCOME`. */
175
+ protocol: number;
176
+ /** The server's release. */
177
+ version: string;
178
+ methods: MethodInfo[];
179
+ events: EventInfo[];
180
+ frames: FrameInfo[];
181
+ errors: ErrorInfo[];
182
+ /** The schemas the others refer to, as `#/$defs/NAME`. */
183
+ $defs: Record<string, unknown>;
184
+ }
185
+ /** A size in cells. */
186
+ export interface Cells {
187
+ cols: number;
188
+ rows: number;
189
+ }
190
+ /** What a method does to the server's state. */
191
+ export type Class =
192
+ /** Answers from the server's state and changes nothing. */
193
+ "read"
194
+ /** Changes a session, an attachment or a pending request. */
195
+ | "mutation"
196
+ /** Starts frames that follow the reply on the connection. */
197
+ | "stream";
198
+ /** `HELLO.client`: a `Peer` as the client sends it. */
199
+ export interface ClientPeer {
200
+ name: string;
201
+ version: string;
202
+ }
203
+ export interface Closed {
204
+ reason: ClosedReason;
205
+ /** The `reason` a `detach` gave. */
206
+ message?: string;
207
+ }
208
+ export type ClosedReason = "closed" | "removed" | "stopping" | "detached";
82
209
  /**
83
- * One command from its OSC 133 marks, as stream offsets: `start` at the
84
- * prompt (`A`), `output` where its output begins (`C`), `end` where it
85
- * ended (`D`) with the `exit` the shell reported.
210
+ * One command from its OSC 133 marks, as stream offsets: `start` at the prompt
211
+ * (`A`), `output` where its output begins (`C`), `end` where it ended (`D`)
212
+ * with the `exit` the shell reported.
86
213
  */
87
214
  export interface Command {
88
215
  start: number;
@@ -90,476 +217,674 @@ export interface Command {
90
217
  end?: number;
91
218
  exit?: number;
92
219
  }
93
- export interface Session {
94
- id: string;
95
- label: string;
96
- status: Status;
97
- argv: string[];
98
- cwd: string;
99
- pid?: number;
100
- cols: number;
101
- rows: number;
102
- title: string;
103
- pwd: string;
104
- on_exit: OnExit;
105
- created_at: string;
106
- exited_at?: string;
107
- exit?: Exit;
220
+ export interface CreateParams {
221
+ /** At most `limits.label` bytes. */
222
+ label?: string;
223
+ /** Default: the user's login shell. */
224
+ argv?: string[];
225
+ /** Default: the server user's home directory. */
226
+ cwd?: string;
227
+ /** Additions and overrides of the server's environment. */
228
+ env?: Record<string, string>;
229
+ /** Default 80. */
230
+ cols?: number;
231
+ /** Default 24. */
232
+ rows?: number;
233
+ /** Default `remove`. */
234
+ on_exit?: OnExit;
235
+ }
236
+ export interface Cursor {
237
+ x: number;
238
+ y: number;
239
+ }
240
+ /** A stream cursor as a request gives it. */
241
+ export interface CursorParams {
108
242
  offset: number;
109
243
  marker: number;
110
- /** Open attachments, in the order they opened. */
111
- attachments: AttachmentInfo[];
112
- command?: Command;
113
- program_status?: StatusRecord[];
114
- attention?: Attention;
115
- size: SizeInfo;
116
244
  }
117
- /** One open attachment of a session. */
118
- export interface AttachmentInfo {
119
- /** Unique on the server and never reused: `detach` takes it. */
245
+ /** `describe`: one method, or the whole catalog. */
246
+ export interface DescribeParams {
247
+ /** A method's name; absent: every method. */
248
+ method?: string;
249
+ }
250
+ /** The `describe` result: `Description` with `method`, else `Catalog`. */
251
+ export type Described = Description | Catalog;
252
+ /** The `describe {method}` result: the method and the schemas it refers to. */
253
+ export interface Description {
254
+ /** The protocol version, as in `WELCOME`. */
255
+ protocol: number;
256
+ /** The server's release. */
257
+ version: string;
258
+ method: MethodInfo;
259
+ /** The schemas `method` refers to, as `#/$defs/NAME`. */
260
+ $defs: Record<string, unknown>;
261
+ }
262
+ /** `detach`: `reason` goes to the attachment as `CLOSED.message`. */
263
+ export interface DetachParams {
264
+ /** The session's id. */
265
+ session: string;
266
+ /** The attachment's `channel`, as `inspect` lists it. */
120
267
  channel: number;
121
- /** The connection's `HELLO.client`. */
122
- client: Peer;
123
- read_only: boolean;
124
- /** The size of its latest viewport report, if it made one. */
125
- viewport?: {
126
- cols: number;
127
- rows: number;
128
- };
129
- since: string;
130
- last_input?: string;
268
+ /** Told to the attachment; at most `limits.text` bytes. */
269
+ reason?: string;
131
270
  }
132
- /** `latest`: the most recent report wins; `smallest`: the smallest
133
- * columns and rows among the attachments' reports; `fixed`: only `resize`
134
- * changes the size. */
135
- export type SizePolicy = "latest" | "smallest" | "fixed";
136
- export interface SizeInfo {
137
- policy: SizePolicy;
138
- /** Under `latest`, the attachment whose report is current. */
139
- owner?: number;
271
+ /** Which side sends a frame. */
272
+ export type Direction = "client" | "server";
273
+ /** The result of a method that answers with success alone. */
274
+ export type Empty = Record<string, unknown>;
275
+ export type ErrorCode =
276
+ /** A connection error under Framing; the connection closes. */
277
+ "protocol_error"
278
+ /** `HELLO.version` is not 1; the connection closes. */
279
+ | "version_mismatch"
280
+ /**
281
+ * Malformed payload, a field the protocol does not define, unknown method, a
282
+ * resume marker above the session's latest, a `subscribe` `after` above the
283
+ * latest event, `read` with `scrollback` and a scope other than `screen`, or
284
+ * `tail` from past the stream's end or with `max_bytes` 0.
285
+ */
286
+ | "invalid_request"
287
+ /** `label`, `text` or `attachments` exceeded, or a snapshot failed. */
288
+ | "limit_exceeded"
289
+ /** No session has the id. */
290
+ | "no_such_session"
291
+ /** `detach` named no open attachment of the session. */
292
+ | "no_such_attachment"
293
+ /**
294
+ * `status` is not `running`, or the stream has ended; for a wait, nothing
295
+ * matched before the stream ended.
296
+ */
297
+ | "not_running"
298
+ /** `remove` on a running session. */
299
+ | "running"
300
+ /** `end` or `signal` found no process to signal. */
301
+ | "signal_failed"
302
+ /** Engine ids differ. */
303
+ | "engine_mismatch"
304
+ /** `OPEN` on a channel already in use. */
305
+ | "channel_in_use"
306
+ /** `INPUT` or `VIEWPORT` on a read-only attachment. */
307
+ | "read_only"
308
+ /** The input would exceed `limits.input_queue`. */
309
+ | "input_overflow"
310
+ /** Second gap during a bootstrap. */
311
+ | "too_slow"
312
+ /** A `cancel` ended the request. */
313
+ | "cancelled"
314
+ /**
315
+ * `read` of `alternate` off the alternate screen, or of `last_command` with
316
+ * no command output marked.
317
+ */
318
+ | "scope_unavailable"
319
+ /** The server failed, or is stopping. */
320
+ | "internal";
321
+ /** One error code. */
322
+ export interface ErrorInfo {
323
+ code: ErrorCode;
324
+ summary: string;
140
325
  }
141
- export interface Page {
142
- sessions: Session[];
143
- next?: string;
326
+ export interface ErrorMessage {
327
+ id?: number;
328
+ code: ErrorCode;
329
+ message: string;
144
330
  }
145
- /** `subscribe`: `after` and `incarnation` together replay the events after
146
- * `after`. */
147
- export interface SubscribeParams {
148
- after?: number;
149
- incarnation?: string;
331
+ /** `EVENT`: an event and its number, from 1 per incarnation. */
332
+ export type Event = {
333
+ seq: number;
334
+ } & (
335
+ /** A session was created. */
336
+ {
337
+ event: "session_created";
338
+ session: Session;
150
339
  }
151
- /** The `subscribe` reply: the first page without `after`, `gap` with it. */
152
- export interface Subscribed {
153
- sessions?: Session[];
154
- next?: string;
155
- oldest: number;
156
- latest: number;
157
- gap?: boolean;
158
- }
159
- export interface Read {
160
- text: string;
161
- cols: number;
162
- rows: number;
163
- cursor?: {
164
- x: number;
165
- y: number;
166
- };
167
- offset: number;
168
- status: Status;
169
- truncated?: boolean;
170
- }
171
- export interface Tail {
172
- text: string;
173
- start_offset: number;
174
- next_offset: number;
175
- complete: boolean;
176
- truncated?: boolean;
177
- }
178
- export interface ListParams {
179
- after?: string;
180
- }
181
- export interface SessionParams {
182
- session: string;
183
- }
184
- export interface SignalParams {
185
- session: string;
186
- signal: string;
187
- }
188
- export interface LabelParams {
189
- session: string;
190
- label: string;
191
- }
192
- /** `resize`: a side left out keeps the session's; so does a policy. */
193
- export interface ResizeParams {
194
- session: string;
195
- cols?: number;
196
- rows?: number;
197
- policy?: SizePolicy;
198
- }
199
- /** `detach`: `reason` reaches the attachment as `CLOSED.message`. */
200
- export interface DetachParams {
201
- session: string;
202
- channel: number;
203
- reason?: string;
204
- }
205
- export type ReadFormat = "text" | "vt" | "html";
206
- export type ReadScope = "screen" | "history" | "alternate" | "last_command";
207
- export interface ReadParams {
208
- session: string;
209
- scrollback?: number;
210
- format?: ReadFormat;
211
- scope?: ReadScope;
212
- }
213
- export interface TailParams {
214
- session: string;
215
- after: number;
216
- max_bytes?: number;
217
- }
218
- /** `send`: exactly one of `text`, `keys` and `data`. */
219
- export interface SendParams {
220
- session: string;
221
- /** UTF-8, written as typed. */
222
- text?: string;
223
- /** Key names, encoded by the session's terminal. */
224
- keys?: string[];
225
- /** Base64 bytes. */
226
- data?: string;
227
- /** `text` or `data` as a paste, bracketed when mode 2004 is set. */
228
- paste?: boolean;
229
- /** A wait armed before the bytes are written. */
230
- wait?: SendWait;
231
- }
232
- export interface SendWait {
233
- until: Until;
234
- timeout_ms?: number;
235
- }
236
- /** What a wait waits for: one or more facts, the first to hold wins. */
237
- export interface Until {
238
- exited?: true;
239
- /** Exactly one of `text` and `regex`. */
240
- output?: {
241
- text?: string;
242
- regex?: string;
243
- };
244
- status?: {
245
- states: string[];
246
- record?: string;
247
- };
248
- prompt?: true;
249
- quiet_ms?: number;
250
- }
251
- /** A stream cursor: the next byte's offset and the latest marker reflected. */
252
- export interface StreamCursor {
253
- offset: number;
254
- marker: number;
255
- }
256
- export interface WaitParams {
257
- session: string;
258
- until: Until;
259
- after?: StreamCursor;
260
- timeout_ms?: number;
261
- }
262
- export interface CancelParams {
263
- id: number;
264
- }
265
- export type WaitReason = "exited" | "matched" | "status" | "prompt" | "quiet" | "timeout";
266
- /** The `wait` result. */
267
- export interface Waited {
268
- reason: WaitReason;
269
- at: StreamCursor;
270
- exit?: Exit;
271
- match?: {
272
- text: string;
273
- offset: number;
274
- };
275
- record?: StatusRecord;
276
- }
277
- /** The `send` result. */
278
- export interface Sent {
279
- /** The cursor once the PTY took the bytes. */
280
- at: StreamCursor;
281
- wait?: Waited;
282
- }
283
- /** The `cancel` result. */
284
- export interface Cancelled {
285
- cancelled: boolean;
286
- }
287
- export interface AckParams {
288
- session: string;
289
- record_ids?: string[];
290
- }
291
- export interface Acked {
292
- record_ids: string[];
293
- }
294
- export interface CreateParams {
295
- label?: string;
296
- argv?: string[];
297
- cwd?: string;
298
- env?: Record<string, string>;
299
- cols?: number;
300
- rows?: number;
301
- on_exit?: OnExit;
302
- }
303
- export type StatusReason = "report" | "clear" | "prompt" | "exit" | "restore" | "evicted" | "ack";
304
- export type ProgressState = "remove" | "set" | "error" | "indeterminate" | "pause";
305
- /** `EVENT`: `seq` counts from 1 per server incarnation. */
306
- export type Event = {
307
- seq: number;
308
- } & ({
309
- event: "session_created";
310
- session: Session;
311
- } | {
340
+ /**
341
+ * Label, `cols`/`rows`, `size` (policy or owner), title, pwd, `attachments`,
342
+ * `attention` or `command` changed; not `last_input` alone.
343
+ */
344
+ | {
312
345
  event: "session_changed";
313
346
  session: Session;
314
- } | {
347
+ }
348
+ /** The stream ended; `exit` is set. */
349
+ | {
315
350
  event: "session_exited";
316
351
  session: Session;
317
- } | {
352
+ }
353
+ /** Removed by request, or by `on_exit: remove`. */
354
+ | {
318
355
  event: "session_removed";
319
356
  id: string;
320
- } | {
357
+ }
358
+ /** One record was set; see Program status. */
359
+ | {
321
360
  event: "program_status_changed";
322
361
  id: string;
323
362
  record: StatusRecord;
324
363
  reason: StatusReason;
325
- } | {
364
+ }
365
+ /** Records were dropped or cleared. */
366
+ | {
326
367
  event: "program_status_removed";
327
368
  id: string;
328
369
  record_ids: string[];
329
370
  reason: StatusReason;
330
- } | {
371
+ }
372
+ /** BEL, at most one per session per 100 ms. */
373
+ | {
331
374
  event: "bell";
332
375
  id: string;
333
- } | {
376
+ }
377
+ /** OSC 9 or OSC 777 `notify`; `title` empty when the sequence has none. */
378
+ | {
334
379
  event: "notification";
335
380
  id: string;
336
381
  title: string;
337
382
  body: string;
338
- } | {
383
+ }
384
+ /** OSC 9;4. */
385
+ | {
339
386
  event: "progress";
340
387
  id: string;
341
388
  state: ProgressState;
342
389
  progress?: number;
343
- } | {
390
+ }
391
+ /** OSC 133 `C`: the command's output starts. */
392
+ | {
344
393
  event: "command_started";
345
394
  id: string;
346
395
  offset: number;
347
- } | {
396
+ }
397
+ /** OSC 133 `D`, with the exit code the shell sent. */
398
+ | {
348
399
  event: "command_ended";
349
400
  id: string;
350
401
  offset: number;
351
402
  exit?: number;
352
- } | {
403
+ }
404
+ /** An `OPEN` attached. */
405
+ | {
353
406
  event: "attachment_opened";
354
407
  id: string;
355
408
  channel: number;
356
409
  client: Peer;
357
410
  read_only: boolean;
358
- } | {
411
+ }
412
+ /** The attachment ended. */
413
+ | {
359
414
  event: "attachment_closed";
360
415
  id: string;
361
416
  channel: number;
362
417
  reason: string;
363
418
  });
364
- export type Scheme = "light" | "dark";
365
- export interface Profile {
366
- fg?: string;
367
- bg?: string;
368
- cursor?: string;
369
- scheme?: Scheme;
370
- }
371
- /** `OPEN.viewport`: the terminal size in cells and, optionally, pixels. */
372
- export interface Size {
373
- cols: number;
374
- rows: number;
375
- cell_width?: number;
376
- cell_height?: number;
377
- }
378
- /** The `VIEWPORT` payload. */
379
- export interface Viewport extends Size {
380
- profile?: Profile;
381
- }
382
- export interface Resume {
383
- incarnation: string;
384
- offset: number;
385
- marker: number;
386
- }
387
- export interface Open {
388
- session: string;
389
- read_only?: boolean;
390
- viewport?: Size;
391
- profile?: Profile;
392
- resume?: Resume;
393
- }
394
- export interface Attached {
395
- mode: "snapshot" | "resume";
396
- offset: number;
397
- marker: number;
398
- cols: number;
399
- rows: number;
400
- session: Session;
401
- /** Total length of the snapshot that follows, in mode `snapshot`. */
402
- snapshot_bytes?: number;
403
- }
404
- export interface Resized {
405
- seq: number;
406
- offset: number;
407
- cols: number;
408
- rows: number;
409
- }
410
- export interface Exited {
411
- seq: number;
412
- offset: number;
413
- exit: Exit;
414
- }
415
- export interface Gap {
416
- from: number;
417
- to: number;
418
- }
419
- export interface Closed {
420
- reason: "closed" | "removed" | "stopping" | "detached";
421
- /** The reason a `detach` gave. */
422
- message?: string;
423
- }
424
- /** The result of a method that answers with success alone. */
425
- export type Empty = Record<string, never>;
426
- /** `describe`: one method, or the whole catalog. */
427
- export interface DescribeParams {
428
- method?: string;
429
- }
430
- /** A JSON Schema (2020-12); `$ref`s point into the catalog's `$defs`. */
431
- export type JsonSchema = {
432
- [key: string]: unknown;
433
- } | boolean;
434
- /** `read` answers from the server's state; `mutation` changes it;
435
- * `stream` starts frames that follow the reply. */
436
- export type Class = "read" | "mutation" | "stream";
437
- /** One method of `REQUEST`. */
438
- export interface MethodInfo {
439
- name: string;
440
- class: Class;
441
- summary: string;
442
- /** Objects refuse undefined fields. */
443
- params: JsonSchema;
444
- /** Objects may gain fields. */
445
- result: JsonSchema;
446
- /** The codes its `ERROR` can carry. */
447
- errors: ErrorCode[];
448
- examples: {
449
- params: unknown;
450
- result: unknown;
451
- }[];
452
- }
453
419
  /** One kind of `EVENT`. */
454
420
  export interface EventInfo {
421
+ /** The `event` field. */
455
422
  name: string;
456
423
  summary: string;
457
- /** The event without `seq`. */
458
- schema: JsonSchema;
424
+ /** JSON Schema of the event, without `seq`. */
425
+ schema: unknown;
459
426
  /** `EVENT` payloads, with `seq`. */
460
427
  examples: unknown[];
461
428
  }
429
+ /** A request's `params` and the `result` of its reply. */
430
+ export interface Example {
431
+ params: unknown;
432
+ result: unknown;
433
+ }
434
+ export type Exit = {
435
+ code: number;
436
+ } | {
437
+ signal: string;
438
+ };
439
+ export interface Exited {
440
+ seq: number;
441
+ offset: number;
442
+ exit: Exit;
443
+ }
444
+ /** One frame type. */
462
445
  export interface FrameInfo {
463
446
  name: string;
447
+ /** The header's `type` byte. */
464
448
  type: number;
465
- direction: "client" | "server";
466
- /** `0`, `n`, or `0 or n`. */
449
+ direction: Direction;
450
+ /** `0` for control, `n` for an attachment, `0 or n` for either. */
467
451
  channel: string;
468
- payload: "json" | "raw" | "empty";
452
+ payload: Payload;
469
453
  summary: string;
470
- schema?: JsonSchema;
454
+ /** JSON Schema of a JSON payload. */
455
+ schema?: unknown;
471
456
  }
472
- export interface ErrorInfo {
473
- code: ErrorCode;
474
- summary: string;
457
+ export interface Gap {
458
+ from: number;
459
+ to: number;
475
460
  }
476
- /** The `describe {}` result. */
477
- export interface Catalog {
478
- protocol: number;
479
- /** The server's release. */
480
- version: string;
481
- methods: MethodInfo[];
482
- events: EventInfo[];
483
- frames: FrameInfo[];
484
- errors: ErrorInfo[];
485
- $defs: Record<string, JsonSchema>;
461
+ export interface Hello {
462
+ /** Always 1. */
463
+ version: number;
464
+ /** Informational. */
465
+ client: ClientPeer;
466
+ /** Engine id; absent for control-only clients. */
467
+ engine?: string;
468
+ /** Capability ids; version 1 defines none. */
469
+ capabilities?: string[];
486
470
  }
487
- /** The `describe {method}` result: the method and the schemas it refers to. */
488
- export interface Description {
489
- protocol: number;
471
+ export interface LabelParams {
472
+ /** The session's id. */
473
+ session: string;
474
+ /** At most `limits.label` bytes. */
475
+ label: string;
476
+ }
477
+ /** Server limits announced in `WELCOME`. Byte counts and milliseconds. */
478
+ export interface Limits {
479
+ /** Payload bytes per frame. */
480
+ max_frame: number;
481
+ /** Client JSON payload bytes. */
482
+ control_body: number;
483
+ /** Retained stream bytes per session. */
484
+ ring: number;
485
+ /** Pending input bytes per session. */
486
+ input_queue: number;
487
+ /** Scrollback bytes per session. */
488
+ scrollback: number;
489
+ /** Continuation tracking bytes per session. */
490
+ continuation: number;
491
+ /** Label bytes. */
492
+ label: number;
493
+ /** Bytes per `cwd`, `title`, `pwd`, and `argv`. */
494
+ text: number;
495
+ /** Retained markers per session. */
496
+ markers: number;
497
+ /** Program status records per session. */
498
+ records: number;
499
+ /** Commands kept per session. */
500
+ commands: number;
501
+ /** Sessions per `list` or `subscribe` reply. */
502
+ page: number;
503
+ /** Milliseconds allowed for `HELLO`. */
504
+ hello_timeout: number;
505
+ /** Milliseconds before `on_exit: remove` removes. */
506
+ remove_grace: number;
507
+ /** Events retained for `subscribe {after}`. */
508
+ events: number;
509
+ /** Open attachments per session. */
510
+ attachments: number;
511
+ }
512
+ export interface ListParams {
513
+ /** The `next` of the previous page. */
514
+ after?: string;
515
+ }
516
+ /** `wait.match`: the text that matched and the offset of its first byte. */
517
+ export interface Match {
518
+ text: string;
519
+ offset: number;
520
+ }
521
+ /** One method of `REQUEST`. */
522
+ export interface MethodInfo {
523
+ name: string;
524
+ class: Class;
525
+ summary: string;
526
+ /** JSON Schema of `params`; objects refuse undefined fields. */
527
+ params: unknown;
528
+ /** JSON Schema of `REPLY.result`; objects may gain fields. */
529
+ result: unknown;
530
+ /** The codes its `ERROR` can carry. */
531
+ errors: ErrorCode[];
532
+ examples: Example[];
533
+ }
534
+ export type OnExit = "remove" | "keep";
535
+ export interface Open {
536
+ /** The session's id. */
537
+ session: string;
538
+ /** Default false. */
539
+ read_only?: boolean;
540
+ viewport?: Size;
541
+ /** Colours as `#rrggbb`; `scheme` is `light` or `dark`. */
542
+ profile?: Profile;
543
+ resume?: Resume;
544
+ }
545
+ /** `until.output`: exactly one of `text` and `regex`. */
546
+ export interface OutputMatch {
547
+ text?: string;
548
+ /** Rust `regex` syntax, on bytes. */
549
+ regex?: string;
550
+ }
551
+ export interface Page {
552
+ /** Ordered by `id`, at most `limits.page`. */
553
+ sessions: Session[];
554
+ /** The last id, when more remain: the next `list`'s `after`. */
555
+ next?: string;
556
+ }
557
+ /** What a frame's payload holds. */
558
+ export type Payload = "json" | "raw" | "empty";
559
+ /** `WELCOME.server`. */
560
+ export interface Peer {
561
+ name: string;
490
562
  version: string;
491
- method: MethodInfo;
492
- $defs: Record<string, JsonSchema>;
493
563
  }
494
- /** Each method's params and result, as the catalog lists them. */
495
- export interface Methods {
496
- create: {
497
- params: CreateParams;
498
- result: Session;
499
- };
500
- list: {
501
- params: ListParams;
502
- result: Page;
503
- };
504
- inspect: {
505
- params: SessionParams;
506
- result: Session;
507
- };
508
- end: {
509
- params: SessionParams;
510
- result: Empty;
511
- };
512
- signal: {
513
- params: SignalParams;
514
- result: Empty;
515
- };
516
- remove: {
517
- params: SessionParams;
518
- result: Empty;
519
- };
520
- label: {
521
- params: LabelParams;
522
- result: Session;
523
- };
524
- resize: {
525
- params: ResizeParams;
526
- result: Empty;
527
- };
528
- read: {
529
- params: ReadParams;
530
- result: Read;
531
- };
532
- tail: {
533
- params: TailParams;
534
- result: Tail;
535
- };
536
- send: {
537
- params: SendParams;
538
- result: Sent;
539
- };
540
- wait: {
541
- params: WaitParams;
542
- result: Waited;
543
- };
544
- cancel: {
545
- params: CancelParams;
546
- result: Cancelled;
547
- };
548
- detach: {
549
- params: DetachParams;
550
- result: Empty;
551
- };
552
- subscribe: {
553
- params: SubscribeParams;
554
- result: Subscribed;
555
- };
556
- ack: {
557
- params: AckParams;
558
- result: Acked;
559
- };
560
- describe: {
561
- params: DescribeParams;
562
- result: Description | Catalog;
563
- };
564
+ export interface Profile {
565
+ fg?: string;
566
+ bg?: string;
567
+ cursor?: string;
568
+ scheme?: Scheme;
569
+ }
570
+ export type ProgressState = "remove" | "set" | "error" | "indeterminate" | "pause";
571
+ export interface Read {
572
+ text: string;
573
+ cols: number;
574
+ rows: number;
575
+ /** Zero-based; absent for a session loaded from a park file. */
576
+ cursor?: Cursor;
577
+ /** Stream offset at the time of the read. */
578
+ offset: number;
579
+ status: Status;
580
+ /**
581
+ * Present and true when lines were left out: cut to fit `max_frame`, or, for
582
+ * `last_command`, bytes the stream no longer holds.
583
+ */
584
+ truncated?: boolean;
585
+ }
586
+ export type ReadFormat = "text" | "vt" | "html";
587
+ export interface ReadParams {
588
+ /** The session's id. */
589
+ session: string;
590
+ /** History lines before the screen, for scope `screen`; default 0. */
591
+ scrollback?: number;
592
+ /** Default `text`. */
593
+ format?: ReadFormat;
594
+ /** Default `screen`. */
595
+ scope?: ReadScope;
596
+ }
597
+ export type ReadScope = "screen" | "history" | "alternate" | "last_command";
598
+ export interface Reply {
599
+ id: number;
600
+ result: unknown;
601
+ }
602
+ export interface Request {
603
+ id: number;
604
+ method: string;
605
+ params: unknown;
606
+ }
607
+ /**
608
+ * `resize`: a side left out keeps the session's; `policy` left out keeps the
609
+ * session's.
610
+ */
611
+ export interface ResizeParams {
612
+ /** The session's id. */
613
+ session: string;
614
+ cols?: number;
615
+ rows?: number;
616
+ policy?: SizePolicy;
617
+ }
618
+ export interface Resized {
619
+ seq: number;
620
+ offset: number;
621
+ cols: number;
622
+ rows: number;
623
+ }
624
+ export interface Resume {
625
+ incarnation: string;
626
+ offset: number;
627
+ marker: number;
628
+ }
629
+ export type Scheme = "light" | "dark";
630
+ /** `send`: exactly one of `text`, `keys` and `data`. */
631
+ export interface SendParams {
632
+ /** The session's id. */
633
+ session: string;
634
+ /** UTF-8, written as typed. */
635
+ text?: string;
636
+ /** Key names, encoded by the session's terminal. */
637
+ keys?: string[];
638
+ /** Base64 bytes. */
639
+ data?: string;
640
+ /**
641
+ * `text` or `data` as a paste, bracketed when mode 2004 is set; default
642
+ * false.
643
+ */
644
+ paste?: boolean;
645
+ /** A wait armed before the bytes are written. */
646
+ wait?: SendWait;
647
+ }
648
+ /**
649
+ * `send.wait`: a `wait` on the same session, from the cursor before the bytes.
650
+ */
651
+ export interface SendWait {
652
+ until: Until;
653
+ /** None: no limit. */
654
+ timeout_ms?: number;
655
+ }
656
+ /** The `send` result. */
657
+ export interface Sent {
658
+ /** The session's cursor when the bytes were queued. */
659
+ at: StreamCursor;
660
+ /** With `send.wait`: its result. */
661
+ wait?: Waited;
662
+ }
663
+ export interface Session {
664
+ /** UUID assigned by the server, never reused. */
665
+ id: string;
666
+ /** At most `limits.label` bytes. */
667
+ label: string;
668
+ status: Status;
669
+ argv: string[];
670
+ /** Working directory at creation. */
671
+ cwd: string;
672
+ /** While the child is alive. */
673
+ pid?: number;
674
+ /** Current size. */
675
+ cols: number;
676
+ /** Current size. */
677
+ rows: number;
678
+ /** From the program, OSC 0 or 2. */
679
+ title: string;
680
+ /** From the program, OSC 7; the path only, host dropped, percent-decoded. */
681
+ pwd: string;
682
+ on_exit: OnExit;
683
+ /** RFC 3339. */
684
+ created_at: string;
685
+ /** RFC 3339. */
686
+ exited_at?: string;
687
+ /** `signal` by name. */
688
+ exit?: Exit;
689
+ /** Current stream offset. */
690
+ offset: number;
691
+ /** Sequence number of the latest marker, 0 if none. */
692
+ marker: number;
693
+ /** Open attachments, in the order they opened. */
694
+ attachments: AttachmentInfo[];
695
+ /** The command running or the last that ran; see Commands. */
696
+ command?: Command;
697
+ /** Only in `inspect`; see Program status. */
698
+ program_status?: StatusRecord[];
699
+ /** The record that most wants the user; see Program status. */
700
+ attention?: Attention;
701
+ /**
702
+ * The size policy, and under `latest` the `channel` of the attachment whose
703
+ * report is current; see Size.
704
+ */
705
+ size: SizeInfo;
706
+ }
707
+ export interface SessionParams {
708
+ /** The session's id. */
709
+ session: string;
710
+ }
711
+ export interface SignalParams {
712
+ /** The session's id. */
713
+ session: string;
714
+ /** A name: `HUP`, `INT`, `TERM`, `KILL`, ... */
715
+ signal: string;
716
+ }
717
+ /** `OPEN.viewport`: the terminal size in cells and, optionally, pixels. */
718
+ export interface Size {
719
+ cols: number;
720
+ rows: number;
721
+ cell_width?: number;
722
+ cell_height?: number;
723
+ }
724
+ /**
725
+ * `Session.size`: the policy and, under `latest`, the attachment whose report
726
+ * is current.
727
+ */
728
+ export interface SizeInfo {
729
+ policy: SizePolicy;
730
+ owner?: number;
731
+ }
732
+ /** How a session's size follows its attachments' viewport reports. */
733
+ export type SizePolicy =
734
+ /** The most recent report wins. */
735
+ "latest"
736
+ /** The smallest columns and rows among the attachments' reports. */
737
+ | "smallest"
738
+ /** Only `resize` changes the size. */
739
+ | "fixed";
740
+ export type Status = "running" | "exited" | "restored";
741
+ /** `until.status`: a record in one of `states`, or the record `record`. */
742
+ export interface StatusMatch {
743
+ /** `idle`, `working`, `done`, `blocked`, `error`. */
744
+ states: string[];
745
+ /** Only the record with this id. */
746
+ record?: string;
747
+ }
748
+ /** Why a program status record was set or removed. */
749
+ export type StatusReason = "report" | "clear" | "prompt" | "exit" | "restore" | "evicted" | "ack";
750
+ /** One program status record (OSC 7501). */
751
+ export interface StatusRecord {
752
+ /** The record id; `""` for the root. */
753
+ id: string;
754
+ /** `idle`, `working`, `done`, `blocked` or `error`. */
755
+ state: string;
756
+ kind?: string;
757
+ /**
758
+ * In `inspect`, resolved from the nearest ancestor when the record has none.
759
+ */
760
+ app?: string;
761
+ title?: string;
762
+ msg?: string;
763
+ /** 0 to 100. */
764
+ progress?: number;
765
+ /** RFC 3339. */
766
+ updated_at: string;
767
+ /** On `done` and `error` records only: false until `ack`. */
768
+ seen?: boolean;
769
+ }
770
+ /**
771
+ * A stream cursor as the server reports it: the next byte's offset and the
772
+ * latest marker reflected.
773
+ */
774
+ export interface StreamCursor {
775
+ offset: number;
776
+ marker: number;
777
+ }
778
+ /**
779
+ * `subscribe`: `after` and `incarnation` together replay the events after
780
+ * `after`; neither is the first page.
781
+ */
782
+ export interface SubscribeParams {
783
+ /** The `seq` of the last event the client applied. */
784
+ after?: number;
785
+ /** The `WELCOME.incarnation` `after` was counted in. */
786
+ incarnation?: string;
787
+ }
788
+ /** The `subscribe` reply: the first page without `after`, `gap` with it. */
789
+ export interface Subscribed {
790
+ /** Without `after`: the first page of sessions. */
791
+ sessions?: Session[];
792
+ /** Without `after`: as in Page. */
793
+ next?: string;
794
+ /** The `seq` of the oldest event retained, `latest + 1` when none is. */
795
+ oldest: number;
796
+ /** The `seq` of the latest event, 0 before the first. */
797
+ latest: number;
798
+ /**
799
+ * With `after`: the events after it are not all retained, or `incarnation` is
800
+ * not the server's; none is replayed.
801
+ */
802
+ gap?: boolean;
803
+ }
804
+ /** `tail`'s result. */
805
+ export interface Tail {
806
+ /**
807
+ * Plain text: the stream without escape sequences, and without controls but
808
+ * LF, CR and TAB; see `tail`.
809
+ */
810
+ text: string;
811
+ /** Where the text starts: `after`, or later when truncated. */
812
+ start_offset: number;
813
+ /** Where it ends; the next `after`. */
814
+ next_offset: number;
815
+ /**
816
+ * Nothing more to read now: `next_offset` is the current stream offset, or
817
+ * what follows it is unfinished.
818
+ */
819
+ complete: boolean;
820
+ /** Present and true when `start_offset` is above `after`. */
821
+ truncated?: boolean;
822
+ }
823
+ export interface TailParams {
824
+ /** The session's id. */
825
+ session: string;
826
+ /** The stream offset to read from. */
827
+ after: number;
828
+ /** Stream bytes to cover, at least 1; default 65536. */
829
+ max_bytes?: number;
830
+ }
831
+ /** What a wait waits for: one or more facts, the first to hold wins. */
832
+ export interface Until {
833
+ /** `true`: the stream ends. */
834
+ exited?: boolean;
835
+ output?: OutputMatch;
836
+ status?: StatusMatch;
837
+ /** `true`: the next OSC 133 `A`. */
838
+ prompt?: boolean;
839
+ /** No output for this long. */
840
+ quiet_ms?: number;
841
+ }
842
+ /** The `VIEWPORT` payload: a size and a profile in one flat object. */
843
+ export interface Viewport {
844
+ cols: number;
845
+ rows: number;
846
+ cell_width?: number;
847
+ cell_height?: number;
848
+ profile?: Profile;
849
+ }
850
+ export interface WaitParams {
851
+ /** The session's id. */
852
+ session: string;
853
+ until: Until;
854
+ /** Default: the session's cursor when the request is handled. */
855
+ after?: CursorParams;
856
+ /** None: no limit. */
857
+ timeout_ms?: number;
858
+ }
859
+ export type WaitReason = "exited" | "matched" | "status" | "prompt" | "quiet" | "timeout";
860
+ /** The `wait` result. */
861
+ export interface Waited {
862
+ reason: WaitReason;
863
+ /**
864
+ * Just past the match; after the output holding the prompt; at the end of the
865
+ * stream; else the cursor when it ended.
866
+ */
867
+ at: StreamCursor;
868
+ /** `exited`: the session's `exit`. */
869
+ exit?: Exit;
870
+ /**
871
+ * `matched`: the plain text that matched and the stream offset of its first
872
+ * byte.
873
+ */
874
+ match?: Match;
875
+ /** `status`: the record, as `inspect` shows it. */
876
+ record?: StatusRecord;
877
+ }
878
+ export interface Welcome {
879
+ /** Always 1. */
880
+ version: number;
881
+ server: Peer;
882
+ /** Engine id of the server. */
883
+ engine: string;
884
+ /** UUID, new on every server start. */
885
+ incarnation: string;
886
+ /** Unknown ids are ignored. */
887
+ capabilities: string[];
888
+ /** The server's limits. */
889
+ limits: Limits;
564
890
  }
565
- export type Method = keyof Methods;