tmux-ide 2.9.27 → 2.9.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/bin/cli.js +796 -97
  2. package/package.json +1 -1
  3. package/packages/contracts/src/pane-stream.ts +36 -0
  4. package/packages/daemon/dist/command-center/resources/terminal-runtime-inventory.js +17 -3
  5. package/packages/daemon/dist/command-center/tmux-servers.js +2 -1
  6. package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/Info.plist +2 -2
  7. package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/MacOS/tmux-ide-notifier +0 -0
  8. package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/Resources/Assets.car +0 -0
  9. package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/_CodeSignature/CodeResources +2 -2
  10. package/packages/daemon/dist/terminal/attachments/native-runtime.js +12 -8
  11. package/packages/daemon/dist/terminal/mirror/mirror-service.js +13 -0
  12. package/packages/daemon/dist/terminal/mirror/native-atomic-snapshot.js +17 -7
  13. package/packages/daemon/dist/terminal/mirror/native-grid-capture.js +129 -5
  14. package/packages/daemon/dist/terminal/mirror/pane-feed.js +4 -0
  15. package/packages/daemon/dist/terminal/mirror/pane-hold.js +13 -0
  16. package/packages/daemon/dist/terminal/mirror/session-channel.js +198 -27
  17. package/packages/daemon/dist/terminal/pane-stream/lease-manager.js +1 -0
  18. package/packages/daemon/dist/terminal/pane-stream/pane-stream-websocket.js +184 -12
  19. package/packages/daemon/dist/terminal/protocol/layout-parse.js +99 -10
  20. package/packages/daemon/dist/terminal/protocol/session-descriptor-discovery.js +5 -2
  21. package/packages/daemon/dist/terminal/session-runtime/terminal-interpreter-backend.js +2 -1
  22. package/packages/daemon/dist/terminal/session-runtime/terminal-replica-interpreter.js +46 -1
  23. package/packages/daemon/dist/terminal/session-runtime/terminal-replica-owner.js +128 -3
  24. package/packages/daemon/dist/terminal/session-runtime/xterm-terminal-interpreter-backend.js +115 -6
  25. package/packages/daemon/dist/tui/mirror/open-tui-workspace-runtime-port.js +19 -1
  26. package/packages/daemon/dist/tui/mirror/runtime/open-tui-generation-host.js +9 -1
  27. package/packages/daemon/dist/tui/mirror/workspace/connection-feedback.js +8 -0
  28. package/packages/daemon/src/command-center/resources/terminal-runtime-inventory.ts +20 -2
  29. package/packages/daemon/src/command-center/tmux-servers.ts +4 -1
  30. package/packages/daemon/src/terminal/attachments/native-runtime.ts +15 -1
  31. package/packages/daemon/src/terminal/mirror/events.ts +31 -1
  32. package/packages/daemon/src/terminal/mirror/mirror-service.ts +19 -0
  33. package/packages/daemon/src/terminal/mirror/native-atomic-snapshot.ts +16 -5
  34. package/packages/daemon/src/terminal/mirror/native-grid-capture.ts +164 -5
  35. package/packages/daemon/src/terminal/mirror/pane-feed.ts +5 -0
  36. package/packages/daemon/src/terminal/mirror/pane-hold.ts +16 -0
  37. package/packages/daemon/src/terminal/mirror/session-channel.ts +253 -38
  38. package/packages/daemon/src/terminal/mirror/trusted-inventory.ts +2 -0
  39. package/packages/daemon/src/terminal/pane-stream/lease-manager.ts +3 -0
  40. package/packages/daemon/src/terminal/pane-stream/pane-stream-websocket.ts +215 -12
  41. package/packages/daemon/src/terminal/protocol/layout-parse.ts +109 -10
  42. package/packages/daemon/src/terminal/protocol/session-descriptor-discovery.ts +10 -1
  43. package/packages/daemon/src/terminal/session-runtime/runtime-observability.ts +2 -1
  44. package/packages/daemon/src/terminal/session-runtime/terminal-interpreter-backend.ts +24 -1
  45. package/packages/daemon/src/terminal/session-runtime/terminal-replica-interpreter.ts +61 -5
  46. package/packages/daemon/src/terminal/session-runtime/terminal-replica-owner.ts +159 -32
  47. package/packages/daemon/src/terminal/session-runtime/xterm-terminal-interpreter-backend.ts +134 -11
  48. package/packages/daemon/src/tui/mirror/open-tui-workspace-runtime-port.ts +19 -0
  49. package/packages/daemon/src/tui/mirror/runtime/open-tui-generation-host.ts +13 -0
  50. package/packages/daemon/src/tui/mirror/workspace/connection-feedback.ts +13 -1
  51. package/packages/daemon-client/src/direct-application-shell-transport.ts +6 -2
  52. package/packages/daemon-client/src/pane-stream-client.ts +24 -6
  53. package/packages/daemon-client/src/workspace-client-types.ts +6 -0
  54. package/packages/daemon-client/src/workspace-client.ts +15 -9
  55. package/packages/daemon-client/src/workspace-event-supervisor.ts +3 -1
