bmux_pane_runtime_plugin_api 0.0.1-alpha.1

Typed public API of the bmux pane-runtime plugin (BPDL-generated bindings)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
// Public, typed contract of the pane-runtime plugin.
//
// The pane-runtime plugin owns every PTY handle + layout tree in the
// bmux process; core server code dispatches through the typed
// services declared here.
//
// Interfaces:
// - `pane-runtime-state`  — read queries over pane + session runtime.
// - `pane-runtime-commands` — mutating commands (split / launch /
//   focus / resize / close / restart / zoom / direct-input / create /
//   destroy sessions with runtime, restore from snapshot).
// - `attach-runtime-commands` — per-client attach lifecycle (attach
//   session, attach context, open, send input, request output batch,
//   set viewport, detach).
// - `attach-runtime-state` — attach-view queries (layout, snapshot,
//   pane-snapshot, pane-images, pane-output-batch).
// - `pane-runtime-events`  — pane + attach lifecycle event stream.

plugin bmux.pane_runtime version 1;

capability PANE_RUNTIME_READ = bmux.pane_runtime.read;
capability PANE_RUNTIME_WRITE = bmux.pane_runtime.write;
capability ATTACH_RUNTIME_WRITE = bmux.attach_runtime.write;
capability ATTACH_RUNTIME_READ = bmux.attach_runtime.read;

@capability(PANE_RUNTIME_READ)
interface pane-runtime-state {
    record pane-summary {
        id: uuid,
        name: string?,
        shell: string,
        focused: bool,
    }

    record session-pane-list {
        session_id: uuid,
        panes: list<pane-summary>,
    }

    record floating-pane-summary {
        id: uuid,
        pane_id: uuid,
        anchor_pane_id: uuid?,
        context_id: uuid?,
        client_id: uuid?,
        x: u16,
        y: u16,
        w: u16,
        h: u16,
        scope: string,
        layer: string,
        z: i32,
        visible: bool,
        opaque: bool,
        accepts_input: bool,
        cursor_owner: bool,
    }

    record floating-pane-list {
        session_id: uuid,
        panes: list<floating-pane-summary>,
    }

    record pane-process-identity {
        session_id: uuid,
        pane_id: uuid,
        pid: u32?,
        process_group_id: i32?,
    }

    record pane-process-list {
        panes: list<pane-process-identity>,
    }

    variant pane-state-error {
        session-not-found,
        pane-not-found,
    }

    query list-panes(session_id: uuid?) -> result<session-pane-list, pane-state-error>;
    query get-pane(session_id: uuid, pane_id: uuid)
        -> result<pane-summary, pane-state-error>;
    query list-floating-panes(session_id: uuid)
        -> result<floating-pane-list, pane-state-error>;
    query list-pane-processes() -> result<pane-process-list, pane-state-error>;
    query get-pane-process(session_id: uuid, pane_id: uuid)
        -> result<pane-process-identity, pane-state-error>;
}

@capability(PANE_RUNTIME_WRITE)
interface pane-runtime-commands {
    // Shared acknowledgement carrying the target pane + session id
    // after a mutating command completes. All mutation commands return
    // a result of this or a command-specific error.
    record pane-ack {
        session_id: uuid,
        pane_id: uuid,
    }

    record session-ack {
        session_id: uuid,
    }

    record floating-pane-ack {
        session_id: uuid,
        pane_id: uuid,
        surface_id: uuid,
    }

    variant pane-command-error {
        session-not-found,
        pane-not-found,
        denied { reason: string },
        failed { reason: string },
    }

    // Errors the session-runtime commands can produce. Names are
    // display hints, not identity: session creation does not reject
    // duplicate names. Identity is the UUID assigned at creation.
    variant session-runtime-command-error {
        session-not-found,
        failed { reason: string },
    }

    // Split an existing pane along the given direction at the given
    // ratio (0.1..=0.9, clamped). Creates a new pane beside the target.
    command split-pane(
        session_id: uuid,
        target: uuid?,
        direction: string,    // "horizontal" | "vertical"
        ratio_percent: u8,    // 10..=90
    ) -> result<pane-ack, pane-command-error>;

    // Launch a new pane with an explicit program + args + cwd + env,
    // splitting from `target` along `direction`.
    command launch-pane(
        session_id: uuid,
        target: uuid?,
        direction: string,    // "horizontal" | "vertical"
        ratio_percent: u8,
        name: string?,
        program: string,
        args: list<string>,
        cwd: string?,
    ) -> result<pane-ack, pane-command-error>;

