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
@@ -83,7 +83,13 @@ export interface ApplicationTerminalInteractionController {
83
83
  adoptGeneration(snapshot: OpenTuiGenerationHostSnapshot | null): void;
84
84
  cancelPendingInput(): void;
85
85
  adoptLayout(snapshot: OpenTuiWorkspaceLayoutSnapshot): void;
86
- selectPane(paneId: string): void;
86
+ /**
87
+ * With `admission`, input sent from now on is ordered behind this pane, and
88
+ * the pane is selected only if `admission` resolves true and no later
89
+ * selection replaced it; otherwise that input is dropped, never delivered to
90
+ * another pane. (The app's root sends no input while an agent is opening.)
91
+ */
92
+ selectPane(paneId: string, admission?: Promise<boolean>): void;
87
93
  selectWindowLink(target: WindowLinkTarget): Promise<void>;
88
94
  unlinkWindowLink(target: WindowLinkTarget): Promise<string>;
89
95
  sendInput(
@@ -822,100 +828,118 @@ export function createApplicationTerminalInteractionController(
822
828
  );
823
829
  };
824
830
 
825
- const paneInput = new TerminalPaneInputRouter<{
826
- readonly input: SessionRuntimeTerminalInput;
827
- readonly parserOrigin?: Omit<
828
- TuiTerminalInputOrigin,
829
- "semanticPaneId" | "generation" | "incarnation" | "revision" | "stateHash"
830
- >;
831
- }>({
832
- select: async (paneId): Promise<boolean> => {
833
- finishLinkSelection(false);
834
- const initial = options.generation();
835
- const selectionControl = controlIdentity(initial);
836
- const selectionVersion = paneInput.selectionVersion;
837
- const selectionCurrent = (): boolean =>
838
- paneInput.selectionVersion === selectionVersion &&
839
- sameControl(selectionControl, controlIdentity(selectionGeneration));
840
- const panePresent = () =>
841
- selectionLayout.windows.some((window) => window.panes.some((pane) => pane.pane === paneId));
842
- if (initial?.status === "rebinding") {
843
- // Reserve the optimistic target now, but send its FIRST mutation only
844
- // after this same control connection has a coherent terminal runtime.
845
- const ready = await selectionWaiter.wait(() => {
846
- if (!selectionCurrent()) return false;
847
- const active = selectionGeneration;
848
- if (active?.status !== "live" || observedLayoutEpoch !== active.rendererEpoch)
849
- return "pending";
850
- return panePresent();
851
- });
852
- if (!ready || !selectionCurrent()) return false;
853
- }
854
- const expected = liveSelectionTarget();
855
- let dispatchedRendererEpoch: number | undefined;
856
- const selecting = pendingWindowSwitch;
857
- const operationId = selecting?.traceId;
858
- const selectionFailure: { current: PaneSelectionFailure | null } = { current: null };
859
- const receipt = expected
860
- ? await selectTerminalPane(
861
- expected,
862
- () => {
863
- if (!selectionControl) return liveSelectionTarget();
864
- return sameControl(selectionControl, controlIdentity(options.generation()))
865
- ? expected
866
- : null;
867
- },
868
- paneId,
869
- operationId,
870
- (failure) => {
871
- selectionFailure.current = failure;
872
- },
873
- windowLinkForPane(options.layout(), paneId) ?? undefined,
874
- () => {
875
- dispatchedRendererEpoch = options.generation()?.rendererEpoch;
876
- },
877
- )
878
- : null;
879
- if (
880
- receipt === null &&
881
- selectionFailure.current?.reason === "topology-changed" &&
882
- selectionCurrent()
883
- ) {
884
- // The daemon may have selected the pane before retiring its stream.
885
- // Observe the replacement runtime; never resubmit an uncertain command
886
- // or manufacture an operation receipt. Input still waits on this promise.
887
- const confirmed = await selectionWaiter.wait(() => {
888
- if (!selectionCurrent()) return false;
889
- const active = selectionGeneration;
890
- if (
891
- active?.status !== "live" ||
892
- active.rendererEpoch === dispatchedRendererEpoch ||
893
- observedLayoutEpoch !== active.rendererEpoch
894
- )
895
- return "pending";
896
- if (!panePresent()) return false;
897
- const current = selectionLayout.current;
898
- const activePanes = current?.panes.filter((pane) => pane.active) ?? [];
899
- if (!current?.currentWindow || activePanes.length !== 1) return "pending";
900
- return activePanes[0]?.pane === paneId ? true : "pending";
901
- });
902
- if (selecting && pendingWindowSwitch === selecting) pendingWindowSwitch = null;
903
- return confirmed && selectionCurrent();
904
- }
905
- if (selecting && pendingWindowSwitch === selecting) {
906
- const receiptAtMicros = options.detailedWindowSwitchTiming ? diagnosticNowMicros() : null;
907
- if (selecting.timing) selecting.timing.receiptAtMicros = receiptAtMicros;
908
- selecting.selectionApplied =
909
- receipt?.applied === true &&
910
- receipt.operationId === selecting.traceId &&
911
- receipt.semanticPaneId === selecting.paneId;
912
- diagnose("window-switch-receipt", {
831
+ // The one way a pane selection reaches the runtime (#764: also used once an
832
+ // admitted agent selection settles).
833
+ const selectInRuntime = async (paneId: string): Promise<boolean> => {
834
+ finishLinkSelection(false);
835
+ const initial = options.generation();
836
+ const selectionControl = controlIdentity(initial);
837
+ const selectionVersion = paneInput.selectionVersion;
838
+ const selectionCurrent = (): boolean =>
839
+ paneInput.selectionVersion === selectionVersion &&
840
+ sameControl(selectionControl, controlIdentity(selectionGeneration));
841
+ const panePresent = () =>
842
+ selectionLayout.windows.some((window) => window.panes.some((pane) => pane.pane === paneId));
843
+ if (initial?.status === "rebinding") {
844
+ // Reserve the optimistic target now, but send its FIRST mutation only
845
+ // after this same control connection has a coherent terminal runtime.
846
+ const ready = await selectionWaiter.wait(() => {
847
+ if (!selectionCurrent()) return false;
848
+ const active = selectionGeneration;
849
+ if (active?.status !== "live" || observedLayoutEpoch !== active.rendererEpoch)
850
+ return "pending";
851
+ return panePresent();
852
+ });
853
+ if (!ready || !selectionCurrent()) return false;
854
+ }
855
+ const expected = liveSelectionTarget();
856
+ let dispatchedRendererEpoch: number | undefined;
857
+ const selecting = pendingWindowSwitch;
858
+ const operationId = selecting?.traceId;
859
+ const selectionFailure: { current: PaneSelectionFailure | null } = { current: null };
860
+ const receipt = expected
861
+ ? await selectTerminalPane(
862
+ expected,
863
+ () => {
864
+ if (!selectionControl) return liveSelectionTarget();
865
+ return sameControl(selectionControl, controlIdentity(options.generation()))
866
+ ? expected
867
+ : null;
868
+ },
869
+ paneId,
870
+ operationId,
871
+ (failure) => {
872
+ selectionFailure.current = failure;
873
+ },
874
+ windowLinkForPane(options.layout(), paneId) ?? undefined,
875
+ () => {
876
+ dispatchedRendererEpoch = options.generation()?.rendererEpoch;
877
+ },
878
+ )
879
+ : null;
880
+ if (
881
+ receipt === null &&
882
+ selectionFailure.current?.reason === "topology-changed" &&
883
+ selectionCurrent()
884
+ ) {
885
+ // The daemon may have selected the pane before retiring its stream.
886
+ // Observe the replacement runtime; never resubmit an uncertain command
887
+ // or manufacture an operation receipt. Input still waits on this promise.
888
+ const confirmed = await selectionWaiter.wait(() => {
889
+ if (!selectionCurrent()) return false;
890
+ const active = selectionGeneration;
891
+ if (
892
+ active?.status !== "live" ||
893
+ active.rendererEpoch === dispatchedRendererEpoch ||
894
+ observedLayoutEpoch !== active.rendererEpoch
895
+ )
896
+ return "pending";
897
+ if (!panePresent()) return false;
898
+ const current = selectionLayout.current;
899
+ const activePanes = current?.panes.filter((pane) => pane.active) ?? [];
900
+ if (!current?.currentWindow || activePanes.length !== 1) return "pending";
901
+ return activePanes[0]?.pane === paneId ? true : "pending";
902
+ });
903
+ if (selecting && pendingWindowSwitch === selecting) pendingWindowSwitch = null;
904
+ return confirmed && selectionCurrent();
905
+ }
906
+ if (selecting && pendingWindowSwitch === selecting) {
907
+ const receiptAtMicros = options.detailedWindowSwitchTiming ? diagnosticNowMicros() : null;
908
+ if (selecting.timing) selecting.timing.receiptAtMicros = receiptAtMicros;
909
+ selecting.selectionApplied =
910
+ receipt?.applied === true &&
911
+ receipt.operationId === selecting.traceId &&
912
+ receipt.semanticPaneId === selecting.paneId;
913
+ diagnose("window-switch-receipt", {
914
+ traceId: selecting.traceId,
915
+ target: selecting.target,
916
+ paneId: selecting.paneId,
917
+ operationId: receipt?.operationId ?? null,
918
+ selected: receipt !== null,
919
+ applied: receipt?.applied === true,
920
+ daemonGeneration: selecting.daemonGeneration,
921
+ clientGeneration: selecting.clientGeneration,
922
+ rendererEpoch: selecting.rendererEpoch,
923
+ sourceEpoch: selecting.sourceEpoch,
924
+ generation: selecting.generation,
925
+ incarnation: selecting.incarnation,
926
+ revision: selecting.revision,
927
+ stateHash: selecting.stateHash,
928
+ cols: selecting.cols,
929
+ rows: selecting.rows,
930
+ failureStage: selectionFailure.current?.stage ?? (expected ? null : "pre-dispatch"),
931
+ failureReason:
932
+ selectionFailure.current?.reason ?? (expected ? null : "generation-replaced"),
933
+ failureBackendReason: selectionFailure.current?.backendReason ?? null,
934
+ durationMicros:
935
+ receiptAtMicros === null ? null : receiptAtMicros - selecting.startedAtMicros,
936
+ ...(receiptAtMicros === null ? {} : { phaseAtMicros: receiptAtMicros }),
937
+ });
938
+ if (!selecting.selectionApplied) {
939
+ diagnoseCritical(`window-switch:${selecting.traceId}:failed`, "window-switch-failed", {
913
940
  traceId: selecting.traceId,
914
941
  target: selecting.target,
915
942
  paneId: selecting.paneId,
916
- operationId: receipt?.operationId ?? null,
917
- selected: receipt !== null,
918
- applied: receipt?.applied === true,
919
943
  daemonGeneration: selecting.daemonGeneration,
920
944
  clientGeneration: selecting.clientGeneration,
921
945
  rendererEpoch: selecting.rendererEpoch,
@@ -926,44 +950,29 @@ export function createApplicationTerminalInteractionController(
926
950
  stateHash: selecting.stateHash,
927
951
  cols: selecting.cols,
928
952
  rows: selecting.rows,
929
- failureStage: selectionFailure.current?.stage ?? (expected ? null : "pre-dispatch"),
930
- failureReason:
931
- selectionFailure.current?.reason ?? (expected ? null : "generation-replaced"),
932
- failureBackendReason: selectionFailure.current?.backendReason ?? null,
953
+ stage: selectionFailure.current?.stage ?? (expected ? "receipt" : "pre-dispatch"),
954
+ reason:
955
+ selectionFailure.current?.reason ??
956
+ (expected ? "receipt-invalid" : "generation-replaced"),
957
+ backendReason: selectionFailure.current?.backendReason ?? null,
933
958
  durationMicros:
934
959
  receiptAtMicros === null ? null : receiptAtMicros - selecting.startedAtMicros,
935
- ...(receiptAtMicros === null ? {} : { phaseAtMicros: receiptAtMicros }),
936
960
  });
937
- if (!selecting.selectionApplied) {
938
- diagnoseCritical(`window-switch:${selecting.traceId}:failed`, "window-switch-failed", {
939
- traceId: selecting.traceId,
940
- target: selecting.target,
941
- paneId: selecting.paneId,
942
- daemonGeneration: selecting.daemonGeneration,
943
- clientGeneration: selecting.clientGeneration,
944
- rendererEpoch: selecting.rendererEpoch,
945
- sourceEpoch: selecting.sourceEpoch,
946
- generation: selecting.generation,
947
- incarnation: selecting.incarnation,
948
- revision: selecting.revision,
949
- stateHash: selecting.stateHash,
950
- cols: selecting.cols,
951
- rows: selecting.rows,
952
- stage: selectionFailure.current?.stage ?? (expected ? "receipt" : "pre-dispatch"),
953
- reason:
954
- selectionFailure.current?.reason ??
955
- (expected ? "receipt-invalid" : "generation-replaced"),
956
- backendReason: selectionFailure.current?.backendReason ?? null,
957
- durationMicros:
958
- receiptAtMicros === null ? null : receiptAtMicros - selecting.startedAtMicros,
959
- });
960
- pendingWindowSwitch = null;
961
- return false;
962
- }
963
- maybeRequestWindowSwitchFrame();
961
+ pendingWindowSwitch = null;
962
+ return false;
964
963
  }
965
- return receipt !== null;
966
- },
964
+ maybeRequestWindowSwitchFrame();
965
+ }
966
+ return receipt !== null;
967
+ };
968
+ const paneInput = new TerminalPaneInputRouter<{
969
+ readonly input: SessionRuntimeTerminalInput;
970
+ readonly parserOrigin?: Omit<
971
+ TuiTerminalInputOrigin,
972
+ "semanticPaneId" | "generation" | "incarnation" | "revision" | "stateHash"
973
+ >;
974
+ }>({
975
+ select: (paneId) => selectInRuntime(paneId),
967
976
  send: async (paneId, routed) => {
968
977
  const { input, parserOrigin } = routed;
969
978
  const selectionVersion = paneInput.selectionVersion;
@@ -1229,9 +1238,21 @@ export function createApplicationTerminalInteractionController(
1229
1238
  maybeRequestWindowSwitchFrame();
1230
1239
  maybeRequestPaneResizeFrame();
1231
1240
  },
1232
- selectPane: (paneId) => {
1241
+ selectPane: (paneId, admission) => {
1233
1242
  finishLinkSelection(false);
1234
- paneInput.selectPane(paneId);
1243
+ if (admission)
1244
+ // Ordered now; selected only once admitted, otherwise held input drops.
1245
+ paneInput.selectPane(paneId, {
1246
+ presentOptimistically: false,
1247
+ selection: () => {
1248
+ // A later selection supersedes this one: never select it after all.
1249
+ const version = paneInput.selectionVersion;
1250
+ return admission.then((admitted) =>
1251
+ admitted && paneInput.selectionVersion === version ? selectInRuntime(paneId) : false,
1252
+ );
1253
+ },
1254
+ });
1255
+ else paneInput.selectPane(paneId);
1235
1256
  selectionWaiter.reconcile();
1236
1257
  },
1237
1258
  async unlinkWindowLink(target) {
@@ -368,6 +368,19 @@ export function createDirectLoopbackDaemonTransport(
368
368
  };
369
369
  let terminalReconnectTimer: unknown | null = null;
370
370
  let terminalReconnectController: AbortController | null = null;
371
+ // Failed terminal reconnects back off as the catalog-only one does (#764):
372
+ // a daemon that keeps refusing the inventory is asked at 1, 2, 4 … 30 s,
373
+ // never at a fixed 1 Hz forever. A committed reconnect resets it.
374
+ let terminalReconnectAttempt = 0;
375
+ // The target the backoff was counted for: another workspace or session
376
+ // starts again at 1 s. Kept apart from supervisorTargetKey, which a
377
+ // retirement clears before its own reconnect.
378
+ let terminalReconnectTargetKey: string | null = null;
379
+ const terminalReconnectDelay = (): number => {
380
+ const delayMs = Math.min(1_000 * 2 ** terminalReconnectAttempt, 30_000);
381
+ terminalReconnectAttempt += 1;
382
+ return delayMs;
383
+ };
371
384
  let catalogReconnectTimer: unknown | null = null;
372
385
  let catalogReconnectAttempt = 0;
373
386
  let scheduleCatalogOnlyReconnect = (): void => undefined;
@@ -457,6 +470,10 @@ export function createDirectLoopbackDaemonTransport(
457
470
  ): WorkspaceEventSupervisor => {
458
471
  const key = `${safeTarget.daemon.instanceId}\0${safeTarget.workspaceName}\0${sessionName}`;
459
472
  if (eventSupervisor && supervisorTargetKey === key) return eventSupervisor;
473
+ if (terminalReconnectTargetKey !== key) {
474
+ terminalReconnectTargetKey = key;
475
+ terminalReconnectAttempt = 0;
476
+ }
460
477
  eventSupervisor?.dispose();
461
478
  const socket = createWebSocket(eventSocketUrl(descriptor, "semantic"), {
462
479
  headers: dependencies.ownerToken
@@ -544,7 +561,7 @@ export function createDirectLoopbackDaemonTransport(
544
561
  terminalReconnectTimer = terminalReconnectClock.setTimeout(() => {
545
562
  terminalReconnectTimer = null;
546
563
  reconnect();
547
- }, 1_000);
564
+ }, terminalReconnectDelay());
548
565
  };
549
566
  const commitReplacement = (): void => {
550
567
  if (
@@ -563,6 +580,7 @@ export function createDirectLoopbackDaemonTransport(
563
580
  retryReplacement();
564
581
  return;
565
582
  }
583
+ terminalReconnectAttempt = 0;
566
584
  sink(resource);
567
585
  if (retainedWorkspaceCatalogReady?.subscriber === catalogSubscriber)
568
586
  retainedWorkspaceCatalogReady.resolve();
@@ -589,14 +607,14 @@ export function createDirectLoopbackDaemonTransport(
589
607
  terminalReconnectTimer = terminalReconnectClock.setTimeout(() => {
590
608
  terminalReconnectTimer = null;
591
609
  reconnect();
592
- }, 1_000);
610
+ }, terminalReconnectDelay());
593
611
  });
594
612
  };
595
613
  if (retiredDuringReconnect) {
596
614
  terminalReconnectTimer = terminalReconnectClock.setTimeout(() => {
597
615
  terminalReconnectTimer = null;
598
616
  reconnect();
599
- }, 1_000);
617
+ }, terminalReconnectDelay());
600
618
  } else {
601
619
  queueMicrotask(reconnect);
602
620
  }
@@ -142,6 +142,18 @@ function deferred(): {
142
142
  return { promise, resolve, reject };
143
143
  }
144
144
 
145
+ /**
146
+ * After the fast retries, a read that keeps failing (the daemon answering 503
147
+ * while it re-qualifies a session, #764) is retried on this slow backoff while
148
+ * the sink is attached; the last step repeats until the budget is spent.
149
+ */
150
+ const TERMINAL_REFRESH_BACKOFF_MS = [250, 500, 1_000] as const;
151
+ const TERMINAL_REFRESH_BACKOFF_LAST_MS = 1_000;
152
+ /** Past this much backoff the stale authority is retired, not shown on. */
153
+ const TERMINAL_REFRESH_BACKOFF_BUDGET_MS = 15_000;
154
+ /** The delay between a sink-requeued or fast-retried refresh and the next. */
155
+ const TERMINAL_REFRESH_STEP_MS = 25;
156
+
145
157
  /**
146
158
  * One permanent parser and physical event socket for a WorkspaceClient generation.
147
159
  * Logical resource barriers are independent; a socket hello never makes a resource live.
@@ -209,6 +221,13 @@ export function createWorkspaceEventSupervisor(
209
221
  let terminalRefreshCoalesced = 0;
210
222
  let terminalRefreshDelayed = false;
211
223
  let terminalRefreshRetryAttempt = 0;
224
+ // The slow backoff after the fast retries (#764): its next step, how much
225
+ // of the budget it has spent, the delay before the next run, and whether
226
+ // the pending timer is a backoff a new request may cut short.
227
+ let terminalRefreshBackoffStep = 0;
228
+ let terminalRefreshBackoffSpent = 0;
229
+ let terminalRefreshNextDelay: number = TERMINAL_REFRESH_STEP_MS;
230
+ let terminalRefreshBackingOff = false;
212
231
  let applicationShellHandlers: ApplicationShellEventHandlers | null = null;
213
232
  let workspaceCatalogInvalidate: (() => void) | null = null;
214
233
  let retirementNotified = false;
@@ -346,6 +365,20 @@ export function createWorkspaceEventSupervisor(
346
365
  reason: "event" | "gap" | "snapshot" | "consumer" = "consumer",
347
366
  continuation = false,
348
367
  ): void => {
368
+ if (!continuation) {
369
+ // A daemon event starts a fresh budget; any new request reads now
370
+ // rather than waiting out a backoff.
371
+ if (reason !== "consumer") {
372
+ terminalRefreshBackoffStep = 0;
373
+ terminalRefreshBackoffSpent = 0;
374
+ }
375
+ if (terminalRefreshBackingOff && terminalRefreshTimer !== null) {
376
+ refreshClock.clearTimeout(terminalRefreshTimer);
377
+ terminalRefreshTimer = null;
378
+ terminalRefreshBackingOff = false;
379
+ terminalRefreshQueued = false;
380
+ }
381
+ }
349
382
  if (!continuation && !terminalRefreshQueued && !terminalRefreshRunning)
350
383
  terminalRefreshRetryAttempt = 0;
351
384
  if (!continuation && reason !== "consumer") {
@@ -376,7 +409,8 @@ export function createWorkspaceEventSupervisor(
376
409
  terminalRefreshDelayed = false;
377
410
  const controller = new AbortController();
378
411
  terminalRefreshController = controller;
379
- let outcome: "success" | "retry" | "exhausted" | "aborted" = "success";
412
+ let outcome: "success" | "retry" | "backoff" | "exhausted" | "aborted" = "success";
413
+ let retire = false;
380
414
  let failure: "read-failed" | "stale-revision" | null = null;
381
415
  try {
382
416
  const resource = await readTerminal(controller.signal, false);
@@ -388,6 +422,8 @@ export function createWorkspaceEventSupervisor(
388
422
  terminalSink(resource);
389
423
  }
390
424
  terminalRefreshRetryAttempt = 0;
425
+ terminalRefreshBackoffStep = 0;
426
+ terminalRefreshBackoffSpent = 0;
391
427
  } catch {
392
428
  if (failure === null && !controller.signal.aborted) failure = "read-failed";
393
429
  const recoverable = !controller.signal.aborted && !disposed && terminalSink !== null;
@@ -398,9 +434,26 @@ export function createWorkspaceEventSupervisor(
398
434
  terminalRefreshRetryAttempt += 1;
399
435
  terminalRefreshQueued = true;
400
436
  outcome = "retry";
437
+ } else if (
438
+ recoverable &&
439
+ failure === "read-failed" &&
440
+ terminalRefreshBackoffSpent < TERMINAL_REFRESH_BACKOFF_BUDGET_MS
441
+ ) {
442
+ // Nothing else will ask again: the daemon publishes no event once
443
+ // it can answer (#764). Keep asking, slowly, within a budget.
444
+ const delay =
445
+ TERMINAL_REFRESH_BACKOFF_MS[terminalRefreshBackoffStep] ??
446
+ TERMINAL_REFRESH_BACKOFF_LAST_MS;
447
+ terminalRefreshBackoffStep += 1;
448
+ terminalRefreshBackoffSpent += delay;
449
+ terminalRefreshNextDelay = delay;
450
+ terminalRefreshQueued = true;
451
+ outcome = "backoff";
401
452
  } else {
402
453
  terminalRefreshQueued = false;
403
454
  outcome = controller.signal.aborted ? "aborted" : "exhausted";
455
+ // A budget spent on failed reads: the terminal on screen is stale.
456
+ retire = outcome === "exhausted" && failure === "read-failed" && recoverable;
404
457
  }
405
458
  } finally {
406
459
  const discardedCoalesced =
@@ -413,9 +466,11 @@ export function createWorkspaceEventSupervisor(
413
466
  attempt,
414
467
  outcome,
415
468
  failure,
469
+ ...(outcome === "backoff" ? { delayMs: terminalRefreshNextDelay } : {}),
416
470
  });
417
471
  if (terminalRefreshController === controller) terminalRefreshController = null;
418
472
  }
473
+ if (retire) notifyRetired();
419
474
  };
420
475
  void run().finally(() => {
421
476
  terminalRefreshRunning = false;
@@ -424,11 +479,15 @@ export function createWorkspaceEventSupervisor(
424
479
  // just-read snapshot. Keep that recovery live, but never let it form a
425
480
  // microtask spin loop against a stale same-revision authority.
426
481
  terminalRefreshDelayed = true;
482
+ const delay = terminalRefreshNextDelay;
483
+ terminalRefreshNextDelay = TERMINAL_REFRESH_STEP_MS;
484
+ terminalRefreshBackingOff = delay > TERMINAL_REFRESH_STEP_MS;
427
485
  terminalRefreshTimer = refreshClock.setTimeout(() => {
428
486
  terminalRefreshTimer = null;
487
+ terminalRefreshBackingOff = false;
429
488
  terminalRefreshQueued = false;
430
489
  refreshTerminalAuthority(terminalRefreshReason, true);
431
- }, 25);
490
+ }, delay);
432
491
  });
433
492
  });
434
493
  };
@@ -683,6 +742,7 @@ export function createWorkspaceEventSupervisor(
683
742
  terminalRefreshQueued = false;
684
743
  if (terminalRefreshTimer !== null) refreshClock.clearTimeout(terminalRefreshTimer);
685
744
  terminalRefreshTimer = null;
745
+ terminalRefreshBackingOff = false;
686
746
  terminalRefreshDelayed = false;
687
747
  terminalRefreshController?.abort();
688
748
  terminalRefreshController = null;
@@ -698,6 +758,7 @@ export function createWorkspaceEventSupervisor(
698
758
  disposed = true;
699
759
  if (terminalRefreshTimer !== null) refreshClock.clearTimeout(terminalRefreshTimer);
700
760
  terminalRefreshTimer = null;
761
+ terminalRefreshBackingOff = false;
701
762
  terminalRefreshQueued = false;
702
763
  terminalRefreshDelayed = false;
703
764
  terminalRefreshController?.abort();
@@ -64,6 +64,8 @@ type TmuxClientResolver = (
64
64
  ) => {
65
65
  executable: string;
66
66
  environment: NodeJS.ProcessEnv;
67
+ /** Global options put before every command, e.g. `["-S", socket]` to pin one server. */
68
+ globalArgs?: readonly string[];
67
69
  };
68
70
 
69
71
  let clientResolver: TmuxClientResolver | undefined;
@@ -84,7 +86,7 @@ export function runTmux(args: string[], options: ExecFileSyncOptions = {}): stri
84
86
  const resolved = clientResolver?.(options.env ?? process.env, options.cwd);
85
87
  return runTmuxBinary(
86
88
  resolved?.executable ?? "tmux",
87
- args,
89
+ resolved?.globalArgs?.length ? [...resolved.globalArgs, ...args] : args,
88
90
  resolved ? { ...options, env: resolved.environment } : options,
89
91
  );
90
92
  }