tmux-ide 2.9.26 → 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.
Files changed (89) hide show
  1. package/README.md +1 -1
  2. package/bin/cli.js +2046 -623
  3. package/package.json +2 -2
  4. package/packages/contracts/src/pane-stream.ts +45 -0
  5. package/packages/contracts/src/terminal-delivery.ts +114 -3
  6. package/packages/core/src/index.ts +1 -0
  7. package/packages/core/src/terminal-delivery-binary.ts +8 -7
  8. package/packages/core/src/terminal-delivery.ts +174 -3
  9. package/packages/core/src/terminal-partial-history.ts +152 -0
  10. package/packages/core/src/terminal-replica.ts +70 -1
  11. package/packages/daemon/dist/command-center/owner-keep-alive.js +30 -0
  12. package/packages/daemon/dist/command-center/resources/terminal-runtime-inventory.js +17 -3
  13. package/packages/daemon/dist/command-center/server.js +3 -0
  14. package/packages/daemon/dist/command-center/tmux-server-attach.js +51 -0
  15. package/packages/daemon/dist/command-center/tmux-servers.js +80 -1
  16. package/packages/daemon/dist/doctor.js +4 -4
  17. package/packages/daemon/dist/lib/app-config.js +7 -0
  18. package/packages/daemon/dist/lib/node-requirement.js +20 -0
  19. package/packages/daemon/dist/lib/require-supported-node.js +8 -0
  20. package/packages/daemon/dist/lib/tmux-server-session-open.js +38 -12
  21. package/packages/daemon/dist/lib/workspace-promotion.js +4 -4
  22. package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/Info.plist +2 -2
  23. package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/MacOS/tmux-ide-notifier +0 -0
  24. package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/Resources/Assets.car +0 -0
  25. package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/_CodeSignature/CodeResources +2 -2
  26. package/packages/daemon/dist/server/pane-stream-upgrade.js +39 -1
  27. package/packages/daemon/dist/terminal/attachments/native-runtime.js +12 -8
  28. package/packages/daemon/dist/terminal/mirror/mirror-service.js +13 -0
  29. package/packages/daemon/dist/terminal/mirror/native-atomic-snapshot.js +17 -7
  30. package/packages/daemon/dist/terminal/mirror/native-grid-capture.js +129 -5
  31. package/packages/daemon/dist/terminal/mirror/pane-feed.js +4 -0
  32. package/packages/daemon/dist/terminal/mirror/pane-hold.js +13 -0
  33. package/packages/daemon/dist/terminal/mirror/session-channel.js +198 -27
  34. package/packages/daemon/dist/terminal/pane-stream/lease-manager.js +1 -0
  35. package/packages/daemon/dist/terminal/pane-stream/pane-stream-websocket.js +198 -12
  36. package/packages/daemon/dist/terminal/protocol/layout-parse.js +99 -10
  37. package/packages/daemon/dist/terminal/protocol/session-descriptor-discovery.js +5 -2
  38. package/packages/daemon/dist/terminal/session-runtime/registry.js +1 -0
  39. package/packages/daemon/dist/terminal/session-runtime/terminal-delivery-hub.js +465 -42
  40. package/packages/daemon/dist/terminal/session-runtime/terminal-interpreter-backend.js +2 -1
  41. package/packages/daemon/dist/terminal/session-runtime/terminal-replica-interpreter.js +46 -1
  42. package/packages/daemon/dist/terminal/session-runtime/terminal-replica-owner.js +128 -3
  43. package/packages/daemon/dist/terminal/session-runtime/xterm-terminal-interpreter-backend.js +115 -6
  44. package/packages/daemon/dist/tui/mirror/open-tui-workspace-runtime-port.js +94 -2
  45. package/packages/daemon/dist/tui/mirror/runtime/open-tui-generation-host.js +9 -1
  46. package/packages/daemon/dist/tui/mirror/theme.js +8 -1
  47. package/packages/daemon/dist/tui/mirror/workspace/connection-feedback.js +8 -0
  48. package/packages/daemon/src/command-center/attach-window-rule.cases.json +84 -0
  49. package/packages/daemon/src/command-center/owner-keep-alive.ts +38 -0
  50. package/packages/daemon/src/command-center/resources/terminal-runtime-inventory.ts +20 -2
  51. package/packages/daemon/src/command-center/server.ts +3 -0
  52. package/packages/daemon/src/command-center/tmux-server-attach.ts +75 -0
  53. package/packages/daemon/src/command-center/tmux-servers.ts +88 -1
  54. package/packages/daemon/src/doctor.ts +4 -4
  55. package/packages/daemon/src/lib/app-config.ts +15 -0
  56. package/packages/daemon/src/lib/node-requirement.ts +22 -0
  57. package/packages/daemon/src/lib/require-supported-node.ts +9 -0
  58. package/packages/daemon/src/lib/tmux-server-session-open.ts +53 -15
  59. package/packages/daemon/src/lib/workspace-promotion.ts +4 -4
  60. package/packages/daemon/src/server/pane-stream-upgrade.ts +41 -1
  61. package/packages/daemon/src/terminal/attachments/native-runtime.ts +15 -1
  62. package/packages/daemon/src/terminal/mirror/events.ts +31 -1
  63. package/packages/daemon/src/terminal/mirror/mirror-service.ts +19 -0
  64. package/packages/daemon/src/terminal/mirror/native-atomic-snapshot.ts +16 -5
  65. package/packages/daemon/src/terminal/mirror/native-grid-capture.ts +164 -5
  66. package/packages/daemon/src/terminal/mirror/pane-feed.ts +5 -0
  67. package/packages/daemon/src/terminal/mirror/pane-hold.ts +16 -0
  68. package/packages/daemon/src/terminal/mirror/session-channel.ts +253 -38
  69. package/packages/daemon/src/terminal/mirror/trusted-inventory.ts +2 -0
  70. package/packages/daemon/src/terminal/pane-stream/lease-manager.ts +3 -0
  71. package/packages/daemon/src/terminal/pane-stream/pane-stream-websocket.ts +240 -12
  72. package/packages/daemon/src/terminal/protocol/layout-parse.ts +109 -10
  73. package/packages/daemon/src/terminal/protocol/session-descriptor-discovery.ts +10 -1
  74. package/packages/daemon/src/terminal/session-runtime/registry.ts +1 -0
  75. package/packages/daemon/src/terminal/session-runtime/runtime-observability.ts +2 -1
  76. package/packages/daemon/src/terminal/session-runtime/terminal-delivery-hub.ts +575 -39
  77. package/packages/daemon/src/terminal/session-runtime/terminal-interpreter-backend.ts +24 -1
  78. package/packages/daemon/src/terminal/session-runtime/terminal-replica-interpreter.ts +61 -5
  79. package/packages/daemon/src/terminal/session-runtime/terminal-replica-owner.ts +159 -32
  80. package/packages/daemon/src/terminal/session-runtime/xterm-terminal-interpreter-backend.ts +134 -11
  81. package/packages/daemon/src/tui/mirror/open-tui-workspace-runtime-port.ts +101 -2
  82. package/packages/daemon/src/tui/mirror/runtime/open-tui-generation-host.ts +13 -0
  83. package/packages/daemon/src/tui/mirror/theme.ts +13 -1
  84. package/packages/daemon/src/tui/mirror/workspace/connection-feedback.ts +13 -1
  85. package/packages/daemon-client/src/direct-application-shell-transport.ts +6 -2
  86. package/packages/daemon-client/src/pane-stream-client.ts +24 -6
  87. package/packages/daemon-client/src/workspace-client-types.ts +6 -0
  88. package/packages/daemon-client/src/workspace-client.ts +15 -9
  89. package/packages/daemon-client/src/workspace-event-supervisor.ts +3 -1