    // Focus a pane. `target` may be a pane id; when `target` is none,
    // focus moves in `direction` (up/down/left/right/next/prev).
    command focus-pane(
        session_id: uuid,
        target: uuid?,
        direction: string,
    ) -> result<pane-ack, pane-command-error>;

    command resize-pane(
        session_id: uuid,
        target: uuid?,
        direction: string,    // "left" | "right" | "up" | "down"
        cells: u16,
    ) -> result<session-ack, pane-command-error>;

    command close-pane(
        session_id: uuid,
        target: uuid?,
    ) -> result<pane-ack, pane-command-error>;

    command restart-pane(
        session_id: uuid,
        target: uuid?,
    ) -> result<pane-ack, pane-command-error>;

    command zoom-pane(
        session_id: uuid,
    ) -> result<pane-ack, pane-command-error>;

    command create-floating-pane(
        session_id: uuid,
        target: uuid?,
        anchor_pane_id: uuid?,
        context_id: uuid?,
        client_id: uuid?,
        x: u16?,
        y: u16?,
        w: u16?,
        h: u16?,
        z: i32?,
        layer: string?,
        scope: string?,
        name: string?,
        program: string?,
        args: list<string>,
        cwd: string?,
    ) -> result<floating-pane-ack, pane-command-error>;

    command move-floating-pane(
        session_id: uuid,
        pane_id: uuid,
        x: u16,
        y: u16,
    ) -> result<floating-pane-ack, pane-command-error>;

    command resize-floating-pane(
        session_id: uuid,
        pane_id: uuid,
        w: u16,
        h: u16,
    ) -> result<floating-pane-ack, pane-command-error>;

    command focus-floating-pane(
        session_id: uuid,
        pane_id: uuid,
    ) -> result<floating-pane-ack, pane-command-error>;

    command raise-floating-pane(
        session_id: uuid,
        pane_id: uuid,
    ) -> result<floating-pane-ack, pane-command-error>;

    command lower-floating-pane(
        session_id: uuid,
        pane_id: uuid,
    ) -> result<floating-pane-ack, pane-command-error>;

    command set-floating-pane-z(
        session_id: uuid,
        pane_id: uuid,
        z: i32,
    ) -> result<floating-pane-ack, pane-command-error>;

    command set-floating-pane-layer(
        session_id: uuid,
        pane_id: uuid,
        layer: string,
    ) -> result<floating-pane-ack, pane-command-error>;

    command close-floating-pane(
        session_id: uuid,
        pane_id: uuid,
    ) -> result<floating-pane-ack, pane-command-error>;

    // Send raw input bytes directly to a pane. Used for unattached
    // programmatic input (e.g. playbook-driven tests).
    command pane-direct-input(
        session_id: uuid,
        pane_id: uuid,
        data: list<u8>,
    ) -> result<pane-ack, pane-command-error>;

    // Update the cached write decision for an already-attached client.
    // The permissions plugin calls this when a role changes so pane input
    // stays hot-path local without becoming stale.
    command set-client-write-permission(
        session_id: uuid,
        client_id: uuid,
        allowed: bool,
    ) -> result<u8, pane-command-error>;

    // Spin up a brand-new session runtime (session manager entry +
    // initial pane PTY). Sessions-plugin bridges `new-session` into
    // this operation.
    command new-session-with-runtime(
        name: string?,
    ) -> result<session-ack, session-runtime-command-error>;

    // Tear down a session's runtime (shut down all pane PTYs, flush
    // recording sinks, release attach tokens). Sessions-plugin bridges
    // `kill-session` into this operation.
    command kill-session-runtime(
        session_id: uuid,
        force_local: bool,
    ) -> result<session-ack, session-runtime-command-error>;

    // Restore a session runtime from a snapshot payload. Invoked by
    // the snapshot orchestrator on server startup. Payload is the
    // opaque bytes from `PaneRuntimeSnapshotV1` (deserialized inside
    // the plugin).
    command restore-session-runtime(
        session_id: uuid,
        snapshot_payload: list<u8>,
    ) -> result<session-ack, session-runtime-command-error>;
}

@capability(ATTACH_RUNTIME_WRITE)
interface attach-runtime-commands {
    // Response from `attach-session` / `attach-context`. Carries the
    // attach grant issued by the AttachTokenManager; client re-presents
    // it on `attach-open`.
    record attach-grant {
        token: uuid,
        session_id: uuid,
        context_id: uuid?,
        expires_epoch_ms: u64,
    }

