tmux-ide 2.9.21 → 2.9.23

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 (131) hide show
  1. package/bin/cli.js +6235 -8473
  2. package/package.json +3 -3
  3. package/packages/contracts/src/index.ts +2 -0
  4. package/packages/contracts/src/pane-reader.ts +121 -0
  5. package/packages/contracts/src/pane-stream.ts +18 -0
  6. package/packages/contracts/src/visual-theme-presets.ts +58 -2
  7. package/packages/contracts/src/websocket-heartbeat.ts +41 -0
  8. package/packages/daemon/dist/command-center/automation.js +1 -1
  9. package/packages/daemon/dist/command-center/daemon-fleet-facts-observer.js +37 -5
  10. package/packages/daemon/dist/command-center/discovery.js +28 -2
  11. package/packages/daemon/dist/command-center/server.js +8 -2
  12. package/packages/daemon/dist/command-center/tmux-server-reader.js +41 -0
  13. package/packages/daemon/dist/command-center/tmux-servers.js +7 -1
  14. package/packages/daemon/dist/doctor.js +147 -43
  15. package/packages/daemon/dist/lib/bounded-tmux-read.js +34 -12
  16. package/packages/daemon/dist/lib/cli-command.js +13 -0
  17. package/packages/daemon/dist/lib/daemon-embed.js +126 -55
  18. package/packages/daemon/dist/lib/daemon-stop-progress.js +58 -0
  19. package/packages/daemon/dist/lib/embedded-daemon-lifecycle.js +11 -0
  20. package/packages/daemon/dist/lib/embedded-tmux-server-owners.js +88 -12
  21. package/packages/daemon/dist/lib/headless-daemon.js +177 -10
  22. package/packages/daemon/dist/lib/log.js +18 -1
  23. package/packages/daemon/dist/lib/pane-reader-files.js +226 -0
  24. package/packages/daemon/dist/lib/remote-tmux-command.js +8 -5
  25. package/packages/daemon/dist/lib/tmux-client-execution.js +73 -7
  26. package/packages/daemon/dist/lib/tmux-external-interaction-observer.js +140 -19
  27. package/packages/daemon/dist/lib/tmux-native-browser.js +4 -2
  28. package/packages/daemon/dist/lib/tmux-pane-reader.js +107 -0
  29. package/packages/daemon/dist/lib/tmux-server-agent-admission.js +6 -1
  30. package/packages/daemon/dist/lib/tmux-server-features.js +38 -0
  31. package/packages/daemon/dist/lib/tmux-server-owner-teardown.js +33 -0
  32. package/packages/daemon/dist/lib/tmux-server-owner.js +38 -37
  33. package/packages/daemon/dist/lib/tmux-server-owners.js +310 -20
  34. package/packages/daemon/dist/lib/tmux-server-registration.js +128 -9
  35. package/packages/daemon/dist/lib/unix-socket-authority.js +58 -3
  36. package/packages/daemon/dist/lib/workspace-pane-creation.js +10 -1
  37. package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/Info.plist +2 -2
  38. package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/MacOS/tmux-ide-notifier +0 -0
  39. package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/Resources/Assets.car +0 -0
  40. package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/_CodeSignature/CodeResources +2 -2
  41. package/packages/daemon/dist/open-browser.js +26 -12
  42. package/packages/daemon/dist/open-reader.js +84 -0
  43. package/packages/daemon/dist/plugins/cli.js +1 -2
  44. package/packages/daemon/dist/plugins/daemon-plugins.js +2 -10
  45. package/packages/daemon/dist/restore.js +57 -40
  46. package/packages/daemon/dist/server/pane-stream-upgrade.js +5 -1
  47. package/packages/daemon/dist/server/websocket-heartbeat.js +103 -0
  48. package/packages/daemon/dist/terminal/attachments/native-runtime.js +32 -14
  49. package/packages/daemon/dist/terminal/mirror/layout-content-rows.js +11 -0
  50. package/packages/daemon/dist/terminal/mirror/mirror-service.js +61 -3
  51. package/packages/daemon/dist/terminal/mirror/session-channel.js +13 -12
  52. package/packages/daemon/dist/terminal/pane-stream/pane-stream-websocket.js +123 -25
  53. package/packages/daemon/dist/terminal/pane-stream/runtime.js +3 -2
  54. package/packages/daemon/dist/terminal/protocol/reader-option.js +66 -0
  55. package/packages/daemon/dist/terminal/protocol/session-descriptor-discovery.js +30 -2
  56. package/packages/daemon/dist/terminal/protocol/stock-split-resize.js +4 -1
  57. package/packages/daemon/dist/terminal/session-runtime/registry.js +17 -0
  58. package/packages/daemon/dist/terminal/session-runtime/terminal-replica-interpreter.js +81 -3
  59. package/packages/daemon/dist/terminal/session-runtime/terminal-replica-owner.js +60 -3
  60. package/packages/daemon/dist/tmux-upgrade/cli.js +106 -0
  61. package/packages/daemon/dist/tmux-upgrade/io.js +540 -0
  62. package/packages/daemon/dist/tmux-upgrade/plan.js +238 -0
  63. package/packages/daemon/dist/tmux-upgrade/run.js +199 -0
  64. package/packages/daemon/dist/tui/chrome/snapshot.js +3 -4
  65. package/packages/daemon/dist/tui/mirror/runtime/application-home-agent-navigation.js +64 -4
  66. package/packages/daemon/dist/tui/mirror/runtime/application-home-agents-owner.js +35 -5
  67. package/packages/daemon/dist/tui/mirror/runtime/application-machine-agent-navigation.js +12 -8
  68. package/packages/daemon/dist/tui/mirror/runtime/application-terminal-interaction-controller.js +125 -111
  69. package/packages/daemon/src/command-center/automation.ts +1 -1
  70. package/packages/daemon/src/command-center/daemon-fleet-facts-observer.ts +49 -8
  71. package/packages/daemon/src/command-center/discovery.ts +35 -2
  72. package/packages/daemon/src/command-center/server.ts +22 -8
  73. package/packages/daemon/src/command-center/tmux-server-reader.ts +62 -0
  74. package/packages/daemon/src/command-center/tmux-servers.ts +7 -1
  75. package/packages/daemon/src/doctor.ts +164 -45
  76. package/packages/daemon/src/lib/bounded-tmux-read.ts +29 -9
  77. package/packages/daemon/src/lib/cli-command.ts +16 -0
  78. package/packages/daemon/src/lib/daemon-embed.ts +176 -64
  79. package/packages/daemon/src/lib/daemon-stop-progress.ts +78 -0
  80. package/packages/daemon/src/lib/embedded-daemon-lifecycle.ts +12 -0
  81. package/packages/daemon/src/lib/embedded-tmux-server-owners.ts +115 -11
  82. package/packages/daemon/src/lib/headless-daemon.ts +205 -12
  83. package/packages/daemon/src/lib/log.ts +18 -1
  84. package/packages/daemon/src/lib/pane-reader-files.ts +294 -0
  85. package/packages/daemon/src/lib/remote-tmux-command.ts +13 -6
  86. package/packages/daemon/src/lib/tmux-client-execution.ts +79 -7
  87. package/packages/daemon/src/lib/tmux-external-interaction-observer.ts +163 -25
  88. package/packages/daemon/src/lib/tmux-native-browser.ts +4 -3
  89. package/packages/daemon/src/lib/tmux-pane-reader.ts +145 -0
  90. package/packages/daemon/src/lib/tmux-server-agent-admission.ts +6 -1
  91. package/packages/daemon/src/lib/tmux-server-features.ts +43 -0
  92. package/packages/daemon/src/lib/tmux-server-owner-teardown.ts +54 -0
  93. package/packages/daemon/src/lib/tmux-server-owner.ts +41 -35
  94. package/packages/daemon/src/lib/tmux-server-owners.ts +427 -22
  95. package/packages/daemon/src/lib/tmux-server-registration.ts +155 -7
  96. package/packages/daemon/src/lib/unix-socket-authority.ts +72 -3
  97. package/packages/daemon/src/lib/workspace-pane-creation.ts +11 -1
  98. package/packages/daemon/src/open-browser.ts +59 -18
  99. package/packages/daemon/src/open-reader.ts +148 -0
  100. package/packages/daemon/src/plugins/cli.ts +1 -2
  101. package/packages/daemon/src/plugins/daemon-plugins.ts +2 -12
  102. package/packages/daemon/src/restore.ts +80 -44
  103. package/packages/daemon/src/server/pane-stream-upgrade.ts +6 -0
  104. package/packages/daemon/src/server/websocket-heartbeat.ts +135 -0
  105. package/packages/daemon/src/terminal/attachments/native-runtime.ts +58 -14
  106. package/packages/daemon/src/terminal/mirror/events.ts +2 -0
  107. package/packages/daemon/src/terminal/mirror/layout-content-rows.ts +11 -0
  108. package/packages/daemon/src/terminal/mirror/mirror-service.ts +61 -2
  109. package/packages/daemon/src/terminal/mirror/session-channel.ts +15 -14
  110. package/packages/daemon/src/terminal/pane-stream/pane-stream-websocket.ts +140 -23
  111. package/packages/daemon/src/terminal/pane-stream/runtime.ts +4 -2
  112. package/packages/daemon/src/terminal/protocol/reader-option.ts +77 -0
  113. package/packages/daemon/src/terminal/protocol/session-descriptor-discovery.ts +41 -1
  114. package/packages/daemon/src/terminal/protocol/stock-split-resize.ts +6 -1
  115. package/packages/daemon/src/terminal/session-runtime/registry.ts +23 -0
  116. package/packages/daemon/src/terminal/session-runtime/runtime-observability.ts +2 -0
  117. package/packages/daemon/src/terminal/session-runtime/terminal-replica-interpreter.ts +100 -3
  118. package/packages/daemon/src/terminal/session-runtime/terminal-replica-owner.ts +60 -3
  119. package/packages/daemon/src/tmux-upgrade/cli.ts +118 -0
  120. package/packages/daemon/src/tmux-upgrade/io.ts +596 -0
  121. package/packages/daemon/src/tmux-upgrade/plan.ts +353 -0
  122. package/packages/daemon/src/tmux-upgrade/run.ts +325 -0
  123. package/packages/daemon/src/tui/chrome/snapshot.ts +3 -4
  124. package/packages/daemon/src/tui/mirror/runtime/application-home-agent-navigation.ts +110 -10
  125. package/packages/daemon/src/tui/mirror/runtime/application-home-agents-owner.ts +58 -6
  126. package/packages/daemon/src/tui/mirror/runtime/application-machine-agent-navigation.ts +20 -9
  127. package/packages/daemon/src/tui/mirror/runtime/application-root-v2.tsx +2 -2
  128. package/packages/daemon/src/tui/mirror/runtime/application-terminal-interaction-controller.ts +149 -128
  129. package/packages/daemon-client/src/direct-application-shell-transport.ts +21 -3
  130. package/packages/daemon-client/src/workspace-event-supervisor.ts +63 -2
  131. package/packages/tmux-bridge/src/runner.ts +3 -1
