tmux-ide 2.9.22 → 2.9.24

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 (104) hide show
  1. package/bin/cli.js +3718 -7603
  2. package/package.json +3 -3
  3. package/packages/contracts/src/index.ts +1 -0
  4. package/packages/contracts/src/websocket-heartbeat.ts +41 -0
  5. package/packages/daemon/dist/command-center/automation.js +1 -1
  6. package/packages/daemon/dist/command-center/daemon-fleet-facts-observer.js +37 -5
  7. package/packages/daemon/dist/command-center/discovery.js +28 -2
  8. package/packages/daemon/dist/command-center/server.js +8 -2
  9. package/packages/daemon/dist/command-center/tmux-servers.js +12 -1
  10. package/packages/daemon/dist/doctor.js +41 -0
  11. package/packages/daemon/dist/lib/bounded-tmux-read.js +34 -12
  12. package/packages/daemon/dist/lib/daemon-embed.js +127 -63
  13. package/packages/daemon/dist/lib/daemon-stop-progress.js +58 -0
  14. package/packages/daemon/dist/lib/embedded-daemon-lifecycle.js +11 -0
  15. package/packages/daemon/dist/lib/embedded-tmux-server-owners.js +88 -12
  16. package/packages/daemon/dist/lib/headless-daemon.js +177 -10
  17. package/packages/daemon/dist/lib/home-agent-observer.js +50 -0
  18. package/packages/daemon/dist/lib/log.js +18 -1
  19. package/packages/daemon/dist/lib/machine-agents.js +18 -1
  20. package/packages/daemon/dist/lib/orphaned-control-clients.js +162 -0
  21. package/packages/daemon/dist/lib/tmux-external-interaction-observer.js +172 -28
  22. package/packages/daemon/dist/lib/tmux-native-browser.js +4 -2
  23. package/packages/daemon/dist/lib/tmux-pane-reader.js +4 -2
  24. package/packages/daemon/dist/lib/tmux-server-agent-admission.js +6 -1
  25. package/packages/daemon/dist/lib/tmux-server-owner-teardown.js +33 -0
  26. package/packages/daemon/dist/lib/tmux-server-owner.js +55 -41
  27. package/packages/daemon/dist/lib/tmux-server-owners.js +310 -20
  28. package/packages/daemon/dist/lib/tmux-server-registration.js +128 -9
  29. package/packages/daemon/dist/lib/unix-socket-authority.js +58 -3
  30. package/packages/daemon/dist/lib/workspace-pane-creation.js +10 -1
  31. package/packages/daemon/dist/lib/workspace-promotion.js +24 -3
  32. package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/Info.plist +2 -2
  33. package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/MacOS/tmux-ide-notifier +0 -0
  34. package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/Resources/Assets.car +0 -0
  35. package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/_CodeSignature/CodeResources +2 -2
  36. package/packages/daemon/dist/plugins/cli.js +1 -2
  37. package/packages/daemon/dist/server/pane-stream-upgrade.js +5 -1
  38. package/packages/daemon/dist/server/websocket-heartbeat.js +103 -0
  39. package/packages/daemon/dist/terminal/attachments/native-runtime.js +49 -16
  40. package/packages/daemon/dist/terminal/mirror/layout-content-rows.js +11 -0
  41. package/packages/daemon/dist/terminal/mirror/mirror-service.js +61 -3
  42. package/packages/daemon/dist/terminal/mirror/session-channel.js +11 -12
  43. package/packages/daemon/dist/terminal/pane-stream/pane-stream-websocket.js +119 -22
  44. package/packages/daemon/dist/terminal/pane-stream/runtime.js +3 -2
  45. package/packages/daemon/dist/terminal/protocol/session-descriptor-discovery.js +23 -0
  46. package/packages/daemon/dist/terminal/protocol/stock-split-resize.js +4 -1
  47. package/packages/daemon/dist/terminal/session-runtime/registry.js +17 -0
  48. package/packages/daemon/dist/terminal/session-runtime/terminal-replica-interpreter.js +81 -3
  49. package/packages/daemon/dist/terminal/session-runtime/terminal-replica-owner.js +60 -3
  50. package/packages/daemon/dist/tui/mirror/runtime/application-home-agent-navigation.js +57 -4
  51. package/packages/daemon/dist/tui/mirror/runtime/application-home-agents-owner.js +18 -7
  52. package/packages/daemon/dist/tui/mirror/runtime/application-machine-agent-navigation.js +17 -0
  53. package/packages/daemon/dist/tui/mirror/runtime/application-machine-navigation.js +4 -2
  54. package/packages/daemon/dist/tui/mirror/runtime/application-terminal-interaction-controller.js +55 -14
  55. package/packages/daemon/src/command-center/automation.ts +1 -1
  56. package/packages/daemon/src/command-center/daemon-fleet-facts-observer.ts +49 -8
  57. package/packages/daemon/src/command-center/discovery.ts +35 -2
  58. package/packages/daemon/src/command-center/server.ts +22 -8
  59. package/packages/daemon/src/command-center/tmux-servers.ts +12 -1
  60. package/packages/daemon/src/doctor.ts +46 -0
  61. package/packages/daemon/src/lib/bounded-tmux-read.ts +29 -9
  62. package/packages/daemon/src/lib/daemon-embed.ts +211 -71
  63. package/packages/daemon/src/lib/daemon-stop-progress.ts +78 -0
  64. package/packages/daemon/src/lib/embedded-daemon-lifecycle.ts +12 -0
  65. package/packages/daemon/src/lib/embedded-tmux-server-owners.ts +115 -11
  66. package/packages/daemon/src/lib/headless-daemon.ts +205 -12
  67. package/packages/daemon/src/lib/home-agent-observer.ts +53 -0
  68. package/packages/daemon/src/lib/log.ts +18 -1
  69. package/packages/daemon/src/lib/machine-agents.ts +25 -1
  70. package/packages/daemon/src/lib/orphaned-control-clients.ts +215 -0
  71. package/packages/daemon/src/lib/tmux-external-interaction-observer.ts +195 -33
  72. package/packages/daemon/src/lib/tmux-native-browser.ts +4 -3
  73. package/packages/daemon/src/lib/tmux-pane-reader.ts +4 -3
  74. package/packages/daemon/src/lib/tmux-server-agent-admission.ts +6 -1
  75. package/packages/daemon/src/lib/tmux-server-owner-teardown.ts +54 -0
  76. package/packages/daemon/src/lib/tmux-server-owner.ts +60 -38
  77. package/packages/daemon/src/lib/tmux-server-owners.ts +427 -22
  78. package/packages/daemon/src/lib/tmux-server-registration.ts +155 -7
  79. package/packages/daemon/src/lib/unix-socket-authority.ts +72 -3
  80. package/packages/daemon/src/lib/workspace-pane-creation.ts +11 -1
  81. package/packages/daemon/src/lib/workspace-promotion.ts +26 -3
  82. package/packages/daemon/src/plugins/cli.ts +1 -2
  83. package/packages/daemon/src/server/pane-stream-upgrade.ts +6 -0
  84. package/packages/daemon/src/server/websocket-heartbeat.ts +135 -0
  85. package/packages/daemon/src/terminal/attachments/native-runtime.ts +79 -16
  86. package/packages/daemon/src/terminal/mirror/layout-content-rows.ts +11 -0
  87. package/packages/daemon/src/terminal/mirror/mirror-service.ts +61 -2
  88. package/packages/daemon/src/terminal/mirror/session-channel.ts +11 -14
  89. package/packages/daemon/src/terminal/pane-stream/pane-stream-websocket.ts +133 -21
  90. package/packages/daemon/src/terminal/pane-stream/runtime.ts +4 -2
  91. package/packages/daemon/src/terminal/protocol/session-descriptor-discovery.ts +31 -0
  92. package/packages/daemon/src/terminal/protocol/stock-split-resize.ts +6 -1
  93. package/packages/daemon/src/terminal/session-runtime/registry.ts +23 -0
  94. package/packages/daemon/src/terminal/session-runtime/runtime-observability.ts +2 -0
  95. package/packages/daemon/src/terminal/session-runtime/terminal-replica-interpreter.ts +100 -3
  96. package/packages/daemon/src/terminal/session-runtime/terminal-replica-owner.ts +60 -3
  97. package/packages/daemon/src/tui/mirror/runtime/application-home-agent-navigation.ts +69 -4
  98. package/packages/daemon/src/tui/mirror/runtime/application-home-agents-owner.ts +30 -13
  99. package/packages/daemon/src/tui/mirror/runtime/application-machine-agent-navigation.ts +38 -1
  100. package/packages/daemon/src/tui/mirror/runtime/application-machine-navigation.ts +7 -2
  101. package/packages/daemon/src/tui/mirror/runtime/application-root-v2.tsx +4 -4
  102. package/packages/daemon/src/tui/mirror/runtime/application-terminal-interaction-controller.ts +71 -17
  103. package/packages/daemon-client/src/direct-application-shell-transport.ts +21 -3
  104. package/packages/daemon-client/src/workspace-event-supervisor.ts +63 -2