    // Response from `attach-open`. Indicates the open succeeded and
    // describes the stream's terminal capabilities.
    record attach-ready {
        session_id: uuid,
        context_id: uuid?,
        can_write: bool,
    }

    record attach-output {
        data: list<u8>,
    }

    record attach-viewport-set {
        session_id: uuid,
        cols: u16,
        rows: u16,
        status_top_inset: u16,
        status_bottom_inset: u16,
        context_id: uuid?,
    }

    record attach-retarget-ready {
        session_id: uuid,
        context_id: uuid?,
        can_write: bool,
        cols: u16,
        rows: u16,
        status_top_inset: u16,
        status_bottom_inset: u16,
    }

    record attach-input-accepted {
        bytes: u32,
    }

    // Selector identifying a session. Exactly one of `id` or `name`
    // should be populated; `id` wins when both are set.
    record session-selector {
        id: uuid?,
        name: string?,
    }

    // Selector identifying a context. Exactly one of `id` or `name`
    // should be populated; `id` wins when both are set.
    record context-selector {
        id: uuid?,
        name: string?,
    }

    variant attach-command-error {
        session-not-found,
        invalid-grant,
        expired-grant,
        denied { reason: string },
        failed { reason: string },
    }

    command attach-session(
        selector: session-selector,
        can_write: bool,
    ) -> result<attach-grant, attach-command-error>;

    command attach-context(
        selector: context-selector,
        can_write: bool,
    ) -> result<attach-grant, attach-command-error>;

    command attach-open(
        session_id: uuid,
        attach_token: uuid,
    ) -> result<attach-ready, attach-command-error>;

    command attach-input(
        session_id: uuid,
        data: list<u8>,
    ) -> result<attach-input-accepted, attach-command-error>;

    command attach-output(
        session_id: uuid,
        max_bytes: u32,
    ) -> result<attach-output, attach-command-error>;

    command attach-set-viewport(
        session_id: uuid,
        cols: u16,
        rows: u16,
        status_top_inset: u16,
        status_bottom_inset: u16,
        cell_pixel_w: u16,
        cell_pixel_h: u16,
    ) -> result<attach-viewport-set, attach-command-error>;

    command attach-retarget-context(
        context_id: uuid,
        can_write: bool,
        cols: u16,
        rows: u16,
        status_top_inset: u16,
        status_bottom_inset: u16,
        cell_pixel_w: u16,
        cell_pixel_h: u16,
    ) -> result<attach-retarget-ready, attach-command-error>;

    command set-client-attach-policy(
        allow_detach: bool,
    ) -> result<u8, attach-command-error>;

    command detach() -> result<u8, attach-command-error>;
}

@capability(ATTACH_RUNTIME_READ)
interface attach-runtime-state {
    record pane-chunk {
        pane_id: uuid,
        data: list<u8>,
        stream_start: u64,
        stream_end: u64,
        stream_gap: bool,
        sync_update_active: bool,
    }

    record pane-mouse-protocol {
        pane_id: uuid,
        // JSON-encoded `AttachMouseProtocolState` (schema is server-internal).
        encoded: list<u8>,
    }

    record pane-input-mode {
        pane_id: uuid,
        // JSON-encoded `AttachInputModeState`.
        encoded: list<u8>,
    }

    record attach-layout {
        session_id: uuid,
        context_id: uuid?,
        focused_pane_id: uuid,
        // JSON-encoded layout payload (panes + layout_root + scene + zoomed).
        encoded: list<u8>,
    }

    record attach-snapshot {
        session_id: uuid,
        context_id: uuid?,
        focused_pane_id: uuid,
        zoomed: bool,
        // JSON-encoded layout payload (panes + layout_root + scene).
        layout_encoded: list<u8>,
        chunks: list<pane-chunk>,
        pane_mouse_protocols: list<pane-mouse-protocol>,
        pane_input_modes: list<pane-input-mode>,
    }

    record attach-pane-snapshot {
        chunks: list<pane-chunk>,
        pane_mouse_protocols: list<pane-mouse-protocol>,
        pane_input_modes: list<pane-input-mode>,
    }

    record attach-pane-output-batch {
        chunks: list<pane-chunk>,
        output_still_pending: bool,
    }

    record pane-grid-snapshot {
        pane_id: uuid,
        stream_end: u64,
        encoded: list<u8>,
    }

    record attach-pane-grid-snapshot {
        snapshots: list<pane-grid-snapshot>,
    }

