tmux-ide 2.9.24 → 2.9.26

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 (77) hide show
  1. package/bin/cli.js +1689 -393
  2. package/package.json +5 -2
  3. package/packages/contracts/src/pane-stream.ts +72 -0
  4. package/packages/contracts/src/terminal-delivery.ts +8 -2
  5. package/packages/contracts/src/terminal-runtime-inventory.ts +61 -1
  6. package/packages/contracts/src/tmux-server-scope.ts +18 -0
  7. package/packages/daemon/dist/command-center/discovery.js +24 -5
  8. package/packages/daemon/dist/command-center/resources/terminal-runtime-inventory.js +42 -2
  9. package/packages/daemon/dist/command-center/server.js +81 -75
  10. package/packages/daemon/dist/command-center/tmux-servers.js +17 -7
  11. package/packages/daemon/dist/doctor.js +46 -10
  12. package/packages/daemon/dist/lib/canonical-daemon-bootstrap.js +20 -2
  13. package/packages/daemon/dist/lib/daemon-crash-snapshot.js +118 -0
  14. package/packages/daemon/dist/lib/daemon-embed.js +6 -0
  15. package/packages/daemon/dist/lib/headless-daemon.js +63 -6
  16. package/packages/daemon/dist/lib/invocation-directory.js +20 -0
  17. package/packages/daemon/dist/lib/runtime-namespace.js +22 -6
  18. package/packages/daemon/dist/lib/tmux-client-execution.js +12 -3
  19. package/packages/daemon/dist/lib/tmux-server-owner.js +4 -2
  20. package/packages/daemon/dist/lib/update-check.js +18 -0
  21. package/packages/daemon/dist/lib/update-daemon-outcome.js +31 -0
  22. package/packages/daemon/dist/lib/update.js +39 -14
  23. package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/Info.plist +2 -2
  24. package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/MacOS/tmux-ide-notifier +0 -0
  25. package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/Resources/Assets.car +0 -0
  26. package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/_CodeSignature/CodeResources +2 -2
  27. package/packages/daemon/dist/terminal/graphics/kitty-graphics.js +16 -4
  28. package/packages/daemon/dist/terminal/mirror/mirror-service.js +26 -0
  29. package/packages/daemon/dist/terminal/mirror/session-channel.js +31 -2
  30. package/packages/daemon/dist/terminal/pane-stream/lease-manager.js +1 -0
  31. package/packages/daemon/dist/terminal/pane-stream/pane-stream-websocket.js +831 -222
  32. package/packages/daemon/dist/terminal/protocol/browser-icon.js +1 -1
  33. package/packages/daemon/dist/terminal/protocol/session-descriptor-discovery.js +26 -3
  34. package/packages/daemon/dist/terminal/session-runtime/registry.js +25 -2
  35. package/packages/daemon/dist/terminal/session-runtime/terminal-delivery-hub.js +121 -6
  36. package/packages/daemon/dist/terminal/session-runtime/terminal-replica-interpreter.js +79 -2
  37. package/packages/daemon/dist/terminal/session-runtime/terminal-replica-owner.js +24 -2
  38. package/packages/daemon/dist/terminal/session-runtime/transport-binding.js +38 -0
  39. package/packages/daemon/dist/terminal/session-runtime/xterm-terminal-interpreter-backend.js +51 -4
  40. package/packages/daemon/dist/tui/chrome/snapshot.js +36 -1
  41. package/packages/daemon/dist/tui/chrome/statusline.js +8 -5
  42. package/packages/daemon/dist/tui/chrome/updater.js +2 -0
  43. package/packages/daemon/src/command-center/discovery.ts +24 -4
  44. package/packages/daemon/src/command-center/resources/terminal-runtime-inventory.ts +48 -1
  45. package/packages/daemon/src/command-center/server.ts +67 -67
  46. package/packages/daemon/src/command-center/tmux-servers.ts +19 -6
  47. package/packages/daemon/src/doctor.ts +50 -9
  48. package/packages/daemon/src/lib/canonical-daemon-bootstrap.ts +31 -5
  49. package/packages/daemon/src/lib/daemon-crash-snapshot.ts +175 -0
  50. package/packages/daemon/src/lib/daemon-embed.ts +22 -0
  51. package/packages/daemon/src/lib/headless-daemon.ts +88 -7
  52. package/packages/daemon/src/lib/invocation-directory.ts +21 -0
  53. package/packages/daemon/src/lib/runtime-namespace.ts +25 -7
  54. package/packages/daemon/src/lib/tmux-client-execution.ts +14 -5
  55. package/packages/daemon/src/lib/tmux-server-owner.ts +6 -3
  56. package/packages/daemon/src/lib/update-check.ts +34 -0
  57. package/packages/daemon/src/lib/update-daemon-outcome.ts +42 -0
  58. package/packages/daemon/src/lib/update.ts +58 -16
  59. package/packages/daemon/src/terminal/graphics/kitty-graphics.ts +22 -6
  60. package/packages/daemon/src/terminal/mirror/events.ts +2 -0
  61. package/packages/daemon/src/terminal/mirror/mirror-service.ts +27 -0
  62. package/packages/daemon/src/terminal/mirror/session-channel.ts +38 -2
  63. package/packages/daemon/src/terminal/pane-stream/lease-manager.ts +3 -0
  64. package/packages/daemon/src/terminal/pane-stream/pane-stream-websocket.ts +915 -236
  65. package/packages/daemon/src/terminal/protocol/browser-icon.ts +1 -1
  66. package/packages/daemon/src/terminal/protocol/session-descriptor-discovery.ts +32 -2
  67. package/packages/daemon/src/terminal/session-runtime/registry.ts +36 -2
  68. package/packages/daemon/src/terminal/session-runtime/terminal-delivery-hub.ts +136 -6
  69. package/packages/daemon/src/terminal/session-runtime/terminal-interpreter-backend.ts +6 -0
  70. package/packages/daemon/src/terminal/session-runtime/terminal-replica-interpreter.ts +76 -2
  71. package/packages/daemon/src/terminal/session-runtime/terminal-replica-owner.ts +21 -1
  72. package/packages/daemon/src/terminal/session-runtime/transport-binding.ts +42 -2
  73. package/packages/daemon/src/terminal/session-runtime/xterm-terminal-interpreter-backend.ts +67 -3
  74. package/packages/daemon/src/tui/chrome/snapshot.ts +47 -1
  75. package/packages/daemon/src/tui/chrome/statusline.ts +7 -4
  76. package/packages/daemon/src/tui/chrome/updater.ts +3 -0
  77. package/packages/daemon-client/src/pane-stream-client.ts +47 -5
