tmux-ide 2.9.21 → 2.9.23

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 (131) hide show
  1. package/bin/cli.js +6235 -8473
  2. package/package.json +3 -3
  3. package/packages/contracts/src/index.ts +2 -0
  4. package/packages/contracts/src/pane-reader.ts +121 -0
  5. package/packages/contracts/src/pane-stream.ts +18 -0
  6. package/packages/contracts/src/visual-theme-presets.ts +58 -2
  7. package/packages/contracts/src/websocket-heartbeat.ts +41 -0
  8. package/packages/daemon/dist/command-center/automation.js +1 -1
  9. package/packages/daemon/dist/command-center/daemon-fleet-facts-observer.js +37 -5
  10. package/packages/daemon/dist/command-center/discovery.js +28 -2
  11. package/packages/daemon/dist/command-center/server.js +8 -2
  12. package/packages/daemon/dist/command-center/tmux-server-reader.js +41 -0
  13. package/packages/daemon/dist/command-center/tmux-servers.js +7 -1
  14. package/packages/daemon/dist/doctor.js +147 -43
  15. package/packages/daemon/dist/lib/bounded-tmux-read.js +34 -12
  16. package/packages/daemon/dist/lib/cli-command.js +13 -0
  17. package/packages/daemon/dist/lib/daemon-embed.js +126 -55
  18. package/packages/daemon/dist/lib/daemon-stop-progress.js +58 -0
  19. package/packages/daemon/dist/lib/embedded-daemon-lifecycle.js +11 -0
  20. package/packages/daemon/dist/lib/embedded-tmux-server-owners.js +88 -12
  21. package/packages/daemon/dist/lib/headless-daemon.js +177 -10
  22. package/packages/daemon/dist/lib/log.js +18 -1
  23. package/packages/daemon/dist/lib/pane-reader-files.js +226 -0
  24. package/packages/daemon/dist/lib/remote-tmux-command.js +8 -5
  25. package/packages/daemon/dist/lib/tmux-client-execution.js +73 -7
  26. package/packages/daemon/dist/lib/tmux-external-interaction-observer.js +140 -19
  27. package/packages/daemon/dist/lib/tmux-native-browser.js +4 -2
  28. package/packages/daemon/dist/lib/tmux-pane-reader.js +107 -0
  29. package/packages/daemon/dist/lib/tmux-server-agent-admission.js +6 -1
  30. package/packages/daemon/dist/lib/tmux-server-features.js +38 -0
  31. package/packages/daemon/dist/lib/tmux-server-owner-teardown.js +33 -0
  32. package/packages/daemon/dist/lib/tmux-server-owner.js +38 -37
  33. package/packages/daemon/dist/lib/tmux-server-owners.js +310 -20
  34. package/packages/daemon/dist/lib/tmux-server-registration.js +128 -9
  35. package/packages/daemon/dist/lib/unix-socket-authority.js +58 -3
  36. package/packages/daemon/dist/lib/workspace-pane-creation.js +10 -1
  37. package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/Info.plist +2 -2
  38. package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/MacOS/tmux-ide-notifier +0 -0
  39. package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/Resources/Assets.car +0 -0
  40. package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/_CodeSignature/CodeResources +2 -2
  41. package/packages/daemon/dist/open-browser.js +26 -12
  42. package/packages/daemon/dist/open-reader.js +84 -0
  43. package/packages/daemon/dist/plugins/cli.js +1 -2
  44. package/packages/daemon/dist/plugins/daemon-plugins.js +2 -10
  45. package/packages/daemon/dist/restore.js +57 -40
  46. package/packages/daemon/dist/server/pane-stream-upgrade.js +5 -1
  47. package/packages/daemon/dist/server/websocket-heartbeat.js +103 -0
  48. package/packages/daemon/dist/terminal/attachments/native-runtime.js +32 -14
  49. package/packages/daemon/dist/terminal/mirror/layout-content-rows.js +11 -0
  50. package/packages/daemon/dist/terminal/mirror/mirror-service.js +61 -3
  51. package/packages/daemon/dist/terminal/mirror/session-channel.js +13 -12
  52. package/packages/daemon/dist/terminal/pane-stream/pane-stream-websocket.js +123 -25
  53. package/packages/daemon/dist/terminal/pane-stream/runtime.js +3 -2
  54. package/packages/daemon/dist/terminal/protocol/reader-option.js +66 -0
  55. package/packages/daemon/dist/terminal/protocol/session-descriptor-discovery.js +30 -2
  56. package/packages/daemon/dist/terminal/protocol/stock-split-resize.js +4 -1
  57. package/packages/daemon/dist/terminal/session-runtime/registry.js +17 -0
  58. package/packages/daemon/dist/terminal/session-runtime/terminal-replica-interpreter.js +81 -3
  59. package/packages/daemon/dist/terminal/session-runtime/terminal-replica-owner.js +60 -3
  60. package/packages/daemon/dist/tmux-upgrade/cli.js +106 -0
  61. package/packages/daemon/dist/tmux-upgrade/io.js +540 -0
  62. package/packages/daemon/dist/tmux-upgrade/plan.js +238 -0
  63. package/packages/daemon/dist/tmux-upgrade/run.js +199 -0
  64. package/packages/daemon/dist/tui/chrome/snapshot.js +3 -4
  65. package/packages/daemon/dist/tui/mirror/runtime/application-home-agent-navigation.js +64 -4
  66. package/packages/daemon/dist/tui/mirror/runtime/application-home-agents-owner.js +35 -5
  67. package/packages/daemon/dist/tui/mirror/runtime/application-machine-agent-navigation.js +12 -8
  68. package/packages/daemon/dist/tui/mirror/runtime/application-terminal-interaction-controller.js +125 -111
  69. package/packages/daemon/src/command-center/automation.ts +1 -1
  70. package/packages/daemon/src/command-center/daemon-fleet-facts-observer.ts +49 -8
  71. package/packages/daemon/src/command-center/discovery.ts +35 -2
  72. package/packages/daemon/src/command-center/server.ts +22 -8
  73. package/packages/daemon/src/command-center/tmux-server-reader.ts +62 -0
  74. package/packages/daemon/src/command-center/tmux-servers.ts +7 -1
  75. package/packages/daemon/src/doctor.ts +164 -45
  76. package/packages/daemon/src/lib/bounded-tmux-read.ts +29 -9
  77. package/packages/daemon/src/lib/cli-command.ts +16 -0
  78. package/packages/daemon/src/lib/daemon-embed.ts +176 -64
  79. package/packages/daemon/src/lib/daemon-stop-progress.ts +78 -0
  80. package/packages/daemon/src/lib/embedded-daemon-lifecycle.ts +12 -0
  81. package/packages/daemon/src/lib/embedded-tmux-server-owners.ts +115 -11
  82. package/packages/daemon/src/lib/headless-daemon.ts +205 -12
  83. package/packages/daemon/src/lib/log.ts +18 -1
  84. package/packages/daemon/src/lib/pane-reader-files.ts +294 -0
  85. package/packages/daemon/src/lib/remote-tmux-command.ts +13 -6
  86. package/packages/daemon/src/lib/tmux-client-execution.ts +79 -7
  87. package/packages/daemon/src/lib/tmux-external-interaction-observer.ts +163 -25
  88. package/packages/daemon/src/lib/tmux-native-browser.ts +4 -3
  89. package/packages/daemon/src/lib/tmux-pane-reader.ts +145 -0
  90. package/packages/daemon/src/lib/tmux-server-agent-admission.ts +6 -1
  91. package/packages/daemon/src/lib/tmux-server-features.ts +43 -0
  92. package/packages/daemon/src/lib/tmux-server-owner-teardown.ts +54 -0
  93. package/packages/daemon/src/lib/tmux-server-owner.ts +41 -35
  94. package/packages/daemon/src/lib/tmux-server-owners.ts +427 -22
  95. package/packages/daemon/src/lib/tmux-server-registration.ts +155 -7
  96. package/packages/daemon/src/lib/unix-socket-authority.ts +72 -3
  97. package/packages/daemon/src/lib/workspace-pane-creation.ts +11 -1
  98. package/packages/daemon/src/open-browser.ts +59 -18
  99. package/packages/daemon/src/open-reader.ts +148 -0
  100. package/packages/daemon/src/plugins/cli.ts +1 -2
  101. package/packages/daemon/src/plugins/daemon-plugins.ts +2 -12
  102. package/packages/daemon/src/restore.ts +80 -44
  103. package/packages/daemon/src/server/pane-stream-upgrade.ts +6 -0
  104. package/packages/daemon/src/server/websocket-heartbeat.ts +135 -0
  105. package/packages/daemon/src/terminal/attachments/native-runtime.ts +58 -14
  106. package/packages/daemon/src/terminal/mirror/events.ts +2 -0
  107. package/packages/daemon/src/terminal/mirror/layout-content-rows.ts +11 -0
  108. package/packages/daemon/src/terminal/mirror/mirror-service.ts +61 -2
  109. package/packages/daemon/src/terminal/mirror/session-channel.ts +15 -14
  110. package/packages/daemon/src/terminal/pane-stream/pane-stream-websocket.ts +140 -23
  111. package/packages/daemon/src/terminal/pane-stream/runtime.ts +4 -2
  112. package/packages/daemon/src/terminal/protocol/reader-option.ts +77 -0
  113. package/packages/daemon/src/terminal/protocol/session-descriptor-discovery.ts +41 -1
  114. package/packages/daemon/src/terminal/protocol/stock-split-resize.ts +6 -1
  115. package/packages/daemon/src/terminal/session-runtime/registry.ts +23 -0
  116. package/packages/daemon/src/terminal/session-runtime/runtime-observability.ts +2 -0
  117. package/packages/daemon/src/terminal/session-runtime/terminal-replica-interpreter.ts +100 -3
  118. package/packages/daemon/src/terminal/session-runtime/terminal-replica-owner.ts +60 -3
  119. package/packages/daemon/src/tmux-upgrade/cli.ts +118 -0
  120. package/packages/daemon/src/tmux-upgrade/io.ts +596 -0
  121. package/packages/daemon/src/tmux-upgrade/plan.ts +353 -0
  122. package/packages/daemon/src/tmux-upgrade/run.ts +325 -0
  123. package/packages/daemon/src/tui/chrome/snapshot.ts +3 -4
  124. package/packages/daemon/src/tui/mirror/runtime/application-home-agent-navigation.ts +110 -10
  125. package/packages/daemon/src/tui/mirror/runtime/application-home-agents-owner.ts +58 -6
  126. package/packages/daemon/src/tui/mirror/runtime/application-machine-agent-navigation.ts +20 -9
  127. package/packages/daemon/src/tui/mirror/runtime/application-root-v2.tsx +2 -2
  128. package/packages/daemon/src/tui/mirror/runtime/application-terminal-interaction-controller.ts +149 -128
  129. package/packages/daemon-client/src/direct-application-shell-transport.ts +21 -3
  130. package/packages/daemon-client/src/workspace-event-supervisor.ts +63 -2
  131. package/packages/tmux-bridge/src/runner.ts +3 -1