@@ -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 = [];
@@ -1066,18 +1084,18 @@ export class WorkspaceTerminalInventoryRuntime {
1066
1084
  }
1067
1085
  catch (error) {
1068
1086
  if (this.#inventoryEpoch !== epoch) {
1069
- if (staleRetry < 1)
1087
+ if (staleRetry < INVENTORY_STALE_RETRIES)
1070
1088
  return this.#readInventory(signal, staleRetry + 1);
1071
- throw new NativeTerminalAttachmentRuntimeError("discovery-failed");
1089
+ throw new NativeTerminalAttachmentRuntimeError("discovery-failed", "overtaken-by-invalidations");
1072
1090
  }
1073
1091
  throw error;
1074
1092
  }
1075
1093
  if (signal.aborted)
1076
1094
  throw new NativeTerminalAttachmentRuntimeError("runtime-disposed");
1077
1095
  if (this.#inventoryEpoch !== epoch) {
1078
- if (staleRetry < 1)
1096
+ if (staleRetry < INVENTORY_STALE_RETRIES)
1079
1097
  return this.#readInventory(signal, staleRetry + 1);
1080
- throw new NativeTerminalAttachmentRuntimeError("discovery-failed");
1098
+ throw new NativeTerminalAttachmentRuntimeError("discovery-failed", "overtaken-by-invalidations");
1081
1099
  }