@@ -9,6 +9,9 @@ export class XtermTerminalInterpreterBackend {
9
9
  #terminal;
10
10
  #rowCache = new WeakMap();
11
11
  #scrollEpoch = 0;
12
+ #historyLimit;
13
+ #collecting = false;
14
+ #lastYbase = null;
12
15
  #lastScrollEpoch = 0;
13
16
  #lastViewportY = 0;
14
17
  #lastBufferType = "normal";
@@ -21,11 +24,16 @@ export class XtermTerminalInterpreterBackend {
21
24
  #historyProjectionInvalidated = false;
22
25
  #scrollOnClear;
23
26
  constructor(options) {
27
+ const historyLimit = options.historyLimit ?? options.scrollback;
28
+ this.#historyLimit = historyLimit;
24
29
  this.#terminal = new Terminal({
25
30
  cols: options.cols,
26
31
  rows: options.rows,
27
- scrollback: options.scrollback,
28
- tmuxHistoryLimit: options.historyLimit ?? options.scrollback,
32
+ // One row of headroom over what the replica may hold (the limit, or a
33
+ // larger captured history): xterm must not recycle the row a scroll
34
+ // adds before #collectHistory sees it.
35
+ scrollback: historyLimit > 0 ? Math.max(options.scrollback, historyLimit) + 1 : options.scrollback,
36
+ tmuxHistoryLimit: historyLimit,
29
37
  allowProposedApi: true,
30
38
  });
31
39
  this.#terminal.loadAddon(new Unicode11Addon());
@@ -67,8 +75,10 @@ export class XtermTerminalInterpreterBackend {
67
75
  this.#terminal.onScroll(() => {
68
76
  // tmux retains normal history while alternate rows scroll independently.
69
77
  // Neither captured nor live alternate scrolling may trim that history.
70
- if (this.#terminal.buffer.active.type === "normal")
71
- this.#scrollEpoch += 1;
78
+ if (this.#terminal.buffer.active.type !== "normal")
79
+ return;
80
+ this.#scrollEpoch += 1;
81
+ this.#collectHistory();
72
82
  });
73
83
  const core = this.#terminal._core;
74
84
  if (!core?.coreService) {
@@ -76,6 +86,43 @@ export class XtermTerminalInterpreterBackend {
76
86
  throw new Error("Unsupported @tmux-ide/xterm-headless private API shape");
77
87
  }
78
88
  }
89
+ /**
90
+ * tmux at its history-limit collects the oldest tenth of history before a
91
+ * scroll would pass it (grid_collect_history), so its history_size moves
92
+ * between 0.9 and 1.0 of the limit. Recycling one row at a time instead kept
93
+ * the replica at the limit, and the owner's history-size check then reseeded
94
+ * the whole pane each time its output paused. The projection reports the
95
+ * collection as an ordinary history trim.
96
+ */
97
+ startHistoryCollection() {
98
+ this.#collecting = true;
99
+ this.#lastYbase = this.#normalBuffer()?.ybase ?? null;
100
+ }
101
+ #normalBuffer() {
102
+ return this.#terminal._core?.buffers?.normal;
103
+ }
104
+ #collectHistory() {
105
+ const buffer = this.#normalBuffer();
106
+ if (!buffer)
107
+ return;
108
+ const before = this.#lastYbase;
109
+ const limit = this.#historyLimit;
110
+ // Only a plain one-row scroll from at or above the limit is collected
111
+ // here. ED2 collects before its own scrolls (one-column.patch), and any
112
+ // other change (reset, resize, a capped ring) is left alone: a history
113
+ // that still differs from tmux is caught by the owner's size check.
114
+ if (this.#collecting &&
115
+ limit > 0 &&
116
+ before !== null &&
117
+ before >= limit &&
118
+ buffer.ybase === before + 1) {
119
+ const trim = Math.min(buffer.ybase, Math.max(1, Math.floor(limit / 10)));
120
+ buffer.lines.trimStart(trim);
121
+ buffer.ybase -= trim;
122
+ buffer.ydisp = Math.max(0, buffer.ydisp - trim);
123
+ }
124
+ this.#lastYbase = buffer.ybase;
125
+ }
79
126
  get cols() {
80
127
  return this.#terminal.cols;
81
128
  }
