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
@@ -52,6 +52,17 @@ export class SessionRuntimeControllerLeaseError extends Error {
52
52
  this.name = "SessionRuntimeControllerLeaseError";
53
53
  }
54
54
  }
55
+ /**
56
+ * An input fenced to a pane lifetime (capability 105) whose lifetime has
57
+ * ended: its owner is gone or was replaced. The input must not reach another
58
+ * lifetime; the pane's delivery tells the client that its lifetime ended.
59
+ */
60
+ export class SessionRuntimeInputLifetimeEndedError extends Error {
61
+ constructor(message) {
62
+ super(message);
63
+ this.name = "SessionRuntimeInputLifetimeEndedError";
64
+ }
65
+ }
55
66
  /**
56
67
  * One daemon-generation lifecycle owner for every discovered tmux session.
57
68
  *
@@ -344,6 +355,10 @@ export class SessionRuntimeRegistry {
344
355
  async verifyWindowOwnership() {
345
356
  await this.#mirror.verifyRegisteredWindows();
346
357
  }
358
+ /** Ownership is being read again: input and geometry wait, they are not refused for good. */
359
+ windowOwnershipPending() {
360
+ return !this.#disposed && this.#mirror.windowOwnershipPending();
361
+ }
347
362
  /** Install the bounded registered-session membership reader. */
