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
@@ -31,6 +31,7 @@ import { PaneStreamLayoutSnapshotFrameSchemaZ, type WindowLinkTopology } from "@
31
31
  import type { TerminalDeliveryGraphics } from "../session-runtime/terminal-delivery-hub.ts";
32
32
  import { z } from "zod";
33
33
  import { logger } from "../../lib/log.ts";
34
+ import type { TmuxServerOwnerRetirement } from "../../lib/tmux-server-owners.ts";
34
35
  import {
35
36
  PANE_STREAM_MAX_HELD_DELTAS,
36
37
  PANE_STREAM_MAX_OUTPUT_BYTES,
@@ -132,6 +133,44 @@ import {
132
133
  export { PANE_STREAM_REDEEM_PATH, PANE_STREAM_WEBSOCKET_SUBPROTOCOL };
133
134
  export const PANE_STREAM_MAX_REDEMPTION_BYTES = 4 * 1024;
134
135
  export const PANE_STREAM_MAX_CONTROL_BYTES = 4 * 1024;
136
+
137
+ export interface PaneStreamShutdownClose {
138
+ readonly code: number;
139
+ readonly reason: "daemon-shutdown" | "tmux-server-retired" | "daemon-restarting";
140
+ }
141
+ /** The daemon process (or its whole generation) is going away. */
142
+ export const PANE_STREAM_DAEMON_SHUTDOWN_CLOSE: PaneStreamShutdownClose = Object.freeze({
143
+ code: 1001,
144
+ reason: "daemon-shutdown",
145
+ });
146
+ /**
147
+ * Only this tmux server owner was retired; the daemon is still up. 1012
148
+ * (service restart) asks the client to list the servers again and reconnect
149
+ * now, without the backoff a vanished daemon deserves (#840).
150
+ */
151
+ export const PANE_STREAM_OWNER_RETIRED_CLOSE: PaneStreamShutdownClose = Object.freeze({
152
+ code: 1012,
153
+ reason: "tmux-server-retired",
154
+ });
155
+ /**
156
+ * The process restarts its daemon generation in place (tmux server replaced,
157
+ * settings restart). A new generation follows at once, possibly on another
158
+ * port: read daemon.json again and reconnect now.
159
+ */
160
+ export const PANE_STREAM_DAEMON_RESTARTING_CLOSE: PaneStreamShutdownClose = Object.freeze({
161
+ code: 1012,
162
+ reason: "daemon-restarting",
163
+ });
164
+ /** What an owner's streams are told when it is disposed for this reason. */
165
+ export function paneStreamCloseForRetirement(
166
+ retirement: TmuxServerOwnerRetirement | undefined,
167
+ ): PaneStreamShutdownClose {
168
+ if (retirement === undefined || retirement === "shutdown")
169
+ return PANE_STREAM_DAEMON_SHUTDOWN_CLOSE;
170
+ return retirement === "generation-restart"
171
+ ? PANE_STREAM_DAEMON_RESTARTING_CLOSE
172
+ : PANE_STREAM_OWNER_RETIRED_CLOSE;
173
+ }
135
174
  export const PANE_STREAM_MAX_REDEMPTION_MS = 1_000;
136
175
 
137
176
  const WS_OPEN = 1;
@@ -731,17 +770,33 @@ export class PaneStreamAdmissionCoordinator {
731
770
  return this.#ledger.snapshot();
732
771
  }
733
772
 
734
- shutdown(): Promise<void> {
773
+ /**
774
+ * Close every stream and refuse new ones. The first caller decides what the
775
+ * clients are told: the daemon going away, or only this tmux server owner
776
+ * being retired while the daemon stays up (reconnect now).
777
+ */
778
+ shutdown(close: PaneStreamShutdownClose = PANE_STREAM_DAEMON_SHUTDOWN_CLOSE): Promise<void> {
735
779
  if (this.#shutdownPromise) return this.#shutdownPromise;
736
780
  this.#shuttingDown = true;
737
- this.#shutdownPromise = this.#finishShutdown();
781
+ // An idle daemon stopping is routine and stays out of the default log:
782
+ // `--headless --json` promises one status line on stdout. Streams that
783
+ // are actually closed, or an owner retired under a live daemon, are not.
784
+ const routine =
785
+ close.reason === "daemon-shutdown" && this.#live.size === 0 && this.#preAuth.size === 0;
786
+ logger[routine ? "debug" : "info"]("pane-stream", "coordinator shutdown", {
787
+ code: close.code,
788
+ reason: close.reason,
789
+ liveStreams: this.#live.size,
790
+ unredeemed: this.#preAuth.size,
791
+ });
792
+ this.#shutdownPromise = this.#finishShutdown(close);
738
793
  return this.#shutdownPromise;
739
794
  }
740
795
 
741
- async #finishShutdown(): Promise<void> {
742
- for (const admission of [...this.#preAuth]) admission.close(1001, "daemon-shutdown");
796
+ async #finishShutdown(close: PaneStreamShutdownClose): Promise<void> {
797
+ for (const admission of [...this.#preAuth]) admission.close(close.code, close.reason);
743
798
  await this.#exclusive(async () => {
744
- for (const connection of [...this.#live]) connection.close(1001, "daemon-shutdown");
799
+ for (const connection of [...this.#live]) connection.close(close.code, close.reason);
745
800
  for (const pending of [...this.#pending.values()]) await this.#retirePending(pending);
746
801
  });
747
802
  await Promise.all([...this.#retiringReleases]);
@@ -1205,6 +1260,8 @@ export class PaneStreamLiveConnection {
1205
1260
  #legacyInputActivated = false;
1206
1261
  #legacyGeometryActivated = false;
1207
1262
  #closed = false;
1263
+ #closeCause: { readonly cause: string; readonly error?: string } | null = null;
1264
+ #heldInput: boolean | null = null;
1208
1265
  #releasePromise: Promise<unknown> | null = null;
1209
1266
  #stopAuthoritySnapshots: (() => void) | null = null;
1210
1267
  #sharedClockOriginMicros: number | null = null;
@@ -1241,6 +1298,8 @@ export class PaneStreamLiveConnection {
1241
1298
  "panes-closed",
1242
1299
  "peer-closed",
1243
1300
  "daemon-shutdown",
1301
+ "tmux-server-retired",
1302
+ "daemon-restarting",
1244
1303
  "redemption-rejected",
1245
1304
  "unknown",
1246
1305
  ]).has(closeReason ?? "")
@@ -1258,6 +1317,8 @@ export class PaneStreamLiveConnection {
1258
1317
  | "panes-closed"
1259
1318
  | "peer-closed"
1260
1319
  | "daemon-shutdown"
1320
+ | "tmux-server-retired"
1321
+ | "daemon-restarting"
1261
1322
  | "redemption-rejected"
1262
1323
  | "unknown";
1263
1324
  this.#observability.recordSpan(
@@ -1391,14 +1452,34 @@ export class PaneStreamLiveConnection {
1391
1452
  void this.#subscribeAll();
1392
1453
  }
1393
1454
 
1455
+ /**
1456
+ * 1011 "stream-unavailable" has ten different origins and the client is told
1457
+ * none of them. The log says which one, with the error text, so a stream
1458
+ * that "just closed" can be traced without a reproduction.
1459
+ */
1460
+ #fail(cause: string, error?: unknown): void {
1461
+ if (this.#closed) return;
1462
+ this.#closeCause = {
1463
+ cause,
1464
+ ...(error === undefined
1465
+ ? {}
1466
+ : { error: (error instanceof Error ? error.message : String(error)).slice(0, 300) }),
1467
+ };
1468
+ this.close(1011, "stream-unavailable");
1469
+ }
1470
+
1394
1471
  close(code = 1000, reason = "stream-closed"): void {
1395
1472
  if (this.#closed) return;
1396
1473
  this.#recordDiagnosticLifecycle("pane-stream-terminal", code, reason);
1397
1474
  logger.info("pane-stream", "stream closed", {
1398
1475
  code,
1399
1476
  reason,
1477
+ ...(this.#closeCause ?? {}),
1400
1478
  session: this.#descriptor.sessionName,
1401
1479
  clientId: this.#clientId,
1480
+ // Whether this connection held input when it went: the next stream of
1481
+ // the same client can only be granted input once that is released.
1482
+ ...(this.#heldInput === null ? {} : { heldInput: this.#heldInput }),
1402
1483
  });
1403
1484
  this.#closed = true;
1404
1485
  for (const demand of this.#surfaceDemands.values()) demand.close();
@@ -1468,8 +1549,8 @@ export class PaneStreamLiveConnection {
1468
1549
  let described: MirrorSessionDescription;
1469
1550
  try {
1470
1551
  described = await this.#mirror.describeSession(this.#descriptor.sessionName);
1471
- } catch {
1472
- this.close(1011, "stream-unavailable");
1552
+ } catch (error) {
1553
+ this.#fail("describe-session-failed", error);
1473
1554
  return;
1474
1555
  }
1475
1556
  if (this.#closed) return;
@@ -1489,8 +1570,8 @@ export class PaneStreamLiveConnection {
1489
1570
  return;
1490
1571
  }
1491
1572
  this.#layoutSubscription = layoutSubscription;
1492
- } catch {
1493
- this.close(1011, "stream-unavailable");
1573
+ } catch (error) {
1574
+ this.#fail("layout-subscribe-failed", error);
1494
1575
  return;
1495
1576
  }
1496
1577
  }
@@ -1514,8 +1595,8 @@ export class PaneStreamLiveConnection {
1514
1595
  continue;
1515
1596
  }
1516
1597
  channel.sub = sub;
1517
- } catch {
1518
- this.close(1011, "stream-unavailable");
1598
+ } catch (error) {
1599
+ this.#fail("pane-subscribe-failed", error);
1519
1600
  return;
1520
1601
  }
1521
1602
  }
@@ -1526,7 +1607,7 @@ export class PaneStreamLiveConnection {
1526
1607
  const binding = this.#sessionRuntimeBinding;
1527
1608
  const offer = this.#descriptor.terminalDelivery;
1528
1609
  if (!binding || !offer) {
1529
- this.close(1011, "stream-unavailable");
1610
+ this.#fail("no-session-runtime-binding");
1530
1611
  return;
1531
1612
  }
1532
1613
  // Layout authority covers the whole session, while content leases may select
@@ -1594,7 +1675,7 @@ export class PaneStreamLiveConnection {
1594
1675
  this.#failTopologyChanged();
1595
1676
  return;
1596
1677
  }
1597
- this.close(1011, "stream-unavailable");
1678
+ this.#fail("semantic-layout-subscribe-failed", cause);
1598
1679
  return;
1599
1680
  }
1600
1681
 
@@ -1652,7 +1733,13 @@ export class PaneStreamLiveConnection {
1652
1733
  )
1653
1734
  ) {
1654
1735
  await Promise.all(opened.map(({ delivery }) => delivery.close().catch(() => undefined)));
1655
- if (!this.#closed) this.close(1011, "stream-unavailable");
1736
+ if (!this.#closed) {
1737
+ const rejected = settled.find((result) => result.status === "rejected");
1738
+ this.#fail(
1739
+ "delivery-negotiation-failed",
1740
+ rejected?.status === "rejected" ? rejected.reason : "a pane's delivery offer was refused",
1741
+ );
1742
+ }
1656
1743
  return;
1657
1744
  }
1658
1745
 
@@ -2536,8 +2623,8 @@ export class PaneStreamLiveConnection {
2536
2623
  this.#sentBytesTotal += bytes;
2537
2624
  try {
2538
2625
  this.#socket.send(encoded, { binary });
2539
- } catch {
2540
- this.close(1011, "stream-unavailable");
2626
+ } catch (error) {
2627
+ this.#fail("socket-send-failed", error);
2541
2628
  return;
2542
2629
  }
2543
2630
  // Stall is judged on the drain tick, never synchronously at send: the
@@ -2579,7 +2666,7 @@ export class PaneStreamLiveConnection {
2579
2666
  if (this.#closed) return;
2580
2667
  const buffered = this.#socket.bufferedAmount ?? 0;
2581
2668
  if (!Number.isSafeInteger(buffered) || buffered < 0) {
2582
- this.close(1011, "stream-unavailable");
2669
+ this.#fail("socket-buffer-invalid");
2583
2670
  return;
2584
2671
  }
2585
2672
  if (buffered > this.#maxSocketBufferedBytes) {
@@ -3039,6 +3126,23 @@ export class PaneStreamLiveConnection {
3039
3126
  }
3040
3127
 
3041
3128
  #sendAuthoritySnapshot(snapshot: SessionRuntimeAuthoritySnapshot): void {
3129
+ // One line when this connection gains or loses input, and one for its
3130
+ // first snapshot: a stream that paints but never accepts keys shows up
3131
+ // here as "holdsInput false" with the client that holds it instead.
3132
+ const self = this.#sessionRuntimeBinding?.clientId ?? null;
3133
+ const holdsInput = self !== null && snapshot.owners.input === self;
3134
+ if (this.#heldInput !== holdsInput) {
3135
+ logger.info("pane-stream", "stream input authority", {
3136
+ session: this.#descriptor.sessionName,
3137
+ clientId: this.#clientId,
3138
+ connectionClientId: self,
3139
+ holdsInput,
3140
+ inputOwner: snapshot.owners.input,
3141
+ clients: snapshot.clients.length,
3142
+ revision: snapshot.revision,
3143
+ });
3144
+ this.#heldInput = holdsInput;
3145
+ }
3042
3146
  this.#sendFrame(null, { type: "authority-snapshot", snapshot });
3043
3147
  }
3044
3148
 
@@ -3134,6 +3238,14 @@ export class PaneStreamLiveConnection {
3134
3238
  ].includes(rawCode)
3135
3239
  ? rawCode
3136
3240
  : "stream-unavailable";
3241
+ // A refused intent is answered to the client only; without this line a
3242
+ // click that did nothing leaves no trace in either log (#764).
3243
+ logger.info("pane-stream", "intent rejected", {
3244
+ session: this.#descriptor.sessionName,
3245
+ clientId: this.#clientId,
3246
+ verb: intent.verb,
3247
+ code,
3248
+ });
3137
3249
  this.#sendFrame(null, {
3138
3250
  type: "semantic-intent-ack",
3139
3251
  operationId,
@@ -3377,8 +3489,8 @@ export class PaneStreamLiveConnection {
3377
3489
  }
3378
3490
  }
3379
3491
  }
3380
- } catch {
3381
- this.close(1011, "stream-unavailable");
3492
+ } catch (error) {
3493
+ this.#fail("control-frame-handler-failed", error);
3382
3494
  }
3383
3495
  }
3384
3496
 
@@ -3390,8 +3502,8 @@ export class PaneStreamLiveConnection {
3390
3502
  code,
3391
3503
  retryable: false,
3392
3504
  });
3393
- } catch {
3394
- this.close(1011, "stream-unavailable");
3505
+ } catch (error) {
3506
+ this.#fail("error-frame-send-failed", error);
3395
3507
  return;
3396
3508
  }
3397
3509
  this.close(1008, code);
@@ -8,6 +8,7 @@ import { PaneStreamLeaseManager } from "./lease-manager.ts";
8
8
  import {
9
9
  PaneStreamAdmissionCoordinator,
10
10
  type PaneStreamAdmissionCoordinatorOptions,
11
+ type PaneStreamShutdownClose,
11
12
  } from "./pane-stream-websocket.ts";
12
13
 
13
14
  export interface PaneStreamRuntimeOptions {
@@ -75,11 +76,12 @@ export class PaneStreamRuntime {
75
76
  });
76
77
  }
77
78
 
78
- dispose(): Promise<void> {
79
+ /** `close` says what the streams are told; the default is a daemon shutdown. */
80
+ dispose(close?: PaneStreamShutdownClose): Promise<void> {
79
81
  if (!this.#disposePromise) {
80
82
  this.#disposePromise = (async () => {
81
83
  this.nativeSurfaces?.close();
82
- await this.coordinator.shutdown();
84
+ await this.coordinator.shutdown(close);
83
85
  })();
84
86
  }
85
87
  return this.#disposePromise;
@@ -64,6 +64,37 @@ export const SESSION_PANE_DESCRIPTOR_FORMAT = [
64
64
  "#{pane_pid}",
65
65
  ].join("\t");
66
66
 
67
+ /**
68
+ * Descriptor fields the program in a pane changes whenever it likes: its
69
+ * command name, the window name tmux derives from it, and its title.
70
+ */
71
+ const VOLATILE_DESCRIPTOR_FIELDS: ReadonlySet<number> = new Set([
72
+ 4, // pane_current_command
73
+ 7, // window_name
74
+ 9, // pane_title
75
+ ]);
76
+
77
+ /**
78
+ * Whether two `list-panes` replies in SESSION_PANE_DESCRIPTOR_FORMAT describe
79
+ * the same panes. A busy pane changes its command and title between any two
80
+ * reads, which is not a pane set that is still changing: those fields are
81
+ * display text, read again on the next refresh (#730).
82
+ */
83
+ export function sameSessionPaneInventory(
84
+ before: readonly string[],
85
+ after: readonly string[],
86
+ ): boolean {
87
+ const stable = (line: string) =>
88
+ line
89
+ .split("\t")
90
+ .map((field, index) => (VOLATILE_DESCRIPTOR_FIELDS.has(index) ? "" : field))
91
+ .join("\t");
92
+ return (
93
+ before.length === after.length &&
94
+ before.every((line, index) => line === after[index] || stable(line) === stable(after[index]!))
95
+ );
96
+ }
97
+
67
98
  /** Decode the escapes emitted by tmux's `qa` format modifier. */
68
99
  export function decodeTmuxArgument(value: string): string {
69
100
  const encoded =
@@ -175,7 +175,12 @@ export interface StockSplitOptions extends StockSplitSizes {
175
175
  }
176
176
  export function parseStockSplitOptions(line: string | undefined): StockSplitOptions | null {
177
177
  const [borderStatus, scrollbars, style] = (line ?? "").split("\t");
178
- if (!/^(off|top|bottom)$/u.test(borderStatus ?? "") || !/^[a-z]+$/u.test(scrollbars ?? ""))
178
+ // The raw value stays: the guarded command compares it with the option. A
179
+ // floating value leaves tiled panes without a status line, like "off".
180
+ if (
181
+ !/^(off|top|bottom|top-floating|bottom-floating)$/u.test(borderStatus ?? "") ||
182
+ !/^[a-z]+$/u.test(scrollbars ?? "")
183
+ )
179
184
  return null;
180
185
  const field = (name: string) =>
181
186
  Number(new RegExp(`\\b${name}=(\\d+)`, "u").exec(style ?? "")?.[1] ?? 0);
@@ -115,6 +115,14 @@ export interface SessionRuntimeRegistryOptions {
115
115
  readonly observability?: SessionRuntimeObservability;
116
116
  /** Deterministic qualification seam; never invoked while observability is disabled. */
117
117
  readonly createTraceCorrelator?: (scheduler: SessionRuntimeScheduler) => RuntimeTraceCorrelator;
118
+ /**
119
+ * A session's terminal inventory may be readable again: a shared-window or
120
+ * registered-window conflict cleared, or its trusted inventory became
121
+ * qualified after it was not. The daemon publishes a
122
+ * terminal-runtime-inventory change so an idle client that met the 503
123
+ * re-reads at once; that read re-qualifies the session (perf plan F13, #764).
124
+ */
125
+ readonly onInventoryRecovered?: (session: string) => void;
118
126
  }
119
127
 
120
128
  /** Opaque daemon-internal proof that an inventory came from one exact runtime owner. */
@@ -324,6 +332,15 @@ export class SessionRuntimeRegistry implements PaneStreamMirror {
324
332
  readonly #scheduler: SessionRuntimeScheduler;
325
333
  readonly #observability: SessionRuntimeObservability;
326
334
  readonly #createTraceCorrelator: (scheduler: SessionRuntimeScheduler) => RuntimeTraceCorrelator;
335
+ readonly #onInventoryRecovered: ((session: string) => void) | null;
336
+
337
+ #announceInventory(session: string): void {
338
+ try {
339
+ this.#onInventoryRecovered?.(session);
340
+ } catch {
341
+ // A publication failure never changes qualification.
342
+ }
343
+ }
327
344
  readonly #sessions = new Map<string, SessionRuntime>();
328
345
  #listenerDisposal: ListenerDisposalSummary | null = null;
329
346
  readonly #proofPrewarmOwnership = new Map<SessionRuntime, { owned: boolean; claims: number }>();
@@ -342,6 +359,7 @@ export class SessionRuntimeRegistry implements PaneStreamMirror {
342
359
  this.#observability = options.observability ?? DISABLED_SESSION_RUNTIME_OBSERVABILITY;
343
360
  this.#createTraceCorrelator =
344
361
  options.createTraceCorrelator ?? ((scheduler) => new RuntimeTraceCorrelator(scheduler));
362
+ this.#onInventoryRecovered = options.onInventoryRecovered ?? null;
345
363
  const diagnosticMirrorOptions: Partial<MirrorServiceOptions> = {
346
364
  onInputAccepted: (session, action, acceptedAtMicros, ok) => {
347
365
  for (const traceId of action.traceIds ?? []) {
@@ -474,6 +492,9 @@ export class SessionRuntimeRegistry implements PaneStreamMirror {
474
492
  onSharedWindowConflict: (session, conflict) => {
475
493
  options.mirror?.onSharedWindowConflict?.(session, conflict);
476
494
  if (conflict) this.#sessions.get(session)?.invalidateSharedWindowAuthority();
495
+ // A cleared conflict is the trigger an idle client needs: nobody else
496
+ // may read the inventory, and the client's re-read re-qualifies it.
497
+ else if (!this.#mirror.hasSharedWindowConflict(session)) this.#announceInventory(session);
477
498
  },
478
499
  onNativeClientActivity: (session) => {
479
500
  options.mirror?.onNativeClientActivity?.(session);
@@ -573,7 +594,9 @@ export class SessionRuntimeRegistry implements PaneStreamMirror {
573
594
  }
574
595
  signal?.throwIfAborted();
575
596
  await abortable(this.#mirror.verifyRegisteredWindows(), signal);
597
+ const wasQualified = runtime.trustedInventoryQualified();
576
598
  runtime.qualifyTrustedInventory(runtimeSessionId);
599
+ if (!wasQualified && runtime.trustedInventoryQualified()) this.#announceInventory(session);
577
600
  } finally {
578
601
  this.#releaseProofPrewarmRuntime(runtime);
579
602
  }
@@ -117,6 +117,8 @@ export interface SessionRuntimeStageSpan {
117
117
  | "panes-closed"
118
118
  | "peer-closed"
119
119
  | "daemon-shutdown"
120
+ | "tmux-server-retired"
121
+ | "daemon-restarting"
120
122
  | "redemption-rejected"
121
123
  | "unknown";
122
124
  readonly deliveryVisibility?: "visible" | "background" | "hidden" | "frozen";
@@ -56,6 +56,31 @@ import type { TerminalGraphicsState } from "@tmux-ide/contracts";
56
56
  // Bound parser work per turn without changing byte-stream semantics. This is a
57
57
  // batch bound, not a producer queue cap: upstream pressure must preserve bytes.
58
58
  const MAX_INGEST_BATCH_BYTES = 256 * 1024;
59
+ /**
60
+ * Under a flood, publish at most one commit per display interval (daemon perf
61
+ * F1). Each commit projects, diffs and hashes the replica; committing after
62
+ * every parsed chunk kept the daemon off tmux's control pipe, so tmux itself
63
+ * ran about 4× slower while a pane was viewed. Rows that scroll through
64
+ * history between two commits are never projected or hashed. A write with no
65
+ * output queued behind it (a keystroke echo, the end of a burst) still
66
+ * commits at once.
67
+ */
68
+ export const COALESCED_COMMIT_INTERVAL_MS = 16;
69
+ /**
70
+ * A flood commit costs far more than the display interval (about 35 ms with a
71
+ * full 2,000-row history), so an interval counted from the commit's start
72
+ * alone never skips anything: the next chunk always arrives "late". After a
73
+ * commit the interpreter therefore also reads queued output for this many
74
+ * times the commit's own cost before it commits again, so at most one part in
75
+ * (1 + factor) of a flood goes to commits (half, at 1).
76
+ */
77
+ export const COALESCED_COMMIT_REST_FACTOR = 1;
78
+ /**
79
+ * Upper bound of that rest. A skipped frame can still wait longer when the
80
+ * queued write behind it opens a synchronized update: then it is published
81
+ * with that update, at its end or by the 250 ms sync recovery.
82
+ */
83
+ export const COALESCED_COMMIT_MAX_REST_MS = 100;
59
84
  type PendingWrite = {
60
85
  data: Uint8Array;
61
86
  offset: number;
@@ -184,6 +209,11 @@ export class TerminalReplicaInterpreter {
184
209
  #needsSeed = true;
185
210
  #closed = false;
186
211
  #walkCount = 0;
212
+ #lastCommitAtMs = Number.NEGATIVE_INFINITY;
213
+ #lastCommitEndMs = Number.NEGATIVE_INFINITY;
214
+ #lastCommitCostMs = 0;
215
+ // A coalesced write skipped its commit and counts on a queued write to publish.
216
+ #coalescedCommitOwed = false;
187
217
  #pendingWrites: WriteGroup | null = null;
188
218
  #widgetGate = false;
189
219
  // kitty graphics: images outlive reseeds; the scanner owns split APCs.
@@ -528,7 +558,11 @@ export class TerminalReplicaInterpreter {
528
558
  this.#emit(update);
529
559
  }
530
560
 
531
- async #write(data: Uint8Array, continuedTrace: SessionRuntimeTraceContext | null): Promise<void> {
561
+ async #write(
562
+ data: Uint8Array,
563
+ continuedTrace: SessionRuntimeTraceContext | null,
564
+ hasBacklog: () => boolean = () => false,
565
+ ): Promise<void> {
532
566
  if (this.#closed || this.#nativeReseedRequested) return;
533
567
  // This optional id is only a controlled next-output probe. It is not a
534
568
  // causal assertion: unrelated external tmux output arriving first may
@@ -547,7 +581,17 @@ export class TerminalReplicaInterpreter {
547
581
  // see. Skipping it matters: every parser write settles on a later timer
548
582
  // turn, so a frame split into dozens of %output chunks would otherwise
549
583
  // serialize dozens of turns and fall behind a 30 fps image stream.
550
- if (scanned.forward.byteLength === 0) return;
584
+ if (scanned.forward.byteLength === 0) {
585
+ // The queued write a coalesced commit was counting on turned out to be
586
+ // all image payload, and nothing else is queued: publish what it skipped.
587
+ // Not inside a synchronized update: its end, or the sync recovery,
588
+ // publishes the owed commit with the whole frame.
589
+ if (this.#coalescedCommitOwed && !hasBacklog() && !this.#backend.modes().synchronizedOutput) {
590
+ this.#commit(false, this.#pendingWriteDirty ?? undefined, trace);
591
+ this.#publishGraphics();
592
+ }
593
+ return;
594
+ }
551
595
  // Scanning can prepend an escape retained from the previous chunk. Bound
552
596
  // the actual parser calls too, and union damage across every fragment.
553
597
  for (let offset = 0; offset < scanned.forward.length; offset += MAX_INGEST_BATCH_BYTES) {
@@ -592,6 +636,20 @@ export class TerminalReplicaInterpreter {
592
636
  if (pendingResize) {
593
637
  this.#commit(false, undefined, trace);
594
638
  } else {
639
+ // Coalesce under a flood: more output is already queued, the last commit
640
+ // is recent, and nobody is timing this write. The dirty range stays in
641
+ // #pendingWriteDirty and the next commit (the queued write's, or any
642
+ // control operation's) merges it, so nothing is dropped. The bootstrap
643
+ // seed is never held: before it no commit has run, so one is always due.
644
+ if (
645
+ trace === null &&
646
+ this.#causalCell === null &&
647
+ hasBacklog() &&
648
+ !this.#coalescedCommitIsDue()
649
+ ) {
650
+ this.#coalescedCommitOwed = true;
651
+ return;
652
+ }
595
653
  this.#commit(false, this.#backend.dirtyRange(), trace);
596
654
  }
597
655
  this.#publishGraphics();
@@ -629,10 +687,36 @@ export class TerminalReplicaInterpreter {
629
687
  this.#syncRecovery = null;
630
688
  }
631
689
 
690
+ /** True once a queued flood may publish again: see the two constants above. */
691
+ #coalescedCommitIsDue(): boolean {
692
+ const now = this.#scheduler.nowMs();
693
+ if (now - this.#lastCommitAtMs < COALESCED_COMMIT_INTERVAL_MS) return false;
694
+ const rest = Math.min(
695
+ COALESCED_COMMIT_MAX_REST_MS,
696
+ COALESCED_COMMIT_REST_FACTOR * this.#lastCommitCostMs,
697
+ );
698
+ return now - this.#lastCommitEndMs >= rest;
699
+ }
700
+
632
701
  #commit(
633
702
  forceSeed: boolean,
634
703
  dirty?: { start: number; end: number },
635
704
  trace: SessionRuntimeTraceContext | null = null,
705
+ ): void {
706
+ this.#lastCommitAtMs = this.#scheduler.nowMs();
707
+ this.#coalescedCommitOwed = false;
708
+ try {
709
+ this.#commitNow(forceSeed, dirty, trace);
710
+ } finally {
711
+ this.#lastCommitEndMs = this.#scheduler.nowMs();
712
+ this.#lastCommitCostMs = this.#lastCommitEndMs - this.#lastCommitAtMs;
713
+ }
714
+ }
715
+
716
+ #commitNow(
717
+ forceSeed: boolean,
718
+ dirty: { start: number; end: number } | undefined,
719
+ trace: SessionRuntimeTraceContext | null,
636
720
  ): void {
637
721
  if (this.#backend.requiresNativeReseed()) {
638
722
  if (!this.#nativeReseedRequested) {
@@ -916,7 +1000,20 @@ export class TerminalReplicaInterpreter {
916
1000
  group.entries.splice(0, completed.length);
917
1001
  group.bytes -= length;
918
1002
  try {
919
- await this.#write(data, group.trace);
1003
+ // Backlog: bytes still in this group, or a newer untraced group
1004
+ // already waiting behind it (a group that has not run yet always
1005
+ // holds an entry). A traced group is a boundary: its commit must
1006
+ // not carry these external bytes. Checked after parsing, when it
1007
+ // is current.
1008
+ await this.#write(
1009
+ data,
1010
+ group.trace,
1011
+ () =>
1012
+ group.entries.length > 0 ||
1013
+ (this.#pendingWrites !== null &&
1014
+ this.#pendingWrites !== group &&
1015
+ this.#pendingWrites.trace === null),
1016
+ );
920
1017
  } catch (error) {
921
1018
  for (const entry of completed) entry.reject(error);
922
1019
  throw error;