@@ -2,7 +2,8 @@ import { TERMINAL_SURFACE_MAX_CONTROL_BYTES, TERMINAL_SURFACE_CAPABILITY_VERSION
2
2
  import { NativeSurfaceViewer } from "../graphics/native-surface-viewer.js";
3
3
  import { compressGraphicsChunk } from "../graphics/compress-chunk.js";
4
4
  import { TERMINAL_GRAPHICS_COMPRESSED_CAPABILITY_VERSION, TERMINAL_GRAPHICS_COMPRESSED_LOCAL_CAPABILITY_VERSION, TERMINAL_PROJECTION_CAPABILITY_VERSION, TERMINAL_PROJECTION_LOCAL_CAPABILITY_VERSION, } from "@tmux-ide/contracts";
5
- import { PANE_STREAM_INPUT_LIFETIME_CAPABILITY_VERSION, PANE_STREAM_INPUT_BYTES_CAPABILITY_VERSION, PANE_STREAM_BROWSER_ICON_CAPABILITY_VERSION, PANE_STREAM_READER_CAPABILITY_VERSION, PANE_STREAM_BROWSER_KIND_CAPABILITY_VERSION, PANE_STREAM_READER_TOPOLOGY_BUNDLE_CAPABILITY_VERSION, PANE_STREAM_TOPOLOGY_IN_PLACE_CAPABILITY_VERSION, } from "@tmux-ide/contracts";
5
+ import { PANE_STREAM_INPUT_LIFETIME_CAPABILITY_VERSION, PANE_STREAM_INPUT_BYTES_CAPABILITY_VERSION, PANE_STREAM_BROWSER_ICON_CAPABILITY_VERSION, PANE_STREAM_READER_CAPABILITY_VERSION, PANE_STREAM_BROWSER_KIND_CAPABILITY_VERSION, PANE_STREAM_READER_TOPOLOGY_BUNDLE_CAPABILITY_VERSION, PANE_STREAM_TOPOLOGY_IN_PLACE_CAPABILITY_VERSION, PANE_STREAM_PANE_HELD_CLOSE_CODE, paneHeldCloseReason, } from "@tmux-ide/contracts";
6
+ import { MirrorPaneHeldError } from "../mirror/pane-hold.js";
6
7
  import { inflateSync } from "node:zlib";
7
8
  import { PaneStreamLayoutSnapshotFrameSchemaZ } from "@tmux-ide/contracts";
8
9
  import { z } from "zod";
@@ -86,6 +87,13 @@ function semanticBackendRefusal(error) {
86
87
  return null;
87
88
  }
88
89
  const TYPE_FIRST_INPUT_FRAME_PREFIX = Buffer.from('{"type":"input",', "utf8");
90
+ /**
91
+ * #882: the panes a stream can attach to and the layout covers. A floating
92
+ * pane is listed by the description but has no tiled cell, so it is left out.
93
+ */
94
+ function tiledPanes(described) {
95
+ return described.panes.filter((pane) => pane.floating !== true);
96
+ }
89
97
  function startsWithBuffer(raw, prefix) {
90
98
  return (raw.length >= prefix.length && raw.compare(prefix, 0, prefix.length, 0, prefix.length) === 0);
91
99
  }
@@ -129,6 +137,32 @@ function sendControl(socket, frame) {
129
137
  }
130
138
  socket.send(encoded, { binary: false });
131
139
  }