1082
1100
  return this.#publishInventory(snapshot, nativeEpoch, signal, epoch);
1083
1101
  }
@@ -1091,16 +1109,16 @@ export class WorkspaceTerminalInventoryRuntime {
1091
1109
  }
1092
1110
  catch (error) {
1093
1111
  if (abort.signal.aborted || this.#inventoryEpoch !== epoch) {
1094
- if (staleRetry < 1)
1112
+ if (staleRetry < INVENTORY_STALE_RETRIES)
1095
1113
  return this.#readInventory(undefined, staleRetry + 1);
1096
- throw new NativeTerminalAttachmentRuntimeError("discovery-failed");
1114
+ throw new NativeTerminalAttachmentRuntimeError("discovery-failed", "overtaken-by-invalidations");
1097
1115
  }
1098
1116
  throw error;
1099
1117
  }
1100
1118
  if (abort.signal.aborted || this.#inventoryEpoch !== epoch) {
1101
- if (staleRetry < 1)
1119
+ if (staleRetry < INVENTORY_STALE_RETRIES)
1102
1120
  return this.#readInventory(undefined, staleRetry + 1);
1103
- throw new NativeTerminalAttachmentRuntimeError("discovery-failed");
1121
+ throw new NativeTerminalAttachmentRuntimeError("discovery-failed", "overtaken-by-invalidations");
1104
1122
  }