@@ -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),
@@ -1,13 +1,15 @@
1
1
  import {
2
2
  TERMINAL_RUNTIME_INVENTORY_RESOURCE_VERSION,
3
3
  TerminalRuntimeInventoryProjectionV1SchemaZ,
4
+ TerminalRuntimeInventoryProjectionV2SchemaZ,
4
5
  type TerminalRuntimeInventoryProjectionV1,
6
+ type TerminalRuntimeInventoryProjectionV2,
5
7
  type TerminalRuntimeInventoryResourceV1,
6
8
  type DaemonInstanceIdentity,
7
9
  } from "@tmux-ide/contracts";
8
10
 
9
11
  import type { NativeTerminalRuntimeSessionSnapshot } from "../../terminal/attachments/native-runtime.ts";
10
- import { projectApplicationShellResource } from "./application-shell.ts";
12
+ import { paneIdentities, projectApplicationShellResource } from "./application-shell.ts";
11
13
 
12
14
  /** Pure, wire-safe agent-free topology projection. */
13
15
  export function projectTerminalRuntimeInventory(
@@ -32,6 +34,51 @@ export function projectTerminalRuntimeInventory(
32
34
  });
33
35
  }
34
36
 
37
+ /**
38
+ * #806: version 1 plus each window and its panes, in tmux order. A window is
39
+ * named only when it has a verified window stamp and every pane in it is
40
+ * available, so its pane set is one a window-scoped issue can accept.
41
+ */
42
+ export function projectTerminalRuntimeInventoryV2(
43
+ session: NativeTerminalRuntimeSessionSnapshot,
44
+ resourceRevision: number,
45
+ ): TerminalRuntimeInventoryProjectionV2 {
46
+ const identities = paneIdentities(session);
47
+ const windows = new Map<
48
+ string,
49
+ { semanticWindowId: string | null; active: boolean; panes: string[]; complete: boolean }
50
+ >();
51
+ session.panes.forEach((pane, index) => {
52
+ if (pane.windowId === undefined) return;
53
+ const stamp = pane.windowStamp ?? null;
54
+ const entry = windows.get(pane.windowId) ?? {
55
+ semanticWindowId: stamp,
56
+ active: false,
57
+ panes: [] as string[],
58
+ complete: true,
59
+ };
60
+ windows.set(pane.windowId, entry);
61
+ const attachability = identities[index]!.attachability;
62
+ if (attachability.status === "available") entry.panes.push(attachability.semanticPaneId);
63
+ else entry.complete = false;
64
+ if (pane.active) entry.active = true;
65
+ });
66
+ return TerminalRuntimeInventoryProjectionV2SchemaZ.parse({
67
+ ...projectTerminalRuntimeInventory(session, resourceRevision),
68
+ windows: [...windows.values()].flatMap((window) =>
69
+ window.complete && window.semanticWindowId !== null && window.panes.length > 0
70
+ ? [
71
+ {
72
+ semanticWindowId: window.semanticWindowId,
73
+ active: window.active,
74
+ semanticPaneIds: [...window.panes].sort(),
75
+ },
76
+ ]
77
+ : [],
78
+ ),
79
+ });
80
+ }
81
+
35
82
  export function terminalRuntimeInventoryEnvelope(
36
83
  daemon: DaemonInstanceIdentity,
37
84
  session: NativeTerminalRuntimeSessionSnapshot,
@@ -11,11 +11,12 @@ import { promisify } from "node:util";
11
11
  import { existsSync, readdirSync } from "node:fs";
12
12
  import { join, dirname, basename } from "node:path";
13
13
  import { fileURLToPath } from "node:url";
14
- import { Hono, type MiddlewareHandler } from "hono";
14
+ import { Hono, type Context, type MiddlewareHandler } from "hono";
15
15
  import { streamSSE } from "hono/streaming";
16
16
  import { cors } from "hono/cors";
17
17
  import {
18
18
  discoverSessions,
19
+ readSessions,
19
20
  readLiveSessionSummaries,
20
21
  buildOverviews,
21
22
  buildProjectDetail,
@@ -537,6 +538,20 @@ function sandboxResolveDir(rawDir: string): SandboxResolveOk | SandboxResolveErr
537
538
  }
538
539
 
539
540
  export function createApp(options: CreateAppOptions = {}): Hono {
541
+ /**
542
+ * The running session a /api/project/:name route acts on. "unavailable" when
543
+ * tmux could not be asked: the session may well still run, so the routes
544
+ * answer 503 tmux-unavailable, not 404 (#753).
545
+ */
546
+ const lookupSession = (name: string): DiscoveredSession | "not-found" | "unavailable" => {
547
+ const sessions = readSessions();
548
+ if (sessions === null) return "unavailable";
549
+ return sessions.find((session) => session.name === name) ?? "not-found";
550
+ };
551
+ const sessionMissing = (c: Context, missing: "not-found" | "unavailable") =>
552
+ missing === "unavailable"
553
+ ? c.json({ error: "Tmux session discovery is unavailable", code: "tmux-unavailable" }, 503)
554
+ : c.json({ error: "Session not found" }, 404);
540
555
  const authConfig: AuthConfig = options.authConfig ?? { method: "none", token_expiry: 86400 };
541
556
  const authService = options.authService ?? new AuthService();
542
557
  const daemonIdentity = options.daemonIdentity ?? {
@@ -830,7 +845,13 @@ export function createApp(options: CreateAppOptions = {}): Hono {
830
845
  });
831
846
 
832
847
  app.get("/api/sessions", (c) => {
833
- const sessions = discoverSessions();
848
+ const sessions = readSessions();
849
+ // An empty list would tell the TUI the sessions are gone while they run (#753).
850
+ if (sessions === null)
851
+ return c.json(
852
+ { error: "Tmux session discovery is unavailable", code: "tmux-unavailable" },
853
+ 503,
854
+ );
834
855
  const overviews = buildOverviews(sessions);
835
856
  return c.json({ sessions: overviews } satisfies DaemonSessionsResponse);
836
857
  });
@@ -986,11 +1007,8 @@ export function createApp(options: CreateAppOptions = {}): Hono {
986
1007
 
987
1008
  app.get("/api/project/:name", (c) => {
988
1009
  const name = c.req.param("name");
989
- const sessions = discoverSessions();
990
- const session = sessions.find((s) => s.name === name);
991
- if (!session) {
992
- return c.json({ error: "Session not found" }, 404);
993
- }
1010
+ const session = lookupSession(name);
1011
+ if (typeof session === "string") return sessionMissing(c, session);
994
1012
  const detail = buildProjectDetail(session);
995
1013
  return c.json({ ...detail } satisfies DaemonProjectResponse);
996
1014
  });
@@ -1121,8 +1139,8 @@ export function createApp(options: CreateAppOptions = {}): Hono {
1121
1139
  const backend = options.applicationShellInventoryBackend;
1122
1140
  if (!backend) {
1123
1141
  if (requestedVersion === String(APPLICATION_SHELL_RESOURCE_V1_VERSION)) {
1124
- const standaloneSession = discoverSessions().find((candidate) => candidate.name === name);
1125
- if (!standaloneSession) return c.json({ error: "Session not found" }, 404);
1142
+ const standaloneSession = lookupSession(name);
1143
+ if (typeof standaloneSession === "string") return sessionMissing(c, standaloneSession);
1126
1144
  markV1Compatibility();
1127
1145
  return c.json({
1128
1146
  version: APPLICATION_SHELL_RESOURCE_V1_VERSION,
@@ -1219,14 +1237,14 @@ export function createApp(options: CreateAppOptions = {}): Hono {
1219
1237
  try {
1220
1238
  panes = listSessionPanes(name);
1221
1239
  } catch {
1222
- return c.json({ error: "Session not found" }, 404);
1240
+ // A missing session, or a tmux that could not be asked (#753).
1241
+ const session = lookupSession(name);
1242
+ return sessionMissing(c, typeof session === "string" ? session : "not-found");
1223
1243
  }
1224
1244
  if (panes.length === 0) {
1225
1245
  // Verify the session actually exists before returning empty
1226
- const sessions = discoverSessions();
1227
- if (!sessions.find((s) => s.name === name)) {
1228
- return c.json({ error: "Session not found" }, 404);
1229
- }
1246
+ const session = lookupSession(name);
1247
+ if (typeof session === "string") return sessionMissing(c, session);
1230
1248
  }
1231
1249
  return c.json({
1232
1250
  panes: panes.map((p) => ({
@@ -1246,9 +1264,8 @@ export function createApp(options: CreateAppOptions = {}): Hono {
1246
1264
 
1247
1265
  app.get("/api/project/:name/terminals", async (c) => {
1248
1266
  const name = c.req.param("name");
1249
- const sessions = discoverSessions();
1250
- const session = sessions.find((s) => s.name === name);
1251
- if (!session) return c.json({ error: "Session not found" }, 404);
1267
+ const session = lookupSession(name);
1268
+ if (typeof session === "string") return sessionMissing(c, session);
1252
1269
  const records = loadTerminals(session.dir);
1253
1270
  const terminals = records.map((t) => {
1254
1271
  const bridge = defaultPtyBridgeRegistry.peek(t.id) as
@@ -1285,9 +1302,8 @@ export function createApp(options: CreateAppOptions = {}): Hono {
1285
1302
  zValidator("json", terminalCreateRequestSchema),
1286
1303
  async (c) => {
1287
1304
  const name = c.req.param("name");
1288
- const sessions = discoverSessions();
1289
- const session = sessions.find((s) => s.name === name);
1290
- if (!session) return c.json({ error: "Session not found" }, 404);
1305
+ const session = lookupSession(name);
1306
+ if (typeof session === "string") return sessionMissing(c, session);
1291
1307
  const body = c.req.valid("json");
1292
1308
  // Pick the id: explicit > deterministic (when script provided) >
1293
1309
  // UUID. The script-derived id collapse is the load-bearing bit
@@ -1330,9 +1346,8 @@ export function createApp(options: CreateAppOptions = {}): Hono {
1330
1346
  async (c) => {
1331
1347
  const name = c.req.param("name");
1332
1348
  const id = c.req.param("id");
1333
- const sessions = discoverSessions();
1334
- const session = sessions.find((s) => s.name === name);
1335
- if (!session) return c.json({ error: "Session not found" }, 404);
1349
+ const session = lookupSession(name);
1350
+ if (typeof session === "string") return sessionMissing(c, session);
1336
1351
  try {
1337
1352
  const record = renameTerminalRecord(session.dir, id, c.req.valid("json").name);
1338
1353
  if (!record) return c.json({ error: "Terminal not found" }, 404);
@@ -1347,9 +1362,8 @@ export function createApp(options: CreateAppOptions = {}): Hono {
1347
1362
  app.delete("/api/project/:name/terminals/:id", async (c) => {
1348
1363
  const name = c.req.param("name");
1349
1364
  const id = c.req.param("id");
1350
- const sessions = discoverSessions();
1351
- const session = sessions.find((s) => s.name === name);
1352
- if (!session) return c.json({ error: "Session not found" }, 404);
1365
+ const session = lookupSession(name);
1366
+ if (typeof session === "string") return sessionMissing(c, session);
1353
1367
  const removedRecord = deleteTerminalRecord(session.dir, id);
1354
1368
  // Kill the live bridge too — keep store + registry consistent.
1355
1369
  const killed = defaultPtyBridgeRegistry.delete(id);
@@ -1366,19 +1380,15 @@ export function createApp(options: CreateAppOptions = {}): Hono {
1366
1380
 
1367
1381
  app.get("/api/project/:name/events", (c) => {
1368
1382
  const name = c.req.param("name");
1369
- const session = discoverSessions().find((s) => s.name === name);
1370
- if (!session) {
1371
- return c.json({ error: "Session not found" }, 404);
1372
- }
1383
+ const session = lookupSession(name);
1384
+ if (typeof session === "string") return sessionMissing(c, session);
1373
1385
  return c.json({ events: [] });
1374
1386
  });
1375
1387
 
1376
1388
  app.get("/api/project/:name/stream", (c) => {
1377
1389
  const name = c.req.param("name");
1378
- const session = discoverSessions().find((s) => s.name === name);
1379
- if (!session) {
1380
- return c.json({ error: "Session not found" }, 404);
1381
- }
1390
+ const session = lookupSession(name);
1391
+ if (typeof session === "string") return sessionMissing(c, session);
1382
1392
 
1383
1393
  return streamSSE(c, async (stream) => {
1384
1394
  projectStreamConnections += 1;
@@ -1408,9 +1418,10 @@ export function createApp(options: CreateAppOptions = {}): Hono {
1408
1418
  writeChanges(session);
1409
1419
  while (!closed) {
1410
1420
  await stream.sleep(250);
1411
- const current = discoverSessions().find((candidate) => candidate.name === name);
1412
- if (!current) break;
1413
- writeChanges(current);
1421
+ const current = lookupSession(name);
1422
+ if (current === "not-found") break;
1423
+ // tmux could not be asked: the session may still run; ask again (#753).
1424
+ if (current !== "unavailable") writeChanges(current);
1414
1425
  const now = Date.now();
1415
1426
  if (now - lastPing >= 25_000) {
1416
1427
  writeSse("ping", { at: new Date().toISOString() });
@@ -1426,11 +1437,8 @@ export function createApp(options: CreateAppOptions = {}): Hono {
1426
1437
 
1427
1438
  app.post("/api/project/:name/inject", async (c) => {
1428
1439
  const name = c.req.param("name");
1429
- const sessions = discoverSessions();
1430
- const session = sessions.find((s) => s.name === name);
1431
- if (!session) {
1432
- return c.json({ error: "Session not found" }, 404);
1433
- }
1440
+ const session = lookupSession(name);
1441
+ if (typeof session === "string") return sessionMissing(c, session);
1434
1442
 
1435
1443
  let body: unknown;
1436
1444
  try {
@@ -1474,11 +1482,8 @@ export function createApp(options: CreateAppOptions = {}): Hono {
1474
1482
  // Send message to a pane by name/title/role/ID
1475
1483
  app.post("/api/project/:name/send", zValidator("json", sendCommandSchema), async (c) => {
1476
1484
  const name = c.req.param("name");
1477
- const sessions = discoverSessions();
1478
- const session = sessions.find((s) => s.name === name);
1479
- if (!session) {
1480
- return c.json({ error: "Session not found" }, 404);
1481
- }
1485
+ const session = lookupSession(name);
1486
+ if (typeof session === "string") return sessionMissing(c, session);
1482
1487
 
1483
1488
  const { target, message, noEnter } = c.req.valid("json");
1484
1489
 
@@ -1522,9 +1527,8 @@ export function createApp(options: CreateAppOptions = {}): Hono {
1522
1527
  // the v2 Config editor to hydrate the form.
1523
1528
  app.get("/api/project/:name/config", async (c) => {
1524
1529
  const name = c.req.param("name");
1525
- const sessions = discoverSessions();
1526
- const session = sessions.find((s) => s.name === name);
1527
- if (!session) return c.json({ error: "Session not found" }, 404);
1530
+ const session = lookupSession(name);
1531
+ if (typeof session === "string") return sessionMissing(c, session);
1528
1532
  try {
1529
1533
  const resolved = await resolveConfig(session.dir);
1530
1534
  if (!resolved.launchConfig || !resolved.path) {
@@ -1550,9 +1554,8 @@ export function createApp(options: CreateAppOptions = {}): Hono {
1550
1554
  // config so the client can re-hydrate without a follow-up GET.
1551
1555
  app.post("/api/project/:name/config", async (c) => {
1552
1556
  const name = c.req.param("name");
1553
- const sessions = discoverSessions();
1554
- const session = sessions.find((s) => s.name === name);
1555
- if (!session) return c.json({ error: "Session not found" }, 404);
1557
+ const session = lookupSession(name);
1558
+ if (typeof session === "string") return sessionMissing(c, session);
1556
1559
  let body: unknown;
1557
1560
  try {
1558
1561
  body = await c.req.json();
@@ -1590,9 +1593,8 @@ export function createApp(options: CreateAppOptions = {}): Hono {
1590
1593
  // 30s timeout so the client can retry on its own.
1591
1594
  app.post("/api/project/:name/restart", async (c) => {
1592
1595
  const name = c.req.param("name");
1593
- const sessions = discoverSessions();
1594
- const session = sessions.find((s) => s.name === name);
1595
- if (!session) return c.json({ error: "Session not found" }, 404);
1596
+ const session = lookupSession(name);
1597
+ if (typeof session === "string") return sessionMissing(c, session);
1596
1598
  try {
1597
1599
  await execFileAsync("tmux-ide", ["restart", "--json"], {
1598
1600
  cwd: session.dir,
@@ -1608,11 +1610,8 @@ export function createApp(options: CreateAppOptions = {}): Hono {
1608
1610
 
1609
1611
  app.post("/api/project/:name/launch", async (c) => {
1610
1612
  const name = c.req.param("name");
1611
- const sessions = discoverSessions();
1612
- const session = sessions.find((s) => s.name === name);
1613
- if (!session) {
1614
- return c.json({ error: "Session not found" }, 404);
1615
- }
1613
+ const session = lookupSession(name);
1614
+ if (typeof session === "string") return sessionMissing(c, session);
1616
1615
 
1617
1616
  // Check if already running
1618
1617
  const state = getSessionState(name);
@@ -1636,11 +1635,8 @@ export function createApp(options: CreateAppOptions = {}): Hono {
1636
1635
  // Stop a tmux-ide session
1637
1636
  app.post("/api/project/:name/stop", async (c) => {
1638
1637
  const name = c.req.param("name");
1639
- const sessions = discoverSessions();
1640
- const session = sessions.find((s) => s.name === name);
1641
- if (!session) {
1642
- return c.json({ error: "Session not found" }, 404);
1643
- }
1638
+ const session = lookupSession(name);
1639
+ if (typeof session === "string") return sessionMissing(c, session);
1644
1640
 
1645
1641
  const state = getSessionState(name);
1646
1642
  if (!state.running) {
@@ -1661,7 +1657,11 @@ export function createApp(options: CreateAppOptions = {}): Hono {
1661
1657
  let prevOverviews: SessionOverview[] = [];
1662
1658
 
1663
1659
  const poll = () => {
1664
- const sessions = discoverSessions();
1660
+ const sessions = readSessions();
1661
+ // tmux could not be asked: the sessions may well still run. Diffing an
1662
+ // empty list would announce every one as removed, then added (#753).
1663
+ // Keep the last answer and wait for the next poll.
1664
+ if (sessions === null) return;
1665
1665
  const overviews = buildOverviews(sessions);
1666
1666
 
1667
1667
  const prevNames = new Set(prevOverviews.map((s) => s.name));
@@ -24,6 +24,7 @@ import {
24
24
  TmuxServersResourceSchemaZ,
25
25
  TmuxServerSessionsResourceSchemaZ,
26
26
  TmuxServerSessionsResourceV2SchemaZ,
27
+ TmuxServerSessionsResourceV3SchemaZ,
27
28
  WorkspaceMultiplexerMutationRequestSchemaZ,
28
29
  WorkspacePaneCreateMutationRequestSchemaZ,
29
30
  WorkspaceSessionCreateArgumentsSchemaZ,
@@ -40,7 +41,10 @@ import { WorkspacePaneCreationError } from "../lib/workspace-pane-creation.ts";
40
41
  import { ownerBearerMatches } from "./owner-authority.ts";
41
42
  import { logger } from "../lib/log.ts";
42
43
  import { mountPaneStreamIssueRoute } from "./pane-stream-issue.ts";
43
- import { projectTerminalRuntimeInventory } from "./resources/terminal-runtime-inventory.ts";
44
+ import {
45
+ projectTerminalRuntimeInventory,
46
+ projectTerminalRuntimeInventoryV2,
47
+ } from "./resources/terminal-runtime-inventory.ts";
44
48
 
45
49
  export interface TmuxServerRoutesOptions {
46
50
  readonly ownerToken: string | null;
@@ -295,7 +299,9 @@ export function mountTmuxServerRoutes(app: Hono, options: TmuxServerRoutesOption
295
299
  `${scoped}/sessions`,
296
300
  route(async (c) => {
297
301
  const server = scope(c);
298
- const v2 = c.req.query("version") === "2";
302
+ // #806: version 3 is version 2 plus the largest window's pane count.
303
+ const v3 = c.req.query("version") === "3";
304
+ const v2 = v3 || c.req.query("version") === "2";
299
305
  const { rows, favicons } = await options.owners.withOwner(server, async (owner) => {
300
306
  const sessions = await owner.catalog();
301
307
  const workspaces = owner.workspaceRegistry.list();
@@ -328,9 +334,10 @@ export function mountTmuxServerRoutes(app: Hono, options: TmuxServerRoutesOption
328
334
  }),
329
335
  );
330
336
  let budget = SESSIONS_RESOURCE_FAVICON_BUDGET_BYTES;
337
+ const schema = v3 ? TmuxServerSessionsResourceV3SchemaZ : TmuxServerSessionsResourceV2SchemaZ;
331
338
  return c.json(
332
- TmuxServerSessionsResourceV2SchemaZ.parse({
333
- version: 2,
339
+ schema.parse({
340
+ version: v3 ? 3 : 2,
334
341
  server,
335
342
  sessions: rows.map(({ session, workspaceName }, index) => {
336
343
  const found = favicons[index] ?? null;
@@ -342,6 +349,7 @@ export function mountTmuxServerRoutes(app: Hono, options: TmuxServerRoutesOption
342
349
  workspaceName,
343
350
  paneCount: session.paneCount,
344
351
  windowCount: session.windowCount,
352
+ ...(v3 ? { largestWindowPaneCount: session.largestWindowPaneCount } : {}),
345
353
  lastActivity: session.lastActivity,
346
354
  favicon: favicon ? { mime: favicon.mime, data: favicon.data } : null,
347
355
  };
@@ -368,6 +376,8 @@ export function mountTmuxServerRoutes(app: Hono, options: TmuxServerRoutesOption
368
376
  route(async (c) => {
369
377
  const server = scope(c);
370
378
  const workspaceName = workspaceSchema.parse(c.req.param("workspaceName"));
379
+ // #806: version 2 also names each window and its panes.
380
+ const v2 = c.req.query("version") === "2";
371
381
  const resource = await options.owners.withOwner(server, async (owner) => {
372
382
  const sessions = await owner.catalog();
373
383
  const workspace = owner.workspaceRegistry.get(workspaceName);
@@ -384,10 +394,13 @@ export function mountTmuxServerRoutes(app: Hono, options: TmuxServerRoutesOption
384
394
  workspace.sessionName,
385
395
  c.req.raw.signal,
386
396
  );
387
- return snapshot ? projectTerminalRuntimeInventory(snapshot, 0) : null;
397
+ if (!snapshot) return null;
398
+ return v2
399
+ ? projectTerminalRuntimeInventoryV2(snapshot, 0)
400
+ : projectTerminalRuntimeInventory(snapshot, 0);
388
401
  });
389
402
  return resource
390
- ? c.json({ version: 1, server, resource })
403
+ ? c.json({ version: v2 ? 2 : 1, server, resource })
391
404
  : c.json({ error: { code: "workspace-not-found" } }, 404);
392
405
  }),
393
406
  );