140
+ /**
141
+ * The hold to close with when every pane that failed to open was held (#872):
142
+ * the longest wait, and too large if any held pane was. Null when any failure
143
+ * was something else.
144
+ */
145
+ function heldOnly(settled) {
146
+ let retryInMs = 0;
147
+ let tooLarge = false;
148
+ for (const result of settled) {
149
+ if (result.status === "fulfilled") {
150
+ if (!result.value.delivery.negotiation.accepted)
151
+ return null;
152
+ continue;
153
+ }
154
+ const reason = result.reason;
155
+ if (!(reason instanceof MirrorPaneHeldError))
156
+ return null;
157
+ retryInMs = Math.max(retryInMs, reason.hold.retryInMs);
158
+ tooLarge ||= reason.hold.why === "too-large";
159
+ }
160
+ // Called only when a pane did not open, so at least one was held here.
161
+ return { retryInMs, why: tooLarge ? "too-large" : "failed" };
162
+ }
163
+ function errorText(error) {
164
+ return (error instanceof Error ? error.message : String(error)).slice(0, 300);
165
+ }
132
166
  function errorFrameCode(error) {
133
167
  if (error instanceof PaneStreamLeaseError && error.code === "ticket-expired") {
134
168
  return "ticket-expired";
@@ -165,6 +199,7 @@ export class PaneStreamAdmissionCoordinator {
165
199
  #flowBudgets;
166
200
  #drainTickMs;
167
201
  #openRetryDelaysMs;
202
+ #deferredPaneRetryDelaysMs;
168
203
  #ownershipWaitMs;
169
204
  #maxSocketBufferedBytes;
170
205
  #maxInputFrames;
@@ -202,6 +237,8 @@ export class PaneStreamAdmissionCoordinator {
202
237
  this.#ledger = new PaneStreamWireLedger(this.#flowBudgets);
203
238
  this.#drainTickMs = boundedInteger(options.drainTickMs, 15, 1_000);
204
239
  this.#openRetryDelaysMs = options.openRetryDelaysMs ?? PANE_STREAM_OPEN_RETRY_DELAYS_MS;
240
+ this.#deferredPaneRetryDelaysMs =
241
+ options.deferredPaneRetryDelaysMs ?? PANE_STREAM_DEFERRED_PANE_RETRY_DELAYS_MS;
205
242
  this.#ownershipWaitMs = options.ownershipWaitMs ?? PANE_STREAM_OWNERSHIP_WAIT_MS;
206
243
  this.#maxSocketBufferedBytes = boundedInteger(options.maxSocketBufferedBytes, 32 << 20, 256 << 20);
207
244
  this.#maxInputFrames = boundedInteger(options.maxInputFramesPerWindow, 16_384, 1 << 20);
@@ -250,10 +287,17 @@ export class PaneStreamAdmissionCoordinator {
250
287
  if (trace)
251
288
  this.#observability.recordSpan("transport", "pane-stream-describe-session", describeStartedAtMicros, this.#observability.nowMicros(), trace);
252
289
  }
253
- catch {
290
+ catch (error) {
291
+ // #585: the client is told only "stream-unavailable"; the log keeps why.
292
+ logger.info("pane-stream", "stream refused", {
293
+ step: "issue",
294
+ cause: "describe-session-failed",
295
+ session: context.sessionName,
296
+ error: errorText(error),
297
+ });
254
298
  throw new PaneStreamAdmissionError("stream-unavailable", "The workspace session could not be described.");
255
299
  }
256
- const known = new Set(described.panes.map((pane) => pane.semanticPaneId));
300
+ const known = new Set(tiledPanes(described).map((pane) => pane.semanticPaneId));
257
301
  for (const pane of request.panes) {
258
302
  if (!known.has(pane)) {
259
303
  throw new PaneStreamAdmissionError("pane-not-found", `The pane ${pane} is not present in the workspace session.`);
@@ -262,7 +306,7 @@ export class PaneStreamAdmissionCoordinator {
262
306
  // #806: a stream for one window is issued for exactly that window's
263
307
  // panes, as the trusted inventory places them now.
264
308
  if (request.semanticWindowId !== undefined) {
265
- const windowPanes = new Set(described.panes
309
+ const windowPanes = new Set(tiledPanes(described)
266
310
  .filter((pane) => pane.semanticWindowId === request.semanticWindowId)
267
311
  .map((pane) => pane.semanticPaneId));
268
312
  if (windowPanes.size !== request.panes.length ||
@@ -495,6 +539,7 @@ export class PaneStreamAdmissionCoordinator {
495
539
  ledger: this.#ledger,
496
540
  drainTickMs: this.#drainTickMs,
497
541
  openRetryDelaysMs: this.#openRetryDelaysMs,
542
+ deferredPaneRetryDelaysMs: this.#deferredPaneRetryDelaysMs,
498
543
  ownershipWaitMs: this.#ownershipWaitMs,
499
544
  maxSocketBufferedBytes: this.#maxSocketBufferedBytes,
500
545
  maxInputFrames: this.#maxInputFrames,
@@ -595,6 +640,9 @@ class PreAuthAdmission {
595
640
  cancelBeforeBind() {
596
641
  this.close(1008, "upgrade-rejected");
597
642
  }
643
+ redeemFromUpgrade(frame) {
644
+ this.#onMessage(frame, false);
645
+ }
598
646
  promote() {
599
647
  if (!this.#open)
600
648
  return;
@@ -649,6 +697,11 @@ class PreAuthAdmission {
649
697
  if (!this.#open)
650
698
  return;
651
699
  const code = errorFrameCode(error);
700
+ logger.info("pane-stream", "stream refused", {
701
+ step: "redeem",
702
+ code,
703
+ error: errorText(error),
704
+ });
652
705
  try {
653
706
  sendControl(socket, {
654
707
  type: "error",
@@ -683,6 +736,12 @@ class PreAuthAdmission {
683
736
  export const PANE_STREAM_TOPOLOGY_SETTLE_MS = 500;
684
737
  /** About half a second in all: long enough for one slow tmux answer, short for a user. */
685
738
  export const PANE_STREAM_OPEN_RETRY_DELAYS_MS = [150, 400];
739
+ /**
740
+ * A pane whose delivery still fails after those is tried again this long
741
+ * after the stream opened without it (about 7 s in all, inside the terminal
742
+ * app's 15 s wait for a hidden pane's state). Then the stream closes (#585).
743
+ */
744
+ export const PANE_STREAM_DEFERRED_PANE_RETRY_DELAYS_MS = [1_000, 2_000, 4_000];
686
745
  /** Input waits this long for ownership to be read again before the stream closes. */
687
746
  export const PANE_STREAM_OWNERSHIP_WAIT_MS = 2_000;
688
747
  /** At most this many input and geometry frames wait for it. */
@@ -729,6 +788,9 @@ export class PaneStreamLiveConnection {
729
788
  #ledger;
730
789
  #drainTickMs;
731
790
  #openRetryDelaysMs;
791
+ /** Waits of `#deferPane`; a close ends them at once (#585). */
792
+ #deferralWaits = new Set();
793
+ #deferredPaneRetryDelaysMs;
732
794
  #ownershipWaitMs;
733
795
  #maxSocketBufferedBytes;
734
796
  #maxInputFrames;
@@ -835,6 +897,7 @@ export class PaneStreamLiveConnection {
835
897
  this.#ledger = options.ledger;
836
898
  this.#drainTickMs = options.drainTickMs;
837
899
  this.#openRetryDelaysMs = options.openRetryDelaysMs;
900
+ this.#deferredPaneRetryDelaysMs = options.deferredPaneRetryDelaysMs;
838
901
  this.#ownershipWaitMs = options.ownershipWaitMs ?? PANE_STREAM_OWNERSHIP_WAIT_MS;
839
902
  this.#maxSocketBufferedBytes = options.maxSocketBufferedBytes;
840
903
  this.#maxInputFrames = options.maxInputFrames;
@@ -913,17 +976,29 @@ export class PaneStreamLiveConnection {
913
976
  * none of them. The log says which one, with the error text, so a stream
914
977
  * that "just closed" can be traced without a reproduction.
915
978
  */
916
- #fail(cause, error) {
979
+ #fail(cause, error, pane) {
917
980
  if (this.#closed)
918
981
  return;
919
982
  this.#closeCause = {
920
983
  cause,
984
+ ...(pane === undefined ? {} : { pane }),
921
985
  ...(error === undefined
922
986
  ? {}
923
987
  : { error: (error instanceof Error ? error.message : String(error)).slice(0, 300) }),
924
988
  };
925
989
  this.close(1011, "stream-unavailable");
926
990
  }
991
+ /**
992
+ * #872: every pane that did not open is held back after failed recoveries.
993
+ * "Try again later", with the time left and why, so a client can say so
994
+ * instead of counting attempts. The client reconnects as for any close.
995
+ */
996
+ #closeHeld(hold, pane) {
997
+ if (this.#closed)
998
+ return;
999
+ this.#closeCause = { cause: "pane-held", ...(pane === undefined ? {} : { pane }) };
1000
+ this.close(PANE_STREAM_PANE_HELD_CLOSE_CODE, paneHeldCloseReason(hold));
1001
+ }
927
1002
  close(code = 1000, reason = "stream-closed") {
928
1003
  if (this.#closed)
929
1004
  return;
@@ -943,6 +1018,11 @@ export class PaneStreamLiveConnection {
943
1018
  : {}),
944
1019
  });
945
1020
  this.#closed = true;
1021
+ for (const { timer, wake } of this.#deferralWaits) {
1022
+ clearTimeout(timer);
1023
+ wake();
1024
+ }
1025
+ this.#deferralWaits.clear();
946
1026
  this.#ownershipHeld.length = 0;
947
1027
  this.#ownershipWake?.();
948
1028
  for (const demand of this.#surfaceDemands.values())
@@ -1019,7 +1099,7 @@ export class PaneStreamLiveConnection {
1019
1099
  }
1020
1100
  if (this.#closed)
1021
1101
  return;
1022
- const known = new Set(described.panes.map((pane) => pane.semanticPaneId));
1102
+ const known = new Set(tiledPanes(described).map((pane) => pane.semanticPaneId));
1023
1103
  if (this.#descriptor.terminalDelivery) {
1024
1104
  await this.#subscribeSemantic(known);
1025
1105
  return;
@@ -1197,14 +1277,37 @@ export class PaneStreamLiveConnection {
1197
1277
  // removes N x attachment latency without allowing a fast pane to make the
1198
1278
  // session look ready while a sibling is still missing. allSettled is
1199
1279
  // deliberate: partial success is always closed before the socket retires.
1280
+ if (this.#descriptor.retryAskedByPerson)
1281
+ this.#mirror.liftRecoveryHolds?.(this.#descriptor.sessionName, channels.map((channel) => channel.semanticPaneId));
1200
1282
  const openings = channels.map((channel) => this.#openPaneDelivery(binding, offer, channel));
1201
1283
  const settled = await Promise.allSettled(openings);
1202
1284
  const opened = settled.flatMap((result) => result.status === "fulfilled" ? [result.value] : []);
1285
+ // #585: one pane that still fails no longer takes the others down. The
1286
+ // stream opens without it and the pane is tried again (`#deferPane`). A
1287
+ // refusal (authority, or a delivery offer not accepted) still closes it.
1288
+ const deferred = channels.flatMap((channel, index) => {
1289
+ const result = settled[index];
1290
+ return result.status === "rejected" ? [{ channel, error: result.reason }] : [];
1291
+ });
1292
+ const deferrable = deferred.length > 0 &&
1293
+ deferred.length < channels.length &&
1294
+ this.#deferredPaneRetryDelaysMs.length > 0 &&
1295
+ opened.every(({ delivery }) => delivery.negotiation.accepted) &&
1296
+ // A held pane is refused until its hold ends: deferred tries only
1297
+ // repeat the refusal, so it closes at once with its hold (#872).
1298
+ deferred.every(({ error }) => !(error instanceof SessionRuntimeControllerLeaseError) &&
1299
+ !(error instanceof MirrorPaneHeldError));
1203
1300
  if (this.#closed ||
1204
- settled.some((result) => result.status === "rejected" || !result.value.delivery.negotiation.accepted)) {
1301
+ (!deferrable &&
1302
+ settled.some((result) => result.status === "rejected" || !result.value.delivery.negotiation.accepted))) {
1205
1303
  await Promise.all(opened.map(({ delivery }) => delivery.close().catch(() => undefined)));
1206
1304
  if (!this.#closed) {
1207
1305
  const rejected = settled.find((result) => result.status === "rejected");
1306
+ const hold = heldOnly(settled);
1307
+ if (hold) {
1308
+ this.#closeHeld(hold);
1309
+ return;
1310
+ }
1208
1311
  this.#fail("delivery-negotiation-failed", rejected?.status === "rejected" ? rejected.reason : "a pane's delivery offer was refused");
1209
1312
  }
1210
1313
  return;
@@ -1258,16 +1361,83 @@ export class PaneStreamLiveConnection {
1258
1361
  opened.sort((left, right) => Number(visibleAtDelivery.has(right.channel.semanticPaneId)) -
1259
1362
  Number(visibleAtDelivery.has(left.channel.semanticPaneId)));
1260
1363
  await this.#publishOpenedDeliveries(opened);
1364
+ if (deferrable)
1365
+ for (const { channel, error } of deferred)
1366
+ void this.#deferPane(binding, offer, channel, error);
1261
1367
  this.#closeIfAllPanesGone();
1262
1368
  }
1369
+ /**
1370
+ * A pane left out of the opening (#585): try its delivery again after each
1371
+ * deferred delay and announce it like a pane added in place. Only when
1372
+ * every try failed does the stream close, naming the pane.
1373
+ */
1374
+ async #deferPane(binding, offer, channel, firstError) {
1375
+ const gone = () => this.#closed || channel.closed || this.#panes.get(channel.semanticPaneId) !== channel;
1376
+ let error = firstError;
1377
+ for (const [index, delayMs] of this.#deferredPaneRetryDelaysMs.entries()) {
1378
+ if (gone())
1379
+ return;
1380
+ logger.info("pane-stream", "pane delivery deferred", {
1381
+ session: this.#descriptor.sessionName,
1382
+ clientId: this.#clientId,
1383
+ pane: channel.semanticPaneId,
1384
+ attempt: index + 1,
1385
+ error: errorText(error),
1386
+ });
1387
+ await new Promise((resolve) => {
1388
+ const wait = {
1389
+ timer: setTimeout(() => {
1390
+ this.#deferralWaits.delete(wait);
1391
+ resolve();
1392
+ }, delayMs),
1393
+ wake: resolve,
1394
+ };
1395
+ wait.timer.unref?.();
1396
+ this.#deferralWaits.add(wait);
1397
+ });
1398
+ if (gone())
1399
+ return;
1400
+ let entry;
1401
+ try {
1402
+ entry = await this.#openPaneDelivery(binding, offer, channel, false);
1403
+ }
1404
+ catch (cause) {
1405
+ if (cause instanceof SessionRuntimeControllerLeaseError) {
1406
+ this.#fail("pane-delivery-open-failed", cause, channel.semanticPaneId);
1407
+ return;
1408
+ }
1409
+ // The pane became held during its deferred tries (#872).
1410
+ if (cause instanceof MirrorPaneHeldError) {
1411
+ if (!gone())
1412
+ this.#closeHeld(cause.hold, channel.semanticPaneId);
1413
+ return;
1414
+ }
1415
+ error = cause;
1416
+ continue;
1417
+ }
1418
+ if (gone()) {
1419
+ await entry.delivery.close().catch(() => undefined);
1420
+ return;
1421
+ }
1422
+ if (!entry.delivery.negotiation.accepted || this.#deliveryIdentityChanged(entry)) {
1423
+ await entry.delivery.close().catch(() => undefined);
1424
+ this.#failTopologyChanged();
1425
+ return;
1426
+ }
1427
+ await this.#publishOpenedDeliveries([entry]);
1428
+ return;
1429
+ }
1430
+ if (!gone())
1431
+ this.#fail("pane-delivery-open-failed", error, channel.semanticPaneId);
1432
+ }
1263
1433
  /** Open one pane's delivery; its messages wait until the pane is announced. */
1264
- async #openPaneDelivery(binding, offer, channel) {
1434
+ async #openPaneDelivery(binding, offer, channel, retry = true) {
1265
1435
  const pending = [];
1266
1436
  let ready = false;
1267
1437
  let negotiated = false;
1268
1438
  // #585: a failed open is tried again (150 ms, 400 ms) before the stream
1269
1439
  // closes; this applies to a pane added in place too.
1270
- const delivery = await this.#retryOpenStep("pane-delivery-open", () => {
1440
+ const open = () => {
1271
1441
  // A try that failed may have delivered something; start clean.
1272
1442
  pending.length = 0;
1273
1443
  return binding.openTerminalDelivery(channel.semanticPaneId, offer, (message) => {
@@ -1276,7 +1446,12 @@ export class PaneStreamLiveConnection {
1276
1446
  else
1277
1447
  return this.#sendTerminalDelivery(channel.semanticPaneId, message);
1278
1448
  }, this.#descriptor.workspaceName);
1279
- });
1449
+ };
1450
+ // A held pane is refused without asking tmux until its hold ends: trying
1451
+ // again inside the same stream only repeats the refusal (#872).
1452
+ const delivery = retry
1453
+ ? await this.#retryOpenStep("pane-delivery-open", open, (error) => error instanceof MirrorPaneHeldError)
1454
+ : await open();
1280
1455
  return {
1281
1456
  channel,
1282
1457
  delivery,
@@ -2107,7 +2282,7 @@ export class PaneStreamLiveConnection {
2107
2282
  }
2108
2283
  if (this.#closed)
2109
2284
  return this.#topologyFailed("closed");
2110
- const next = [...new Set(described.panes.map((pane) => pane.semanticPaneId))].sort();
2285
+ const next = [...new Set(tiledPanes(described).map((pane) => pane.semanticPaneId))].sort();
2111
2286
  if (next.length === 0)
2112
2287
  return this.#topologyFailed("session has no panes");
2113
2288
  const frames = this.#validateInitialLayout(snapshot.layouts, next);
@@ -2127,7 +2302,7 @@ export class PaneStreamLiveConnection {
2127
2302
  let windowPanes = null;
2128
2303
  if (window !== null) {
2129
2304
  windowPanes = [
2130
- ...new Set(described.panes
2305
+ ...new Set(tiledPanes(described)
2131
2306
  .filter((pane) => pane.semanticWindowId === window)
2132
2307
  .map((pane) => pane.semanticPaneId)),
2133
2308
  ].sort();
@@ -2668,6 +2843,17 @@ export class PaneStreamLiveConnection {
2668
2843
  channel.delivery.projectionReceipt(frame.receipt);
2669
2844
  return;
2670
2845
  }
2846
+ if (frame.type === "terminal-delivery-history-request") {
2847
+ const channel = this.#deliveryChannel(frame.request);
2848
+ if (!channel)
2849
+ return;
2850
+ if (!channel.delivery?.historyRequest ||
2851
+ !channel.delivery.negotiation.accepted ||
2852
+ channel.delivery.negotiation.negotiated.partialHistory !== "tail-v1")
2853
+ return this.#failProtocol("protocol-error");
2854
+ channel.delivery.historyRequest(frame.request);
2855
+ return;
2856
+ }
2671
2857
  if (frame.type === "terminal-projection-materialize") {
2672
2858
  const channel = this.#deliveryChannel(frame.request);
2673
2859
  if (!channel)
@@ -22,6 +22,51 @@
22
22
  // Internal parsing bound, matching fleet catalog capacity. This is NOT the
23
23
  // smaller pane-stream publication limit; future wire callers must enforce that.
24
24
  const MAX_TREE_LEAVES = 512;
25
+ /**
26
+ * #882: the bundled build appends `<cell,cell…>`, one leaf cell per floating
27
+ * pane, and also lists each one as an extra child of the root split, where it
28
+ * overlaps the tiled panes. Split the string into the tiled part and the
29
+ * floating leaves; each floating id must occur exactly once in the tiled part
30
+ * and once in the section. Null when the section is malformed.
31
+ */
32
+ function splitFloating(s) {
33
+ if (!s.endsWith(">"))
34
+ return { tiled: s, floating: [] };
35
+ const open = s.lastIndexOf("<");
36
+ if (open <= 0)
37
+ return null;
38
+ const section = s.slice(open + 1, -1);
39
+ const floating = [];
40
+ let pos = 0;
41
+ while (pos < section.length) {
42
+ const dims = readDims(section, pos);
43
+ if (!dims || section[dims.pos] !== ",")
44
+ return null;
45
+ const id = readInt(section, dims.pos + 1);
46
+ if (!id)
47
+ return null;
48
+ floating.push({
49
+ id: `%${id.value}`,
50
+ left: dims.left,
51
+ top: dims.top,
52
+ width: dims.width,
53
+ height: dims.height,
54
+ });
55
+ pos = id.pos;
56
+ if (pos === section.length)
57
+ break;
58
+ if (section[pos] !== ",")
59
+ return null;
60
+ pos += 1;
61
+ if (pos === section.length)
62
+ return null;
63
+ }
64
+ if (floating.length === 0)
65
+ return null;
66
+ if (new Set(floating.map((leaf) => leaf.id)).size !== floating.length)
67
+ return null;
68
+ return { tiled: s.slice(0, open), floating };
69
+ }
25
70
  /**
26
71
  * Bounded ancestry parser, deliberately stricter than the legacy flat parser.
27
72
  * Up to 512 leaves (fleet catalog bound), 1023 nodes, depth 64 and 64 KiB.
@@ -31,26 +76,52 @@ const MAX_TREE_LEAVES = 512;
31
76
  export function parseLayoutTree(layout) {
32
77
  if (layout.length > 64 * 1024 || !/^[0-9a-fA-F]{4},/.test(layout))
33
78
  return null;
34
- const s = layout.slice(5);
35
- const root = parseCell(s, 0, [], { nodes: 0, ids: new Set() });
36
- if (!root?.node || root.pos !== s.length || root.node.left !== 0 || root.node.top !== 0)
79
+ const split = splitFloating(layout.slice(5));
80
+ if (!split)
81
+ return null;
82
+ const s = split.tiled;
83
+ const skip = floatingIds(split.floating);
84
+ const root = parseCell(s, 0, [], { nodes: 0, ids: new Set() }, 1, skip);
85
+ if (!root?.node ||
86
+ root.pos !== s.length ||
87
+ root.node.left !== 0 ||
88
+ root.node.top !== 0 ||
89
+ !skip.allSeenOnce())
37
90
  return null;
38
91
  return root.node;
39
92
  }
93
+ /** The floating ids to leave out of the tiled tree, each to be seen once. */
94
+ function floatingIds(floating) {
95
+ const seen = new Map(floating.map((leaf) => [leaf.id, 0]));
96
+ return {
97
+ has: (id) => seen.has(id),
98
+ see: (id) => seen.set(id, (seen.get(id) ?? 0) + 1),
99
+ allSeenOnce: () => [...seen.values()].every((count) => count === 1),
100
+ };
101
+ }
40
102
  /** Parse a tmux layout string (`csum,WxH,X,Y…`). Null on any malformed input
41
103
  * (the caller falls back to the slow list-panes path — never throw here). */
42
104
  export function parseLayout(layout) {
43
105
  if (!/^[0-9a-fA-F]{4},/.test(layout))
44
106
  return null;
45
- const s = layout.slice(5);
107
+ const split = splitFloating(layout.slice(5));
108
+ if (!split)
109
+ return null;
110
+ const s = split.tiled;
111
+ const skip = floatingIds(split.floating);
46
112
  const leaves = [];
47
- const root = parseCell(s, 0, leaves);
48
- if (!root || root.pos !== s.length)
113
+ const root = parseCell(s, 0, leaves, undefined, 1, skip);
114
+ if (!root || root.pos !== s.length || !skip.allSeenOnce() || leaves.length === 0)
49
115
  return null;
50
- return { width: root.width, height: root.height, leaves };
116
+ return {
117
+ width: root.width,
118
+ height: root.height,
119
+ leaves,
120
+ ...(split.floating.length > 0 ? { floating: split.floating } : {}),
121
+ };
51
122
  }
52
123
  /** Recursive-descent cell parse from `pos`; appends leaves in layout order. */
53
- function parseCell(s, pos, leaves, tree, depth = 1) {
124
+ function parseCell(s, pos, leaves, tree, depth = 1, skip) {
54
125
  if (tree && (depth > 64 || ++tree.nodes > MAX_TREE_LEAVES * 2 - 1))
55
126
  return null;
56
127
  const dims = readDims(s, pos);
@@ -72,6 +143,10 @@ function parseCell(s, pos, leaves, tree, depth = 1) {
72
143
  if (!id)
73
144
  return null;
74
145
  const leaf = { id: `%${id.value}`, left, top, width, height };
146
+ if (skip?.has(leaf.id)) {
147
+ skip.see(leaf.id);
148
+ return { width, height, pos: id.pos, floating: true };
149
+ }
75
150
  if (tree) {
76
151
  if (!Number.isSafeInteger(id.value) ||
77
152
  tree.ids.has(leaf.id) ||
@@ -90,12 +165,15 @@ function parseCell(s, pos, leaves, tree, depth = 1) {
90
165
  if (ch === "{" || ch === "[") {
91
166
  const close = ch === "{" ? "}" : "]";
92
167
  const children = [];
168
+ let droppedFloating = 0;
93
169
  pos++;
94
170
  for (;;) {
95
- const child = parseCell(s, pos, leaves, tree, depth + 1);
171
+ const child = parseCell(s, pos, leaves, tree, depth + 1, skip);
96
172
  if (!child)
97
173
  return null;
98
- if (tree && child.node)
174
+ if (child.floating)
175
+ droppedFloating += 1;
176
+ else if (tree && child.node)
99
177
  children.push(child.node);
100
178
  pos = child.pos;
101
179
  if (s[pos] === ",") {
@@ -105,6 +183,17 @@ function parseCell(s, pos, leaves, tree, depth = 1) {
105
183
  if (s[pos] === close) {
106
184
  if (!tree)
107
185
  return { width, height, pos: pos + 1 };
186
+ // A split left with one tiled child once its floats are dropped is
187
+ // that child (the bundled build wraps a lone pane and its floats).
188
+ // It must fill the split exactly; otherwise tilesParent refuses it.
189
+ const lone = children.length === 1 ? children[0] : null;
190
+ if (droppedFloating > 0 &&
191
+ lone &&
192
+ lone.left === left &&
193
+ lone.top === top &&
194
+ lone.width === width &&
195
+ lone.height === height)
196
+ return { width, height, pos: pos + 1, node: lone };
108
197
  const axis = ch === "{" ? "cols" : "rows";
109
198
  const node = { kind: "split", axis, left, top, width, height, children };
110
199
  if (!tilesParent(node))
@@ -35,6 +35,8 @@ export const SESSION_PANE_DESCRIPTOR_FORMAT = [
35
35
  "#{pane_pid}",
36
36
  // Set only by a terminal browser that has tmux-ide's native controls (#718).
37
37
  "#{qa:@tmux_ide_browser_control}",
38
+ // #882: tmux 3.7+ floating panes have no cell in the tiled layout.
39
+ "#{pane_floating_flag}",
38
40
  ].join("\t");
39
41
  /**
40
42
  * Descriptor fields the program in a pane changes whenever it likes: its
@@ -131,9 +133,9 @@ export function parseSessionPaneDescriptorReply(lines) {
131
133
  continue;
132
134
  }
133
135
  const encoded = utf8Line.split("\t");
134
- if (encoded.length < 21 || encoded.length > 26)
136
+ if (encoded.length < 21 || encoded.length > 27)
135
137
  continue;
136
- const [runtimePaneId = "", semanticPaneId = "", role = "", type = "", currentCommand = "", cwd = "", windowIndexRaw = "", windowName = "", windowId = "", title = "", runtimeSessionId = "", paneIndexRaw = "", name = "", missionStamp = "", paneActiveRaw = "", windowActiveRaw = "", semanticWindowId = "", sessionName = "", windowPaneCountRaw = "", sessionWindowCountRaw = "", nativePaneBirthId = "", nameSource = "", browserIconRaw = "", readerRaw = "", panePidRaw = "", browserControl = "",] = encoded.map(decodeTmuxArgument);
138
+ const [runtimePaneId = "", semanticPaneId = "", role = "", type = "", currentCommand = "", cwd = "", windowIndexRaw = "", windowName = "", windowId = "", title = "", runtimeSessionId = "", paneIndexRaw = "", name = "", missionStamp = "", paneActiveRaw = "", windowActiveRaw = "", semanticWindowId = "", sessionName = "", windowPaneCountRaw = "", sessionWindowCountRaw = "", nativePaneBirthId = "", nameSource = "", browserIconRaw = "", readerRaw = "", panePidRaw = "", browserControl = "", floatingRaw = "",] = encoded.map(decodeTmuxArgument);
137
139
  if (!/^%(?:0|[1-9][0-9]*)$/u.test(runtimePaneId) || runtimePaneId.length > 32)
138
140
  continue;
139
141
  if (!/^\$(?:0|[1-9][0-9]*)$/u.test(runtimeSessionId) || runtimeSessionId.length > 32)
@@ -197,6 +199,7 @@ export function parseSessionPaneDescriptorReply(lines) {
197
199
  windowActive: windowActiveRaw === "1",
198
200
  windowPaneCount,
199
201
  sessionWindowCount,
202
+ floating: floatingRaw === "1",
200
203
  });
201
204
  }
202
205
  return { descriptors, malformedUtf8Records };
@@ -1694,6 +1694,7 @@ class SessionRuntimeConsumerImpl {
1694
1694
  ack: (ack) => upstream.ack(ack),
1695
1695
  ...(upstream.projectionReceipt ? { projectionReceipt: upstream.projectionReceipt } : {}),
1696
1696
  ...(upstream.materialize ? { materialize: upstream.materialize } : {}),
1697
+ ...(upstream.historyRequest ? { historyRequest: upstream.historyRequest } : {}),
1697
1698
  ...(upstream.prioritize ? { prioritize: upstream.prioritize } : {}),
1698
1699
  nack: (nack) => upstream.nack(nack),
1699
1700
  setVisibility: (visibility) => upstream.setVisibility(visibility),