@@ -13,6 +13,13 @@ import {
13
13
  decodeNativeGridCapture,
14
14
  isStockRawGridCapture,
15
15
  isNativeBootstrapCapture,
16
+ decodeNativeHistoryPiece,
17
+ nativeSeedHistoryRows,
18
+ NATIVE_HISTORY_PIECE_CELL_BUDGET,
19
+ type NativeHistoryRequest,
20
+ NATIVE_BOOTSTRAP_PROBE_FLAGS,
21
+ NATIVE_BOOTSTRAP_PROBE_LIMITS,
22
+ readNativeBootstrapProbe,
16
23
  type NativeGridCapture,
17
24
  } from "./native-grid-capture.ts";
18
25
  /**
@@ -98,6 +105,8 @@ import type {
98
105
  MirrorLayoutAuthoritySnapshot,
99
106
  MirrorLayoutEvent,
100
107
  MirrorPaneEvent,
108
+ MirrorPaneHold,
109
+ MirrorPaneHoldWhy,
101
110
  MirrorSessionDescription,
102
111
  } from "./events.ts";
103
112
  import { liveSessionIdForNativeIdentity } from "../protocol/live-session-identity.ts";
@@ -149,6 +158,14 @@ const RECOVERY_COMMAND_DEADLINE_MS = 500;
149
158
  const RECOVERY_NO_PROGRESS_DEADLINE_MS = 3_000;
150
159
  const RECOVERY_ABSOLUTE_DEADLINE_MS = 5_000;
151
160
  const RECOVERY_MAX_ATTEMPTS = 4;
161
+ // A pane whose recoveries keep failing is not asked again at once (#869). Each
162
+ // recovery makes tmux build a whole capture, and a client that lost its stream
163
+ // opens a new one every few seconds for as long as its window is open. From
164
+ // the second failure in a row the pane refuses a new recovery, without a tmux
165
+ // command, for 2 s doubling to 30 s. A recovery that converges ends it.
166
+ const RECOVERY_HOLD_AFTER_FAILURES = 2;
167
+ const RECOVERY_HOLD_BASE_MS = 2_000;
168
+ const RECOVERY_HOLD_MAX_MS = 30_000;
152
169
  const MAX_QUEUED_SNAPSHOTS = 64;
153
170
  const RECOVERY_CAPTURE_MAX_BYTES = 16 * 1024 * 1024;
154
171
  // Budget row bookkeeping separately from wire bytes (64 bytes per retained
@@ -156,6 +173,12 @@ const RECOVERY_CAPTURE_MAX_BYTES = 16 * 1024 * 1024;
156
173
  // Both the wire-byte cap and this finite allocation bound remain enforced.
157
174
  const RECOVERY_CAPTURE_MAX_LINES = RECOVERY_CAPTURE_MAX_BYTES / 64;
158
175
  const RECOVERY_CURSOR_MAX_BYTES = 1_024;
176
+ /** #873: a seed's width when the layout does not know the pane yet. */
177
+ const NATIVE_SEED_FALLBACK_COLS = 512;
178
+ const NATIVE_HISTORY_PIECE_LIMITS = {
179
+ maxBytes: RECOVERY_CAPTURE_MAX_BYTES,
180
+ maxLines: RECOVERY_CAPTURE_MAX_LINES,
181
+ } as const;
159
182
  const RECOVERY_CURSOR_PROBE_FORMAT = [
160
183
  "#{cursor_x}",
161
184
  "#{cursor_y}",
@@ -206,21 +229,21 @@ export type MirrorFlowRecoveryFailureReason =
206
229
  | "notification-queue-overflow"
207
230
  | "no-progress"
208
231
  | "absolute-deadline"
209
- | "attempts-exhausted";
232
+ | "attempts-exhausted"
233
+ /** Refused without a tmux command: the pane's last recoveries all failed. */
234
+ | "held-after-failures";
210
235
 
211
- /** Cache only proven server capability; malformed or failed reads can recover. */
236
+ /**
237
+ * A complete native capture that proves the server cannot bootstrap a replica.
238
+ * Cache only proven server capability; malformed reads can recover.
239
+ */
212
240
  function nativeBootstrapUnsupported(
213
- ok: boolean,
214
241
  lines: readonly string[],
215
242
  native: NativeGridCapture | null,
216
243
  ): boolean {
217
- if (ok)
218
- return (
219
- isStockRawGridCapture(lines) ||
220
- (native !== null && (native.version !== 2 || native.currentAttributes === undefined))
221
- );
222
- return lines.some((line) =>
223
- /^(?:parse error: )?(?:command capture-pane: )?unknown flag -R$/.test(line.trim()),
244
+ return (
245
+ isStockRawGridCapture(lines) ||
246
+ (native !== null && (native.version !== 2 || native.currentAttributes === undefined))
224
247
  );
225
248
  }
226
249
 
@@ -305,6 +328,8 @@ export interface SessionChannelOptions {
305
328
 
306
329
  export interface PaneSubscriptionHandle {
307
330
  readHistorySize(): Promise<number | null>;
331
+ /** #873: older native history rows, answered by one `history` event. */
332
+ requestNativeHistory(request: NativeHistoryRequest): boolean;
308
333
  captureNativeBacking(): Promise<NativeGridReadResult>;
309
334
  readonly semanticPaneId: string;
310
335
  freeze(): void;
@@ -342,6 +367,12 @@ interface PaneRecord {
342
367
  readonly subs: Set<SubRecord>;
343
368
  incarnation: number;
344
369
  snapshotLayoutGeneration: number;
370
+ /** Recoveries that failed in a row since the last one that converged. */
371
+ failedRecoveries: number;
372
+ /** Until this monotonic time a new recovery fails without asking tmux. */
373
+ recoveryHoldUntilMs: number;
374
+ /** Why the last counted failure failed, for a refusal to say (#872). */
375
+ heldWhy: MirrorPaneHoldWhy;
345
376
  }
346
377
 
347
378
  interface SnapshotLease {
@@ -804,6 +835,7 @@ export class SessionChannel {
804
835
  displayNameSource: display.source,
805
836
  windowName: pane.descriptor?.windowName ?? null,
806
837
  active: pane.active,
838
+ ...(pane.descriptor?.floating ? { floating: true as const } : {}),
807
839
  };
808
840
  });
809
841
  return {
@@ -1146,6 +1178,16 @@ export class SessionChannel {
1146
1178
  );
1147
1179
  }
1148
1180
 
1181
+ /**
1182
+ * A person asked to retry (#872): the pane's next recovery asks tmux even
1183
+ * inside its hold. The failure count is kept, so a failure holds it for the
1184
+ * next, longer time. Nothing for a pane that is not held or not known.
1185
+ */
1186
+ liftRecoveryHold(semanticPaneId: string): void {
1187
+ const pane = this.panesBySemantic.get(semanticPaneId);
1188
+ if (pane) pane.recoveryHoldUntilMs = 0;
1189
+ }
1190
+
1149
1191
  subscribePane(
1150
1192
  semanticPaneId: string,
1151
1193
  onEvent: (event: MirrorPaneEvent) => void,
@@ -1185,6 +1227,7 @@ export class SessionChannel {
1185
1227
  () =>
1186
1228
  !sub.closed && sub.pane === pane && this.panesBySemantic.get(semanticPaneId) === pane,
1187
1229
  ),
1230
+ requestNativeHistory: (request) => this.requestNativeHistory(sub, request),
1188
1231
  readHistorySize: () =>
1189
1232
  new Promise((resolve) => {
1190
1233
  const current = () =>
@@ -1263,16 +1306,19 @@ export class SessionChannel {
1263
1306
  const identity = await this.attachedSessionIdentity();
1264
1307
  const inventory = await this.describeTrustedInventory(identity.runtimeSessionId);
1265
1308
  if (this.disposed) throw new Error(`mirror session ${this.opts.session} is disposed`);
1309
+ // #882: a floating pane has no cell in the tiled layout, so neither the
1310
+ // pane set a stream expects nor the layout coverage includes it.
1311
+ const tiled = inventory.panes.filter((pane) => pane.floating !== true);
1266
1312
 
1267
1313
  const expectedByWindow = new Map<string, Set<string>>();
1268
- for (const pane of inventory.panes) {
1314
+ for (const pane of tiled) {
1269
1315
  const expected = expectedByWindow.get(pane.runtimeWindowId) ?? new Set<string>();
1270
1316
  expected.add(pane.semanticPaneId);
1271
1317
  expectedByWindow.set(pane.runtimeWindowId, expected);
1272
1318
  }
1273
1319
  if (expectedSemanticPaneIds) {
1274
1320
  const requested = [...expectedSemanticPaneIds].sort();
1275
- const authoritative = inventory.panes.map(({ semanticPaneId }) => semanticPaneId).sort();
1321
+ const authoritative = tiled.map(({ semanticPaneId }) => semanticPaneId).sort();
1276
1322
  if (
1277
1323
  requested.length === 0 ||
1278
1324
  new Set(requested).size !== requested.length ||
@@ -1710,6 +1756,91 @@ export class SessionChannel {
1710
1756
  };
1711
1757
  }
1712
1758
 
1759
+ /**
1760
+ * #873: history rows a native first-open capture reads: the newest that fit
1761
+ * the seed budget at the pane's tmux size. Older rows are read later in
1762
+ * pieces (`requestNativeHistory`), so the open does not depend on the
1763
+ * history's length. Without a known size, assume a 512-column pane.
1764
+ */
1765
+ private nativeSeedHistoryRowsFor(pane: PaneRecord): number {
1766
+ const size = this.layoutSizeFor(pane.runtimeId);
1767
+ const rows = size
1768
+ ? nativeSeedHistoryRows(size.cols, size.rows)
1769
+ : nativeSeedHistoryRows(NATIVE_SEED_FALLBACK_COLS, 1);
1770
+ const limit = this.opts.historyLines;
1771
+ return limit === undefined ? rows : Math.min(limit, rows);
1772
+ }
1773
+
1774
+ /**
1775
+ * #873: read history rows `endRow - rows .. endRow - 1` (tmux's numbers,
1776
+ * from its oldest row) for this subscriber. The answer is one `history`
1777
+ * event, sent from the reply callback so it keeps its place among the
1778
+ * deltas. It is null unless the read stayed clear of every output, layout
1779
+ * and reseed crossing: then the subscriber's parser, having applied every
1780
+ * earlier delta, holds exactly the state tmux read the rows from.
1781
+ */
1782
+ private requestNativeHistory(sub: SubRecord, request: NativeHistoryRequest): boolean {
1783
+ const pane = sub.pane;
1784
+ const { endRow, rows, historySize } = request;
1785
+ if (
1786
+ this.disposed ||
1787
+ sub.closed ||
1788
+ sub.frozen ||
1789
+ !sub.nativeBootstrap ||
1790
+ this.nativeBootstrapUnavailable ||
1791
+ sub.feed.currentState() !== "live" ||
1792
+ ![endRow, rows, historySize].every((value) => Number.isSafeInteger(value)) ||
1793
+ endRow < 1 ||
1794
+ rows < 1 ||
1795
+ historySize < endRow
1796
+ )
1797
+ return false;
1798
+ const runtimeId = pane.runtimeId;
1799
+ const size = this.layoutSizeFor(runtimeId);
1800
+ const cols = size?.cols ?? NATIVE_SEED_FALLBACK_COLS;
1801
+ const wanted = Math.min(
1802
+ rows,
1803
+ endRow,
1804
+ Math.max(1, Math.floor(NATIVE_HISTORY_PIECE_CELL_BUDGET / cols)),
1805
+ );
1806
+ const start = endRow - wanted - historySize;
1807
+ const end = endRow - 1 - historySize;
1808
+ this.input.flush();
1809
+ const outputOrdinal = this.outputOrdinals.get(runtimeId) ?? 0;
1810
+ const feedEpoch = sub.feed.reseedEpoch();
1811
+ const incarnation = pane.incarnation;
1812
+ let marker: string | null = null;
1813
+ this.captureWithViewer(
1814
+ runtimeId,
1815
+ ["-R", "-S", String(start), "-E", String(end)],
1816
+ (value) => {
1817
+ marker = value;
1818
+ },
1819
+ (reply) => {
1820
+ if (marker) {
1821
+ if (reply.ok) this.clearInternalReadMarkerOption(runtimeId, marker);
1822
+ else this.retireInternalReadMarker(runtimeId, marker);
1823
+ }
1824
+ if (sub.closed || this.disposed) return;
1825
+ const windowId = pane.windowRuntimeId;
1826
+ const current =
1827
+ !sub.frozen &&
1828
+ sub.pane === pane &&
1829
+ this.panesByRuntime.get(runtimeId) === pane &&
1830
+ pane.incarnation === incarnation &&
1831
+ sub.feed.currentState() === "live" &&
1832
+ sub.feed.reseedEpoch() === feedEpoch &&
1833
+ (this.outputOrdinals.get(runtimeId) ?? 0) === outputOrdinal &&
1834
+ !(windowId !== null && this.pendingLayoutOutput.has(windowId));
1835
+ const piece =
1836
+ current && reply.ok ? decodeNativeHistoryPiece(reply.lines.join("\n") + "\n") : null;
1837
+ sub.onEvent({ type: "history", piece });
1838
+ },
1839
+ NATIVE_HISTORY_PIECE_LIMITS,
1840
+ );
1841
+ return true;
1842
+ }
1843
+
1713
1844
  private layoutSizeFor(runtime: string): { cols: number; rows: number } | null {
1714
1845
  for (const layout of this.layoutByWindow.values()) {
1715
1846
  const leaf = layout.leaves.find((candidate) => candidate.id === runtime);
@@ -1873,8 +2004,12 @@ export class SessionChannel {
1873
2004
  cancelAbsoluteDeadline: null,
1874
2005
  };
1875
2006
  this.recoveries.set(pane.runtimeId, recovery);
1876
- this.snapshotQueue.set(pane.runtimeId, recovery);
1877
- this.drainSnapshots();
2007
+ if (recovery.startedAtMs < pane.recoveryHoldUntilMs)
2008
+ this.failRecovery(recovery, "held-after-failures");
2009
+ else {
2010
+ this.snapshotQueue.set(pane.runtimeId, recovery);
2011
+ this.drainSnapshots();
2012
+ }
1878
2013
  }
1879
2014
 
1880
2015
  private beginLocalOverflowRecovery(pane: PaneRecord): void {
@@ -2064,6 +2199,8 @@ export class SessionChannel {
2064
2199
  ) {
2065
2200
  // Negotiate the live server before placing -R in a NOHOOKS transaction:
2066
2201
  // an unsupported flag aborts that hook before its completion sentinel.
2202
+ // The probe reads one row, never the history (#869): it has to answer
2203
+ // inside a command deadline whatever the pane holds.
2067
2204
  recovery.nativeProbeAttempts = (recovery.nativeProbeAttempts ?? 0) + 1;
2068
2205
  let marker: string | null = null;
2069
2206
  let probeSettled = false;
@@ -2075,7 +2212,7 @@ export class SessionChannel {
2075
2212
  }, RECOVERY_COMMAND_DEADLINE_MS);
2076
2213
  this.captureWithViewer(
2077
2214
  pane.runtimeId,
2078
- ["-R", "-S", "-"],
2215
+ NATIVE_BOOTSTRAP_PROBE_FLAGS,
2079
2216
  (value) => {
2080
2217
  marker = value;
2081
2218
  },
@@ -2085,9 +2222,9 @@ export class SessionChannel {
2085
2222
  probeSettled = true;
2086
2223
  recovery.cancelCommandDeadline?.();
2087
2224
  recovery.cancelCommandDeadline = null;
2088
- const native = reply.ok ? decodeNativeGridCapture(reply.lines.join("\n")) : null;
2089
- if (native && isNativeBootstrapCapture(native)) this.nativeBootstrapConfirmed = true;
2090
- else if (nativeBootstrapUnsupported(reply.ok, reply.lines, native)) {
2225
+ const probe = readNativeBootstrapProbe(reply.ok, reply.lines);
2226
+ if (probe === "native") this.nativeBootstrapConfirmed = true;
2227
+ else if (probe === "unsupported") {
2091
2228
  this.nativeBootstrapUnavailable = true;
2092
2229
  for (const current of this.panesByRuntime.values())
2093
2230
  for (const sub of current.subs) sub.nativeBootstrap = false;
@@ -2098,7 +2235,7 @@ export class SessionChannel {
2098
2235
  }
2099
2236
  this.startStockSnapshot(pane, recovery, lease);
2100
2237
  },
2101
- { maxBytes: RECOVERY_CAPTURE_MAX_BYTES, maxLines: RECOVERY_CAPTURE_MAX_LINES },
2238
+ NATIVE_BOOTSTRAP_PROBE_LIMITS,
2102
2239
  );
2103
2240
  return;
2104
2241
  }
@@ -2330,16 +2467,24 @@ export class SessionChannel {
2330
2467
  const accepted = this.opts.ownedViewer!.tryDispatch(
2331
2468
  this.io,
2332
2469
  target.representation === "dual"
2333
- ? nativeAtomicDualSnapshotPlan({
2334
- serverEpoch: target.serverEpoch,
2335
- paneId: target.paneId,
2336
- paneBirthId: target.paneBirthId,
2337
- })
2338
- : nativeAtomicSnapshotPlan({
2339
- serverEpoch: target.serverEpoch,
2340
- paneId: target.paneId,
2341
- paneBirthId: target.paneBirthId,
2342
- }),
2470
+ ? nativeAtomicDualSnapshotPlan(
2471
+ {
2472
+ serverEpoch: target.serverEpoch,
2473
+ paneId: target.paneId,
2474
+ paneBirthId: target.paneBirthId,
2475
+ },
2476
+ undefined,
2477
+ this.nativeSeedHistoryRowsFor(pane),
2478
+ )
2479
+ : nativeAtomicSnapshotPlan(
2480
+ {
2481
+ serverEpoch: target.serverEpoch,
2482
+ paneId: target.paneId,
2483
+ paneBirthId: target.paneBirthId,
2484
+ },
2485
+ undefined,
2486
+ this.nativeSeedHistoryRowsFor(pane),
2487
+ ),
2343
2488
  (reply) => {
2344
2489
  if (settled || !exact()) {
2345
2490
  failed();
@@ -2605,7 +2750,7 @@ export class SessionChannel {
2605
2750
  const body =
2606
2751
  `set-option -po -t ${pane.runtimeId} ${INTERNAL_READ_OPERATION_OPTION} ${internalReadMarker}` +
2607
2752
  ` ; ${sentinel("start")}` +
2608
- ` ; capture-pane -p ${nativeCapture ? "-R" : "-e -J"} -S -${this.opts.historyLines ?? ""} -t ${pane.runtimeId}` +
2753
+ ` ; capture-pane -p ${nativeCapture ? "-R" : "-e -J"} -S -${nativeCapture ? this.nativeSeedHistoryRowsFor(pane) : (this.opts.historyLines ?? "")} -t ${pane.runtimeId}` +
2609
2754
  ` ; ${sentinel("capture-end")}` +
2610
2755
  (dualCapture
2611
2756
  ? ` ; capture-pane -p -e -J -S -${this.opts.historyLines ?? ""} -t ${pane.runtimeId} ; ${sentinel("ansi-capture-end")}`
@@ -2685,9 +2830,11 @@ export class SessionChannel {
2685
2830
  return;
2686
2831
  }
2687
2832
  const captureLines = Object.freeze([...result.captureLines]);
2688
- const native = nativeCapture ? decodeNativeGridCapture(captureLines.join("\n")) : null;
2833
+ const native = nativeCapture
2834
+ ? decodeNativeGridCapture(captureLines.join("\n"), { tail: true })
2835
+ : null;
2689
2836
  if (nativeCapture && (!native || !isNativeBootstrapCapture(native))) {
2690
- if (nativeBootstrapUnsupported(true, captureLines, native)) {
2837
+ if (nativeBootstrapUnsupported(captureLines, native)) {
2691
2838
  this.nativeBootstrapUnavailable = true;
2692
2839
  for (const { sub } of participants) sub.nativeBootstrap = false;
2693
2840
  }
@@ -2833,6 +2980,8 @@ export class SessionChannel {
2833
2980
  recovery.cancelAbsoluteDeadline = null;
2834
2981
  this.recoveries.delete(recovery.runtimeId);
2835
2982
  recovery.retired = true;
2983
+ // Its hold, if it had one, ended before this recovery could start.
2984
+ pane.failedRecoveries = 0;
2836
2985
  this.ledger.noteContinued(recovery.runtimeId);
2837
2986
  if (recovery.reason === "requested") this.ledger.clearRequest(recovery.runtimeId);
2838
2987
  for (const sub of pane.subs) {
@@ -2861,6 +3010,17 @@ export class SessionChannel {
2861
3010
  ): void {
2862
3011
  const pane = this.recoveryPane(recovery);
2863
3012
  if (!pane) return;
3013
+ // A refusal is not another failure: it must not lengthen its own hold.
3014
+ if (failureReason !== "held-after-failures") {
3015
+ pane.failedRecoveries += 1;
3016
+ pane.heldWhy =
3017
+ recovery.collectorFailureReason === "capture-byte-cap" ? "too-large" : "failed";
3018
+ const repeats = pane.failedRecoveries - RECOVERY_HOLD_AFTER_FAILURES;
3019
+ if (repeats >= 0)
3020
+ pane.recoveryHoldUntilMs =
3021
+ this.recoveryNowMs() +
3022
+ Math.min(RECOVERY_HOLD_MAX_MS, RECOVERY_HOLD_BASE_MS * 2 ** repeats);
3023
+ }
2864
3024
  recovery.cancelCommandDeadline?.();
2865
3025
  recovery.cancelCommandDeadline = null;
2866
3026
  recovery.cancelNoProgressDeadline?.();
@@ -2876,11 +3036,25 @@ export class SessionChannel {
2876
3036
  recovery.atomicCollectorNonce = null;
2877
3037
  if (collectorNonce) this.io.retireAtomicPaneSnapshotCollector?.(collectorNonce, "retired");
2878
3038
  this.observeRecovery(pane, recovery, "nonconverged", failureReason);
3039
+ // A refusal says so, with the time left and the last failure's cause, so
3040
+ // the client can tell it from a try and say why the pane does not open.
3041
+ const hold: MirrorPaneHold | null =
3042
+ failureReason === "held-after-failures"
3043
+ ? {
3044
+ // Positive: a refusal starts before the hold ends.
3045
+ retryInMs: Math.ceil(pane.recoveryHoldUntilMs - this.recoveryNowMs()),
3046
+ why: pane.heldWhy,
3047
+ }
3048
+ : null;
2879
3049
  for (const sub of pane.subs) {
2880
3050
  sub.cancelCapture?.();
2881
3051
  if (sub.closed || sub.frozen) continue;
2882
3052
  try {
2883
- sub.onEvent({ type: "fault", reason: "native-recovery-failed" });
3053
+ sub.onEvent(
3054
+ hold
3055
+ ? { type: "fault", reason: "native-recovery-failed", hold }
3056
+ : { type: "fault", reason: "native-recovery-failed" },
3057
+ );
2884
3058
  } catch {
2885
3059
  // A consumer must not prevent sibling subscribers from retiring.
2886
3060
  }
@@ -2979,6 +3153,13 @@ export class SessionChannel {
2979
3153
  if (pane && Number.isSafeInteger(size)) {
2980
3154
  const cleared = size === 0 && (pane.historySize ?? 0) > 0;
2981
3155
  pane.historySize = size;
3156
+ // A cleared history is a new pane to capture: what made its
3157
+ // recoveries fail may be gone, so it is asked again at once (#872).
3158
+ // tmux trimming a full history drops only a tenth and keeps the hold.
3159
+ if (cleared) {
3160
+ pane.failedRecoveries = 0;
3161
+ pane.recoveryHoldUntilMs = 0;
3162
+ }
2982
3163
  // A quiet native clear writes no PTY bytes. Reuse the ordered seed path.
2983
3164
  if (cleared && !this.recoveries.has(pane.runtimeId)) {
2984
3165
  for (const sub of pane.subs) if (!sub.closed && !sub.frozen) this.reseedPlain(sub);
@@ -3117,8 +3298,17 @@ export class SessionChannel {
3117
3298
  return;
3118
3299
  }
3119
3300
  const leafIds = new Set(membership.leaves.map((leaf) => leaf.id));
3301
+ // #882: a floating pane is never a leaf. The bundled build lists it in
3302
+ // the layout's floating section, so its absence there means it closed.
3303
+ // tmux 3.8 leaves it out of a control client's layout altogether, so a
3304
+ // known float there always reads as possibly gone: tmux's pane list
3305
+ // decides. Without that read a closed float stayed listed.
3306
+ const floatingIds = new Set((membership.floating ?? []).map((leaf) => leaf.id));
3120
3307
  const knownPaneVanished = [...this.panesByRuntime.values()].some(
3121
- (pane) => pane.windowRuntimeId === change.windowId && !leafIds.has(pane.runtimeId),
3308
+ (pane) =>
3309
+ pane.windowRuntimeId === change.windowId &&
3310
+ !leafIds.has(pane.runtimeId) &&
3311
+ !floatingIds.has(pane.runtimeId),
3122
3312
  );
3123
3313
  if (
3124
3314
  membership.leaves.some((leaf) => !this.panesByRuntime.has(leaf.id)) ||
@@ -3598,15 +3788,36 @@ export class SessionChannel {
3598
3788
  const stagedPaneIds = new Set<string>();
3599
3789
  let stagedPaneCount = 0;
3600
3790
  let stagedPaneMembershipExact = true;
3791
+ // #882: a floating pane (tmux 3.7+) has no cell in the tiled layout. It
3792
+ // belongs to its window by tmux's own pane list; every other pane must be
3793
+ // exactly one tiled leaf, as before.
3794
+ const floatingByWindow = new Map<string, Set<string>>();
3795
+ for (const descriptor of descriptors) {
3796
+ if (!descriptor.floating) continue;
3797
+ const floating = floatingByWindow.get(descriptor.windowId!) ?? new Set<string>();
3798
+ floating.add(descriptor.runtimePaneId);
3799
+ floatingByWindow.set(descriptor.windowId!, floating);
3800
+ }
3801
+ let floatingPaneCount = 0;
3601
3802
  for (const [runtimeWindowId, layout] of confirmedWindowStage.layouts) {
3602
3803
  const membership = layout.zoomed ? layout.unzoomed : layout;
3603
- if (!membership || membership.leaves.length !== computedWindowCounts.get(runtimeWindowId)) {
3804
+ const floating = floatingByWindow.get(runtimeWindowId) ?? new Set<string>();
3805
+ if (
3806
+ !membership ||
3807
+ membership.leaves.length + floating.size !== computedWindowCounts.get(runtimeWindowId) ||
3808
+ (membership.floating ?? []).some((leaf) => !floating.has(leaf.id))
3809
+ ) {
3604
3810
  stagedPaneMembershipExact = false;
3605
3811
  break;
3606
3812
  }
3813
+ floatingPaneCount += floating.size;
3607
3814
  for (const leaf of membership.leaves) {
3608
3815
  stagedPaneCount += 1;
3609
- if (stagedPaneIds.has(leaf.id) || descriptorWindowByPane.get(leaf.id) !== runtimeWindowId) {
3816
+ if (
3817
+ stagedPaneIds.has(leaf.id) ||
3818
+ floating.has(leaf.id) ||
3819
+ descriptorWindowByPane.get(leaf.id) !== runtimeWindowId
3820
+ ) {
3610
3821
  stagedPaneMembershipExact = false;
3611
3822
  break;
3612
3823
  }
@@ -3619,8 +3830,8 @@ export class SessionChannel {
3619
3830
  confirmedWindowStage.links.length !== descriptors[0]!.sessionWindowCount ||
3620
3831
  confirmedWindowStage.windows.size !== computedWindowCounts.size ||
3621
3832
  !stagedPaneMembershipExact ||
3622
- stagedPaneCount !== descriptors.length ||
3623
- stagedPaneIds.size !== descriptors.length ||
3833
+ stagedPaneCount + floatingPaneCount !== descriptors.length ||
3834
+ stagedPaneIds.size + floatingPaneCount !== descriptors.length ||
3624
3835
  [...computedWindowCounts.keys()].some(
3625
3836
  (runtimeWindowId) => !confirmedWindowStage.windows.has(runtimeWindowId),
3626
3837
  )
@@ -3721,6 +3932,7 @@ export class SessionChannel {
3721
3932
  missionStamp: descriptor.missionStamp,
3722
3933
  nativePaneBirthId: descriptor.nativePaneBirthId ?? null,
3723
3934
  dir: descriptor.cwd ?? "",
3935
+ ...(descriptor.floating ? { floating: true } : {}),
3724
3936
  });
3725
3937
  });
3726
3938
  return Object.freeze({
@@ -4180,6 +4392,9 @@ export class SessionChannel {
4180
4392
  subs: new Set(),
4181
4393
  incarnation: ++this.paneIncarnation,
4182
4394
  snapshotLayoutGeneration: 0,
4395
+ failedRecoveries: 0,
4396
+ recoveryHoldUntilMs: 0,
4397
+ heldWhy: "failed",
4183
4398
  };
4184
4399
  this.panesByRuntime.set(record.runtimeId, record);
4185
4400
  this.panesBySemantic.set(record.semanticId, record);
@@ -22,6 +22,8 @@ export interface TrustedMirrorPaneInventory {
22
22
  readonly type: string | null;
23
23
  readonly missionStamp: string | null;
24
24
  readonly dir: string;
25
+ /** #882: a floating pane, listed but with no cell in the tiled layout. */
26
+ readonly floating?: boolean;
25
27
  }
26
28
 
27
29
  export interface TrustedMirrorSessionInventory {
@@ -67,6 +67,8 @@ export interface PaneStreamLeaseDescriptor {
67
67
  readonly panes: readonly string[];
68
68
  /** #806: the one window this stream was issued for, or null for a pane set of the session. */
69
69
  readonly semanticWindowId: string | null;
70
+ /** #872: a person asked for this stream; its panes' holds are lifted before it opens. */
71
+ readonly retryAskedByPerson: boolean;
70
72
  readonly viewerMode: PaneStreamViewerMode;
71
73
  readonly terminalDelivery: TerminalDeliveryOffer | null;
72
74
  readonly status: PaneStreamLeaseStatus;
@@ -368,6 +370,7 @@ export class PaneStreamLeaseManager {
368
370
  runtimeSessionId: state.runtimeSessionId,
369
371
  panes: [...state.request.panes],
370
372
  semanticWindowId: state.request.semanticWindowId ?? null,
373
+ retryAskedByPerson: state.request.retryAskedByPerson === true,
371
374
  viewerMode: state.request.viewerMode,
372
375
  terminalDelivery: state.request.terminalDelivery ?? null,
373
376
  status: state.status,