    record pane-grid-window-request {
        pane_id: uuid,
        scrollback_offset: u32,
        rows: u32,
        anchor_total_scrolled_rows: u64?,
    }

    record pane-grid-window {
        pane_id: uuid,
        scrollback_offset: u32,
        max_scrollback_offset: u32,
        total_scrolled_rows: u64,
        anchor_delta_rows: u32,
        anchor_clamped: bool,
        stream_end: u64,
        encoded: list<u8>,
    }

    record attach-pane-grid-window {
        windows: list<pane-grid-window>,
    }

    record pane-grid-delta {
        pane_id: uuid,
        base_revision: u64,
        revision: u64,
        desynced: bool,
        encoded: list<u8>,
    }

    record attach-pane-grid-delta {
        deltas: list<pane-grid-delta>,
    }

    record attach-pane-images {
        // JSON-encoded `Vec<AttachPaneImageDelta>`.
        encoded: list<u8>,
    }

    variant attach-state-error {
        not-attached,
        session-not-found,
        failed { reason: string },
    }

    query attach-layout-state(
        session_id: uuid,
    ) -> result<attach-layout, attach-state-error>;

    query attach-snapshot-state(
        session_id: uuid,
        max_bytes_per_pane: u32,
    ) -> result<attach-snapshot, attach-state-error>;

    query attach-pane-snapshot-state(
        session_id: uuid,
        pane_ids: list<uuid>,
        max_bytes_per_pane: u32,
    ) -> result<attach-pane-snapshot, attach-state-error>;

    query attach-pane-output-batch(
        session_id: uuid,
        pane_ids: list<uuid>,
        max_bytes: u32,
    ) -> result<attach-pane-output-batch, attach-state-error>;

    query attach-pane-grid-snapshot-state(
        session_id: uuid,
        pane_ids: list<uuid>,
        max_rows_per_pane: u32,
    ) -> result<attach-pane-grid-snapshot, attach-state-error>;

    query attach-pane-grid-window-state(
        session_id: uuid,
        windows: list<pane-grid-window-request>,
    ) -> result<attach-pane-grid-window, attach-state-error>;

    query attach-pane-grid-delta-state(
        session_id: uuid,
        pane_ids: list<uuid>,
        base_revisions: list<u64>,
        max_batches_per_pane: u32,
    ) -> result<attach-pane-grid-delta, attach-state-error>;

    query attach-pane-images(
        session_id: uuid,
        pane_ids: list<uuid>,
        since_sequences: list<u64>,
    ) -> result<attach-pane-images, attach-state-error>;
}

interface pane-runtime-events {
    enum attach-view-component {
        scene,
        surface-content,
        layout,
        status,
    }

    variant pane-event {
        client-attached { session_id: uuid },
        client-detached { session_id: uuid },
        exited { session_id: uuid, pane_id: uuid, reason: string? },
        restarted { session_id: uuid, pane_id: uuid },
        output-available { session_id: uuid, pane_id: uuid },
        image-available { session_id: uuid, pane_id: uuid },
        attach-view-changed {
            context_id: uuid?,
            session_id: uuid,
            revision: u64,
            components: list<attach-view-component>,
        },
    }

    events pane-event;
}

// Reactive state channel announcing the currently-focused pane (and
// the zoomed pane, if any) for every live session. Pane-runtime is
// the authoritative owner of this state; it publishes a fresh snapshot
// whenever any session's focus/zoom transitions, and also at attach
// time so newly-attached consumers observe the current state without
// an extra query round-trip.
//
// Payload semantics:
// - `entries` maps session-id to a per-session `focus-snapshot`. A
//   session with no entry means "no focus state observed yet"; most
//   consumers can ignore such gaps.
// - `focused_pane_id` is the pane currently receiving input focus.
// - `zoomed_pane_id` is the pane that has taken over the viewport
//   via zoom mode; `None` means not zoomed.
// - `revision` is a monotonic counter that advances on every publish;
//   consumers can use it to deduplicate or order updates.
//
// Subscribers use `EventBus::subscribe_state::<SessionFocusStateMap>`
// to obtain the current value synchronously plus a live-update
// receiver.
interface pane-runtime-focus {
    record focus-snapshot {
        focused_pane_id: uuid,
        zoomed_pane_id: uuid?,
    }

    record session-focus-state-map {
        entries: map<uuid, focus-snapshot>,
        revision: u64,
    }

    @state events session-focus-state-map;
}