348
363
  setRegisteredWindowReader(reader) {
349
364
  return this.#mirror.setRegisteredWindowReader(reader);
@@ -767,6 +782,8 @@ class SessionRuntime {
767
782
  #consumersByClientId = new Map();
768
783
  #terminalReplicas = new Map();
769
784
  #terminalReplicaClocks = new Map();
785
+ /** The renderer's last reported cell size; every pane's image placements use it. */
786
+ #cellPixels = null;
770
787
  #outputTraces;
771
788
  #outputObservations = new Map();
772
789
  #createTraceCorrelator;
@@ -1058,7 +1075,7 @@ class SessionRuntime {
1058
1075
  ? this.#terminalReplicas.get(semanticPaneId)
1059
1076
  : this.#terminalReplicaOwner(semanticPaneId);
1060
1077
  if (!replicaOwner)
1061
- throw new Error("Input target lifetime unavailable");
1078
+ throw new SessionRuntimeInputLifetimeEndedError("Input target lifetime unavailable");
1062
1079
  if (causalProbe) {
1063
1080
  this.#activeCausalCellProbes += 1;
1064
1081
  let settled = false;
@@ -1088,7 +1105,7 @@ class SessionRuntime {
1088
1105
  (expectedLifetime.generation !== this.generation ||
1089
1106
  this.#terminalReplicas.get(semanticPaneId) !== replicaOwner ||
1090
1107
  replicaOwner.inputAdmissionIncarnation() !== expectedLifetime.incarnation))
1091
- throw new Error("Input target lifetime changed");
1108
+ throw new SessionRuntimeInputLifetimeEndedError("Input target lifetime changed");
1092
1109
  if (input.kind === "text")
1093
1110
  this.#mirror.sendText(this.session, semanticPaneId, input.data, performanceTraceId, causalProbe !== null);
1094
1111
  else if (input.kind === "bytes")
@@ -1165,6 +1182,9 @@ class SessionRuntime {
1165
1182
  setCellPixels(clientId, width, height, precise) {
1166
1183
  this.#assertConnected(clientId);
1167
1184
  this.#mirror.setCellPixels?.(this.session, width, height, precise);
1185
+ this.#cellPixels = { width, height, ...(precise ? { precise } : {}) };
1186
+ for (const owner of this.#terminalReplicas.values())
1187
+ owner.setCellPixels(width, height, precise);
1168
1188
  }
1169
1189
  fitViewportWithAuthority(clientId, lease, cols, rows, semanticWindowId) {
1170
1190
  this.assertGeometryAuthority(clientId, lease);
@@ -1340,6 +1360,8 @@ class SessionRuntime {
1340
1360
  : {}),
1341
1361
  });
1342
1362
  owner = candidate;
1363
+ if (this.#cellPixels)
1364
+ owner.setCellPixels(this.#cellPixels.width, this.#cellPixels.height, this.#cellPixels.precise);
1343
1365
  this.#terminalReplicas.set(semanticPaneId, owner);
1344
1366
  }
1345
1367
  return owner;
@@ -1,4 +1,5 @@
1
1
  import { assertStockCaptureRepresentable } from "./stock-capture-fidelity.js";
2
+ import { logger } from "../../lib/log.js";
2
3
  import { rememberNativeSeedBacking } from "./native-seed-backing.js";
3
4
  import { detectWidgetMarkerFromReplicaRows, } from "@tmux-ide/contracts";
4
5
  import { applyTerminalReplicaPatch, assembleTerminalReplicaSnapshot, blankTerminalReplicaSnapshot, hashTerminalReplicaSnapshot, hashTerminalReplicaTombstone, hashTerminalWidgetContent, terminalReplicaRowsEqual, } from "@tmux-ide/core";
@@ -40,6 +41,9 @@ export class TerminalReplicaInterpreter {
40
41
  #nativeSeedBackingCandidate;
41
42
  #generation;
42
43
  #workspaceName;
44
+ #stockTabsNoted = false;
45
+ #seedOrdinal = 0;
46
+ #reconstructedSeed = null;
43
47
  #semanticPaneId;
44
48
  #incarnation;
45
49
  #scrollback;
@@ -182,6 +186,14 @@ export class TerminalReplicaInterpreter {
182
186
  currentSeed() {
183
187
  return this.#needsSeed ? null : this.#seed();
184
188
  }
189
+ /**
190
+ * Names the current seed when its tab cells were reconstructed from a stock
191
+ * capture; null otherwise. Such a seed can wrap a reflowed line at other
192
+ * places than tmux does, so its history can differ from tmux's in length.
193
+ */
194
+ reconstructedSeed() {
195
+ return this.#reconstructedSeed;
196
+ }
185
197
  /** Prioritize one future parser admission, independent of diagnostic tracing. */
186
198
  prioritizeNextWrite() {
187
199
  if (!this.#closed)
@@ -249,7 +261,12 @@ export class TerminalReplicaInterpreter {
249
261
  if (this.#closed)
250
262
  return;
251
263
  if (operation.type === "reseed") {
252
- if (operation.bootstrap === "painted-capture" && !operation.native)
264
+ // A stock capture prints a saved tab cell as one HT and drops its width.
265
+ // Paint it to the next tab stop; refuse only when the parser cannot say
266
+ // where its cursor is.
267
+ const paintCapturedTabs = operation.bootstrap === "painted-capture" && !operation.native;
268
+ let seedReconstructed;
269
+ if (paintCapturedTabs && !this.#backend.graphicsCursor)
253
270
  assertStockCaptureRepresentable(operation.captureChunks ?? operation.chunks);
254
271
  this.#causalCell?.fail("reseeded");
255
272
  const nativeCols = operation.nativeCols ?? operation.cols;
@@ -264,9 +281,25 @@ export class TerminalReplicaInterpreter {
264
281
  try {
265
282
  if (operation.native && !replacement.importNativeGrid?.(operation.native))
266
283
  throw new Error("Native bootstrap requires a compatible interpreter");
284
+ // Capture chunks come first and in order; anything else is live output,
285
+ // where HT stays cursor motion.
286
+ const captured = operation.captureChunks ?? operation.chunks;
287
+ let nextCaptured = 0;
288
+ let reconstructed = false;
267
289
  for (const chunk of operation.chunks) {
268
- await this.#writeToBackend(replacement, chunk);
290
+ const fromCapture = paintCapturedTabs &&
291
+ nextCaptured < captured.length &&
292
+ Buffer.compare(chunk, captured[nextCaptured]) === 0;
293
+ if (fromCapture)
294
+ nextCaptured += 1;
295
+ if (fromCapture && chunk.includes(9)) {
296
+ reconstructed = true;
297
+ await this.#writeStockCapture(replacement, chunk);
298
+ }
299
+ else
300
+ await this.#writeToBackend(replacement, chunk);
269
301
  }
302
+ seedReconstructed = reconstructed;
270
303
  if (operation.wraparound !== undefined)
271
304
  replacement.setAuthoritativeWraparound(operation.wraparound);
272
305
  if (operation.observedModes)
@@ -303,6 +336,8 @@ export class TerminalReplicaInterpreter {
303
336
  if (!sameGraphicsBasis)
304
337
  this.#kitty.dropCursorPlacements();
305
338
  this.#nativeReseedRequested = false;
339
+ this.#seedOrdinal += 1;
340
+ this.#reconstructedSeed = seedReconstructed ? this.#seedOrdinal : null;
306
341
  this.#scrollback = scrollback;
307
342
  this.#bootstrap = {
308
343
  kind: operation.bootstrap,
@@ -482,6 +517,46 @@ export class TerminalReplicaInterpreter {
482
517
  this.#tail = run.catch(() => undefined);
483
518
  }, 250);
484
519
  }
520
+ /**
521
+ * Replay one stock `capture-pane -e` chunk. tmux stores a tab as one wide
522
+ * cell and prints it as a single HT, without its width. Blank the cells up
523
+ * to the next default tab stop instead (ECH, then CUF): that is the cell tmux
524
+ * made when the tab was written at this column, and erased cells take the
525
+ * rendition the capture set for it, as tmux's blank tab cell does. tmux never
526
+ * tabs into the last column (`input_c0_dispatch`).
527
+ * Where this differs from tmux: a row edited after its tab was written
528
+ * (insert or delete character) or written under custom tab stops is columns
529
+ * off in that row. A line reflowed by a resize is worse: tmux keeps the tab
530
+ * cell's width, this measures it again from the new column, so the line can
531
+ * wrap at other places and the pane can hold other rows than tmux shows,
532
+ * until that output scrolls away or is redrawn. The owner accepts the
533
+ * resulting difference in history length (`reconstructedSeed`).
534
+ */
535
+ async #writeStockCapture(backend, chunk) {
536
+ let start = 0;
537
+ for (;;) {
538
+ const tab = chunk.indexOf(9, start);
539
+ if (tab < 0)
540
+ break;
541
+ if (tab > start)
542
+ await this.#writeToBackend(backend, chunk.subarray(start, tab));
543
+ const column = backend.graphicsCursor().x;
544
+ const stop = Math.min(backend.cols - 1, (Math.floor(column / 8) + 1) * 8);
545
+ if (stop > column)
546
+ await this.#writeToBackend(backend, `\x1b[${stop - column}X\x1b[${stop - column}C`);
547
+ start = tab + 1;
548
+ }
549
+ if (!this.#stockTabsNoted) {
550
+ this.#stockTabsNoted = true;
551
+ // Once per pane: its saved rows are not tmux's exact cells on this server.
552
+ logger.info("terminal-replica", "stock capture: tab positions reconstructed", {
553
+ pane: this.#semanticPaneId,
554
+ workspace: this.#workspaceName,
555
+ });
556
+ }
557
+ if (start < chunk.length)
558
+ await this.#writeToBackend(backend, chunk.subarray(start));
559
+ }
485
560
  #writeToBackend(backend, data) {
486
561
  if (this.#prioritizeNextWrite) {
487
562
  this.#prioritizeNextWrite = false;
@@ -45,6 +45,7 @@ export class SessionRuntimeTerminalReplicaOwner {
45
45
  #historyTimer = null;
46
46
  #historyChecking = false;
47
47
  #historyDirty = false;
48
+ #reconstructedHistoryGap = null;
48
49
  constructor(generation, session, semanticPaneId, mirror, options) {
49
50
  this.generation = generation;
50
51
  this.session = session;
@@ -325,6 +326,10 @@ export class SessionRuntimeTerminalReplicaOwner {
325
326
  listener(current);
326
327
  return this.#interpreter.onGraphics(listener);
327
328
  }
329
+ /** The renderer's cell size, for image placements that give no `c`/`r` (group H). */
330
+ setCellPixels(width, height, precise) {
331
+ this.#interpreter.kittyImages().setCellPixels(width, height, precise);
332
+ }
328
333
  /** Image bytes by content digest, while the pane's store still holds them. */
329
334
  graphicsImage(digest) {
330
335
  return this.#interpreter.kittyImages().imageByDigest(digest) ?? null;
@@ -394,8 +399,25 @@ export class SessionRuntimeTerminalReplicaOwner {
394
399
  size === null)
395
400
  return;
396
401
  const seed = this.#interpreter.currentSeed();
397
- if (seed && seed.snapshot.history.length !== size)
398
- upstream.reseed();
402
+ if (!seed)
403
+ return;
404
+ const gap = size - seed.snapshot.history.length;
405
+ // A seed with reconstructed tabs can differ from tmux in row count, and
406
+ // a new capture would paint the same rows again. Accept the difference
407
+ // that seed has at its first check, zero included, and reseed only when
408
+ // the difference changes.
409
+ const reconstructed = this.#interpreter.reconstructedSeed();
410
+ if (reconstructed !== null) {
411
+ if (this.#reconstructedHistoryGap?.seed !== reconstructed) {
412
+ this.#reconstructedHistoryGap = { seed: reconstructed, gap };
413
+ return;
414
+ }
415
+ if (this.#reconstructedHistoryGap.gap === gap)
416
+ return;
417
+ }
418
+ else if (gap === 0)
419
+ return;
420
+ upstream.reseed();
399
421
  }
400
422
  catch {
401
423
  // Unavailable metadata is not evidence that history disappeared.
@@ -207,6 +207,44 @@ export class SessionRuntimeTransportBinding {
207
207
  throw new SessionRuntimeControllerLeaseError("stale-controller-lease", "The interactive transport does not own input authority.");
208
208
  this.#binder.registry.assertExecutionHandle(this.#baseHandle, semanticPaneId);
209
209
  }
210
+ /**
211
+ * The session's pane set changed under this live transport (#723). The
212
+ * caller is the daemon's own stream boundary, and the panes come from its
213
+ * trusted inventory of this binding's session: a client can never name a
214
+ * pane here. The grant stays exact: added panes join it, removed panes leave
215
+ * it, and every execution handle is rebuilt from the amended set.
216
+ * All-or-nothing: an invalid pane id changes nothing.
217
+ */
218
+ amendPaneGrant(change) {
219
+ this.#assertOpen();
220
+ const added = change.added.map((paneId) => TerminalAttachmentSemanticPaneIdSchemaZ.parse(paneId));
221
+ const removed = change.removed.map((paneId) => TerminalAttachmentSemanticPaneIdSchemaZ.parse(paneId));
222
+ for (const paneId of removed) {
223
+ if (!this.#allowedSourcePaneIds.delete(paneId))
224
+ continue;
225
+ if (!this.#contributedSourcePaneIds.delete(paneId))
226
+ continue;
227
+ const next = (this.#shared.grantRefs.get(paneId) ?? 0) - 1;
228
+ if (next > 0)
229
+ this.#shared.grantRefs.set(paneId, next);
230
+ else
231
+ this.#shared.grantRefs.delete(paneId);
232
+ }
233
+ for (const paneId of added) {
234
+ if (this.#allowedSourcePaneIds.has(paneId))
235
+ continue;
236
+ this.#allowedSourcePaneIds.add(paneId);
237
+ // As at bind: only an interactive transport contributes authorship.
238
+ if (!this.#interactive)
239
+ continue;
240
+ this.#contributedSourcePaneIds.add(paneId);
241
+ this.#shared.grantRefs.set(paneId, (this.#shared.grantRefs.get(paneId) ?? 0) + 1);
242
+ }
243
+ // Handles carry a copy of the grant; the next use rebuilds them.
244
+ this.#baseHandle = null;
245
+ this.#baseHandleLease = null;
246
+ this.#intentHandles.clear();
247
+ }
210
248
  openTerminalDelivery(semanticPaneId, offer, onMessage, deliveryWorkspaceName) {
211
249
  const address = WorkspaceIdSchemaZ.parse(deliveryWorkspaceName ?? this.session);
212
250
  this.#assertOpen();
@@ -20,7 +20,8 @@ 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 } from "../detect/process-tree.js";
23
+ import { readProcessTable, readProcessTableAsync, resolveAgentCommand, } from "../detect/process-tree.js";
24
+ import { snapshotIsRestorePoint, } from "../../lib/daemon-crash-snapshot.js";
24
25
  import { isListableSession } from "../team/sessions.js";
25
26
  // ---------------------------------------------------------------------------
26
27
  // Read validation — a snapshot on disk is untrusted input
@@ -265,10 +266,24 @@ export function snapshotEvery() {
265
266
  const n = raw ? Number(raw) : NaN;
266
267
  return Number.isInteger(n) && n > 0 ? n : SNAPSHOT_EVERY;
267
268
  }
269
+ export { snapshotIsRestorePoint };
270
+ /**
271
+ * The file and builder the daemon's own writer uses (#783). The process that
272
+ * owns a headless daemon passes this in; the engine may not import it.
273
+ */
274
+ export const fleetCrashSnapshotSource = {
275
+ sessionFormat: SNAPSHOT_SESSION_FORMAT,
276
+ paneFormat: SNAPSHOT_PANE_FORMAT,
277
+ build: async (panes, sessions) => buildSnapshot(panes, sessions, await readProcessTableAsync()),
278
+ read: () => readSnapshot(),
279
+ write: writeSnapshot,
280
+ fingerprint: snapshotFingerprint,
281
+ };
268
282
  export function createSnapshotter(deps) {
269
283
  let ticks = 0;
270
284
  let seeded = false;
271
285
  let lastFingerprint = null;
286
+ let held = false;
272
287
  return {
273
288
  onTick() {
274
289
  ticks++;
@@ -280,6 +295,26 @@ export function createSnapshotter(deps) {
280
295
  seeded = true;
281
296
  }
282
297
  const snapshot = deps.collect();
298
+ if (deps.serverStartMs) {
299
+ const existing = deps.read();
300
+ let serverStartMs = Number.NaN;
301
+ try {
302
+ serverStartMs = deps.serverStartMs();
303
+ }
304
+ catch {
305
+ // Unknown start time: not a restore point.
306
+ }
307
+ const sessions = snapshot.sessions.map((session) => session.name);
308
+ if (snapshotIsRestorePoint(existing, { serverStartMs, sessions })) {
309
+ held = true;
310
+ return;
311
+ }
312
+ if (held) {
313
+ // Released: the file changed hands or is gone. Compare with it afresh.
314
+ held = false;
315
+ lastFingerprint = existing ? snapshotFingerprint(existing) : null;
316
+ }
317
+ }
283
318
  const fingerprint = snapshotFingerprint(snapshot);
284
319
  if (fingerprint === lastFingerprint)
285
320
  return;
@@ -496,10 +496,14 @@ export function unadoptSession(session) {
496
496
  clearPaneChromeWindows([session]);
497
497
  for (const argv of unadoptOptionCommands(session))
498
498
  runTmux(argv);
499
- // KNOWN SIMPLIFICATION: the popup key AND the status-click router are
500
- // SERVER-wide binds, so unadopting one session removes them for ALL adopted
501
- // sessions. Acceptable for now — best-effort so a missing bind (already
499
+ // The popup key, the status-click router, the right-click menus and every
500
+ // Alt/prefix key are SERVER-wide binds. Another session on this server that
501
+ // is still adopted keeps using them, so they go only with the last adopted
502
+ // session (this session's marker is already gone above). A probe that fails
503
+ // reads as "none left", as before. Best-effort so a missing bind (already
502
504
  // unadopted) doesn't throw. Unbind the SAME configured keys adopt bound.
505
+ if (listAdoptedSessions().length > 0)
506
+ return;
503
507
  const keys = getAppConfig().keys;
504
508
  // The mouse binds (status-click router + the two right-click menu openers).
505
509
  for (const undo of [
@@ -547,6 +551,5 @@ export function unadoptSession(session) {
547
551
  }
548
552
  }
549
553
  // The updater only needs to run while something is adopted.
550
- if (listAdoptedSessions().length === 0)
551
- stopUpdater();
554
+ stopUpdater();
552
555
  }
@@ -592,6 +592,8 @@ export function runUpdaterLoop() {
592
592
  read: readSnapshot,
593
593
  write: writeSnapshot,
594
594
  every: config.updater.snapshotEvery,
595
+ // A dead server's snapshot is kept until its sessions are restored (#783).
596
+ serverStartMs: () => Number(runTmux(["display-message", "-p", "#{start_time}"]).toString().trim()) * 1000,
595
597
  });
596
598
  const shouldGiveUp = createUnreachableCounter();
597
599
  const tick = () => {
@@ -40,7 +40,9 @@ let _tmuxRunner: TmuxRunner = (args) =>
40
40
  execFileSync("tmux", ["-u", ...runtimeTmuxArgs(args)], {
41
41
  encoding: "utf-8",
42
42
  maxBuffer: 1024 * 1024,
43
- stdio: ["ignore", "pipe", "ignore"],
43
+ // Keep stderr on the error: it is how a caller tells "no server running"
44
+ // from a server it could not reach. Nothing is printed either way.
45
+ stdio: ["ignore", "pipe", "pipe"],
44
46
  }).trim();
45
47
 
46
48
  export function _setTmuxRunner(fn: TmuxRunner): () => void {
@@ -75,8 +77,20 @@ function semanticPaneIds(session: string): ReadonlyMap<string, string> {
75
77
  }
76
78
 
77
79
  export function listTmuxSessions(): string[] {
78
- const raw = tmuxSilent(["list-sessions", "-F", "#{session_name}"]);
79
- if (!raw) return [];
80
+ return readTmuxSessions() ?? [];
81
+ }
82
+
83
+ /**
84
+ * {@link listTmuxSessions}, but null when tmux could not be asked. Only a
85
+ * server that is not running has no sessions (#753).
86
+ */
87
+ export function readTmuxSessions(): string[] | null {
88
+ let raw: string;
89
+ try {
90
+ raw = _tmuxRunner(["list-sessions", "-F", "#{session_name}"]);
91
+ } catch (error) {
92
+ return serverNotRunning(error) ? [] : null;
93
+ }
80
94
  return raw.split("\n").filter(Boolean);
81
95
  }
82
96
 
@@ -478,7 +492,13 @@ function assembleAdoptedFleet(
478
492
  }
479
493
 
480
494
  export function discoverSessions(): SessionInfo[] {
481
- const sessionNames = listTmuxSessions();
495
+ return readSessions() ?? [];
496
+ }
497
+
498
+ /** {@link discoverSessions}, but null when tmux could not be asked (#753). */
499
+ export function readSessions(): SessionInfo[] | null {
500
+ const sessionNames = readTmuxSessions();
501
+ if (sessionNames === null) return null;
482
502
  const results: SessionInfo[] = [];
483
503
 
484
504
  // Once the workspace registry is loaded (post daemon-embed startup),