tmux-ide 2.9.27 → 2.9.28
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.
- package/bin/cli.js +796 -97
- package/package.json +1 -1
- package/packages/contracts/src/pane-stream.ts +36 -0
- package/packages/daemon/dist/command-center/resources/terminal-runtime-inventory.js +17 -3
- package/packages/daemon/dist/command-center/tmux-servers.js +2 -1
- package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/Info.plist +2 -2
- package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/MacOS/tmux-ide-notifier +0 -0
- package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/Resources/Assets.car +0 -0
- package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/_CodeSignature/CodeResources +2 -2
- package/packages/daemon/dist/terminal/attachments/native-runtime.js +12 -8
- package/packages/daemon/dist/terminal/mirror/mirror-service.js +13 -0
- package/packages/daemon/dist/terminal/mirror/native-atomic-snapshot.js +17 -7
- package/packages/daemon/dist/terminal/mirror/native-grid-capture.js +129 -5
- package/packages/daemon/dist/terminal/mirror/pane-feed.js +4 -0
- package/packages/daemon/dist/terminal/mirror/pane-hold.js +13 -0
- package/packages/daemon/dist/terminal/mirror/session-channel.js +198 -27
- package/packages/daemon/dist/terminal/pane-stream/lease-manager.js +1 -0
- package/packages/daemon/dist/terminal/pane-stream/pane-stream-websocket.js +184 -12
- package/packages/daemon/dist/terminal/protocol/layout-parse.js +99 -10
- package/packages/daemon/dist/terminal/protocol/session-descriptor-discovery.js +5 -2
- package/packages/daemon/dist/terminal/session-runtime/terminal-interpreter-backend.js +2 -1
- package/packages/daemon/dist/terminal/session-runtime/terminal-replica-interpreter.js +46 -1
- package/packages/daemon/dist/terminal/session-runtime/terminal-replica-owner.js +128 -3
- package/packages/daemon/dist/terminal/session-runtime/xterm-terminal-interpreter-backend.js +115 -6
- package/packages/daemon/dist/tui/mirror/open-tui-workspace-runtime-port.js +19 -1
- package/packages/daemon/dist/tui/mirror/runtime/open-tui-generation-host.js +9 -1
- package/packages/daemon/dist/tui/mirror/workspace/connection-feedback.js +8 -0
- package/packages/daemon/src/command-center/resources/terminal-runtime-inventory.ts +20 -2
- package/packages/daemon/src/command-center/tmux-servers.ts +4 -1
- package/packages/daemon/src/terminal/attachments/native-runtime.ts +15 -1
- package/packages/daemon/src/terminal/mirror/events.ts +31 -1
- package/packages/daemon/src/terminal/mirror/mirror-service.ts +19 -0
- package/packages/daemon/src/terminal/mirror/native-atomic-snapshot.ts +16 -5
- package/packages/daemon/src/terminal/mirror/native-grid-capture.ts +164 -5
- package/packages/daemon/src/terminal/mirror/pane-feed.ts +5 -0
- package/packages/daemon/src/terminal/mirror/pane-hold.ts +16 -0
- package/packages/daemon/src/terminal/mirror/session-channel.ts +253 -38
- package/packages/daemon/src/terminal/mirror/trusted-inventory.ts +2 -0
- package/packages/daemon/src/terminal/pane-stream/lease-manager.ts +3 -0
- package/packages/daemon/src/terminal/pane-stream/pane-stream-websocket.ts +215 -12
- package/packages/daemon/src/terminal/protocol/layout-parse.ts +109 -10
- package/packages/daemon/src/terminal/protocol/session-descriptor-discovery.ts +10 -1
- package/packages/daemon/src/terminal/session-runtime/runtime-observability.ts +2 -1
- package/packages/daemon/src/terminal/session-runtime/terminal-interpreter-backend.ts +24 -1
- package/packages/daemon/src/terminal/session-runtime/terminal-replica-interpreter.ts +61 -5
- package/packages/daemon/src/terminal/session-runtime/terminal-replica-owner.ts +159 -32
- package/packages/daemon/src/terminal/session-runtime/xterm-terminal-interpreter-backend.ts +134 -11
- package/packages/daemon/src/tui/mirror/open-tui-workspace-runtime-port.ts +19 -0
- package/packages/daemon/src/tui/mirror/runtime/open-tui-generation-host.ts +13 -0
- package/packages/daemon/src/tui/mirror/workspace/connection-feedback.ts +13 -1
- package/packages/daemon-client/src/direct-application-shell-transport.ts +6 -2
- package/packages/daemon-client/src/pane-stream-client.ts +24 -6
- package/packages/daemon-client/src/workspace-client-types.ts +6 -0
- package/packages/daemon-client/src/workspace-client.ts +15 -9
- package/packages/daemon-client/src/workspace-event-supervisor.ts +3 -1
|
@@ -28,8 +28,12 @@ import {
|
|
|
28
28
|
PANE_STREAM_BROWSER_KIND_CAPABILITY_VERSION,
|
|
29
29
|
PANE_STREAM_READER_TOPOLOGY_BUNDLE_CAPABILITY_VERSION,
|
|
30
30
|
PANE_STREAM_TOPOLOGY_IN_PLACE_CAPABILITY_VERSION,
|
|
31
|
+
PANE_STREAM_PANE_HELD_CLOSE_CODE,
|
|
32
|
+
paneHeldCloseReason,
|
|
31
33
|
type PaneStreamInputLifetime,
|
|
34
|
+
type PaneStreamPaneHold,
|
|
32
35
|
} from "@tmux-ide/contracts";
|
|
36
|
+
import { MirrorPaneHeldError } from "../mirror/pane-hold.ts";
|
|
33
37
|
import { inflateSync } from "node:zlib";
|
|
34
38
|
import { PaneStreamLayoutSnapshotFrameSchemaZ, type WindowLinkTopology } from "@tmux-ide/contracts";
|
|
35
39
|
import type { TerminalDeliveryGraphics } from "../session-runtime/terminal-delivery-hub.ts";
|
|
@@ -205,6 +209,14 @@ function semanticBackendRefusal(error: unknown): string | null {
|
|
|
205
209
|
}
|
|
206
210
|
const TYPE_FIRST_INPUT_FRAME_PREFIX = Buffer.from('{"type":"input",', "utf8");
|
|
207
211
|
|
|
212
|
+
/**
|
|
213
|
+
* #882: the panes a stream can attach to and the layout covers. A floating
|
|
214
|
+
* pane is listed by the description but has no tiled cell, so it is left out.
|
|
215
|
+
*/
|
|
216
|
+
function tiledPanes(described: MirrorSessionDescription): MirrorSessionDescription["panes"] {
|
|
217
|
+
return described.panes.filter((pane) => pane.floating !== true);
|
|
218
|
+
}
|
|
219
|
+
|
|
208
220
|
function startsWithBuffer(raw: Buffer, prefix: Buffer): boolean {
|
|
209
221
|
return (
|
|
210
222
|
raw.length >= prefix.length && raw.compare(prefix, 0, prefix.length, 0, prefix.length) === 0
|
|
@@ -236,6 +248,8 @@ export interface PaneStreamMirror {
|
|
|
236
248
|
expectedSemanticPaneIds?: readonly string[],
|
|
237
249
|
): Promise<{ readonly description: MirrorSessionDescription; readonly runtimeSessionId: string }>;
|
|
238
250
|
subscribe(request: MirrorSubscribeRequest): Promise<MirrorSubscription>;
|
|
251
|
+
/** #872: a person's retry; the panes' next recoveries ask tmux even inside a hold. */
|
|
252
|
+
liftRecoveryHolds?(session: string, semanticPaneIds: readonly string[]): void;
|
|
239
253
|
subscribeLayout?(
|
|
240
254
|
session: string,
|
|
241
255
|
onLayout: (event: MirrorLayoutEvent) => void,
|
|
@@ -350,6 +364,12 @@ export interface PaneStreamAdmissionCoordinatorOptions {
|
|
|
350
364
|
readonly drainTickMs?: number;
|
|
351
365
|
/** Waits between tries of a step of a stream's opening that failed (#585). */
|
|
352
366
|
readonly openRetryDelaysMs?: readonly number[];
|
|
367
|
+
/**
|
|
368
|
+
* Waits between later tries of a pane whose delivery still failed after the
|
|
369
|
+
* opening's tries, while the stream runs without it (#585). Empty: that
|
|
370
|
+
* pane's failure closes the stream at once.
|
|
371
|
+
*/
|
|
372
|
+
readonly deferredPaneRetryDelaysMs?: readonly number[];
|
|
353
373
|
/** How long input waits for registered-window ownership to be read again. */
|
|
354
374
|
readonly ownershipWaitMs?: number;
|
|
355
375
|
/** Hard whole-socket ceiling; the ledger should stall panes far earlier. */
|
|
@@ -472,6 +492,36 @@ function sendControl(socket: DirectTerminalSocket, frame: Readonly<Record<string
|
|
|
472
492
|
socket.send(encoded, { binary: false });
|
|
473
493
|
}
|
|
474
494
|
|
|
495
|
+
/**
|
|
496
|
+
* The hold to close with when every pane that failed to open was held (#872):
|
|
497
|
+
* the longest wait, and too large if any held pane was. Null when any failure
|
|
498
|
+
* was something else.
|
|
499
|
+
*/
|
|
500
|
+
function heldOnly(
|
|
501
|
+
settled: readonly PromiseSettledResult<{
|
|
502
|
+
readonly delivery: { readonly negotiation: { readonly accepted: boolean } };
|
|
503
|
+
}>[],
|
|
504
|
+
): PaneStreamPaneHold | null {
|
|
505
|
+
let retryInMs = 0;
|
|
506
|
+
let tooLarge = false;
|
|
507
|
+
for (const result of settled) {
|
|
508
|
+
if (result.status === "fulfilled") {
|
|
509
|
+
if (!result.value.delivery.negotiation.accepted) return null;
|
|
510
|
+
continue;
|
|
511
|
+
}
|
|
512
|
+
const reason: unknown = result.reason;
|
|
513
|
+
if (!(reason instanceof MirrorPaneHeldError)) return null;
|
|
514
|
+
retryInMs = Math.max(retryInMs, reason.hold.retryInMs);
|
|
515
|
+
tooLarge ||= reason.hold.why === "too-large";
|
|
516
|
+
}
|
|
517
|
+
// Called only when a pane did not open, so at least one was held here.
|
|
518
|
+
return { retryInMs, why: tooLarge ? "too-large" : "failed" };
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
function errorText(error: unknown): string {
|
|
522
|
+
return (error instanceof Error ? error.message : String(error)).slice(0, 300);
|
|
523
|
+
}
|
|
524
|
+
|
|
475
525
|
function errorFrameCode(error: unknown): PaneStreamErrorFrameCode {
|
|
476
526
|
if (error instanceof PaneStreamLeaseError && error.code === "ticket-expired") {
|
|
477
527
|
return "ticket-expired";
|
|
@@ -511,6 +561,7 @@ export class PaneStreamAdmissionCoordinator {
|
|
|
511
561
|
readonly #flowBudgets: PaneStreamFlowBudgets;
|
|
512
562
|
readonly #drainTickMs: number;
|
|
513
563
|
readonly #openRetryDelaysMs: readonly number[];
|
|
564
|
+
readonly #deferredPaneRetryDelaysMs: readonly number[];
|
|
514
565
|
readonly #ownershipWaitMs: number;
|
|
515
566
|
readonly #maxSocketBufferedBytes: number;
|
|
516
567
|
readonly #maxInputFrames: number;
|
|
@@ -553,6 +604,8 @@ export class PaneStreamAdmissionCoordinator {
|
|
|
553
604
|
this.#ledger = new PaneStreamWireLedger(this.#flowBudgets);
|
|
554
605
|
this.#drainTickMs = boundedInteger(options.drainTickMs, 15, 1_000);
|
|
555
606
|
this.#openRetryDelaysMs = options.openRetryDelaysMs ?? PANE_STREAM_OPEN_RETRY_DELAYS_MS;
|
|
607
|
+
this.#deferredPaneRetryDelaysMs =
|
|
608
|
+
options.deferredPaneRetryDelaysMs ?? PANE_STREAM_DEFERRED_PANE_RETRY_DELAYS_MS;
|
|
556
609
|
this.#ownershipWaitMs = options.ownershipWaitMs ?? PANE_STREAM_OWNERSHIP_WAIT_MS;
|
|
557
610
|
this.#maxSocketBufferedBytes = boundedInteger(
|
|
558
611
|
options.maxSocketBufferedBytes,
|
|
@@ -633,13 +686,20 @@ export class PaneStreamAdmissionCoordinator {
|
|
|
633
686
|
this.#observability!.nowMicros(),
|
|
634
687
|
trace,
|
|
635
688
|
);
|
|
636
|
-
} catch {
|
|
689
|
+
} catch (error) {
|
|
690
|
+
// #585: the client is told only "stream-unavailable"; the log keeps why.
|
|
691
|
+
logger.info("pane-stream", "stream refused", {
|
|
692
|
+
step: "issue",
|
|
693
|
+
cause: "describe-session-failed",
|
|
694
|
+
session: context.sessionName,
|
|
695
|
+
error: errorText(error),
|
|
696
|
+
});
|
|
637
697
|
throw new PaneStreamAdmissionError(
|
|
638
698
|
"stream-unavailable",
|
|
639
699
|
"The workspace session could not be described.",
|
|
640
700
|
);
|
|
641
701
|
}
|
|
642
|
-
const known = new Set(described.
|
|
702
|
+
const known = new Set(tiledPanes(described).map((pane) => pane.semanticPaneId));
|
|
643
703
|
for (const pane of request.panes) {
|
|
644
704
|
if (!known.has(pane)) {
|
|
645
705
|
throw new PaneStreamAdmissionError(
|
|
@@ -652,7 +712,7 @@ export class PaneStreamAdmissionCoordinator {
|
|
|
652
712
|
// panes, as the trusted inventory places them now.
|
|
653
713
|
if (request.semanticWindowId !== undefined) {
|
|
654
714
|
const windowPanes = new Set(
|
|
655
|
-
described
|
|
715
|
+
tiledPanes(described)
|
|
656
716
|
.filter((pane) => pane.semanticWindowId === request.semanticWindowId)
|
|
657
717
|
.map((pane) => pane.semanticPaneId),
|
|
658
718
|
);
|
|
@@ -960,6 +1020,7 @@ export class PaneStreamAdmissionCoordinator {
|
|
|
960
1020
|
ledger: this.#ledger,
|
|
961
1021
|
drainTickMs: this.#drainTickMs,
|
|
962
1022
|
openRetryDelaysMs: this.#openRetryDelaysMs,
|
|
1023
|
+
deferredPaneRetryDelaysMs: this.#deferredPaneRetryDelaysMs,
|
|
963
1024
|
ownershipWaitMs: this.#ownershipWaitMs,
|
|
964
1025
|
maxSocketBufferedBytes: this.#maxSocketBufferedBytes,
|
|
965
1026
|
maxInputFrames: this.#maxInputFrames,
|
|
@@ -1146,6 +1207,11 @@ class PreAuthAdmission implements PaneStreamPreAuthAdmission {
|
|
|
1146
1207
|
void this.#onRedeem(this, frame, socket).catch((error: unknown) => {
|
|
1147
1208
|
if (!this.#open) return;
|
|
1148
1209
|
const code = errorFrameCode(error);
|
|
1210
|
+
logger.info("pane-stream", "stream refused", {
|
|
1211
|
+
step: "redeem",
|
|
1212
|
+
code,
|
|
1213
|
+
error: errorText(error),
|
|
1214
|
+
});
|
|
1149
1215
|
try {
|
|
1150
1216
|
sendControl(socket, {
|
|
1151
1217
|
type: "error",
|
|
@@ -1188,6 +1254,7 @@ interface LiveConnectionOptions {
|
|
|
1188
1254
|
readonly ledger: PaneStreamWireLedger;
|
|
1189
1255
|
readonly drainTickMs: number;
|
|
1190
1256
|
readonly openRetryDelaysMs: readonly number[];
|
|
1257
|
+
readonly deferredPaneRetryDelaysMs: readonly number[];
|
|
1191
1258
|
readonly ownershipWaitMs: number;
|
|
1192
1259
|
readonly maxSocketBufferedBytes: number;
|
|
1193
1260
|
readonly maxInputFrames: number;
|
|
@@ -1227,6 +1294,12 @@ interface OpenedPaneDelivery {
|
|
|
1227
1294
|
|
|
1228
1295
|
/** About half a second in all: long enough for one slow tmux answer, short for a user. */
|
|
1229
1296
|
export const PANE_STREAM_OPEN_RETRY_DELAYS_MS: readonly number[] = [150, 400];
|
|
1297
|
+
/**
|
|
1298
|
+
* A pane whose delivery still fails after those is tried again this long
|
|
1299
|
+
* after the stream opened without it (about 7 s in all, inside the terminal
|
|
1300
|
+
* app's 15 s wait for a hidden pane's state). Then the stream closes (#585).
|
|
1301
|
+
*/
|
|
1302
|
+
export const PANE_STREAM_DEFERRED_PANE_RETRY_DELAYS_MS: readonly number[] = [1_000, 2_000, 4_000];
|
|
1230
1303
|
/** Input waits this long for ownership to be read again before the stream closes. */
|
|
1231
1304
|
export const PANE_STREAM_OWNERSHIP_WAIT_MS = 2_000;
|
|
1232
1305
|
/** At most this many input and geometry frames wait for it. */
|
|
@@ -1321,6 +1394,9 @@ export class PaneStreamLiveConnection {
|
|
|
1321
1394
|
readonly #ledger: PaneStreamWireLedger;
|
|
1322
1395
|
readonly #drainTickMs: number;
|
|
1323
1396
|
readonly #openRetryDelaysMs: readonly number[];
|
|
1397
|
+
/** Waits of `#deferPane`; a close ends them at once (#585). */
|
|
1398
|
+
readonly #deferralWaits = new Set<{ timer: ReturnType<typeof setTimeout>; wake: () => void }>();
|
|
1399
|
+
readonly #deferredPaneRetryDelaysMs: readonly number[];
|
|
1324
1400
|
readonly #ownershipWaitMs: number;
|
|
1325
1401
|
readonly #maxSocketBufferedBytes: number;
|
|
1326
1402
|
readonly #maxInputFrames: number;
|
|
@@ -1466,6 +1542,7 @@ export class PaneStreamLiveConnection {
|
|
|
1466
1542
|
this.#ledger = options.ledger;
|
|
1467
1543
|
this.#drainTickMs = options.drainTickMs;
|
|
1468
1544
|
this.#openRetryDelaysMs = options.openRetryDelaysMs;
|
|
1545
|
+
this.#deferredPaneRetryDelaysMs = options.deferredPaneRetryDelaysMs;
|
|
1469
1546
|
this.#ownershipWaitMs = options.ownershipWaitMs ?? PANE_STREAM_OWNERSHIP_WAIT_MS;
|
|
1470
1547
|
this.#maxSocketBufferedBytes = options.maxSocketBufferedBytes;
|
|
1471
1548
|
this.#maxInputFrames = options.maxInputFrames;
|
|
@@ -1553,10 +1630,11 @@ export class PaneStreamLiveConnection {
|
|
|
1553
1630
|
* none of them. The log says which one, with the error text, so a stream
|
|
1554
1631
|
* that "just closed" can be traced without a reproduction.
|
|
1555
1632
|
*/
|
|
1556
|
-
#fail(cause: string, error?: unknown): void {
|
|
1633
|
+
#fail(cause: string, error?: unknown, pane?: string): void {
|
|
1557
1634
|
if (this.#closed) return;
|
|
1558
1635
|
this.#closeCause = {
|
|
1559
1636
|
cause,
|
|
1637
|
+
...(pane === undefined ? {} : { pane }),
|
|
1560
1638
|
...(error === undefined
|
|
1561
1639
|
? {}
|
|
1562
1640
|
: { error: (error instanceof Error ? error.message : String(error)).slice(0, 300) }),
|
|
@@ -1564,6 +1642,17 @@ export class PaneStreamLiveConnection {
|
|
|
1564
1642
|
this.close(1011, "stream-unavailable");
|
|
1565
1643
|
}
|
|
1566
1644
|
|
|
1645
|
+
/**
|
|
1646
|
+
* #872: every pane that did not open is held back after failed recoveries.
|
|
1647
|
+
* "Try again later", with the time left and why, so a client can say so
|
|
1648
|
+
* instead of counting attempts. The client reconnects as for any close.
|
|
1649
|
+
*/
|
|
1650
|
+
#closeHeld(hold: PaneStreamPaneHold, pane?: string): void {
|
|
1651
|
+
if (this.#closed) return;
|
|
1652
|
+
this.#closeCause = { cause: "pane-held", ...(pane === undefined ? {} : { pane }) };
|
|
1653
|
+
this.close(PANE_STREAM_PANE_HELD_CLOSE_CODE, paneHeldCloseReason(hold));
|
|
1654
|
+
}
|
|
1655
|
+
|
|
1567
1656
|
close(code = 1000, reason = "stream-closed"): void {
|
|
1568
1657
|
if (this.#closed) return;
|
|
1569
1658
|
this.#recordDiagnosticLifecycle("pane-stream-terminal", code, reason);
|
|
@@ -1582,6 +1671,11 @@ export class PaneStreamLiveConnection {
|
|
|
1582
1671
|
: {}),
|
|
1583
1672
|
});
|
|
1584
1673
|
this.#closed = true;
|
|
1674
|
+
for (const { timer, wake } of this.#deferralWaits) {
|
|
1675
|
+
clearTimeout(timer);
|
|
1676
|
+
wake();
|
|
1677
|
+
}
|
|
1678
|
+
this.#deferralWaits.clear();
|
|
1585
1679
|
this.#ownershipHeld.length = 0;
|
|
1586
1680
|
this.#ownershipWake?.();
|
|
1587
1681
|
for (const demand of this.#surfaceDemands.values()) demand.close();
|
|
@@ -1658,7 +1752,7 @@ export class PaneStreamLiveConnection {
|
|
|
1658
1752
|
return;
|
|
1659
1753
|
}
|
|
1660
1754
|
if (this.#closed) return;
|
|
1661
|
-
const known = new Set(described.
|
|
1755
|
+
const known = new Set(tiledPanes(described).map((pane) => pane.semanticPaneId));
|
|
1662
1756
|
if (this.#descriptor.terminalDelivery) {
|
|
1663
1757
|
await this.#subscribeSemantic(known);
|
|
1664
1758
|
return;
|
|
@@ -1850,20 +1944,50 @@ export class PaneStreamLiveConnection {
|
|
|
1850
1944
|
// removes N x attachment latency without allowing a fast pane to make the
|
|
1851
1945
|
// session look ready while a sibling is still missing. allSettled is
|
|
1852
1946
|
// deliberate: partial success is always closed before the socket retires.
|
|
1947
|
+
if (this.#descriptor.retryAskedByPerson)
|
|
1948
|
+
this.#mirror.liftRecoveryHolds?.(
|
|
1949
|
+
this.#descriptor.sessionName,
|
|
1950
|
+
channels.map((channel) => channel.semanticPaneId),
|
|
1951
|
+
);
|
|
1853
1952
|
const openings = channels.map((channel) => this.#openPaneDelivery(binding, offer, channel));
|
|
1854
1953
|
const settled = await Promise.allSettled(openings);
|
|
1855
1954
|
const opened = settled.flatMap((result) =>
|
|
1856
1955
|
result.status === "fulfilled" ? [result.value] : [],
|
|
1857
1956
|
);
|
|
1957
|
+
// #585: one pane that still fails no longer takes the others down. The
|
|
1958
|
+
// stream opens without it and the pane is tried again (`#deferPane`). A
|
|
1959
|
+
// refusal (authority, or a delivery offer not accepted) still closes it.
|
|
1960
|
+
const deferred = channels.flatMap((channel, index) => {
|
|
1961
|
+
const result = settled[index]!;
|
|
1962
|
+
return result.status === "rejected" ? [{ channel, error: result.reason as unknown }] : [];
|
|
1963
|
+
});
|
|
1964
|
+
const deferrable =
|
|
1965
|
+
deferred.length > 0 &&
|
|
1966
|
+
deferred.length < channels.length &&
|
|
1967
|
+
this.#deferredPaneRetryDelaysMs.length > 0 &&
|
|
1968
|
+
opened.every(({ delivery }) => delivery.negotiation.accepted) &&
|
|
1969
|
+
// A held pane is refused until its hold ends: deferred tries only
|
|
1970
|
+
// repeat the refusal, so it closes at once with its hold (#872).
|
|
1971
|
+
deferred.every(
|
|
1972
|
+
({ error }) =>
|
|
1973
|
+
!(error instanceof SessionRuntimeControllerLeaseError) &&
|
|
1974
|
+
!(error instanceof MirrorPaneHeldError),
|
|
1975
|
+
);
|
|
1858
1976
|
if (
|
|
1859
1977
|
this.#closed ||
|
|
1860
|
-
|
|
1861
|
-
(
|
|
1862
|
-
|
|
1978
|
+
(!deferrable &&
|
|
1979
|
+
settled.some(
|
|
1980
|
+
(result) => result.status === "rejected" || !result.value.delivery.negotiation.accepted,
|
|
1981
|
+
))
|
|
1863
1982
|
) {
|
|
1864
1983
|
await Promise.all(opened.map(({ delivery }) => delivery.close().catch(() => undefined)));
|
|
1865
1984
|
if (!this.#closed) {
|
|
1866
1985
|
const rejected = settled.find((result) => result.status === "rejected");
|
|
1986
|
+
const hold = heldOnly(settled);
|
|
1987
|
+
if (hold) {
|
|
1988
|
+
this.#closeHeld(hold);
|
|
1989
|
+
return;
|
|
1990
|
+
}
|
|
1867
1991
|
this.#fail(
|
|
1868
1992
|
"delivery-negotiation-failed",
|
|
1869
1993
|
rejected?.status === "rejected" ? rejected.reason : "a pane's delivery offer was refused",
|
|
@@ -1933,21 +2057,91 @@ export class PaneStreamLiveConnection {
|
|
|
1933
2057
|
Number(visibleAtDelivery.has(left.channel.semanticPaneId)),
|
|
1934
2058
|
);
|
|
1935
2059
|
await this.#publishOpenedDeliveries(opened);
|
|
2060
|
+
if (deferrable)
|
|
2061
|
+
for (const { channel, error } of deferred)
|
|
2062
|
+
void this.#deferPane(binding, offer, channel, error);
|
|
1936
2063
|
this.#closeIfAllPanesGone();
|
|
1937
2064
|
}
|
|
1938
2065
|
|
|
2066
|
+
/**
|
|
2067
|
+
* A pane left out of the opening (#585): try its delivery again after each
|
|
2068
|
+
* deferred delay and announce it like a pane added in place. Only when
|
|
2069
|
+
* every try failed does the stream close, naming the pane.
|
|
2070
|
+
*/
|
|
2071
|
+
async #deferPane(
|
|
2072
|
+
binding: SessionRuntimePaneStreamTransportBinding,
|
|
2073
|
+
offer: NonNullable<PaneStreamLeaseDescriptor["terminalDelivery"]>,
|
|
2074
|
+
channel: PaneChannel,
|
|
2075
|
+
firstError: unknown,
|
|
2076
|
+
): Promise<void> {
|
|
2077
|
+
const gone = () =>
|
|
2078
|
+
this.#closed || channel.closed || this.#panes.get(channel.semanticPaneId) !== channel;
|
|
2079
|
+
let error = firstError;
|
|
2080
|
+
for (const [index, delayMs] of this.#deferredPaneRetryDelaysMs.entries()) {
|
|
2081
|
+
if (gone()) return;
|
|
2082
|
+
logger.info("pane-stream", "pane delivery deferred", {
|
|
2083
|
+
session: this.#descriptor.sessionName,
|
|
2084
|
+
clientId: this.#clientId,
|
|
2085
|
+
pane: channel.semanticPaneId,
|
|
2086
|
+
attempt: index + 1,
|
|
2087
|
+
error: errorText(error),
|
|
2088
|
+
});
|
|
2089
|
+
await new Promise<void>((resolve) => {
|
|
2090
|
+
const wait = {
|
|
2091
|
+
timer: setTimeout(() => {
|
|
2092
|
+
this.#deferralWaits.delete(wait);
|
|
2093
|
+
resolve();
|
|
2094
|
+
}, delayMs),
|
|
2095
|
+
wake: resolve,
|
|
2096
|
+
};
|
|
2097
|
+
wait.timer.unref?.();
|
|
2098
|
+
this.#deferralWaits.add(wait);
|
|
2099
|
+
});
|
|
2100
|
+
if (gone()) return;
|
|
2101
|
+
let entry: OpenedPaneDelivery;
|
|
2102
|
+
try {
|
|
2103
|
+
entry = await this.#openPaneDelivery(binding, offer, channel, false);
|
|
2104
|
+
} catch (cause) {
|
|
2105
|
+
if (cause instanceof SessionRuntimeControllerLeaseError) {
|
|
2106
|
+
this.#fail("pane-delivery-open-failed", cause, channel.semanticPaneId);
|
|
2107
|
+
return;
|
|
2108
|
+
}
|
|
2109
|
+
// The pane became held during its deferred tries (#872).
|
|
2110
|
+
if (cause instanceof MirrorPaneHeldError) {
|
|
2111
|
+
if (!gone()) this.#closeHeld(cause.hold, channel.semanticPaneId);
|
|
2112
|
+
return;
|
|
2113
|
+
}
|
|
2114
|
+
error = cause;
|
|
2115
|
+
continue;
|
|
2116
|
+
}
|
|
2117
|
+
if (gone()) {
|
|
2118
|
+
await entry.delivery.close().catch(() => undefined);
|
|
2119
|
+
return;
|
|
2120
|
+
}
|
|
2121
|
+
if (!entry.delivery.negotiation.accepted || this.#deliveryIdentityChanged(entry)) {
|
|
2122
|
+
await entry.delivery.close().catch(() => undefined);
|
|
2123
|
+
this.#failTopologyChanged();
|
|
2124
|
+
return;
|
|
2125
|
+
}
|
|
2126
|
+
await this.#publishOpenedDeliveries([entry]);
|
|
2127
|
+
return;
|
|
2128
|
+
}
|
|
2129
|
+
if (!gone()) this.#fail("pane-delivery-open-failed", error, channel.semanticPaneId);
|
|
2130
|
+
}
|
|
2131
|
+
|
|
1939
2132
|
/** Open one pane's delivery; its messages wait until the pane is announced. */
|
|
1940
2133
|
async #openPaneDelivery(
|
|
1941
2134
|
binding: SessionRuntimePaneStreamTransportBinding,
|
|
1942
2135
|
offer: NonNullable<PaneStreamLeaseDescriptor["terminalDelivery"]>,
|
|
1943
2136
|
channel: PaneChannel,
|
|
2137
|
+
retry = true,
|
|
1944
2138
|
): Promise<OpenedPaneDelivery> {
|
|
1945
2139
|
const pending: TerminalDeliveryServerMessage[] = [];
|
|
1946
2140
|
let ready = false;
|
|
1947
2141
|
let negotiated = false;
|
|
1948
2142
|
// #585: a failed open is tried again (150 ms, 400 ms) before the stream
|
|
1949
2143
|
// closes; this applies to a pane added in place too.
|
|
1950
|
-
const
|
|
2144
|
+
const open = () => {
|
|
1951
2145
|
// A try that failed may have delivered something; start clean.
|
|
1952
2146
|
pending.length = 0;
|
|
1953
2147
|
return binding.openTerminalDelivery(
|
|
@@ -1960,7 +2154,16 @@ export class PaneStreamLiveConnection {
|
|
|
1960
2154
|
},
|
|
1961
2155
|
this.#descriptor.workspaceName,
|
|
1962
2156
|
);
|
|
1963
|
-
}
|
|
2157
|
+
};
|
|
2158
|
+
// A held pane is refused without asking tmux until its hold ends: trying
|
|
2159
|
+
// again inside the same stream only repeats the refusal (#872).
|
|
2160
|
+
const delivery = retry
|
|
2161
|
+
? await this.#retryOpenStep(
|
|
2162
|
+
"pane-delivery-open",
|
|
2163
|
+
open,
|
|
2164
|
+
(error) => error instanceof MirrorPaneHeldError,
|
|
2165
|
+
)
|
|
2166
|
+
: await open();
|
|
1964
2167
|
return {
|
|
1965
2168
|
channel,
|
|
1966
2169
|
delivery,
|
|
@@ -2820,7 +3023,7 @@ export class PaneStreamLiveConnection {
|
|
|
2820
3023
|
return this.#topologyFailed("session inventory unavailable", error);
|
|
2821
3024
|
}
|
|
2822
3025
|
if (this.#closed) return this.#topologyFailed("closed");
|
|
2823
|
-
const next = [...new Set(described.
|
|
3026
|
+
const next = [...new Set(tiledPanes(described).map((pane) => pane.semanticPaneId))].sort();
|
|
2824
3027
|
if (next.length === 0) return this.#topologyFailed("session has no panes");
|
|
2825
3028
|
const frames = this.#validateInitialLayout(snapshot.layouts, next);
|
|
2826
3029
|
if (!frames) return "stale";
|
|
@@ -2841,7 +3044,7 @@ export class PaneStreamLiveConnection {
|
|
|
2841
3044
|
if (window !== null) {
|
|
2842
3045
|
windowPanes = [
|
|
2843
3046
|
...new Set(
|
|
2844
|
-
described
|
|
3047
|
+
tiledPanes(described)
|
|
2845
3048
|
.filter((pane) => pane.semanticWindowId === window)
|
|
2846
3049
|
.map((pane) => pane.semanticPaneId),
|
|
2847
3050
|
),
|
|
@@ -38,7 +38,51 @@ export interface ParsedLayout {
|
|
|
38
38
|
/** The root cell's WxH — the authoritative window size. */
|
|
39
39
|
width: number;
|
|
40
40
|
height: number;
|
|
41
|
+
/** The tiled panes only. */
|
|
41
42
|
leaves: LayoutLeaf[];
|
|
43
|
+
/**
|
|
44
|
+
* #882: floating panes, listed but not placed in the tiled tree. Present
|
|
45
|
+
* only when tmux-ide's bundled tmux (3.7c) sends its `<…>` section; stock
|
|
46
|
+
* tmux 3.8 leaves floating panes out of a control client's layout.
|
|
47
|
+
*/
|
|
48
|
+
floating?: LayoutLeaf[];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* #882: the bundled build appends `<cell,cell…>`, one leaf cell per floating
|
|
53
|
+
* pane, and also lists each one as an extra child of the root split, where it
|
|
54
|
+
* overlaps the tiled panes. Split the string into the tiled part and the
|
|
55
|
+
* floating leaves; each floating id must occur exactly once in the tiled part
|
|
56
|
+
* and once in the section. Null when the section is malformed.
|
|
57
|
+
*/
|
|
58
|
+
function splitFloating(s: string): { tiled: string; floating: LayoutLeaf[] } | null {
|
|
59
|
+
if (!s.endsWith(">")) return { tiled: s, floating: [] };
|
|
60
|
+
const open = s.lastIndexOf("<");
|
|
61
|
+
if (open <= 0) return null;
|
|
62
|
+
const section = s.slice(open + 1, -1);
|
|
63
|
+
const floating: LayoutLeaf[] = [];
|
|
64
|
+
let pos = 0;
|
|
65
|
+
while (pos < section.length) {
|
|
66
|
+
const dims = readDims(section, pos);
|
|
67
|
+
if (!dims || section[dims.pos] !== ",") return null;
|
|
68
|
+
const id = readInt(section, dims.pos + 1);
|
|
69
|
+
if (!id) return null;
|
|
70
|
+
floating.push({
|
|
71
|
+
id: `%${id.value}`,
|
|
72
|
+
left: dims.left,
|
|
73
|
+
top: dims.top,
|
|
74
|
+
width: dims.width,
|
|
75
|
+
height: dims.height,
|
|
76
|
+
});
|
|
77
|
+
pos = id.pos;
|
|
78
|
+
if (pos === section.length) break;
|
|
79
|
+
if (section[pos] !== ",") return null;
|
|
80
|
+
pos += 1;
|
|
81
|
+
if (pos === section.length) return null;
|
|
82
|
+
}
|
|
83
|
+
if (floating.length === 0) return null;
|
|
84
|
+
if (new Set(floating.map((leaf) => leaf.id)).size !== floating.length) return null;
|
|
85
|
+
return { tiled: s.slice(0, open), floating };
|
|
42
86
|
}
|
|
43
87
|
|
|
44
88
|
/** Opt-in validated ancestry. Runtime pane IDs are not semantic pane identities. */
|
|
@@ -67,22 +111,50 @@ interface TreeContext {
|
|
|
67
111
|
*/
|
|
68
112
|
export function parseLayoutTree(layout: string): LayoutTreeNode | null {
|
|
69
113
|
if (layout.length > 64 * 1024 || !/^[0-9a-fA-F]{4},/.test(layout)) return null;
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
114
|
+
const split = splitFloating(layout.slice(5));
|
|
115
|
+
if (!split) return null;
|
|
116
|
+
const s = split.tiled;
|
|
117
|
+
const skip = floatingIds(split.floating);
|
|
118
|
+
const root = parseCell(s, 0, [], { nodes: 0, ids: new Set() }, 1, skip);
|
|
119
|
+
if (
|
|
120
|
+
!root?.node ||
|
|
121
|
+
root.pos !== s.length ||
|
|
122
|
+
root.node.left !== 0 ||
|
|
123
|
+
root.node.top !== 0 ||
|
|
124
|
+
!skip.allSeenOnce()
|
|
125
|
+
)
|
|
73
126
|
return null;
|
|
74
127
|
return root.node;
|
|
75
128
|
}
|
|
76
129
|
|
|
130
|
+
/** The floating ids to leave out of the tiled tree, each to be seen once. */
|
|
131
|
+
function floatingIds(floating: readonly LayoutLeaf[]) {
|
|
132
|
+
const seen = new Map(floating.map((leaf) => [leaf.id, 0]));
|
|
133
|
+
return {
|
|
134
|
+
has: (id: string) => seen.has(id),
|
|
135
|
+
see: (id: string) => seen.set(id, (seen.get(id) ?? 0) + 1),
|
|
136
|
+
allSeenOnce: () => [...seen.values()].every((count) => count === 1),
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
type FloatingIds = ReturnType<typeof floatingIds>;
|
|
140
|
+
|
|
77
141
|
/** Parse a tmux layout string (`csum,WxH,X,Y…`). Null on any malformed input
|
|
78
142
|
* (the caller falls back to the slow list-panes path — never throw here). */
|
|
79
143
|
export function parseLayout(layout: string): ParsedLayout | null {
|
|
80
144
|
if (!/^[0-9a-fA-F]{4},/.test(layout)) return null;
|
|
81
|
-
const
|
|
145
|
+
const split = splitFloating(layout.slice(5));
|
|
146
|
+
if (!split) return null;
|
|
147
|
+
const s = split.tiled;
|
|
148
|
+
const skip = floatingIds(split.floating);
|
|
82
149
|
const leaves: LayoutLeaf[] = [];
|
|
83
|
-
const root = parseCell(s, 0, leaves);
|
|
84
|
-
if (!root || root.pos !== s.length) return null;
|
|
85
|
-
return {
|
|
150
|
+
const root = parseCell(s, 0, leaves, undefined, 1, skip);
|
|
151
|
+
if (!root || root.pos !== s.length || !skip.allSeenOnce() || leaves.length === 0) return null;
|
|
152
|
+
return {
|
|
153
|
+
width: root.width,
|
|
154
|
+
height: root.height,
|
|
155
|
+
leaves,
|
|
156
|
+
...(split.floating.length > 0 ? { floating: split.floating } : {}),
|
|
157
|
+
};
|
|
86
158
|
}
|
|
87
159
|
|
|
88
160
|
/** Recursive-descent cell parse from `pos`; appends leaves in layout order. */
|
|
@@ -92,7 +164,15 @@ function parseCell(
|
|
|
92
164
|
leaves: LayoutLeaf[],
|
|
93
165
|
tree?: TreeContext,
|
|
94
166
|
depth = 1,
|
|
95
|
-
|
|
167
|
+
skip?: FloatingIds,
|
|
168
|
+
): {
|
|
169
|
+
width: number;
|
|
170
|
+
height: number;
|
|
171
|
+
pos: number;
|
|
172
|
+
node?: LayoutTreeNode;
|
|
173
|
+
/** #882: a floating pane's copy inside the tiled part; its parent drops it. */
|
|
174
|
+
floating?: true;
|
|
175
|
+
} | null {
|
|
96
176
|
if (tree && (depth > 64 || ++tree.nodes > MAX_TREE_LEAVES * 2 - 1)) return null;
|
|
97
177
|
const dims = readDims(s, pos);
|
|
98
178
|
if (!dims) return null;
|
|
@@ -113,6 +193,10 @@ function parseCell(
|
|
|
113
193
|
const id = readInt(s, pos + 1);
|
|
114
194
|
if (!id) return null;
|
|
115
195
|
const leaf = { id: `%${id.value}`, left, top, width, height };
|
|
196
|
+
if (skip?.has(leaf.id)) {
|
|
197
|
+
skip.see(leaf.id);
|
|
198
|
+
return { width, height, pos: id.pos, floating: true };
|
|
199
|
+
}
|
|
116
200
|
if (tree) {
|
|
117
201
|
if (
|
|
118
202
|
!Number.isSafeInteger(id.value) ||
|
|
@@ -133,11 +217,13 @@ function parseCell(
|
|
|
133
217
|
if (ch === "{" || ch === "[") {
|
|
134
218
|
const close = ch === "{" ? "}" : "]";
|
|
135
219
|
const children: LayoutTreeNode[] = [];
|
|
220
|
+
let droppedFloating = 0;
|
|
136
221
|
pos++;
|
|
137
222
|
for (;;) {
|
|
138
|
-
const child = parseCell(s, pos, leaves, tree, depth + 1);
|
|
223
|
+
const child = parseCell(s, pos, leaves, tree, depth + 1, skip);
|
|
139
224
|
if (!child) return null;
|
|
140
|
-
if (
|
|
225
|
+
if (child.floating) droppedFloating += 1;
|
|
226
|
+
else if (tree && child.node) children.push(child.node);
|
|
141
227
|
pos = child.pos;
|
|
142
228
|
if (s[pos] === ",") {
|
|
143
229
|
pos++;
|
|
@@ -145,6 +231,19 @@ function parseCell(
|
|
|
145
231
|
}
|
|
146
232
|
if (s[pos] === close) {
|
|
147
233
|
if (!tree) return { width, height, pos: pos + 1 };
|
|
234
|
+
// A split left with one tiled child once its floats are dropped is
|
|
235
|
+
// that child (the bundled build wraps a lone pane and its floats).
|
|
236
|
+
// It must fill the split exactly; otherwise tilesParent refuses it.
|
|
237
|
+
const lone = children.length === 1 ? children[0]! : null;
|
|
238
|
+
if (
|
|
239
|
+
droppedFloating > 0 &&
|
|
240
|
+
lone &&
|
|
241
|
+
lone.left === left &&
|
|
242
|
+
lone.top === top &&
|
|
243
|
+
lone.width === width &&
|
|
244
|
+
lone.height === height
|
|
245
|
+
)
|
|
246
|
+
return { width, height, pos: pos + 1, node: lone };
|
|
148
247
|
const axis = ch === "{" ? "cols" : "rows";
|
|
149
248
|
const node: LayoutTreeNode = { kind: "split", axis, left, top, width, height, children };
|
|
150
249
|
if (!tilesParent(node)) return null;
|
|
@@ -29,6 +29,11 @@ export interface SessionPaneDescriptor {
|
|
|
29
29
|
windowActive: boolean;
|
|
30
30
|
windowPaneCount: number;
|
|
31
31
|
sessionWindowCount: number;
|
|
32
|
+
/**
|
|
33
|
+
* #882: a floating pane (tmux 3.7 and later). It has no cell in the tiled
|
|
34
|
+
* layout; tmux older than 3.7 prints nothing and the pane reads as tiled.
|
|
35
|
+
*/
|
|
36
|
+
floating?: boolean;
|
|
32
37
|
}
|
|
33
38
|
|
|
34
39
|
/**
|
|
@@ -66,6 +71,8 @@ export const SESSION_PANE_DESCRIPTOR_FORMAT = [
|
|
|
66
71
|
"#{pane_pid}",
|
|
67
72
|
// Set only by a terminal browser that has tmux-ide's native controls (#718).
|
|
68
73
|
"#{qa:@tmux_ide_browser_control}",
|
|
74
|
+
// #882: tmux 3.7+ floating panes have no cell in the tiled layout.
|
|
75
|
+
"#{pane_floating_flag}",
|
|
69
76
|
].join("\t");
|
|
70
77
|
|
|
71
78
|
/**
|
|
@@ -176,7 +183,7 @@ export function parseSessionPaneDescriptorReply(
|
|
|
176
183
|
continue;
|
|
177
184
|
}
|
|
178
185
|
const encoded = utf8Line.split("\t");
|
|
179
|
-
if (encoded.length < 21 || encoded.length >
|
|
186
|
+
if (encoded.length < 21 || encoded.length > 27) continue;
|
|
180
187
|
const [
|
|
181
188
|
runtimePaneId = "",
|
|
182
189
|
semanticPaneId = "",
|
|
@@ -204,6 +211,7 @@ export function parseSessionPaneDescriptorReply(
|
|
|
204
211
|
readerRaw = "",
|
|
205
212
|
panePidRaw = "",
|
|
206
213
|
browserControl = "",
|
|
214
|
+
floatingRaw = "",
|
|
207
215
|
] = encoded.map(decodeTmuxArgument);
|
|
208
216
|
if (!/^%(?:0|[1-9][0-9]*)$/u.test(runtimePaneId) || runtimePaneId.length > 32) continue;
|
|
209
217
|
if (!/^\$(?:0|[1-9][0-9]*)$/u.test(runtimeSessionId) || runtimeSessionId.length > 32) continue;
|
|
@@ -270,6 +278,7 @@ export function parseSessionPaneDescriptorReply(
|
|
|
270
278
|
windowActive: windowActiveRaw === "1",
|
|
271
279
|
windowPaneCount,
|
|
272
280
|
sessionWindowCount,
|
|
281
|
+
floating: floatingRaw === "1",
|
|
273
282
|
});
|
|
274
283
|
}
|
|
275
284
|
return { descriptors, malformedUtf8Records };
|