1105
1123
  return this.#publishInventory(value, nativeEpoch, abort.signal, epoch);
1106
1124
  })().finally(() => {
@@ -1156,9 +1174,9 @@ export class WorkspaceTerminalInventoryRuntime {
1156
1174
  assertLive();
1157
1175
  if (this.#inventoryEpoch === epoch)
1158
1176
  return null;
1159
- if (staleRetry < 1)
1177
+ if (staleRetry < INVENTORY_STALE_RETRIES)
1160
1178
  return this.#discoverTerminalRuntimeSession(requestedSessionName, signal, staleRetry + 1);
1161
- return Promise.reject(new NativeTerminalAttachmentRuntimeError("discovery-failed"));
1179
+ return Promise.reject(new NativeTerminalAttachmentRuntimeError("discovery-failed", "overtaken-by-invalidations"));
1162
1180
  };
1163
1181
  assertLive();
1164
1182
  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";
@@ -365,6 +365,7 @@ export class SessionChannel {
365
365
  await this.io.start();
366
366
  await this.captureAttachedSessionIdentity();
367
367
  this.io.send("refresh-client -B 'tmux-ide-browser-icon:%*:#{@tmux_ide_browser_icon}'");
368
+ this.io.send("refresh-client -B 'tmux-ide-reader:%*:#{@tmux_ide_reader}'");
368
369
  // Changing border placement can resize PTYs without changing the layout
369
370
  // string, so tmux emits no layout-change. Subscribe to this window option.
370
371
  this.io.send("refresh-client -B 'tmux-ide-pane-borders:@*:#{pane-border-status}'");
@@ -2266,7 +2267,8 @@ export class SessionChannel {
2266
2267
  name === "session-renamed" ||
2267
2268
  name === "sessions-changed")
2268
2269
  this.opts.onWindowTopologyChanged?.();
2269
- if (name === "subscription-changed" && rest.startsWith("tmux-ide-browser-icon ")) {
2270
+ if (name === "subscription-changed" &&
2271
+ (rest.startsWith("tmux-ide-browser-icon ") || rest.startsWith("tmux-ide-reader "))) {
2270
2272
  this.scheduleSync();
2271
2273
  return;
2272
2274
  }
@@ -2306,7 +2308,7 @@ export class SessionChannel {
2306
2308
  }
2307
2309
  }
2308
2310
  const windowOptionHint = name === "subscription-changed"
2309
- ? (/^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) ??
2310
2312
  /^tmux-ide-copy-keys\s+\$[0-9]+\s+(@[0-9]+)\s+[0-9]+\s+-\s*:\s*(?:emacs|vi)\s*$/u.exec(rest))
2311
2313
  : null;
2312
2314
  if (windowOptionHint) {
@@ -2452,11 +2454,9 @@ export class SessionChannel {
2452
2454
  if (this.disposed ||
2453
2455
  this.pendingLayoutOutput.get(change.windowId)?.layout !== pendingLayout)
2454
2456
  return;
2455
- const border = reply.lines[0];
2457
+ const border = tiledPaneBorderStatus(reply.lines[0]);
2456
2458
  const window = this.windowsByRuntime.get(change.windowId);
2457
- if (!reply.ok ||
2458
- !window ||
2459
- (border !== "top" && border !== "bottom" && border !== "off")) {
2459
+ if (!reply.ok || !window || border === null) {
2460
2460
  this.scheduleSync();
2461
2461
  return;
2462
2462
  }
@@ -2672,6 +2672,7 @@ export class SessionChannel {
2672
2672
  displayName: display?.name ?? null,
2673
2673
  displayNameSource: display?.source ?? null,
2674
2674
  browserIcon: pane?.descriptor?.browserIcon ?? null,
2675
+ reader: pane?.descriptor?.reader ?? null,
2675
2676
  left: leaf.left,
2676
2677
  top: leaf.top,
2677
2678
  width: leaf.width,
@@ -2843,8 +2844,7 @@ export class SessionChannel {
2843
2844
  const repairedPanes = await this.repairTrustedPaneIdentity(descriptors, windowStage.layouts);
2844
2845
  const afterLines = await this.io.request(`list-panes -s -t "${expectedRuntimeSessionId}" -F "${SESSION_PANE_DESCRIPTOR_FORMAT}"`);
2845
2846
  const confirmedWindowStage = await this.stageWindows(expectedRuntimeSessionId);
2846
- const coherent = beforeLines.length === afterLines.length &&
2847
- beforeLines.every((line, index) => line === afterLines[index]);
2847
+ const coherent = sameSessionPaneInventory(beforeLines, afterLines);
2848
2848
  if (windowStage.repairedIdentity ||
2849
2849
  confirmedWindowStage.repairedIdentity ||
2850
2850
  repairedPanes ||
@@ -3103,15 +3103,16 @@ export class SessionChannel {
3103
3103
  if (parts.length !== 10) {
3104
3104
  throw new Error(`window layout truth for ${this.opts.session} is malformed`);
3105
3105
  }
3106
- const [runtimeId = "", stampRaw = "", nameRaw = "", active = "", visible = "", zoomed = "", borderStatus = "off", full = visible, modeKeys, indexRaw = "",] = parts;
3106
+ const [runtimeId = "", stampRaw = "", nameRaw = "", active = "", visible = "", zoomed = "", borderStatusRaw = "off", full = visible, modeKeys, indexRaw = "",] = parts;
3107
3107
  const index = Number(indexRaw);
3108
+ const borderStatus = tiledPaneBorderStatus(borderStatusRaw);
3108
3109
  if (!/^@[0-9]+$/u.test(runtimeId) ||
3109
3110
  !/^(?:0|[1-9][0-9]*)$/u.test(indexRaw) ||
3110
3111
  !Number.isSafeInteger(index) ||
3111
3112
  seenIndexes.has(index) ||
3112
3113
  (active !== "0" && active !== "1") ||
3113
3114
  (zoomed !== "0" && zoomed !== "1") ||
3114
- (borderStatus !== "top" && borderStatus !== "bottom" && borderStatus !== "off") ||
3115
+ borderStatus === null ||
3115
3116
  (modeKeys !== undefined && modeKeys !== "emacs" && modeKeys !== "vi")) {
3116
3117
  throw new Error(`window layout truth for ${this.opts.session} is malformed`);
3117
3118
  }
@@ -2,7 +2,7 @@ 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, } 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, } from "@tmux-ide/contracts";
6
6
  import { inflateSync } from "node:zlib";
7
7
  import { PaneStreamLayoutSnapshotFrameSchemaZ } from "@tmux-ide/contracts";
8
8
  import { z } from "zod";
@@ -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 }) => {
@@ -1332,7 +1404,9 @@ export class PaneStreamLiveConnection {
1332
1404
  this.#observeSurfaceDemand([channel.semanticPaneId]);
1333
1405
  // Renderers that cannot inflate see raw formats; their bytes are inflated
1334
1406
  // when served.
1335
- const zlib = this.#descriptor.terminalDelivery?.protocolVersions.some((version) => version === TERMINAL_GRAPHICS_ZLIB_CAPABILITY_VERSION || version === 117) === true;
1407
+ const zlib = this.#descriptor.terminalDelivery?.protocolVersions.some((version) => version === TERMINAL_GRAPHICS_ZLIB_CAPABILITY_VERSION ||
1408
+ version === PANE_STREAM_BROWSER_ICON_CAPABILITY_VERSION ||
1409
+ version === PANE_STREAM_READER_CAPABILITY_VERSION) === true;
1336
1410
  channel.graphicsZlib = zlib;
1337
1411
  channel.graphicsLocal =
1338
1412
  !!this.#localImages &&
@@ -1793,6 +1867,9 @@ export class PaneStreamLiveConnection {
1793
1867
  }
1794
1868
  this.#sendFrame(null, frame);
1795
1869
  }
1870
+ #offers(version) {
1871
+ return this.#descriptor.terminalDelivery?.protocolVersions.includes(version) === true;
1872
+ }
1796
1873
  #layoutFrame(event) {
1797
1874
  const frame = {
1798
1875
  type: "layout",
@@ -1808,9 +1885,13 @@ export class PaneStreamLiveConnection {
1808
1885
  pane: pane.semanticPaneId,
1809
1886
  displayName: pane.displayName,
1810
1887
  displayNameSource: pane.displayNameSource,
1811
- ...(this.#descriptor.terminalDelivery?.protocolVersions.includes(117)
1888
+ ...(this.#offers(PANE_STREAM_BROWSER_ICON_CAPABILITY_VERSION) ||
1889
+ this.#offers(PANE_STREAM_READER_CAPABILITY_VERSION)
1812
1890
  ? { browserIcon: pane.browserIcon ?? null }
1813
1891
  : {}),
1892
+ ...(this.#offers(PANE_STREAM_READER_CAPABILITY_VERSION)
1893
+ ? { reader: pane.reader ? { name: pane.reader.name } : null }
1894
+ : {}),
1814
1895
  left: pane.left,
1815
1896
  top: pane.top,
1816
1897
  width: pane.width,
@@ -1897,8 +1978,8 @@ export class PaneStreamLiveConnection {
1897
1978
  try {
1898
1979
  this.#socket.send(encoded, { binary });
1899
1980
  }
1900
- catch {
1901
- this.close(1011, "stream-unavailable");
1981
+ catch (error) {
1982
+ this.#fail("socket-send-failed", error);
1902
1983
  return;
1903
1984
  }
1904
1985
  // Stall is judged on the drain tick, never synchronously at send: the
@@ -1940,7 +2021,7 @@ export class PaneStreamLiveConnection {
1940
2021
  return;
1941
2022
  const buffered = this.#socket.bufferedAmount ?? 0;
1942
2023
  if (!Number.isSafeInteger(buffered) || buffered < 0) {
1943
- this.close(1011, "stream-unavailable");
2024
+ this.#fail("socket-buffer-invalid");
1944
2025
  return;
1945
2026
  }
1946
2027
  if (buffered > this.#maxSocketBufferedBytes) {
@@ -2373,6 +2454,23 @@ export class PaneStreamLiveConnection {
2373
2454
  return true;
2374
2455
  }
2375
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
+ }
2376
2474
  this.#sendFrame(null, { type: "authority-snapshot", snapshot });
2377
2475
  }
2378
2476
  #prepareInputAuthority(geometry) {
@@ -2651,8 +2749,8 @@ export class PaneStreamLiveConnection {
2651
2749
  }
2652
2750
  }
2653
2751
  }
2654
- catch {
2655
- this.close(1011, "stream-unavailable");
2752
+ catch (error) {
2753
+ this.#fail("control-frame-handler-failed", error);
2656
2754
  }
2657
2755
  }
2658
2756
  #failProtocol(code) {
@@ -2664,8 +2762,8 @@ export class PaneStreamLiveConnection {
2664
2762
  retryable: false,
2665
2763
  });
2666
2764
  }
2667
- catch {
2668
- this.close(1011, "stream-unavailable");
2765
+ catch (error) {
2766
+ this.#fail("error-frame-send-failed", error);
2669
2767
  return;
2670
2768
  }
2671
2769
  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;