tmux-ide 2.9.24 → 2.9.25

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 (56) hide show
  1. package/bin/cli.js +1352 -350
  2. package/package.json +4 -2
  3. package/packages/contracts/src/pane-stream.ts +53 -0
  4. package/packages/daemon/dist/command-center/discovery.js +24 -5
  5. package/packages/daemon/dist/command-center/server.js +81 -75
  6. package/packages/daemon/dist/doctor.js +46 -10
  7. package/packages/daemon/dist/lib/canonical-daemon-bootstrap.js +20 -2
  8. package/packages/daemon/dist/lib/daemon-crash-snapshot.js +118 -0
  9. package/packages/daemon/dist/lib/daemon-embed.js +6 -0
  10. package/packages/daemon/dist/lib/headless-daemon.js +63 -6
  11. package/packages/daemon/dist/lib/invocation-directory.js +20 -0
  12. package/packages/daemon/dist/lib/runtime-namespace.js +22 -6
  13. package/packages/daemon/dist/lib/tmux-client-execution.js +12 -3
  14. package/packages/daemon/dist/lib/update-check.js +18 -0
  15. package/packages/daemon/dist/lib/update-daemon-outcome.js +31 -0
  16. package/packages/daemon/dist/lib/update.js +39 -14
  17. package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/Info.plist +2 -2
  18. package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/MacOS/tmux-ide-notifier +0 -0
  19. package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/Resources/Assets.car +0 -0
  20. package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/_CodeSignature/CodeResources +2 -2
  21. package/packages/daemon/dist/terminal/graphics/kitty-graphics.js +16 -4
  22. package/packages/daemon/dist/terminal/mirror/mirror-service.js +26 -0
  23. package/packages/daemon/dist/terminal/mirror/session-channel.js +25 -1
  24. package/packages/daemon/dist/terminal/pane-stream/pane-stream-websocket.js +741 -208
  25. package/packages/daemon/dist/terminal/session-runtime/registry.js +24 -2
  26. package/packages/daemon/dist/terminal/session-runtime/terminal-replica-interpreter.js +77 -2
  27. package/packages/daemon/dist/terminal/session-runtime/terminal-replica-owner.js +24 -2
  28. package/packages/daemon/dist/terminal/session-runtime/transport-binding.js +38 -0
  29. package/packages/daemon/dist/tui/chrome/snapshot.js +36 -1
  30. package/packages/daemon/dist/tui/chrome/statusline.js +8 -5
  31. package/packages/daemon/dist/tui/chrome/updater.js +2 -0
  32. package/packages/daemon/src/command-center/discovery.ts +24 -4
  33. package/packages/daemon/src/command-center/server.ts +67 -67
  34. package/packages/daemon/src/doctor.ts +50 -9
  35. package/packages/daemon/src/lib/canonical-daemon-bootstrap.ts +31 -5
  36. package/packages/daemon/src/lib/daemon-crash-snapshot.ts +175 -0
  37. package/packages/daemon/src/lib/daemon-embed.ts +22 -0
  38. package/packages/daemon/src/lib/headless-daemon.ts +88 -7
  39. package/packages/daemon/src/lib/invocation-directory.ts +21 -0
  40. package/packages/daemon/src/lib/runtime-namespace.ts +25 -7
  41. package/packages/daemon/src/lib/tmux-client-execution.ts +14 -5
  42. package/packages/daemon/src/lib/update-check.ts +34 -0
  43. package/packages/daemon/src/lib/update-daemon-outcome.ts +42 -0
  44. package/packages/daemon/src/lib/update.ts +58 -16
  45. package/packages/daemon/src/terminal/graphics/kitty-graphics.ts +22 -6
  46. package/packages/daemon/src/terminal/mirror/mirror-service.ts +27 -0
  47. package/packages/daemon/src/terminal/mirror/session-channel.ts +30 -1
  48. package/packages/daemon/src/terminal/pane-stream/pane-stream-websocket.ts +811 -223
  49. package/packages/daemon/src/terminal/session-runtime/registry.ts +35 -2
  50. package/packages/daemon/src/terminal/session-runtime/terminal-replica-interpreter.ts +74 -2
  51. package/packages/daemon/src/terminal/session-runtime/terminal-replica-owner.ts +21 -1
  52. package/packages/daemon/src/terminal/session-runtime/transport-binding.ts +42 -2
  53. package/packages/daemon/src/tui/chrome/snapshot.ts +47 -1
  54. package/packages/daemon/src/tui/chrome/statusline.ts +7 -4
  55. package/packages/daemon/src/tui/chrome/updater.ts +3 -0
  56. package/packages/daemon-client/src/pane-stream-client.ts +47 -5
