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
@@ -171,7 +171,7 @@ export function mountAutomationRoutes(app: Hono, options: AutomationRoutesOption
171
171
  const panes: AutomationPanesResponse["panes"] = [];
172
172
  const credential = c.req.header(PANE_SOURCE_CREDENTIAL_HEADER);
173
173
  let source: Endpoint | null = null;
174
- for (const scope of await options.owners.refresh()) {
174
+ for (const scope of await options.owners.observe()) {
175
175
  if (!scope.generation) continue;
176
176
  await options.owners.withOwner(
177
177
  { serverId: scope.serverId, generation: scope.generation },
@@ -29,6 +29,8 @@ export interface DaemonFleetFactsObserverOptions {
29
29
  readonly onAgentSessionsChanged: (sessions: readonly string[]) => void;
30
30
  readonly onAgentTurnCompleted: (completion: AgentTurnCompletion) => void;
31
31
  readonly intervalMs?: number;
32
+ /** Interval after {@link FLEET_FACTS_UNCHANGED_TICKS_BEFORE_BACKOFF} unchanged ticks. */
33
+ readonly idleIntervalMs?: number;
32
34
  readonly readTimeoutMs?: number;
33
35
  readonly setTimer?: (callback: () => void, delayMs: number) => ReturnType<typeof setTimeout>;
34
36
  readonly clearTimer?: (timer: ReturnType<typeof setTimeout>) => void;
@@ -64,6 +66,9 @@ interface ReadyWaiter {
64
66
  export class DaemonFleetFactsObserver {
65
67
  readonly #options: DaemonFleetFactsObserverOptions;
66
68
  readonly #intervalMs: number;
69
+ readonly #idleIntervalMs: number;
70
+ #unchangedTicks = 0;
71
+ #changedThisTick = false;
67
72
  readonly #setTimer: NonNullable<DaemonFleetFactsObserverOptions["setTimer"]>;
68
73
  readonly #clearTimer: NonNullable<DaemonFleetFactsObserverOptions["clearTimer"]>;
69
74
  readonly #refs = new Map<FleetFactsDemand, number>();
@@ -91,6 +96,10 @@ export class DaemonFleetFactsObserver {
91
96
  constructor(options: DaemonFleetFactsObserverOptions) {
92
97
  this.#options = options;
93
98
  this.#intervalMs = options.intervalMs ?? FLEET_FACTS_POLL_MS;
99
+ this.#idleIntervalMs = Math.max(
100
+ this.#intervalMs,
101
+ options.idleIntervalMs ?? FLEET_FACTS_IDLE_POLL_MS,
102
+ );
94
103
  this.#setTimer =
95
104
  options.setTimer ??
96
105
  ((callback, delayMs) => {
@@ -116,6 +125,8 @@ export class DaemonFleetFactsObserver {
116
125
  resolveReady = resolve;
117
126
  });
118
127
  const waiter = { demands: unique, resolve: resolveReady };
128
+ // A new subscriber is activity: poll at the base rate again.
129
+ this.#unchangedTicks = 0;
119
130
  this.#waiters.add(waiter);
120
131
  this.#settleWaiters();
121
132
  this.#queueStart();
@@ -182,10 +193,18 @@ export class DaemonFleetFactsObserver {
182
193
  void this.#runOnce(true);
183
194
  return;
184
195
  }
185
- this.#timer = this.#setTimer(() => {
186
- this.#timer = null;
187
- void this.runOnce();
188
- }, this.#intervalMs);
196
+ // Back off while nothing changes (perf F6); any change resets it.
197
+ this.#unchangedTicks = this.#changedThisTick ? 0 : this.#unchangedTicks + 1;
198
+ this.#changedThisTick = false;
199
+ this.#timer = this.#setTimer(
200
+ () => {
201
+ this.#timer = null;
202
+ void this.runOnce();
203
+ },
204
+ this.#unchangedTicks >= FLEET_FACTS_UNCHANGED_TICKS_BEFORE_BACKOFF
205
+ ? this.#idleIntervalMs
206
+ : this.#intervalMs,
207
+ );
189
208
  },
190
209
  );
191
210
  return this.#running;
@@ -434,31 +453,44 @@ export class DaemonFleetFactsObserver {
434
453
  if (acceptSessions) {
435
454
  const previous = this.#sessionNames;
436
455
  const previousTopology = this.#terminalTopology;
456
+ if (!previous) this.#changedThisTick = true;
437
457
  this.#sessionNames = next.sessions;
438
458
  this.#terminalTopology = next.terminalTopology ?? next.sessions;
439
- if (previous && JSON.stringify(previous) !== JSON.stringify(next.sessions))
459
+ if (previous && JSON.stringify(previous) !== JSON.stringify(next.sessions)) {
460
+ this.#changedThisTick = true;
440
461
  this.#options.onSessionsChanged();
462
+ }
441
463
  if (
442
464
  previousTopology &&
443
465
  JSON.stringify(previousTopology) !== JSON.stringify(this.#terminalTopology)
444
466
  ) {
467
+ this.#changedThisTick = true;
445
468
  this.#options.onTerminalTopologyChanged?.();
446
469
  }
447
470
  }
448
471
  if (acceptAdopted) {
449
472
  const previous = this.#adoptedNames;
450
473
  this.#adoptedNames = next.adopted;
451
- if (previous && JSON.stringify(previous) !== JSON.stringify(next.adopted))
474
+ if (previous && JSON.stringify(previous) !== JSON.stringify(next.adopted)) {
475
+ this.#changedThisTick = true;
452
476
  this.#options.onAdoptedChanged();
477
+ }
453
478
  }
454
479
  }
455
480
 
456
481
  #acceptAgents(next: AgentStateReading): void {
457
482
  const previous = this.#agentFacts;
458
483
  this.#agentFacts = next;
459
- if (!previous) return;
484
+ if (!previous) {
485
+ // A baseline read is not an idle tick.
486
+ this.#changedThisTick = true;
487
+ return;
488
+ }
460
489
  const changed = diffChangedSessions(previous, next);
461
- if (changed.length > 0) this.#options.onAgentSessionsChanged(changed);
490
+ if (changed.length > 0) {
491
+ this.#changedThisTick = true;
492
+ this.#options.onAgentSessionsChanged(changed);
493
+ }
462
494
  for (const completion of diffTurnCompletions(previous, next))
463
495
  this.#options.onAgentTurnCompleted(completion);
464
496
  }
@@ -556,6 +588,15 @@ export function createDefaultFleetFactsReaders(): Pick<
556
588
  * only while a client is subscribed.
557
589
  */
558
590
  export const FLEET_FACTS_POLL_MS = 500;
591
+ /**
592
+ * After this many ticks in a row with no change, re-read every
593
+ * {@link FLEET_FACTS_IDLE_POLL_MS} instead (perf F6). With the app connected
594
+ * and nothing happening, the 500 ms poll was most of the daemon's idle CPU.
595
+ * Any change returns to 500 ms on the next tick, and 1 s still keeps an agent
596
+ * flip visible within about 1 s (#716).
597
+ */
598
+ export const FLEET_FACTS_UNCHANGED_TICKS_BEFORE_BACKOFF = 10;
599
+ export const FLEET_FACTS_IDLE_POLL_MS = 1_000;
559
600
 
560
601
  export const SESSION_COMPOSITION_TMUX_ARGS = [
561
602
  "list-panes",
@@ -99,6 +99,39 @@ export interface LiveSessionSummary {
99
99
  export function discoverLiveSessionSummaries(
100
100
  runTmux: TmuxRunner = _tmuxRunner,
101
101
  ): LiveSessionSummary[] {
102
+ return readLiveSessionSummaries(runTmux) ?? [];
103
+ }
104
+
105
+ /**
106
+ * Whether a failed tmux client says its server is not running. tmux prints
107
+ * "no server running" for a refused connection and names ENOENT for a missing
108
+ * socket; a socket path that is gone before the client starts fails in `lstat`.
109
+ */
110
+ function serverNotRunning(error: unknown): boolean {
111
+ type Failure = { stderr?: unknown; code?: unknown; syscall?: unknown; cause?: unknown };
112
+ // The tmux runners wrap the child-process failure as the `cause` of a TmuxError.
113
+ for (const failure of [error as Failure | null, (error as Failure | null)?.cause as Failure]) {
114
+ if (!failure) continue;
115
+ if (failure.code === "ENOENT" && failure.syscall === "lstat") return true;
116
+ if (
117
+ /^(?:no server running on |error connecting to .* \(No such file or directory\)$)/mu.test(
118
+ String(failure.stderr ?? ""),
119
+ )
120
+ )
121
+ return true;
122
+ }
123
+ return false;
124
+ }
125
+
126
+ /**
127
+ * {@link discoverLiveSessionSummaries}, but null when tmux could not be asked:
128
+ * an unreadable socket, a timeout, a client that would not start. Only a server
129
+ * that is not running has no sessions. An empty list for the other failures
130
+ * tells the user their sessions are gone while they are still running (#753).
131
+ */
132
+ export function readLiveSessionSummaries(
133
+ runTmux: TmuxRunner = _tmuxRunner,
134
+ ): LiveSessionSummary[] | null {
102
135
  let raw: string;
103
136
  try {
104
137
  raw = runTmux([
@@ -107,8 +140,8 @@ export function discoverLiveSessionSummaries(
107
140
  "-F",
108
141
  "#{pid}\t#{session_id}\t#{session_created}\t#{session_name}",
109
142
  ]);
110
- } catch {
111
- return [];
143
+ } catch (error) {
144
+ return serverNotRunning(error) ? [] : null;
112
145
  }
113
146
  if (!raw) return [];
114
147
  const sessions = new Map<string, LiveSessionSummary>();
@@ -16,7 +16,7 @@ import { streamSSE } from "hono/streaming";
16
16
  import { cors } from "hono/cors";
17
17
  import {
18
18
  discoverSessions,
19
- discoverLiveSessionSummaries,
19
+ readLiveSessionSummaries,
20
20
  buildOverviews,
21
21
  buildProjectDetail,
22
22
  type FleetSessionFacts,
@@ -220,12 +220,17 @@ export interface CreateAppOptions {
220
220
  operation: "terminal-resource-handler-admitted" | "terminal-resource-response-projection",
221
221
  ): void;
222
222
  } | null;
223
- /** Injectable live tmux projection for catalog tests and alternate hosts. */
224
- catalogLiveSessions?: () => readonly {
225
- readonly liveSessionId: `live-session.${string}`;
226
- readonly sessionName: string;
227
- readonly paneCount: number;
228
- }[];
223
+ /**
224
+ * Injectable live tmux projection for catalog tests and alternate hosts.
225
+ * Null when tmux could not be asked; an empty list only for no sessions.
226
+ */
227
+ catalogLiveSessions?: () =>
228
+ | readonly {
229
+ readonly liveSessionId: `live-session.${string}`;
230
+ readonly sessionName: string;
231
+ readonly paneCount: number;
232
+ }[]
233
+ | null;
229
234
  /** Injectable daemon-generation-pinned adopted fleet projection. */
230
235
  catalogFleet?: () => FleetSessionFacts[] | null | Promise<FleetSessionFacts[] | null>;
231
236
  fleetPreviewCapture?: (
@@ -881,7 +886,16 @@ export function createApp(options: CreateAppOptions = {}): Hono {
881
886
  },
882
887
  ],
883
888
  );
884
- const observedSessions = options.catalogLiveSessions?.() ?? discoverLiveSessionSummaries();
889
+ const observedSessions = options.catalogLiveSessions
890
+ ? options.catalogLiveSessions()
891
+ : readLiveSessionSummaries();
892
+ // As for the fleet catalog: an unreachable tmux must not replace the
893
+ // client's last known sessions with a successful empty list (#753).
894
+ if (observedSessions === null)
895
+ return c.json(
896
+ { error: "Tmux session discovery is unavailable", code: "tmux-unavailable" },
897
+ 503,
898
+ );
885
899
  const liveSessions = observedSessions.map(({ sessionName, paneCount }) => ({
886
900
  sessionName,
887
901
  fleetSessionId: fleetSessionIdForName(sessionName),
@@ -38,6 +38,7 @@ import { createSessionFaviconResolver, type SessionFavicon } from "../lib/sessio
38
38
  import { WorkspaceMultiplexerError } from "../lib/workspace-multiplexer-verbs.ts";
39
39
  import { WorkspacePaneCreationError } from "../lib/workspace-pane-creation.ts";
40
40
  import { ownerBearerMatches } from "./owner-authority.ts";
41
+ import { logger } from "../lib/log.ts";
41
42
  import { mountPaneStreamIssueRoute } from "./pane-stream-issue.ts";
42
43
  import { projectTerminalRuntimeInventory } from "./resources/terminal-runtime-inventory.ts";
43
44
 
@@ -96,6 +97,16 @@ function failure(c: Context, error: unknown): Response {
96
97
  return c.json({ error: { code: error.code } }, 409);
97
98
  if (error instanceof z.ZodError || error instanceof SyntaxError || error instanceof TypeError)
98
99
  return c.json({ error: { code: "invalid-request" } }, 400);
100
+ // Everything above tells the client its cause. This answer does not, and a
101
+ // client can only retry it: the cause goes to the daemon's own log.
102
+ const code = (error as { code?: unknown } | null)?.code;
103
+ logger.warn("tmux-server-routes", "request failed as server-unavailable", {
104
+ method: c.req.method,
105
+ route: c.req.routePath,
106
+ errorName: error instanceof Error ? error.name : typeof error,
107
+ ...(typeof code === "string" ? { errorCode: code.slice(0, 80) } : {}),
108
+ error: (error instanceof Error ? error.message : String(error)).slice(0, 300),
109
+ });
99
110
  return c.json({ error: { code: "server-unavailable" } }, 503);
100
111
  }
101
112
  /** Owner capability is mandatory even when the ordinary local HTTP surface is open. */
@@ -126,7 +137,7 @@ export function mountTmuxServerRoutes(app: Hono, options: TmuxServerRoutesOption
126
137
  base,
127
138
  route(async (c) =>
128
139
  c.json(
129
- TmuxServersResourceSchemaZ.parse({ version: 1, servers: await options.owners.refresh() }),
140
+ TmuxServersResourceSchemaZ.parse({ version: 1, servers: await options.owners.observe() }),
130
141
  ),
131
142
  ),
132
143
  );
@@ -350,6 +350,50 @@ function runTmuxFeatureProbes(executable: string): CheckResult {
350
350
  }
351
351
  }
352
352
 
353
+ /**
354
+ * PURE — which tmux server the daemon uses, and whether this shell's `tmux`
355
+ * means the same one.
356
+ *
357
+ * A daemon started outside tmux (launchd, systemd, `--headless` from a plain
358
+ * shell) addresses the socket named "default" and gives its tmux clients a
359
+ * scrubbed environment, so it always looks in /tmp/tmux-<uid>/ and ignores
360
+ * TMUX_TMPDIR. A shell that exports TMUX_TMPDIR, or sits in a tmux started
361
+ * with -S or -L, is then on a server that daemon cannot see. The explicit
362
+ * TMUX_IDE_TMUX_SOCKET_PATH / TMUX_IDE_TMUX_SOCKET_NAME settings apply to both.
363
+ */
364
+ export function tmuxServerSocketRow(environment: NodeJS.ProcessEnv, uid: number): CheckResult {
365
+ const defaultDirectory = join("/tmp", `tmux-${String(uid)}`);
366
+ const explicitPath = environment[TMUX_SOCKET_PATH_ENV];
367
+ const explicitName = environment.TMUX_IDE_TMUX_SOCKET_NAME;
368
+ const daemonSocket = explicitPath
369
+ ? explicitPath
370
+ : join(defaultDirectory, explicitName ? explicitName : "default");
371
+ const insideTmux = /^(.*),[0-9]+,[0-9]+$/u.exec(environment.TMUX ?? "")?.[1];
372
+ const shellSocket =
373
+ insideTmux ?? join(environment.TMUX_TMPDIR || "/tmp", `tmux-${String(uid)}`, "default");
374
+ const same = (left: string, right: string): boolean =>
375
+ left.replace(/^\/private\/tmp\//u, "/tmp/") === right.replace(/^\/private\/tmp\//u, "/tmp/");
376
+ if (explicitPath || explicitName || same(shellSocket, daemonSocket))
377
+ return {
378
+ label: "tmux server",
379
+ pass: true,
380
+ detail: `the daemon uses ${daemonSocket}${explicitPath || explicitName ? " (set explicitly)" : ""}`,
381
+ optional: true,
382
+ };
383
+ const why = insideTmux
384
+ ? "this shell is inside a tmux on another socket"
385
+ : "TMUX_TMPDIR is set, and the daemon ignores it";
386
+ return {
387
+ label: "tmux server",
388
+ pass: false,
389
+ detail:
390
+ `this shell's tmux uses ${shellSocket}, a background daemon uses ${daemonSocket} (${why}): ` +
391
+ `it will not see this shell's sessions. Set ${TMUX_SOCKET_PATH_ENV}=${shellSocket} in the daemon's environment` +
392
+ (insideTmux ? "" : ", or unset TMUX_TMPDIR"),
393
+ optional: true,
394
+ };
395
+ }
396
+
353
397
  export function nodeVersionRow(version: string): CheckResult {
354
398
  const major = Number(version.split(".")[0]);
355
399
  const pass = Number.isInteger(major) && major >= 20;
@@ -552,6 +596,8 @@ export async function doctor({
552
596
  ),
553
597
  );
554
598
 
599
+ checks.push(tmuxServerSocketRow(process.env, process.getuid?.() ?? 0));
600
+
555
601
  // Canonical daemon identity + log provenance (credential-free), so a triage
556
602
  // never chases a stale, manually redirected log file.
557
603
  checks.push(
@@ -1,6 +1,12 @@
1
1
  import { withBundledTmuxResources } from "./bundled-tmux.ts";
2
2
  import { execFile } from "node:child_process";
3
- /** Read-only child ownership: TERM at deadline/abort, KILL after grace; settle after close. */
3
+ export const BOUNDED_TMUX_KILL_GRACE_MS = 250;
4
+ /**
5
+ * Read-only child ownership: TERM at deadline/abort, KILL after grace; settle
6
+ * after close. "close" needs every holder of the pipes to let go, so once the
7
+ * child has been killed the read settles one more grace later regardless: a
8
+ * wrapper's lingering grandchild must not turn a deadline into a hang (#839).
9
+ */
4
10
  export function boundedTmuxRead(
5
11
  executable: string,
6
12
  args: readonly string[],
@@ -30,11 +36,31 @@ export function boundedTmuxRead(
30
36
  output = stdout;
31
37
  },
32
38
  );
39
+ let abandon: ReturnType<typeof setTimeout> | null = null;
40
+ let settled = false;
41
+ const settle = () => {
42
+ if (settled) return;
43
+ settled = true;
44
+ clearTimeout(deadline);
45
+ if (escalation) clearTimeout(escalation);
46
+ if (abandon) clearTimeout(abandon);
47
+ options.signal?.removeEventListener("abort", stop);
48
+ if (failure) reject(failure);
49
+ else resolve(output);
50
+ };
33
51
  const stop = () => {
34
52
  failure ??= new Error("Tmux read cancelled or deadline exceeded");
35
53
  if (escalation) return;
36
54
  child.kill("SIGTERM");
37
- escalation = setTimeout(() => child.kill("SIGKILL"), 250);
55
+ escalation = setTimeout(() => {
56
+ child.kill("SIGKILL");
57
+ abandon = setTimeout(() => {
58
+ child.stdout?.destroy();
59
+ child.stderr?.destroy();
60
+ settle();
61
+ }, BOUNDED_TMUX_KILL_GRACE_MS);
62
+ abandon.unref?.();
63
+ }, BOUNDED_TMUX_KILL_GRACE_MS);
38
64
  escalation.unref?.();
39
65
  };
40
66
  const deadline = setTimeout(stop, options.timeoutMs ?? 5000);
@@ -43,13 +69,7 @@ export function boundedTmuxRead(
43
69
  child.once("error", (error) => {
44
70
  failure ??= error;
45
71
  });
46
- child.once("close", () => {
47
- clearTimeout(deadline);
48
- if (escalation) clearTimeout(escalation);
49
- options.signal?.removeEventListener("abort", stop);
50
- if (failure) reject(failure);
51
- else resolve(output);
52
- });
72
+ child.once("close", settle);
53
73
  if (options.signal?.aborted) stop();
54
74
  });
55
75
  }