@@ -43,10 +43,16 @@ const ERROR_MESSAGES = {
43
43
  };
44
44
  export class NativeTerminalAttachmentRuntimeError extends Error {
45
45
  code;
46
- constructor(code) {
46
+ /**
47
+ * Which of the several origins of this code it was. For diagnostics only:
48
+ * the message a client sees stays the same.
49
+ */
50
+ detail;
51
+ constructor(code, detail) {
47
52
  super(ERROR_MESSAGES[code]);
48
53
  this.name = "NativeTerminalAttachmentRuntimeError";
49
54
  this.code = code;
55
+ this.detail = detail;
50
56
  }
51
57
  }
52
58
  let nativeTerminalAttachmentRuntimeConstructions = 0;
@@ -463,7 +469,7 @@ async function requiredTmuxResult(runner, argv, signal) {
463
469
  if (result.status === "not-found")
464
470
  return null;
465
471
  if (result.status !== "ok") {
466
- throw new NativeTerminalAttachmentRuntimeError("discovery-failed");
472
+ throw new NativeTerminalAttachmentRuntimeError("discovery-failed", `tmux-command-${result.status}`);
467
473
  }
468
474
  return result.stdout;
469
475
  }
@@ -584,6 +590,18 @@ function parsePaneSnapshot(stdout, expected) {
584
590
  * before any pane query, and a second identity/topology snapshot closes races.
585
591
  */
586
592
  const INVENTORY_FENCE_ATTEMPTS = 4;
593
+ /**
594
+ * A read that was overtaken by an inventory invalidation is not a failed
595
+ * read: the answer it was computing is simply out of date, so it is read
596
+ * again. One retry was not enough while tmux topology is in motion: creating
597
+ * an agent pane invalidates the inventory several times within a few hundred
598
+ * milliseconds, a read overtaken twice failed with "discovery-failed", the
599
+ * inventory route answered 503, and a click on the new agent's row landed on
600
+ * "That agent changed or disappeared" until the client's backoff recovered
601
+ * seconds later (#764, journey soak 43257599866). Still bounded: a server
602
+ * whose topology never stops moving must not hold a reader for ever.
603
+ */
604
+ export const INVENTORY_STALE_RETRIES = 4;
587
605
  /** 25, 50, 100 ms: enough for a mutation's identity stamps, bounded for every reader. */
588
606
  const settleDelay = (attempt) => new Promise((resolve) => setTimeout(resolve, 25 * 2 ** (attempt - 1)));
589
607
  export async function discoverWorkspaceRegistryTerminalInventory(registry, runner, signal) {
@@ -634,7 +652,7 @@ export async function discoverWorkspaceRegistryTerminalInventory(registry, runne
634
652
  await settleDelay(attempt);
635
653
  const after = await requiredTmuxResult(runner, argv, signal);
636
654
  if (after === null)
637
- throw new NativeTerminalAttachmentRuntimeError("discovery-failed");
655
+ throw new NativeTerminalAttachmentRuntimeError("discovery-failed", "session-vanished-mid-read");
638
656
  const next = parsePaneSnapshot(after, identity);
639
657
  if (matches(previous, next))
640
658
  stable = next;
@@ -642,7 +660,7 @@ export async function discoverWorkspaceRegistryTerminalInventory(registry, runne
642
660
  previous = next;
643
661
  }
644
662
  if (!stable)
645
- throw new NativeTerminalAttachmentRuntimeError("discovery-failed");
663
+ throw new NativeTerminalAttachmentRuntimeError("discovery-failed", "topology-not-settled");
646
664
  bySessionName.set(sessionName, stable.panes);
647
665
  }
648
666
  const panes = [];
@@ -1057,6 +1075,21 @@ export class WorkspaceTerminalInventoryRuntime {
1057
1075
  throw new NativeTerminalAttachmentRuntimeError("runtime-disposed");
1058
1076
  const epoch = this.#inventoryEpoch;
1059
1077
  const nativeEpoch = this.#nativeServerEpoch?.() ?? null;
1078
+ // An invalidation can also land while the snapshot is being adopted. That
1079
+ // publication is refused, as before, and the inventory is read again: it
1080
+ // used to fail the caller, and at startup the caller is the daemon.
1081
+ const publish = async (value, publicationSignal) => {
1082
+ try {
1083
+ return await this.#publishInventory(value, nativeEpoch, publicationSignal, epoch);
1084
+ }
1085
+ catch (error) {
1086
+ if (this.#disposed || signal?.aborted || this.#inventoryEpoch === epoch)
1087
+ throw error;
1088
+ if (staleRetry < INVENTORY_STALE_RETRIES)
1089
+ return this.#readInventory(signal, staleRetry + 1);
1090
+ throw new NativeTerminalAttachmentRuntimeError("discovery-failed", "overtaken-by-invalidations");
1091
+ }
1092
+ };
1060
1093
  if (signal) {
1061
1094
  if (signal.aborted)
1062
1095
  throw new NativeTerminalAttachmentRuntimeError("runtime-disposed");
@@ -1066,20 +1099,20 @@ export class WorkspaceTerminalInventoryRuntime {
1066
1099
  }
1067
1100
  catch (error) {
1068
1101
  if (this.#inventoryEpoch !== epoch) {
1069
- if (staleRetry < 1)
1102
+ if (staleRetry < INVENTORY_STALE_RETRIES)
1070
1103
  return this.#readInventory(signal, staleRetry + 1);
1071
- throw new NativeTerminalAttachmentRuntimeError("discovery-failed");
1104
+ throw new NativeTerminalAttachmentRuntimeError("discovery-failed", "overtaken-by-invalidations");
1072
1105
  }
1073
1106
  throw error;
1074
1107
  }
1075
1108
  if (signal.aborted)
1076
1109
  throw new NativeTerminalAttachmentRuntimeError("runtime-disposed");
1077
1110
  if (this.#inventoryEpoch !== epoch) {
1078
- if (staleRetry < 1)
1111
+ if (staleRetry < INVENTORY_STALE_RETRIES)
1079
1112
  return this.#readInventory(signal, staleRetry + 1);
1080
- throw new NativeTerminalAttachmentRuntimeError("discovery-failed");
1113
+ throw new NativeTerminalAttachmentRuntimeError("discovery-failed", "overtaken-by-invalidations");
1081
1114
  }
1082
- return this.#publishInventory(snapshot, nativeEpoch, signal, epoch);
1115
+ return publish(snapshot, signal);
1083
1116
  }
1084
1117
  if (this.#inventoryRead?.epoch === epoch)
1085
1118
  return this.#inventoryRead.promise;
@@ -1091,18 +1124,18 @@ export class WorkspaceTerminalInventoryRuntime {
1091
1124
  }
1092
1125
  catch (error) {
1093
1126
  if (abort.signal.aborted || this.#inventoryEpoch !== epoch) {
1094
- if (staleRetry < 1)
1127
+ if (staleRetry < INVENTORY_STALE_RETRIES)
1095
1128
  return this.#readInventory(undefined, staleRetry + 1);
1096
- throw new NativeTerminalAttachmentRuntimeError("discovery-failed");
1129
+ throw new NativeTerminalAttachmentRuntimeError("discovery-failed", "overtaken-by-invalidations");
1097
1130
  }
1098
1131
  throw error;
1099
1132
  }
1100
1133
  if (abort.signal.aborted || this.#inventoryEpoch !== epoch) {
1101
- if (staleRetry < 1)
1134
+ if (staleRetry < INVENTORY_STALE_RETRIES)
1102
1135
  return this.#readInventory(undefined, staleRetry + 1);
1103
- throw new NativeTerminalAttachmentRuntimeError("discovery-failed");
1136
+ throw new NativeTerminalAttachmentRuntimeError("discovery-failed", "overtaken-by-invalidations");
1104
1137
  }
1105
- return this.#publishInventory(value, nativeEpoch, abort.signal, epoch);
1138
+ return publish(value, abort.signal);
1106
1139
  })().finally(() => {
1107
1140
  if (this.#inventoryRead?.promise === promise)
1108
1141
  this.#inventoryRead = null;
@@ -1156,9 +1189,9 @@ export class WorkspaceTerminalInventoryRuntime {
1156
1189
  assertLive();
1157
1190
  if (this.#inventoryEpoch === epoch)
1158
1191
  return null;
1159
- if (staleRetry < 1)
1192
+ if (staleRetry < INVENTORY_STALE_RETRIES)
1160
1193
  return this.#discoverTerminalRuntimeSession(requestedSessionName, signal, staleRetry + 1);
1161
- return Promise.reject(new NativeTerminalAttachmentRuntimeError("discovery-failed"));
1194
+ return Promise.reject(new NativeTerminalAttachmentRuntimeError("discovery-failed", "overtaken-by-invalidations"));
1162
1195
  };
1163
1196
  assertLive();
1164
1197
  const nativeEpoch = this.#nativeServerEpoch?.() ?? null;
@@ -7,3 +7,14 @@ export function layoutContentRows(paneTop, paneHeight, windowRows, border) {
7
7
  const touchesStatusEdge = border === "top" ? paneTop === 0 : paneTop + paneHeight === windowRows;
8
8
  return paneHeight - (touchesStatusEdge ? 1 : 0);
9
9
  }
10
+ /**
11
+ * The status line a window's tiled panes have, from its `pane-border-status`.
12
+ * tmux 3.8's `top-floating` and `bottom-floating` put a status line on floating
13
+ * panes only (`window_get_pane_status`), so tiled panes are laid out as "off".
14
+ * Null for a value this daemon does not know.
15
+ */
16
+ export function tiledPaneBorderStatus(option) {
17
+ if (option === "off" || option === "top" || option === "bottom")
18
+ return option;
19
+ return option === "top-floating" || option === "bottom-floating" ? "off" : null;
20
+ }
@@ -25,6 +25,8 @@ import { execFile } from "node:child_process";
25
25
  import { MirrorControlChannel, } from "./control-channel.js";
26
26
  import { SessionChannel, } from "./session-channel.js";
27
27
  import { controlModeAuthorityKey, processControlModeOwnershipRegistry, } from "./control-mode-ownership.js";
28
+ /** Backoff for re-reading registered windows after a failed read (#764). */
29
+ const OWNERSHIP_RETRY_MS = [100, 250, 500, 1_000];
28
30
  export class MirrorService {
29
31
  opts;
30
32
  channels = new Map();
@@ -46,26 +48,74 @@ export class MirrorService {
46
48
  };
47
49
  }
48
50
  invalidateRegisteredWindows() {
51
+ this.opts.onWindowOwnershipDiagnostic?.("guard-invalidate", {
52
+ wasPending: this.registeredWindows?.pending() ?? null,
53
+ });
49
54
  this.registeredWindows?.invalidate();
50
55
  }
56
+ /**
57
+ * #764: a failed re-read must not leave every session "being verified"
58
+ * for good. Nothing else re-reads until the next operation, so retry with
59
+ * a short bounded backoff while a channel is retained; success pushes
60
+ * any conflict as usual.
61
+ */
62
+ ownershipRetries = 0;
63
+ ownershipRetry = null;
64
+ retryRegisteredWindows(guard) {
65
+ if (this.ownershipRetry || this.disposed || guard !== this.registeredWindows)
66
+ return;
67
+ if (this.channelSessions.size === 0)
68
+ return;
69
+ const delay = OWNERSHIP_RETRY_MS[Math.min(this.ownershipRetries, OWNERSHIP_RETRY_MS.length - 1)];
70
+ this.ownershipRetries += 1;
71
+ this.ownershipRetry = setTimeout(() => {
72
+ this.ownershipRetry = null;
73
+ if (this.disposed || guard !== this.registeredWindows || !guard.pending())
74
+ return;
75
+ void this.verifyRegisteredWindows().catch(() => { });
76
+ }, delay);
77
+ this.ownershipRetry.unref?.();
78
+ }
51
79
  async verifyRegisteredWindows() {
52
80
  const guard = this.registeredWindows;
53
81
  if (!guard)
54
82
  return;
55
- await guard.verify();
83
+ const diagnostic = this.opts.onWindowOwnershipDiagnostic;
84
+ diagnostic?.("guard-verify-start", { pending: guard.pending() });
85
+ try {
86
+ await guard.verify();
87
+ }
88
+ catch (error) {
89
+ const detail = error?.detail;
90
+ diagnostic?.("guard-verify-failed", {
91
+ reason: error instanceof Error ? error.message.slice(0, 200) : "unknown",
92
+ // Which origin of the failure it was, when the thrower said so.
93
+ ...(typeof detail === "string" ? { detail: detail.slice(0, 80) } : {}),
94
+ });
95
+ this.retryRegisteredWindows(guard);
96
+ throw error;
97
+ }
98
+ this.ownershipRetries = 0;
56
99
  if (guard !== this.registeredWindows || this.disposed)
57
100
  throw new Error("Window ownership changed during discovery");
101
+ const blocked = [];
58
102
  for (const [channel, session] of this.channelSessions) {
59
103
  if (guard.blocked(session)) {
104
+ blocked.push(session);
60
105
  channel.setGeometryParticipation(false);
61
106
  if (!this.registeredConflicts.has(session)) {
62
107
  this.registeredConflicts.add(session);
108
+ diagnostic?.("guard-conflict-push", { session });
63
109
  this.opts.onSharedWindowConflict?.(session, true);
64
110
  }
65
111
  }
66
- else
67
- this.registeredConflicts.delete(session);
112
+ else if (this.registeredConflicts.delete(session)) {
113
+ // The registered-window conflict cleared: report it like a shared-window
114
+ // clear, so idle clients re-read the inventory (perf plan F13).
115
+ this.opts.onSharedWindowConflict?.(session, false);
116
+ }
68
117
  }
118
+ diagnostic?.("guard-verify-ok", { blocked, channels: this.channelSessions.size });
69
119
  }
70
120
  pendingDisposals = new Set();
71
121
  drainingChannels = new Map();
@@ -398,6 +448,7 @@ export class MirrorService {
398
448
  continue;
399
449
  if (conflict)
400
450
  peer.setGeometryParticipation(false);
451
+ this.opts.onWindowOwnershipDiagnostic?.("membership-conflict-push", { session, conflict });
401
452
  this.opts.onSharedWindowConflict?.(session, conflict);
402
453
  }
403
454
  }
@@ -512,6 +563,9 @@ export class MirrorService {
512
563
  }
513
564
  async dispose() {
514
565
  this.disposed = true;
566
+ if (this.ownershipRetry)
567
+ clearTimeout(this.ownershipRetry);
568
+ this.ownershipRetry = null;
515
569
  this.registeredWindows?.dispose();
516
570
  this.sessionExitListeners.clear();
517
571
  const entries = [...this.channels.values()];
@@ -569,6 +623,10 @@ export class MirrorService {
569
623
  hasSharedWindowConflict: () => this.hasSharedWindowConflict(session),
570
624
  beforeIdentityRepair: () => this.verifyRegisteredWindows(),
571
625
  onWindowTopologyChanged: () => {
626
+ this.opts.onWindowOwnershipDiagnostic?.("topology-notification", {
627
+ session,
628
+ current: this.channelSessions.has(channel),
629
+ });
572
630
  if (this.channelSessions.has(channel))
573
631
  this.invalidateRegisteredWindows();
574
632
  },
@@ -1,5 +1,5 @@
1
1
  import { STOCK_SPLIT_OPTIONS_FORMAT } from "../protocol/stock-split-resize.js";
2
- import { layoutContentRows } from "./layout-content-rows.js";
2
+ import { layoutContentRows, tiledPaneBorderStatus } from "./layout-content-rows.js";
3
3
  import { decodeNativeAtomicSnapshot, decodeNativeAtomicDualSnapshot, nativeAtomicDualSnapshotPlan, nativeAtomicSnapshotPlan, } from "./native-atomic-snapshot.js";
4
4
  import { boundedTmuxInteractionAppendCommand } from "../../lib/tmux-interaction-retention.js";
5
5
  import { decodeNativeGridCapture, isStockRawGridCapture, isNativeBootstrapCapture, } from "./native-grid-capture.js";
@@ -38,7 +38,7 @@ import { textToHexKeys } from "../protocol/control.js";
38
38
  import { InputCoalescer } from "../protocol/input-coalescer.js";
39
39
  import { NativeGridCaptureReader } from "./native-grid-reader.js";
40
40
  import { parseLayout, parseLayoutTree, parseLayoutChange, parseSessionWindowChanged, parseWindowPaneChanged, } from "../protocol/layout-parse.js";
41
- import { SESSION_PANE_DESCRIPTOR_FORMAT, SessionDescriptorDiscovery, decodeControlReplyUtf8, decodeTmuxArgument, parseSessionPaneDescriptorReply, } from "../protocol/session-descriptor-discovery.js";
41
+ import { SESSION_PANE_DESCRIPTOR_FORMAT, sameSessionPaneInventory, SessionDescriptorDiscovery, decodeControlReplyUtf8, decodeTmuxArgument, parseSessionPaneDescriptorReply, } from "../protocol/session-descriptor-discovery.js";
42
42
  import { resolvePaneDisplayName } from "../protocol/pane-display-name.js";
43
43
  import { finalizeWorkspaceTmuxReconciliation, planWorkspaceTmuxReconciliation, } from "../protocol/workspace-tmux-adapter.js";
44
44
  import { liveSessionIdForNativeIdentity } from "../protocol/live-session-identity.js";
@@ -2308,7 +2308,7 @@ export class SessionChannel {
2308
2308
  }
2309
2309
  }
2310
2310
  const windowOptionHint = name === "subscription-changed"
2311
- ? (/^tmux-ide-pane-borders\s+\$[0-9]+\s+(@[0-9]+)\s+[0-9]+\s+-\s*:\s*(?:top|bottom|off)\s*$/u.exec(rest) ??
2311
+ ? (/^tmux-ide-pane-borders\s+\$[0-9]+\s+(@[0-9]+)\s+[0-9]+\s+-\s*:\s*(?:top|bottom|off|top-floating|bottom-floating)\s*$/u.exec(rest) ??
2312
2312
  /^tmux-ide-copy-keys\s+\$[0-9]+\s+(@[0-9]+)\s+[0-9]+\s+-\s*:\s*(?:emacs|vi)\s*$/u.exec(rest))
2313
2313
  : null;
2314
2314
  if (windowOptionHint) {
@@ -2454,11 +2454,9 @@ export class SessionChannel {
2454
2454
  if (this.disposed ||
2455
2455
  this.pendingLayoutOutput.get(change.windowId)?.layout !== pendingLayout)
2456
2456
  return;
2457
- const border = reply.lines[0];
2457
+ const border = tiledPaneBorderStatus(reply.lines[0]);
2458
2458
  const window = this.windowsByRuntime.get(change.windowId);
2459
- if (!reply.ok ||
2460
- !window ||
2461
- (border !== "top" && border !== "bottom" && border !== "off")) {
2459
+ if (!reply.ok || !window || border === null) {
2462
2460
  this.scheduleSync();
2463
2461
  return;
2464
2462
  }
@@ -2846,8 +2844,7 @@ export class SessionChannel {
2846
2844
  const repairedPanes = await this.repairTrustedPaneIdentity(descriptors, windowStage.layouts);
2847
2845
  const afterLines = await this.io.request(`list-panes -s -t "${expectedRuntimeSessionId}" -F "${SESSION_PANE_DESCRIPTOR_FORMAT}"`);
2848
2846
  const confirmedWindowStage = await this.stageWindows(expectedRuntimeSessionId);
2849
- const coherent = beforeLines.length === afterLines.length &&
2850
- beforeLines.every((line, index) => line === afterLines[index]);
2847
+ const coherent = sameSessionPaneInventory(beforeLines, afterLines);
2851
2848
  if (windowStage.repairedIdentity ||
2852
2849
  confirmedWindowStage.repairedIdentity ||
2853
2850
  repairedPanes ||
@@ -3083,7 +3080,8 @@ export class SessionChannel {
3083
3080
  !leftLayout ||
3084
3081
  !rightLayout ||
3085
3082
  leftWindow.semanticId !== rightWindow.semanticId ||
3086
- leftWindow.name !== rightWindow.name ||
3083
+ // Not the name: tmux derives it from the running command, and the
3084
+ // pane rows' own check ignores it too (sameSessionPaneInventory, #730).
3087
3085
  leftWindow.paneBorderStatus !== rightWindow.paneBorderStatus ||
3088
3086
  leftWindow.modeKeys !== rightWindow.modeKeys ||
3089
3087
  !layoutIdentitiesEqual(leftLayout, rightLayout)) {
@@ -3106,15 +3104,16 @@ export class SessionChannel {
3106
3104
  if (parts.length !== 10) {
3107
3105
  throw new Error(`window layout truth for ${this.opts.session} is malformed`);
3108
3106
  }
3109
- const [runtimeId = "", stampRaw = "", nameRaw = "", active = "", visible = "", zoomed = "", borderStatus = "off", full = visible, modeKeys, indexRaw = "",] = parts;
3107
+ const [runtimeId = "", stampRaw = "", nameRaw = "", active = "", visible = "", zoomed = "", borderStatusRaw = "off", full = visible, modeKeys, indexRaw = "",] = parts;
3110
3108
  const index = Number(indexRaw);
3109
+ const borderStatus = tiledPaneBorderStatus(borderStatusRaw);
3111
3110
  if (!/^@[0-9]+$/u.test(runtimeId) ||
3112
3111
  !/^(?:0|[1-9][0-9]*)$/u.test(indexRaw) ||
3113
3112
  !Number.isSafeInteger(index) ||
3114
3113
  seenIndexes.has(index) ||
3115
3114
  (active !== "0" && active !== "1") ||
3116
3115
  (zoomed !== "0" && zoomed !== "1") ||
3117
- (borderStatus !== "top" && borderStatus !== "bottom" && borderStatus !== "off") ||
3116
+ borderStatus === null ||
3118
3117
  (modeKeys !== undefined && modeKeys !== "emacs" && modeKeys !== "vi")) {
3119
3118
  throw new Error(`window layout truth for ${this.opts.session} is malformed`);
3120
3119
  }
@@ -30,6 +30,37 @@ import { DEFAULT_PANE_STREAM_FLOW_BUDGETS, PaneStreamWireLedger, } from "./wire-
30
30
  export { PANE_STREAM_REDEEM_PATH, PANE_STREAM_WEBSOCKET_SUBPROTOCOL };
31
31
  export const PANE_STREAM_MAX_REDEMPTION_BYTES = 4 * 1024;
32
32
  export const PANE_STREAM_MAX_CONTROL_BYTES = 4 * 1024;
33
+ /** The daemon process (or its whole generation) is going away. */
34
+ export const PANE_STREAM_DAEMON_SHUTDOWN_CLOSE = Object.freeze({
35
+ code: 1001,
36
+ reason: "daemon-shutdown",
37
+ });
38
+ /**
39
+ * Only this tmux server owner was retired; the daemon is still up. 1012
40
+ * (service restart) asks the client to list the servers again and reconnect
41
+ * now, without the backoff a vanished daemon deserves (#840).
42
+ */
43
+ export const PANE_STREAM_OWNER_RETIRED_CLOSE = Object.freeze({
44
+ code: 1012,
45
+ reason: "tmux-server-retired",
46
+ });
47
+ /**
48
+ * The process restarts its daemon generation in place (tmux server replaced,
49
+ * settings restart). A new generation follows at once, possibly on another
50
+ * port: read daemon.json again and reconnect now.
51
+ */
52
+ export const PANE_STREAM_DAEMON_RESTARTING_CLOSE = Object.freeze({
53
+ code: 1012,
54
+ reason: "daemon-restarting",
55
+ });
56
+ /** What an owner's streams are told when it is disposed for this reason. */
57
+ export function paneStreamCloseForRetirement(retirement) {
58
+ if (retirement === undefined || retirement === "shutdown")
59
+ return PANE_STREAM_DAEMON_SHUTDOWN_CLOSE;
60
+ return retirement === "generation-restart"
61
+ ? PANE_STREAM_DAEMON_RESTARTING_CLOSE
62
+ : PANE_STREAM_OWNER_RETIRED_CLOSE;
63
+ }
33
64
  export const PANE_STREAM_MAX_REDEMPTION_MS = 1_000;
34
65
  const WS_OPEN = 1;
35
66
  const CANONICAL_KEY_INPUT_FRAME_PREFIX = Buffer.from('{"kind":"key",', "utf8");
@@ -342,19 +373,34 @@ export class PaneStreamAdmissionCoordinator {
342
373
  flowSnapshot() {
343
374
  return this.#ledger.snapshot();
344
375
  }
345
- shutdown() {
376
+ /**
377
+ * Close every stream and refuse new ones. The first caller decides what the
378
+ * clients are told: the daemon going away, or only this tmux server owner
379
+ * being retired while the daemon stays up (reconnect now).
380
+ */
381
+ shutdown(close = PANE_STREAM_DAEMON_SHUTDOWN_CLOSE) {
346
382
  if (this.#shutdownPromise)
347
383
  return this.#shutdownPromise;
348
384
  this.#shuttingDown = true;
349
- this.#shutdownPromise = this.#finishShutdown();
385
+ // An idle daemon stopping is routine and stays out of the default log:
386
+ // `--headless --json` promises one status line on stdout. Streams that
387
+ // are actually closed, or an owner retired under a live daemon, are not.
388
+ const routine = close.reason === "daemon-shutdown" && this.#live.size === 0 && this.#preAuth.size === 0;
389
+ logger[routine ? "debug" : "info"]("pane-stream", "coordinator shutdown", {
390
+ code: close.code,
391
+ reason: close.reason,
392
+ liveStreams: this.#live.size,
393
+ unredeemed: this.#preAuth.size,
394
+ });
395
+ this.#shutdownPromise = this.#finishShutdown(close);
350
396
  return this.#shutdownPromise;
351
397
  }
352
- async #finishShutdown() {
398
+ async #finishShutdown(close) {
353
399
  for (const admission of [...this.#preAuth])
354
- admission.close(1001, "daemon-shutdown");
400
+ admission.close(close.code, close.reason);
355
401
  await this.#exclusive(async () => {
356
402
  for (const connection of [...this.#live])
357
- connection.close(1001, "daemon-shutdown");
403
+ connection.close(close.code, close.reason);
358
404
  for (const pending of [...this.#pending.values()])
359
405
  await this.#retirePending(pending);
360
406
  });
@@ -685,6 +731,8 @@ export class PaneStreamLiveConnection {
685
731
  #legacyInputActivated = false;
686
732
  #legacyGeometryActivated = false;
687
733
  #closed = false;
734
+ #closeCause = null;
735
+ #heldInput = null;
688
736
  #releasePromise = null;
689
737
  #stopAuthoritySnapshots = null;
690
738
  #sharedClockOriginMicros = null;
@@ -707,6 +755,8 @@ export class PaneStreamLiveConnection {
707
755
  "panes-closed",
708
756
  "peer-closed",
709
757
  "daemon-shutdown",
758
+ "tmux-server-retired",
759
+ "daemon-restarting",
710
760
  "redemption-rejected",
711
761
  "unknown",
712
762
  ]).has(closeReason ?? "")
@@ -827,6 +877,22 @@ export class PaneStreamLiveConnection {
827
877
  this.#observeSurfaceDemand(this.#descriptor.panes);
828
878
  void this.#subscribeAll();
829
879
  }
880
+ /**
881
+ * 1011 "stream-unavailable" has ten different origins and the client is told
882
+ * none of them. The log says which one, with the error text, so a stream
883
+ * that "just closed" can be traced without a reproduction.
884
+ */
885
+ #fail(cause, error) {
886
+ if (this.#closed)
887
+ return;
888
+ this.#closeCause = {
889
+ cause,
890
+ ...(error === undefined
891
+ ? {}
892
+ : { error: (error instanceof Error ? error.message : String(error)).slice(0, 300) }),
893
+ };
894
+ this.close(1011, "stream-unavailable");
895
+ }
830
896
  close(code = 1000, reason = "stream-closed") {
831
897
  if (this.#closed)
832
898
  return;
@@ -834,8 +900,12 @@ export class PaneStreamLiveConnection {
834
900
  logger.info("pane-stream", "stream closed", {
835
901
  code,
836
902
  reason,
903
+ ...(this.#closeCause ?? {}),
837
904
  session: this.#descriptor.sessionName,
838
905
  clientId: this.#clientId,
906
+ // Whether this connection held input when it went: the next stream of
907
+ // the same client can only be granted input once that is released.
908
+ ...(this.#heldInput === null ? {} : { heldInput: this.#heldInput }),
839
909
  });
840
910
  this.#closed = true;
841
911
  for (const demand of this.#surfaceDemands.values())
@@ -906,8 +976,8 @@ export class PaneStreamLiveConnection {
906
976
  try {
907
977
  described = await this.#mirror.describeSession(this.#descriptor.sessionName);
908
978
  }
909
- catch {
910
- this.close(1011, "stream-unavailable");
979
+ catch (error) {
980
+ this.#fail("describe-session-failed", error);
911
981
  return;
912
982
  }
913
983
  if (this.#closed)
@@ -926,8 +996,8 @@ export class PaneStreamLiveConnection {
926
996
  }
927
997
  this.#layoutSubscription = layoutSubscription;
928
998
  }
929
- catch {
930
- this.close(1011, "stream-unavailable");
999
+ catch (error) {
1000
+ this.#fail("layout-subscribe-failed", error);
931
1001
  return;
932
1002
  }
933
1003
  }
@@ -953,8 +1023,8 @@ export class PaneStreamLiveConnection {
953
1023
  }
954
1024
  channel.sub = sub;
955
1025
  }
956
- catch {
957
- this.close(1011, "stream-unavailable");
1026
+ catch (error) {
1027
+ this.#fail("pane-subscribe-failed", error);
958
1028
  return;
959
1029
  }
960
1030
  }
@@ -964,7 +1034,7 @@ export class PaneStreamLiveConnection {
964
1034
  const binding = this.#sessionRuntimeBinding;
965
1035
  const offer = this.#descriptor.terminalDelivery;
966
1036
  if (!binding || !offer) {
967
- this.close(1011, "stream-unavailable");
1037
+ this.#fail("no-session-runtime-binding");
968
1038
  return;
969
1039
  }
970
1040
  // Layout authority covers the whole session, while content leases may select
@@ -1031,7 +1101,7 @@ export class PaneStreamLiveConnection {
1031
1101
  this.#failTopologyChanged();
1032
1102
  return;
1033
1103
  }
1034
- this.close(1011, "stream-unavailable");
1104
+ this.#fail("semantic-layout-subscribe-failed", cause);
1035
1105
  return;
1036
1106
  }
1037
1107
  // Start visible sources first, preserving descriptor order within each
@@ -1071,8 +1141,10 @@ export class PaneStreamLiveConnection {
1071
1141
  if (this.#closed ||
1072
1142
  settled.some((result) => result.status === "rejected" || !result.value.delivery.negotiation.accepted)) {
1073
1143
  await Promise.all(opened.map(({ delivery }) => delivery.close().catch(() => undefined)));
1074
- if (!this.#closed)
1075
- this.close(1011, "stream-unavailable");
1144
+ if (!this.#closed) {
1145
+ const rejected = settled.find((result) => result.status === "rejected");
1146
+ this.#fail("delivery-negotiation-failed", rejected?.status === "rejected" ? rejected.reason : "a pane's delivery offer was refused");
1147
+ }
1076
1148
  return;
1077
1149
  }
1078
1150
  const deliveryIdentityChanged = opened.some(({ channel, delivery, pending }) => {
@@ -1906,8 +1978,8 @@ export class PaneStreamLiveConnection {
1906
1978
  try {
1907
1979
  this.#socket.send(encoded, { binary });
1908
1980
  }
1909
- catch {
1910
- this.close(1011, "stream-unavailable");
1981
+ catch (error) {
1982
+ this.#fail("socket-send-failed", error);
1911
1983
  return;
1912
1984
  }
1913
1985
  // Stall is judged on the drain tick, never synchronously at send: the
@@ -1949,7 +2021,7 @@ export class PaneStreamLiveConnection {
1949
2021
  return;
1950
2022
  const buffered = this.#socket.bufferedAmount ?? 0;
1951
2023
  if (!Number.isSafeInteger(buffered) || buffered < 0) {
1952
- this.close(1011, "stream-unavailable");
2024
+ this.#fail("socket-buffer-invalid");
1953
2025
  return;
1954
2026
  }
1955
2027
  if (buffered > this.#maxSocketBufferedBytes) {
@@ -2382,6 +2454,23 @@ export class PaneStreamLiveConnection {
2382
2454
  return true;
2383
2455
  }
2384
2456
  #sendAuthoritySnapshot(snapshot) {
2457
+ // One line when this connection gains or loses input, and one for its
2458
+ // first snapshot: a stream that paints but never accepts keys shows up
2459
+ // here as "holdsInput false" with the client that holds it instead.
2460
+ const self = this.#sessionRuntimeBinding?.clientId ?? null;
2461
+ const holdsInput = self !== null && snapshot.owners.input === self;
2462
+ if (this.#heldInput !== holdsInput) {
2463
+ logger.info("pane-stream", "stream input authority", {
2464
+ session: this.#descriptor.sessionName,
2465
+ clientId: this.#clientId,
2466
+ connectionClientId: self,
2467
+ holdsInput,
2468
+ inputOwner: snapshot.owners.input,
2469
+ clients: snapshot.clients.length,
2470
+ revision: snapshot.revision,
2471
+ });
2472
+ this.#heldInput = holdsInput;
2473
+ }
2385
2474
  this.#sendFrame(null, { type: "authority-snapshot", snapshot });
2386
2475
  }
2387
2476
  #prepareInputAuthority(geometry) {
@@ -2469,6 +2558,14 @@ export class PaneStreamLiveConnection {
2469
2558
  ].includes(rawCode)
2470
2559
  ? rawCode
2471
2560
  : "stream-unavailable";
2561
+ // A refused intent is answered to the client only; without this line a
2562
+ // click that did nothing leaves no trace in either log (#764).
2563
+ logger.info("pane-stream", "intent rejected", {
2564
+ session: this.#descriptor.sessionName,
2565
+ clientId: this.#clientId,
2566
+ verb: intent.verb,
2567
+ code,
2568
+ });
2472
2569
  this.#sendFrame(null, {
2473
2570
  type: "semantic-intent-ack",
2474
2571
  operationId,
@@ -2660,8 +2757,8 @@ export class PaneStreamLiveConnection {
2660
2757
  }
2661
2758
  }
2662
2759
  }
2663
- catch {
2664
- this.close(1011, "stream-unavailable");
2760
+ catch (error) {
2761
+ this.#fail("control-frame-handler-failed", error);
2665
2762
  }
2666
2763
  }
2667
2764
  #failProtocol(code) {
@@ -2673,8 +2770,8 @@ export class PaneStreamLiveConnection {
2673
2770
  retryable: false,
2674
2771
  });
2675
2772
  }
2676
- catch {
2677
- this.close(1011, "stream-unavailable");
2773
+ catch (error) {
2774
+ this.#fail("error-frame-send-failed", error);
2678
2775
  return;
2679
2776
  }
2680
2777
  this.close(1008, code);
@@ -48,11 +48,12 @@ export class PaneStreamRuntime {
48
48
  },
49
49
  });
50
50
  }
51
- dispose() {
51
+ /** `close` says what the streams are told; the default is a daemon shutdown. */
52
+ dispose(close) {
52
53
  if (!this.#disposePromise) {
53
54
  this.#disposePromise = (async () => {
54
55
  this.nativeSurfaces?.close();
55
- await this.coordinator.shutdown();
56
+ await this.coordinator.shutdown(close);
56
57
  })();
57
58
  }
58
59
  return this.#disposePromise;