@@ -1,13 +1,18 @@
1
1
  import { retainsAgentControl } from "./application-retained-agent.js";
2
2
  import { createApplicationHomeAgentNavigator, } from "./application-home-agent-navigation.js";
3
3
  import { applicationGenerationNavigationKey } from "./application-generation-starter.js";
4
- import { waitForHomeAgentSemantic } from "./application-home-agents-owner.js";
4
+ import { agentOpeningOwnsKey, waitForHomeAgentListed, waitForHomeAgentSemantic, } from "./application-home-agents-owner.js";
5
5
  /** Machine identity fences the existing exact-agent admission owner. No independent input path. */
6
6
  export function createApplicationMachineAgentNavigator(options) {
7
7
  let current = null;
8
8
  let disposed = false;
9
9
  let opening = false;
10
10
  let request = 0;
11
+ const cancel = () => {
12
+ request++;
13
+ opening = false;
14
+ current?.cancel();
15
+ };
11
16
  return {
12
17
  open(machineId, target, source = "mouse") {
13
18
  current?.dispose();
@@ -23,7 +28,7 @@ export function createApplicationMachineAgentNavigator(options) {
23
28
  retainsAgentControl(generation(), target)) {
24
29
  // Reserve before the next key; the terminal controller waits for a fresh
25
30
  // coherent runtime and remains the only owner of physical input.
26
- options.selectPane(target.paneId, source);
31
+ options.selectPane(target.paneId);
27
32
  options.showTerminals(source);
28
33
  options.setNote(null);
29
34
  opening = false;
@@ -47,8 +52,9 @@ export function createApplicationMachineAgentNavigator(options) {
47
52
  };
48
53
  },
49
54
  waitForGeneration: (key, signal) => waitForHomeAgentSemantic(generation, key, signal),
55
+ waitForAgent: (key, listed, signal) => waitForHomeAgentListed(generation, key, listed, signal),
50
56
  startGeneration: (session, prepared, origin, focus, admission) => options.startGeneration(session, prepared, origin, focus, () => selected() && options.isCurrentTarget(machineId, target) && (admission?.() ?? true)),
51
- selectPane: options.selectPane,
57
+ selectPane: (paneId, _source, admission) => admission ? options.selectPane(paneId, admission) : options.selectPane(paneId),
52
58
  showTerminals: options.showTerminals,
53
59
  setNote: options.setNote,
54
60
  });
@@ -58,11 +64,9 @@ export function createApplicationMachineAgentNavigator(options) {
58
64
  });