@@ -220,6 +220,18 @@ export class SessionRuntimeControllerLeaseError extends Error {
220
220
  }
221
221
  }
222
222
 
223
+ /**
224
+ * An input fenced to a pane lifetime (capability 105) whose lifetime has
225
+ * ended: its owner is gone or was replaced. The input must not reach another
226
+ * lifetime; the pane's delivery tells the client that its lifetime ended.
227
+ */
228
+ export class SessionRuntimeInputLifetimeEndedError extends Error {
229
+ constructor(message: string) {
230
+ super(message);
231
+ this.name = "SessionRuntimeInputLifetimeEndedError";
232
+ }
233
+ }
234
+
223
235
  export interface SessionRuntimeConsumer {
224
236
  readonly generation: SessionRuntimeGeneration;
225
237
  readonly session: string;
@@ -696,6 +708,11 @@ export class SessionRuntimeRegistry implements PaneStreamMirror {
696
708
  await this.#mirror.verifyRegisteredWindows();
697
709
  }
698
710
 
711
+ /** Ownership is being read again: input and geometry wait, they are not refused for good. */
712
+ windowOwnershipPending(): boolean {
713
+ return !this.#disposed && this.#mirror.windowOwnershipPending();
714
+ }
715
+
699
716
  /** Install the bounded registered-session membership reader. */
700
717
  setRegisteredWindowReader(
701
718
  reader: import("../mirror/registered-window-guard.ts").RegisteredWindowReader,
@@ -1264,6 +1281,12 @@ class SessionRuntime {
1264
1281
  readonly #consumersByClientId = new Map<string, SessionRuntimeConsumerImpl>();
1265
1282
  readonly #terminalReplicas = new Map<string, SessionRuntimeTerminalReplicaOwner>();
1266
1283
  readonly #terminalReplicaClocks = new Map<string, { epoch: number; revision: number }>();
1284
+ /** The renderer's last reported cell size; every pane's image placements use it. */
1285
+ #cellPixels: {
1286
+ width: number;
1287
+ height: number;
1288
+ precise?: { width: number; height: number };
1289
+ } | null = null;
1267
1290
  #outputTraces: RuntimeTraceCorrelator | null;
1268
1291
  readonly #outputObservations = new Map<
1269
1292
  string,
@@ -1658,7 +1681,8 @@ class SessionRuntime {
1658
1681
  const replicaOwner = expectedLifetime
1659
1682
  ? this.#terminalReplicas.get(semanticPaneId)
1660
1683
  : this.#terminalReplicaOwner(semanticPaneId);
1661
- if (!replicaOwner) throw new Error("Input target lifetime unavailable");
1684
+ if (!replicaOwner)
1685
+ throw new SessionRuntimeInputLifetimeEndedError("Input target lifetime unavailable");
1662
1686
  if (causalProbe) {
1663
1687
  this.#activeCausalCellProbes += 1;
1664
1688
  let settled = false;
@@ -1689,7 +1713,7 @@ class SessionRuntime {
1689
1713
  this.#terminalReplicas.get(semanticPaneId) !== replicaOwner ||
1690
1714
  replicaOwner.inputAdmissionIncarnation() !== expectedLifetime.incarnation)
1691
1715
  )
1692
- throw new Error("Input target lifetime changed");
1716
+ throw new SessionRuntimeInputLifetimeEndedError("Input target lifetime changed");
1693
1717
  if (input.kind === "text")
1694
1718
  this.#mirror.sendText(
1695
1719
  this.session,
@@ -1818,6 +1842,9 @@ class SessionRuntime {
1818
1842
  ): void {
1819
1843
  this.#assertConnected(clientId);
1820
1844
  this.#mirror.setCellPixels?.(this.session, width, height, precise);
1845
+ this.#cellPixels = { width, height, ...(precise ? { precise } : {}) };
1846
+ for (const owner of this.#terminalReplicas.values())
1847
+ owner.setCellPixels(width, height, precise);
1821
1848
  }
1822
1849
 
1823
1850
  fitViewportWithAuthority(
@@ -2042,6 +2069,12 @@ class SessionRuntime {
2042
2069
  },
2043
2070
  );
2044
2071
  owner = candidate;
2072
+ if (this.#cellPixels)
2073
+ owner.setCellPixels(
2074
+ this.#cellPixels.width,
2075
+ this.#cellPixels.height,
2076
+ this.#cellPixels.precise,
2077
+ );
2045
2078
  this.#terminalReplicas.set(semanticPaneId, owner);
2046
2079
  }
2047
2080
  return owner;
@@ -1,4 +1,5 @@
1
1
  import { assertStockCaptureRepresentable } from "./stock-capture-fidelity.ts";
2
+ import { logger } from "../../lib/log.ts";
2
3
  import { rememberNativeSeedBacking } from "./native-seed-backing.ts";
3
4
  import type { NativeGridCapture } from "../mirror/native-grid-capture.ts";
4
5
  import type { MirrorObservedTerminalModes } from "../mirror/events.ts";
@@ -184,6 +185,9 @@ export class TerminalReplicaInterpreter {
184
185
  #nativeSeedBackingCandidate: NativeGridCapture | undefined;
185
186
  readonly #generation: SessionRuntimeGeneration;
186
187
  readonly #workspaceName: string;
188
+ #stockTabsNoted = false;
189
+ #seedOrdinal = 0;
190
+ #reconstructedSeed: number | null = null;
187
191
  readonly #semanticPaneId: string;
188
192
  readonly #incarnation: string;
189
193
  #scrollback: number;
@@ -344,6 +348,15 @@ export class TerminalReplicaInterpreter {
344
348
  return this.#needsSeed ? null : this.#seed();
345
349
  }
346
350
 
351
+ /**
352
+ * Names the current seed when its tab cells were reconstructed from a stock
353
+ * capture; null otherwise. Such a seed can wrap a reflowed line at other
354
+ * places than tmux does, so its history can differ from tmux's in length.
355
+ */
356
+ reconstructedSeed(): number | null {
357
+ return this.#reconstructedSeed;
358
+ }
359
+
347
360
  /** Prioritize one future parser admission, independent of diagnostic tracing. */
348
361
  prioritizeNextWrite(): void {
349
362
  if (!this.#closed) this.#prioritizeNextWrite = true;
@@ -428,7 +441,12 @@ export class TerminalReplicaInterpreter {
428
441
  ): Promise<void> {
429
442
  if (this.#closed) return;
430
443
  if (operation.type === "reseed") {
431
- if (operation.bootstrap === "painted-capture" && !operation.native)
444
+ // A stock capture prints a saved tab cell as one HT and drops its width.
445
+ // Paint it to the next tab stop; refuse only when the parser cannot say
446
+ // where its cursor is.
447
+ const paintCapturedTabs = operation.bootstrap === "painted-capture" && !operation.native;
448
+ let seedReconstructed: boolean;
449
+ if (paintCapturedTabs && !this.#backend.graphicsCursor)
432
450
  assertStockCaptureRepresentable(operation.captureChunks ?? operation.chunks);
433
451
  this.#causalCell?.fail("reseeded");
434
452
  const nativeCols = operation.nativeCols ?? operation.cols;
@@ -447,9 +465,23 @@ export class TerminalReplicaInterpreter {
447
465
  try {
448
466
  if (operation.native && !replacement.importNativeGrid?.(operation.native))
449
467
  throw new Error("Native bootstrap requires a compatible interpreter");
468
+ // Capture chunks come first and in order; anything else is live output,
469
+ // where HT stays cursor motion.
470
+ const captured = operation.captureChunks ?? operation.chunks;
471
+ let nextCaptured = 0;
472
+ let reconstructed = false;
450
473
  for (const chunk of operation.chunks) {
451
- await this.#writeToBackend(replacement, chunk);
474
+ const fromCapture =
475
+ paintCapturedTabs &&
476
+ nextCaptured < captured.length &&
477
+ Buffer.compare(chunk, captured[nextCaptured]!) === 0;
478
+ if (fromCapture) nextCaptured += 1;
479
+ if (fromCapture && chunk.includes(9)) {
480
+ reconstructed = true;
481
+ await this.#writeStockCapture(replacement, chunk);
482
+ } else await this.#writeToBackend(replacement, chunk);
452
483
  }
484
+ seedReconstructed = reconstructed;
453
485
  if (operation.wraparound !== undefined)
454
486
  replacement.setAuthoritativeWraparound(operation.wraparound);
455
487
  if (operation.observedModes) replacement.setAuthoritativeModes(operation.observedModes);
@@ -484,6 +516,8 @@ export class TerminalReplicaInterpreter {
484
516
  previous.modes().alternateScreen === replacement.modes().alternateScreen;
485
517
  if (!sameGraphicsBasis) this.#kitty.dropCursorPlacements();
486
518
  this.#nativeReseedRequested = false;
519
+ this.#seedOrdinal += 1;
520
+ this.#reconstructedSeed = seedReconstructed ? this.#seedOrdinal : null;
487
521
  this.#scrollback = scrollback;
488
522
  this.#bootstrap = {
489
523
  kind: operation.bootstrap,
@@ -673,6 +707,44 @@ export class TerminalReplicaInterpreter {
673
707
  }, 250);
674
708
  }
675
709
 
710
+ /**
711
+ * Replay one stock `capture-pane -e` chunk. tmux stores a tab as one wide
712
+ * cell and prints it as a single HT, without its width. Blank the cells up
713
+ * to the next default tab stop instead (ECH, then CUF): that is the cell tmux
714
+ * made when the tab was written at this column, and erased cells take the
715
+ * rendition the capture set for it, as tmux's blank tab cell does. tmux never
716
+ * tabs into the last column (`input_c0_dispatch`).
717
+ * Where this differs from tmux: a row edited after its tab was written
718
+ * (insert or delete character) or written under custom tab stops is columns
719
+ * off in that row. A line reflowed by a resize is worse: tmux keeps the tab
720
+ * cell's width, this measures it again from the new column, so the line can
721
+ * wrap at other places and the pane can hold other rows than tmux shows,
722
+ * until that output scrolls away or is redrawn. The owner accepts the
723
+ * resulting difference in history length (`reconstructedSeed`).
724
+ */
725
+ async #writeStockCapture(backend: TerminalInterpreterBackend, chunk: Uint8Array): Promise<void> {
726
+ let start = 0;
727
+ for (;;) {
728
+ const tab = chunk.indexOf(9, start);
729
+ if (tab < 0) break;
730
+ if (tab > start) await this.#writeToBackend(backend, chunk.subarray(start, tab));
731
+ const column = backend.graphicsCursor!().x;
732
+ const stop = Math.min(backend.cols - 1, (Math.floor(column / 8) + 1) * 8);
733
+ if (stop > column)
734
+ await this.#writeToBackend(backend, `\x1b[${stop - column}X\x1b[${stop - column}C`);
735
+ start = tab + 1;
736
+ }
737
+ if (!this.#stockTabsNoted) {
738
+ this.#stockTabsNoted = true;
739
+ // Once per pane: its saved rows are not tmux's exact cells on this server.
740
+ logger.info("terminal-replica", "stock capture: tab positions reconstructed", {
741
+ pane: this.#semanticPaneId,
742
+ workspace: this.#workspaceName,
743
+ });
744
+ }
745
+ if (start < chunk.length) await this.#writeToBackend(backend, chunk.subarray(start));
746
+ }
747
+
676
748
  #writeToBackend(backend: TerminalInterpreterBackend, data: Uint8Array | string): Promise<void> {
677
749
  if (this.#prioritizeNextWrite) {
678
750
  this.#prioritizeNextWrite = false;
@@ -128,6 +128,7 @@ export class SessionRuntimeTerminalReplicaOwner {
128
128
  #historyTimer: SessionRuntimeTimer | null = null;
129
129
  #historyChecking = false;
130
130
  #historyDirty = false;
131
+ #reconstructedHistoryGap: { readonly seed: number; readonly gap: number } | null = null;
131
132
 
132
133
  constructor(
133
134
  readonly generation: SessionRuntimeGeneration,
@@ -437,6 +438,11 @@ export class SessionRuntimeTerminalReplicaOwner {
437
438
  return this.#interpreter.onGraphics(listener);
438
439
  }
439
440
 
441
+ /** The renderer's cell size, for image placements that give no `c`/`r` (group H). */
442
+ setCellPixels(width: number, height: number, precise?: { width: number; height: number }): void {
443
+ this.#interpreter.kittyImages().setCellPixels(width, height, precise);
444
+ }
445
+
440
446
  /** Image bytes by content digest, while the pane's store still holds them. */
441
447
  graphicsImage(digest: string): KittyImage | null {
442
448
  return this.#interpreter.kittyImages().imageByDigest(digest) ?? null;
@@ -515,7 +521,21 @@ export class SessionRuntimeTerminalReplicaOwner {
515
521
  )
516
522
  return;
517
523
  const seed = this.#interpreter.currentSeed();
518
- if (seed && seed.snapshot.history.length !== size) upstream.reseed();
524
+ if (!seed) return;
525
+ const gap = size - seed.snapshot.history.length;
526
+ // A seed with reconstructed tabs can differ from tmux in row count, and
527
+ // a new capture would paint the same rows again. Accept the difference
528
+ // that seed has at its first check, zero included, and reseed only when
529
+ // the difference changes.
530
+ const reconstructed = this.#interpreter.reconstructedSeed();
531
+ if (reconstructed !== null) {
532
+ if (this.#reconstructedHistoryGap?.seed !== reconstructed) {
533
+ this.#reconstructedHistoryGap = { seed: reconstructed, gap };
534
+ return;
535
+ }
536
+ if (this.#reconstructedHistoryGap.gap === gap) return;
537
+ } else if (gap === 0) return;
538
+ upstream.reseed();
519
539
  } catch {
520
540
  // Unavailable metadata is not evidence that history disappeared.
521
541
  } finally {
@@ -135,8 +135,8 @@ function authenticatedSurface(transport: SessionRuntimeTransport, hostClientId:
135
135
  export class SessionRuntimeTransportBinding {
136
136
  readonly #binder: SessionRuntimeTransportBinder;
137
137
  readonly #shared: SharedClient;
138
- readonly #allowedSourcePaneIds: ReadonlySet<string>;
139
- readonly #contributedSourcePaneIds: ReadonlySet<string>;
138
+ readonly #allowedSourcePaneIds: Set<string>;
139
+ readonly #contributedSourcePaneIds: Set<string>;
140
140
  readonly #interactive: boolean;
141
141
  readonly #explicitAuthority: boolean;
142
142
  readonly #deliverySubscriberId: string;
@@ -315,6 +315,46 @@ export class SessionRuntimeTransportBinding {
315
315
  this.#binder.registry.assertExecutionHandle(this.#baseHandle, semanticPaneId);
316
316
  }
317
317
 
318
+ /**
319
+ * The session's pane set changed under this live transport (#723). The
320
+ * caller is the daemon's own stream boundary, and the panes come from its
321
+ * trusted inventory of this binding's session: a client can never name a
322
+ * pane here. The grant stays exact: added panes join it, removed panes leave
323
+ * it, and every execution handle is rebuilt from the amended set.
324
+ * All-or-nothing: an invalid pane id changes nothing.
325
+ */
326
+ amendPaneGrant(change: {
327
+ readonly added: readonly string[];
328
+ readonly removed: readonly string[];
329
+ }): void {
330
+ this.#assertOpen();
331
+ const added = change.added.map((paneId) =>
332
+ TerminalAttachmentSemanticPaneIdSchemaZ.parse(paneId),
333
+ );
334
+ const removed = change.removed.map((paneId) =>
335
+ TerminalAttachmentSemanticPaneIdSchemaZ.parse(paneId),
336
+ );
337
+ for (const paneId of removed) {
338
+ if (!this.#allowedSourcePaneIds.delete(paneId)) continue;
339
+ if (!this.#contributedSourcePaneIds.delete(paneId)) continue;
340
+ const next = (this.#shared.grantRefs.get(paneId) ?? 0) - 1;
341
+ if (next > 0) this.#shared.grantRefs.set(paneId, next);
342
+ else this.#shared.grantRefs.delete(paneId);
343
+ }
344
+ for (const paneId of added) {
345
+ if (this.#allowedSourcePaneIds.has(paneId)) continue;
346
+ this.#allowedSourcePaneIds.add(paneId);
347
+ // As at bind: only an interactive transport contributes authorship.
348
+ if (!this.#interactive) continue;
349
+ this.#contributedSourcePaneIds.add(paneId);
350
+ this.#shared.grantRefs.set(paneId, (this.#shared.grantRefs.get(paneId) ?? 0) + 1);
351
+ }
352
+ // Handles carry a copy of the grant; the next use rebuilds them.
353
+ this.#baseHandle = null;
354
+ this.#baseHandleLease = null;
355
+ this.#intentHandles.clear();
356
+ }
357
+
318
358
  openTerminalDelivery(
319
359
  semanticPaneId: string,
320
360
  offer: TerminalDeliveryOffer,
@@ -20,7 +20,16 @@ import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "
20
20
  import { dirname, join } from "node:path";
21
21
  import { z } from "zod";
22
22
  import { runTmux } from "@tmux-ide/tmux-bridge";
23
- import { readProcessTable, resolveAgentCommand, type ProcEntry } from "../detect/process-tree.ts";
23
+ import {
24
+ readProcessTable,
25
+ readProcessTableAsync,
26
+ resolveAgentCommand,
27
+ type ProcEntry,
28
+ } from "../detect/process-tree.ts";
29
+ import {
30
+ snapshotIsRestorePoint,
31
+ type CrashSnapshotSource,
32
+ } from "../../lib/daemon-crash-snapshot.ts";
24
33
  import { isListableSession } from "../team/sessions.ts";
25
34
 
26
35
  // ---------------------------------------------------------------------------
@@ -384,12 +393,29 @@ export function snapshotEvery(): number {
384
393
  return Number.isInteger(n) && n > 0 ? n : SNAPSHOT_EVERY;
385
394
  }
386
395
 
396
+ export { snapshotIsRestorePoint };
397
+
398
+ /**
399
+ * The file and builder the daemon's own writer uses (#783). The process that
400
+ * owns a headless daemon passes this in; the engine may not import it.
401
+ */
402
+ export const fleetCrashSnapshotSource: CrashSnapshotSource<FleetSnapshot> = {
403
+ sessionFormat: SNAPSHOT_SESSION_FORMAT,
404
+ paneFormat: SNAPSHOT_PANE_FORMAT,
405
+ build: async (panes, sessions) => buildSnapshot(panes, sessions, await readProcessTableAsync()),
406
+ read: () => readSnapshot(),
407
+ write: writeSnapshot,
408
+ fingerprint: snapshotFingerprint,
409
+ };
410
+
387
411
  /** Deps for {@link createSnapshotter} — injectable so the throttle is unit-tested. */
388
412
  export interface SnapshotterDeps {
389
413
  collect: () => FleetSnapshot;
390
414
  read: () => FleetSnapshot | null;
391
415
  write: (snapshot: FleetSnapshot) => void;
392
416
  every: number;
417
+ /** When the running tmux server started. With it, a restore point is not replaced. */
418
+ serverStartMs?: () => number;
393
419
  }
394
420
 
395
421
  /**
@@ -406,6 +432,7 @@ export function createSnapshotter(deps: SnapshotterDeps): Snapshotter {
406
432
  let ticks = 0;
407
433
  let seeded = false;
408
434
  let lastFingerprint: string | null = null;
435
+ let held = false;
409
436
  return {
410
437
  onTick(): void {
411
438
  ticks++;
@@ -416,6 +443,25 @@ export function createSnapshotter(deps: SnapshotterDeps): Snapshotter {
416
443
  seeded = true;
417
444
  }
418
445
  const snapshot = deps.collect();
446
+ if (deps.serverStartMs) {
447
+ const existing = deps.read();
448
+ let serverStartMs = Number.NaN;
449
+ try {
450
+ serverStartMs = deps.serverStartMs();
451
+ } catch {
452
+ // Unknown start time: not a restore point.
453
+ }
454
+ const sessions = snapshot.sessions.map((session) => session.name);
455
+ if (snapshotIsRestorePoint(existing, { serverStartMs, sessions })) {
456
+ held = true;
457
+ return;
458
+ }
459
+ if (held) {
460
+ // Released: the file changed hands or is gone. Compare with it afresh.
461
+ held = false;
462
+ lastFingerprint = existing ? snapshotFingerprint(existing) : null;
463
+ }
464
+ }
419
465
  const fingerprint = snapshotFingerprint(snapshot);
420
466
  if (fingerprint === lastFingerprint) return;
421
467
  lastFingerprint = fingerprint;
@@ -555,10 +555,13 @@ export function unadoptSession(session: string): void {
555
555
  // fallback if the fleet probe races a tab closing.
556
556
  clearPaneChromeWindows([session]);
557
557
  for (const argv of unadoptOptionCommands(session)) runTmux(argv);
558
- // KNOWN SIMPLIFICATION: the popup key AND the status-click router are
559
- // SERVER-wide binds, so unadopting one session removes them for ALL adopted
560
- // sessions. Acceptable for now — best-effort so a missing bind (already
558
+ // The popup key, the status-click router, the right-click menus and every
559
+ // Alt/prefix key are SERVER-wide binds. Another session on this server that
560
+ // is still adopted keeps using them, so they go only with the last adopted
561
+ // session (this session's marker is already gone above). A probe that fails
562
+ // reads as "none left", as before. Best-effort so a missing bind (already
561
563
  // unadopted) doesn't throw. Unbind the SAME configured keys adopt bound.
564
+ if (listAdoptedSessions().length > 0) return;
562
565
  const keys = getAppConfig().keys;
563
566
  // The mouse binds (status-click router + the two right-click menu openers).
564
567
  for (const undo of [
@@ -600,5 +603,5 @@ export function unadoptSession(session: string): void {
600
603
  }
601
604
  }
602
605
  // The updater only needs to run while something is adopted.
603
- if (listAdoptedSessions().length === 0) stopUpdater();
606
+ stopUpdater();
604
607
  }
@@ -754,6 +754,9 @@ export function runUpdaterLoop(): void {
754
754
  read: readSnapshot,
755
755
  write: writeSnapshot,
756
756
  every: config.updater.snapshotEvery,
757
+ // A dead server's snapshot is kept until its sessions are restored (#783).
758
+ serverStartMs: () =>
759
+ Number(runTmux(["display-message", "-p", "#{start_time}"]).toString().trim()) * 1000,
757
760
  });
758
761
  const shouldGiveUp = createUnreachableCounter();
759
762
  const tick = () => {
@@ -5,6 +5,8 @@ import {
5
5
  TERMINAL_DELIVERY_BINARY_CAPABILITY_VERSION,
6
6
  TERMINAL_DELIVERY_BINARY_LOCAL_CAPABILITY_VERSION,
7
7
  PANE_STREAM_INPUT_BYTES_CAPABILITY_VERSION,
8
+ PANE_STREAM_READER_TOPOLOGY_BUNDLE_CAPABILITY_VERSION,
9
+ PANE_STREAM_TOPOLOGY_IN_PLACE_CAPABILITY_VERSION,
8
10
  PaneStreamInputLifetimeSchemaZ,
9
11
  type PaneStreamInputLifetime,
10
12
  PANE_STREAM_PROTOCOL_VERSION,
@@ -292,6 +294,14 @@ export interface OpenPaneStreamClientOptions {
292
294
  readonly onLayoutSnapshot?: (
293
295
  frame: Extract<PaneStreamServerFrame, { type: "layout-snapshot" }>,
294
296
  ) => void;
297
+ /**
298
+ * Capability 119 (#723): the stream's pane set changed in place. Offer 119
299
+ * in `stream.terminalDelivery.protocolVersions` only together with this
300
+ * handler; without it a `topology` frame fails the stream. The frame was
301
+ * checked against the live pane set. A removed pane gets no further frames;
302
+ * an added pane's `onNegotiated` and deliveries follow the next layout.
303
+ */
304
+ readonly onTopology?: (frame: Extract<PaneStreamServerFrame, { type: "topology" }>) => void;
295
305
  readonly onInputAck?: (event: {
296
306
  readonly pane: string;
297
307
  readonly sequence: number;
@@ -335,6 +345,7 @@ export type ConnectIssuedPaneStreamRuntimeClientOptions = Pick<
335
345
  | "onTerminalGraphics"
336
346
  | "onTerminalGraphicsBlob"
337
347
  | "onLayoutSnapshot"
348
+ | "onTopology"
338
349
  | "onInputAck"
339
350
  | "onCausalCellProof"
340
351
  | "onCausalCellFailure"
@@ -483,6 +494,10 @@ export async function connectIssuedPaneStreamRuntimeClient(
483
494
  let closed = false;
484
495
  let verified = false;
485
496
  const binaryPanes = new Set<string>();
497
+ // The stream's pane set. It starts as the issued one and changes only by a
498
+ // `topology` frame from a daemon that confirmed capability 119 (#723).
499
+ let livePanes: readonly string[] = [...descriptor.panes];
500
+ let topologyInPlace = false;
486
501
  const binaryGraphicsPanes = new Set<string>();
487
502
  const offeredBinary = options.stream.terminalDelivery.protocolVersions.some(
488
503
  (version) =>
@@ -1022,7 +1037,7 @@ export async function connectIssuedPaneStreamRuntimeClient(
1022
1037
  if (input.kind === "bytes" && !supportsInputBytes)
1023
1038
  return Promise.reject(new Error("Byte input capability unavailable"));
1024
1039
  const pane = target.semanticPaneId;
1025
- if (!descriptor.panes.includes(pane)) {
1040
+ if (!livePanes.includes(pane)) {
1026
1041
  return Promise.reject(
1027
1042
  new PaneStreamOperationError("invalid-pane", "Terminal input target is outside the lease"),
1028
1043
  );
@@ -1278,7 +1293,7 @@ export async function connectIssuedPaneStreamRuntimeClient(
1278
1293
  try {
1279
1294
  if (data[0] === 84 && data[1] === 68 && data[2] === 67 && data[3] === 49) {
1280
1295
  const { header, bytes } = decodeTerminalDeliveryBinaryChunk(data);
1281
- if (!descriptor.panes.includes(header.pane) || !binaryPanes.has(header.pane))
1296
+ if (!livePanes.includes(header.pane) || !binaryPanes.has(header.pane))
1282
1297
  return fail("Unnegotiated binary terminal delivery");
1283
1298
  options.onTerminalDelivery(header.pane, {
1284
1299
  type: "terminal.delivery.chunk",
@@ -1291,7 +1306,7 @@ export async function connectIssuedPaneStreamRuntimeClient(
1291
1306
  });
1292
1307
  } else {
1293
1308
  const { header, bytes } = decodeTerminalGraphicsBinary(data);
1294
- if (!descriptor.panes.includes(header.pane) || !binaryGraphicsPanes.has(header.pane))
1309
+ if (!livePanes.includes(header.pane) || !binaryGraphicsPanes.has(header.pane))
1295
1310
  return fail("Unnegotiated binary graphics delivery");
1296
1311
  options.onTerminalGraphicsBlob?.(header.pane, header.blob, bytes);
1297
1312
  }
@@ -1351,6 +1366,13 @@ export async function connectIssuedPaneStreamRuntimeClient(
1351
1366
  return fail("Pane-stream peer client identity did not match the redeemed connection");
1352
1367
  connectionClientId = frame.connectionClientId ?? null;
1353
1368
  supportsInputLifetime = frame.inputLifetime === true;
1369
+ topologyInPlace =
1370
+ frame.topologyInPlace === true &&
1371
+ options.stream.terminalDelivery.protocolVersions.some(
1372
+ (version) =>
1373
+ version === PANE_STREAM_TOPOLOGY_IN_PLACE_CAPABILITY_VERSION ||
1374
+ version === PANE_STREAM_READER_TOPOLOGY_BUNDLE_CAPABILITY_VERSION,
1375
+ );
1354
1376
  supportsInputBytes =
1355
1377
  frame.inputBytes === true &&
1356
1378
  options.stream.terminalDelivery.protocolVersions.includes(
@@ -1441,13 +1463,33 @@ export async function connectIssuedPaneStreamRuntimeClient(
1441
1463
  options.onCausalCellFailure?.(frame.failure);
1442
1464
  return;
1443
1465
  }
1466
+ if (frame.type === "topology") {
1467
+ if (!topologyInPlace || !options.onTopology) return fail("Unsolicited pane-stream topology");
1468
+ const expected = new Set(livePanes.filter((pane) => !frame.removed.includes(pane)));
1469
+ for (const pane of frame.added) expected.add(pane);
1470
+ if (
1471
+ frame.removed.some((pane) => !livePanes.includes(pane)) ||
1472
+ frame.added.some((pane) => livePanes.includes(pane)) ||
1473
+ expected.size !== frame.panes.length ||
1474
+ frame.panes.some((pane) => !expected.has(pane))
1475
+ )
1476
+ return fail("Pane-stream topology did not match the live pane set");
1477
+ livePanes = [...frame.panes];
1478
+ for (const pane of frame.removed) {
1479
+ binaryPanes.delete(pane);
1480
+ binaryGraphicsPanes.delete(pane);
1481
+ negotiatedDeliveries.delete(pane);
1482
+ }
1483
+ options.onTopology(frame);
1484
+ return;
1485
+ }
1444
1486
  if (frame.type === "terminal-graphics") {
1445
- if (!descriptor.panes.includes(frame.pane)) return fail("Unissued graphics pane");
1487
+ if (!livePanes.includes(frame.pane)) return fail("Unissued graphics pane");
1446
1488
  if (frame.state.binaryBlobs === true) binaryGraphicsPanes.add(frame.pane);
1447
1489
  else binaryGraphicsPanes.delete(frame.pane);
1448
1490
  }
1449
1491
  if (frame.type === "terminal-delivery-ready") {
1450
- if (!descriptor.panes.includes(frame.pane)) return fail("Unissued terminal pane");
1492
+ if (!livePanes.includes(frame.pane)) return fail("Unissued terminal pane");
1451
1493
  binaryPanes.delete(frame.pane);
1452
1494
  if (
1453
1495
  frame.negotiation.accepted &&