59
65
  },
60
66
  opening: () => opening,
61
- cancel() {
62
- request++;
63
- opening = false;
64
- current?.cancel();
65
- },
67
+ cancel,
68
+ /** Esc cancels an open in progress; other keys are ignored meanwhile. */
69
+ ownsKey: (name) => agentOpeningOwnsKey(name, { opening: () => opening, cancel }),
66
70
  dispose() {
67
71
  disposed = true;
68
72
  request++;
@@ -525,88 +525,110 @@ export function createApplicationTerminalInteractionController(options) {
525
525
  return;
526
526
  finishLinkSelection(snapshot.current !== null && paneForWindow(snapshot.current) === pending.paneId);
527
527
  };
528
- const paneInput = new TerminalPaneInputRouter({
529
- select: async (paneId) => {
530
- finishLinkSelection(false);
531
- const initial = options.generation();
532
- const selectionControl = controlIdentity(initial);
533
- const selectionVersion = paneInput.selectionVersion;
534
- const selectionCurrent = () => paneInput.selectionVersion === selectionVersion &&
535
- sameControl(selectionControl, controlIdentity(selectionGeneration));
536
- const panePresent = () => selectionLayout.windows.some((window) => window.panes.some((pane) => pane.pane === paneId));
537
- if (initial?.status === "rebinding") {
538
- // Reserve the optimistic target now, but send its FIRST mutation only
539
- // after this same control connection has a coherent terminal runtime.
540
- const ready = await selectionWaiter.wait(() => {
541
- if (!selectionCurrent())
542
- return false;
543
- const active = selectionGeneration;
544
- if (active?.status !== "live" || observedLayoutEpoch !== active.rendererEpoch)
545
- return "pending";
546
- return panePresent();
547
- });
548
- if (!ready || !selectionCurrent())
528
+ // The one way a pane selection reaches the runtime (#764: also used once an
529
+ // admitted agent selection settles).
530
+ const selectInRuntime = async (paneId) => {
531
+ finishLinkSelection(false);
532
+ const initial = options.generation();
533
+ const selectionControl = controlIdentity(initial);
534
+ const selectionVersion = paneInput.selectionVersion;
535
+ const selectionCurrent = () => paneInput.selectionVersion === selectionVersion &&
536
+ sameControl(selectionControl, controlIdentity(selectionGeneration));
537
+ const panePresent = () => selectionLayout.windows.some((window) => window.panes.some((pane) => pane.pane === paneId));
538
+ if (initial?.status === "rebinding") {
539
+ // Reserve the optimistic target now, but send its FIRST mutation only
540
+ // after this same control connection has a coherent terminal runtime.
541
+ const ready = await selectionWaiter.wait(() => {
542
+ if (!selectionCurrent())
549
543
  return false;
550
- }
551
- const expected = liveSelectionTarget();
552
- let dispatchedRendererEpoch;
553
- const selecting = pendingWindowSwitch;
554
- const operationId = selecting?.traceId;
555
- const selectionFailure = { current: null };
556
- const receipt = expected
557
- ? await selectTerminalPane(expected, () => {
558
- if (!selectionControl)
559
- return liveSelectionTarget();
560
- return sameControl(selectionControl, controlIdentity(options.generation()))
561
- ? expected
562
- : null;
563
- }, paneId, operationId, (failure) => {
564
- selectionFailure.current = failure;
565
- }, windowLinkForPane(options.layout(), paneId) ?? undefined, () => {
566
- dispatchedRendererEpoch = options.generation()?.rendererEpoch;
567
- })
568
- : null;
569
- if (receipt === null &&
570
- selectionFailure.current?.reason === "topology-changed" &&
571
- selectionCurrent()) {
572
- // The daemon may have selected the pane before retiring its stream.
573
- // Observe the replacement runtime; never resubmit an uncertain command
574
- // or manufacture an operation receipt. Input still waits on this promise.
575
- const confirmed = await selectionWaiter.wait(() => {
576
- if (!selectionCurrent())
577
- return false;
578
- const active = selectionGeneration;
579
- if (active?.status !== "live" ||
580
- active.rendererEpoch === dispatchedRendererEpoch ||
581
- observedLayoutEpoch !== active.rendererEpoch)
582
- return "pending";
583
- if (!panePresent())
584
- return false;
585
- const current = selectionLayout.current;
586
- const activePanes = current?.panes.filter((pane) => pane.active) ?? [];
587
- if (!current?.currentWindow || activePanes.length !== 1)
588
- return "pending";
589
- return activePanes[0]?.pane === paneId ? true : "pending";
590
- });
591
- if (selecting && pendingWindowSwitch === selecting)
592
- pendingWindowSwitch = null;
593
- return confirmed && selectionCurrent();
594
- }
595
- if (selecting && pendingWindowSwitch === selecting) {
596
- const receiptAtMicros = options.detailedWindowSwitchTiming ? diagnosticNowMicros() : null;
597
- if (selecting.timing)
598
- selecting.timing.receiptAtMicros = receiptAtMicros;
599
- selecting.selectionApplied =
600
- receipt?.applied === true &&
601
- receipt.operationId === selecting.traceId &&
602
- receipt.semanticPaneId === selecting.paneId;
603
- diagnose("window-switch-receipt", {
544
+ const active = selectionGeneration;
545
+ if (active?.status !== "live" || observedLayoutEpoch !== active.rendererEpoch)
546
+ return "pending";
547
+ return panePresent();
548
+ });
549
+ if (!ready || !selectionCurrent())
550
+ return false;
551
+ }
552
+ const expected = liveSelectionTarget();
553
+ let dispatchedRendererEpoch;
554
+ const selecting = pendingWindowSwitch;
555
+ const operationId = selecting?.traceId;
556
+ const selectionFailure = { current: null };
557
+ const receipt = expected
558
+ ? await selectTerminalPane(expected, () => {
559
+ if (!selectionControl)
560
+ return liveSelectionTarget();
561
+ return sameControl(selectionControl, controlIdentity(options.generation()))
562
+ ? expected
563
+ : null;
564
+ }, paneId, operationId, (failure) => {
565
+ selectionFailure.current = failure;
566
+ }, windowLinkForPane(options.layout(), paneId) ?? undefined, () => {
567
+ dispatchedRendererEpoch = options.generation()?.rendererEpoch;
568
+ })
569
+ : null;
570
+ if (receipt === null &&
571
+ selectionFailure.current?.reason === "topology-changed" &&
572
+ selectionCurrent()) {
573
+ // The daemon may have selected the pane before retiring its stream.
574
+ // Observe the replacement runtime; never resubmit an uncertain command
575
+ // or manufacture an operation receipt. Input still waits on this promise.
576
+ const confirmed = await selectionWaiter.wait(() => {
577
+ if (!selectionCurrent())
578
+ return false;
579
+ const active = selectionGeneration;
580
+ if (active?.status !== "live" ||
581
+ active.rendererEpoch === dispatchedRendererEpoch ||
582
+ observedLayoutEpoch !== active.rendererEpoch)
583
+ return "pending";
584
+ if (!panePresent())
585
+ return false;
586
+ const current = selectionLayout.current;
587
+ const activePanes = current?.panes.filter((pane) => pane.active) ?? [];
588
+ if (!current?.currentWindow || activePanes.length !== 1)
589
+ return "pending";
590
+ return activePanes[0]?.pane === paneId ? true : "pending";
591
+ });
592
+ if (selecting && pendingWindowSwitch === selecting)
593
+ pendingWindowSwitch = null;
594
+ return confirmed && selectionCurrent();
595
+ }
596
+ if (selecting && pendingWindowSwitch === selecting) {
597
+ const receiptAtMicros = options.detailedWindowSwitchTiming ? diagnosticNowMicros() : null;
598
+ if (selecting.timing)
599
+ selecting.timing.receiptAtMicros = receiptAtMicros;
600
+ selecting.selectionApplied =
601
+ receipt?.applied === true &&
602
+ receipt.operationId === selecting.traceId &&
603
+ receipt.semanticPaneId === selecting.paneId;
604
+ diagnose("window-switch-receipt", {
605
+ traceId: selecting.traceId,
606
+ target: selecting.target,
607
+ paneId: selecting.paneId,
608
+ operationId: receipt?.operationId ?? null,
609
+ selected: receipt !== null,
610
+ applied: receipt?.applied === true,
611
+ daemonGeneration: selecting.daemonGeneration,
612
+ clientGeneration: selecting.clientGeneration,
613
+ rendererEpoch: selecting.rendererEpoch,
614
+ sourceEpoch: selecting.sourceEpoch,
615
+ generation: selecting.generation,
616
+ incarnation: selecting.incarnation,
617
+ revision: selecting.revision,
618
+ stateHash: selecting.stateHash,
619
+ cols: selecting.cols,
620
+ rows: selecting.rows,
621
+ failureStage: selectionFailure.current?.stage ?? (expected ? null : "pre-dispatch"),
622
+ failureReason: selectionFailure.current?.reason ?? (expected ? null : "generation-replaced"),
623
+ failureBackendReason: selectionFailure.current?.backendReason ?? null,
624
+ durationMicros: receiptAtMicros === null ? null : receiptAtMicros - selecting.startedAtMicros,
625
+ ...(receiptAtMicros === null ? {} : { phaseAtMicros: receiptAtMicros }),
626
+ });
627
+ if (!selecting.selectionApplied) {
628
+ diagnoseCritical(`window-switch:${selecting.traceId}:failed`, "window-switch-failed", {
604
629
  traceId: selecting.traceId,
605
630
  target: selecting.target,
606
631
  paneId: selecting.paneId,
607
- operationId: receipt?.operationId ?? null,
608
- selected: receipt !== null,
609
- applied: receipt?.applied === true,
610
632
  daemonGeneration: selecting.daemonGeneration,
611
633
  clientGeneration: selecting.clientGeneration,
612
634
  rendererEpoch: selecting.rendererEpoch,
@@ -617,40 +639,21 @@ export function createApplicationTerminalInteractionController(options) {
617
639
  stateHash: selecting.stateHash,
618
640
  cols: selecting.cols,
619
641
  rows: selecting.rows,
620
- failureStage: selectionFailure.current?.stage ?? (expected ? null : "pre-dispatch"),
621
- failureReason: selectionFailure.current?.reason ?? (expected ? null : "generation-replaced"),
622
- failureBackendReason: selectionFailure.current?.backendReason ?? null,
642
+ stage: selectionFailure.current?.stage ?? (expected ? "receipt" : "pre-dispatch"),
643
+ reason: selectionFailure.current?.reason ??
644
+ (expected ? "receipt-invalid" : "generation-replaced"),
645
+ backendReason: selectionFailure.current?.backendReason ?? null,
623
646
  durationMicros: receiptAtMicros === null ? null : receiptAtMicros - selecting.startedAtMicros,
624
- ...(receiptAtMicros === null ? {} : { phaseAtMicros: receiptAtMicros }),
625
647
  });
626
- if (!selecting.selectionApplied) {
627
- diagnoseCritical(`window-switch:${selecting.traceId}:failed`, "window-switch-failed", {
628
- traceId: selecting.traceId,
629
- target: selecting.target,
630
- paneId: selecting.paneId,
631
- daemonGeneration: selecting.daemonGeneration,
632
- clientGeneration: selecting.clientGeneration,
633
- rendererEpoch: selecting.rendererEpoch,
634
- sourceEpoch: selecting.sourceEpoch,
635
- generation: selecting.generation,
636
- incarnation: selecting.incarnation,
637
- revision: selecting.revision,
638
- stateHash: selecting.stateHash,
639
- cols: selecting.cols,
640
- rows: selecting.rows,
641
- stage: selectionFailure.current?.stage ?? (expected ? "receipt" : "pre-dispatch"),
642
- reason: selectionFailure.current?.reason ??
643
- (expected ? "receipt-invalid" : "generation-replaced"),
644
- backendReason: selectionFailure.current?.backendReason ?? null,
645
- durationMicros: receiptAtMicros === null ? null : receiptAtMicros - selecting.startedAtMicros,
646
- });
647
- pendingWindowSwitch = null;
648
- return false;
649
- }
650
- maybeRequestWindowSwitchFrame();
648
+ pendingWindowSwitch = null;
649
+ return false;
651
650
  }
652
- return receipt !== null;
653
- },
651
+ maybeRequestWindowSwitchFrame();
652
+ }
653
+ return receipt !== null;
654
+ };
655
+ const paneInput = new TerminalPaneInputRouter({
656
+ select: (paneId) => selectInRuntime(paneId),
654
657
  send: async (paneId, routed) => {
655
658
  const { input, parserOrigin } = routed;
656
659
  const selectionVersion = paneInput.selectionVersion;
@@ -913,9 +916,20 @@ export function createApplicationTerminalInteractionController(options) {
913
916
  maybeRequestWindowSwitchFrame();
914
917
  maybeRequestPaneResizeFrame();
915
918
  },
916
- selectPane: (paneId) => {
919
+ selectPane: (paneId, admission) => {
917
920
  finishLinkSelection(false);
918
- paneInput.selectPane(paneId);
921
+ if (admission)
922
+ // Ordered now; selected only once admitted, otherwise held input drops.
923
+ paneInput.selectPane(paneId, {
924
+ presentOptimistically: false,
925
+ selection: () => {
926
+ // A later selection supersedes this one: never select it after all.
927
+ const version = paneInput.selectionVersion;
928
+ return admission.then((admitted) => admitted && paneInput.selectionVersion === version ? selectInRuntime(paneId) : false);
929
+ },
930
+ });
931
+ else
932
+ paneInput.selectPane(paneId);
919
933
  selectionWaiter.reconcile();
920
934
  },
921
935
  async unlinkWindowLink(target) {
@@ -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),
@@ -0,0 +1,62 @@
1
+ import type { Context, Hono } from "hono";
2
+ import { z } from "zod";
3
+ import {
4
+ PaneReaderAssetRequestSchemaZ,
5
+ PaneReaderRequestSchemaZ,
6
+ TmuxServerScopeSchemaZ,
7
+ } from "@tmux-ide/contracts";
8
+ import { TmuxServerScopeError, type TmuxServerOwners } from "../lib/tmux-server-owners.ts";
9
+ import type { NativeTmuxServerOwner } from "../lib/tmux-server-owner.ts";
10
+
11
+ /**
12
+ * The native Markdown reader's routes (card #756). Mount only below the
13
+ * owner-authenticated, no-store scoped router. Responses never carry a path,
14
+ * a file-system error or validation detail.
15
+ */
16
+ export function mountTmuxServerReaderRoutes(
17
+ app: Hono,
18
+ options: {
19
+ readonly scopedPath: string;
20
+ readonly owners: TmuxServerOwners<NativeTmuxServerOwner>;
21
+ readonly readBody: (request: Request) => Promise<unknown>;
22
+ },
23
+ ): void {
24
+ const handle =
25
+ (schema: z.ZodType<{ target: { generation: string } }>, kind: "read" | "asset") =>
26
+ async (c: Context) => {
27
+ const scope = TmuxServerScopeSchemaZ.safeParse({
28
+ serverId: c.req.param("serverId"),
29
+ generation: c.req.param("generation"),
30
+ });
31
+ if (!scope.success) return c.json({ error: { code: "invalid-request" } }, 400);
32
+ let request: { target: { generation: string } };
33
+ try {
34
+ request = schema.parse(await options.readBody(c.req.raw));
35
+ } catch {
36
+ return c.json({ error: { code: "invalid-request" } }, 400);
37
+ }
38
+ if (request.target.generation !== scope.data.generation)
39
+ return c.json({ error: { code: "stale-generation" } }, 409);
40
+ try {
41
+ c.req.raw.signal.throwIfAborted();
42
+ const response: unknown = await options.owners.withOwner(
43
+ scope.data,
44
+ (owner): Promise<unknown> =>
45
+ kind === "read"
46
+ ? owner.paneReader.read(request, c.req.raw.signal)
47
+ : owner.paneReader.asset(request, c.req.raw.signal),
48
+ );
49
+ c.req.raw.signal.throwIfAborted();
50
+ return c.json(response);
51
+ } catch (error) {
52
+ if (error instanceof TmuxServerScopeError)
53
+ return c.json(
54
+ { error: { code: "scope-unavailable" } },
55
+ error.code === "not-found" ? 404 : 409,
56
+ );
57
+ return c.json({ error: { code: "reader-unavailable" } }, 503);
58
+ }
59
+ };
60
+ app.post(`${options.scopedPath}/reader`, handle(PaneReaderRequestSchemaZ, "read"));
61
+ app.post(`${options.scopedPath}/reader/asset`, handle(PaneReaderAssetRequestSchemaZ, "asset"));
62
+ }
@@ -5,6 +5,7 @@ import { WindowSplitLayoutUnavailable } from "../terminal/mirror/window-split-au
5
5
  import { streamTmuxInteractions } from "./tmux-server-interaction-events.ts";
6
6
  import { mountTmuxServerNativeBackingRoute } from "./tmux-server-native-backing.ts";
7
7
  import { mountTmuxServerEditorContextRoute } from "./tmux-server-editor-context.ts";
8
+ import { mountTmuxServerReaderRoutes } from "./tmux-server-reader.ts";
8
9
  import { Hono, type Context } from "hono";
9
10
  import { streamSSE } from "hono/streaming";
10
11
  import { projectApplicationShellResource } from "./resources/application-shell.ts";
@@ -125,7 +126,7 @@ export function mountTmuxServerRoutes(app: Hono, options: TmuxServerRoutesOption
125
126
  base,
126
127
  route(async (c) =>
127
128
  c.json(
128
- TmuxServersResourceSchemaZ.parse({ version: 1, servers: await options.owners.refresh() }),
129
+ TmuxServersResourceSchemaZ.parse({ version: 1, servers: await options.owners.observe() }),
129
130
  ),
130
131
  ),
131
132
  );
@@ -157,6 +158,11 @@ export function mountTmuxServerRoutes(app: Hono, options: TmuxServerRoutesOption
157
158
  owners: options.owners,
158
159
  readBody: (request) => boundedJson(request, 8 * 1024),
159
160
  });
161
+ mountTmuxServerReaderRoutes(app, {
162
+ scopedPath: scoped,
163
+ owners: options.owners,
164
+ readBody: (request) => boundedJson(request, 8 * 1024),
165
+ });
160
166
  app.post(
161
167
  `${scoped}/native-browser`,
162
168
  route(async (c) => {