tmux-ide 2.9.25 → 2.9.27

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 (67) hide show
  1. package/README.md +1 -1
  2. package/bin/cli.js +1577 -559
  3. package/package.json +3 -2
  4. package/packages/contracts/src/pane-stream.ts +28 -0
  5. package/packages/contracts/src/terminal-delivery.ts +122 -5
  6. package/packages/contracts/src/terminal-runtime-inventory.ts +61 -1
  7. package/packages/contracts/src/tmux-server-scope.ts +18 -0
  8. package/packages/core/src/index.ts +1 -0
  9. package/packages/core/src/terminal-delivery-binary.ts +8 -7
  10. package/packages/core/src/terminal-delivery.ts +174 -3
  11. package/packages/core/src/terminal-partial-history.ts +152 -0
  12. package/packages/core/src/terminal-replica.ts +70 -1
  13. package/packages/daemon/dist/command-center/owner-keep-alive.js +30 -0
  14. package/packages/daemon/dist/command-center/resources/terminal-runtime-inventory.js +42 -2
  15. package/packages/daemon/dist/command-center/server.js +3 -0
  16. package/packages/daemon/dist/command-center/tmux-server-attach.js +51 -0
  17. package/packages/daemon/dist/command-center/tmux-servers.js +95 -7
  18. package/packages/daemon/dist/doctor.js +4 -4
  19. package/packages/daemon/dist/lib/app-config.js +7 -0
  20. package/packages/daemon/dist/lib/node-requirement.js +20 -0
  21. package/packages/daemon/dist/lib/require-supported-node.js +8 -0
  22. package/packages/daemon/dist/lib/tmux-server-owner.js +4 -2
  23. package/packages/daemon/dist/lib/tmux-server-session-open.js +38 -12
  24. package/packages/daemon/dist/lib/workspace-promotion.js +4 -4
  25. package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/Info.plist +2 -2
  26. package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/MacOS/tmux-ide-notifier +0 -0
  27. package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/Resources/Assets.car +0 -0
  28. package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/_CodeSignature/CodeResources +2 -2
  29. package/packages/daemon/dist/server/pane-stream-upgrade.js +39 -1
  30. package/packages/daemon/dist/terminal/mirror/session-channel.js +6 -1
  31. package/packages/daemon/dist/terminal/pane-stream/lease-manager.js +1 -0
  32. package/packages/daemon/dist/terminal/pane-stream/pane-stream-websocket.js +112 -22
  33. package/packages/daemon/dist/terminal/protocol/browser-icon.js +1 -1
  34. package/packages/daemon/dist/terminal/protocol/session-descriptor-discovery.js +26 -3
  35. package/packages/daemon/dist/terminal/session-runtime/registry.js +2 -0
  36. package/packages/daemon/dist/terminal/session-runtime/terminal-delivery-hub.js +571 -33
  37. package/packages/daemon/dist/terminal/session-runtime/terminal-replica-interpreter.js +2 -0
  38. package/packages/daemon/dist/terminal/session-runtime/xterm-terminal-interpreter-backend.js +51 -4
  39. package/packages/daemon/dist/tui/mirror/open-tui-workspace-runtime-port.js +76 -2
  40. package/packages/daemon/dist/tui/mirror/theme.js +8 -1
  41. package/packages/daemon/src/command-center/attach-window-rule.cases.json +84 -0
  42. package/packages/daemon/src/command-center/owner-keep-alive.ts +38 -0
  43. package/packages/daemon/src/command-center/resources/terminal-runtime-inventory.ts +48 -1
  44. package/packages/daemon/src/command-center/server.ts +3 -0
  45. package/packages/daemon/src/command-center/tmux-server-attach.ts +75 -0
  46. package/packages/daemon/src/command-center/tmux-servers.ts +103 -6
  47. package/packages/daemon/src/doctor.ts +4 -4
  48. package/packages/daemon/src/lib/app-config.ts +15 -0
  49. package/packages/daemon/src/lib/node-requirement.ts +22 -0
  50. package/packages/daemon/src/lib/require-supported-node.ts +9 -0
  51. package/packages/daemon/src/lib/tmux-server-owner.ts +6 -3
  52. package/packages/daemon/src/lib/tmux-server-session-open.ts +53 -15
  53. package/packages/daemon/src/lib/workspace-promotion.ts +4 -4
  54. package/packages/daemon/src/server/pane-stream-upgrade.ts +41 -1
  55. package/packages/daemon/src/terminal/mirror/events.ts +2 -0
  56. package/packages/daemon/src/terminal/mirror/session-channel.ts +8 -1
  57. package/packages/daemon/src/terminal/pane-stream/lease-manager.ts +3 -0
  58. package/packages/daemon/src/terminal/pane-stream/pane-stream-websocket.ts +136 -20
  59. package/packages/daemon/src/terminal/protocol/browser-icon.ts +1 -1
  60. package/packages/daemon/src/terminal/protocol/session-descriptor-discovery.ts +32 -2
  61. package/packages/daemon/src/terminal/session-runtime/registry.ts +2 -0
  62. package/packages/daemon/src/terminal/session-runtime/terminal-delivery-hub.ts +696 -30
  63. package/packages/daemon/src/terminal/session-runtime/terminal-interpreter-backend.ts +6 -0
  64. package/packages/daemon/src/terminal/session-runtime/terminal-replica-interpreter.ts +2 -0
  65. package/packages/daemon/src/terminal/session-runtime/xterm-terminal-interpreter-backend.ts +67 -3
  66. package/packages/daemon/src/tui/mirror/open-tui-workspace-runtime-port.ts +82 -2
  67. package/packages/daemon/src/tui/mirror/theme.ts +13 -1
@@ -41,6 +41,12 @@ export interface TerminalInterpreterBackend {
41
41
  setAuthoritativeModes(modes: MirrorObservedTerminalModes): void;
42
42
  /** A pre-existing saved buffer became active without authoritative backing. */
43
43
  requiresNativeReseed(): boolean;
44
+ /**
45
+ * From now on, collect history at the limit the way tmux does. Off while a
46
+ * capture is replayed: tmux's captured history (which can exceed a lowered
47
+ * limit) is replayed as it is.
48
+ */
49
+ startHistoryCollection?(): void;
44
50
  modes(): TerminalReplicaModes;
45
51
  dirtyRange(): { readonly start: number; readonly end: number } | undefined;
46
52
  project(
@@ -270,6 +270,7 @@ export class TerminalReplicaInterpreter {
270
270
  rows: options.rows,
271
271
  scrollback: this.#scrollback,
272
272
  });
273
+ this.#backend.startHistoryCollection?.();
273
274
  this.#kitty = new KittyImageStore(
274
275
  options.kittyImageBudget ? { budget: options.kittyImageBudget } : {},
275
276
  );
@@ -501,6 +502,7 @@ export class TerminalReplicaInterpreter {
501
502
  this.#admitRaw(chunk);
502
503
  this.#observeMarkerBytes(chunk);
503
504
  }
505
+ replacement.startHistoryCollection?.();
504
506
  const previous = this.#backend;
505
507
  this.#backend = replacement;
506
508
  this.#attachKitty(replacement);
@@ -23,6 +23,9 @@ export class XtermTerminalInterpreterBackend implements TerminalInterpreterBacke
23
23
  readonly #terminal: Terminal;
24
24
  readonly #rowCache = new WeakMap<object, CachedRow>();
25
25
  #scrollEpoch = 0;
26
+ readonly #historyLimit: number;
27
+ #collecting = false;
28
+ #lastYbase: number | null = null;
26
29
  #lastScrollEpoch = 0;
27
30
  #lastViewportY = 0;
28
31
  #lastBufferType = "normal";
@@ -36,11 +39,17 @@ export class XtermTerminalInterpreterBackend implements TerminalInterpreterBacke
36
39
  #scrollOnClear: boolean | undefined;
37
40
 
38
41
  constructor(options: TerminalInterpreterBackendFactoryOptions) {
42
+ const historyLimit = options.historyLimit ?? options.scrollback;
43
+ this.#historyLimit = historyLimit;
39
44
  this.#terminal = new Terminal({
40
45
  cols: options.cols,
41
46
  rows: options.rows,
42
- scrollback: options.scrollback,
43
- tmuxHistoryLimit: options.historyLimit ?? options.scrollback,
47
+ // One row of headroom over what the replica may hold (the limit, or a
48
+ // larger captured history): xterm must not recycle the row a scroll
49
+ // adds before #collectHistory sees it.
50
+ scrollback:
51
+ historyLimit > 0 ? Math.max(options.scrollback, historyLimit) + 1 : options.scrollback,
52
+ tmuxHistoryLimit: historyLimit,
44
53
  allowProposedApi: true,
45
54
  });
46
55
  this.#terminal.loadAddon(new Unicode11Addon());
@@ -81,7 +90,9 @@ export class XtermTerminalInterpreterBackend implements TerminalInterpreterBacke
81
90
  this.#terminal.onScroll(() => {
82
91
  // tmux retains normal history while alternate rows scroll independently.
83
92
  // Neither captured nor live alternate scrolling may trim that history.
84
- if (this.#terminal.buffer.active.type === "normal") this.#scrollEpoch += 1;
93
+ if (this.#terminal.buffer.active.type !== "normal") return;
94
+ this.#scrollEpoch += 1;
95
+ this.#collectHistory();
85
96
  });
86
97
  const core = (
87
98
  this.#terminal as unknown as {
@@ -94,6 +105,59 @@ export class XtermTerminalInterpreterBackend implements TerminalInterpreterBacke
94
105
  }
95
106
  }
96
107
 
108
+ /**
109
+ * tmux at its history-limit collects the oldest tenth of history before a
110
+ * scroll would pass it (grid_collect_history), so its history_size moves
111
+ * between 0.9 and 1.0 of the limit. Recycling one row at a time instead kept
112
+ * the replica at the limit, and the owner's history-size check then reseeded
113
+ * the whole pane each time its output paused. The projection reports the
114
+ * collection as an ordinary history trim.
115
+ */
116
+ startHistoryCollection(): void {
117
+ this.#collecting = true;
118
+ this.#lastYbase = this.#normalBuffer()?.ybase ?? null;
119
+ }
120
+
121
+ #normalBuffer() {
122
+ return (
123
+ this.#terminal as unknown as {
124
+ _core?: {
125
+ buffers?: {
126
+ normal?: {
127
+ ybase: number;
128
+ ydisp: number;
129
+ lines: { trimStart(count: number): void };
130
+ };
131
+ };
132
+ };
133
+ }
134
+ )._core?.buffers?.normal;
135
+ }
136
+
137
+ #collectHistory(): void {
138
+ const buffer = this.#normalBuffer();
139
+ if (!buffer) return;
140
+ const before = this.#lastYbase;
141
+ const limit = this.#historyLimit;
142
+ // Only a plain one-row scroll from at or above the limit is collected
143
+ // here. ED2 collects before its own scrolls (one-column.patch), and any
144
+ // other change (reset, resize, a capped ring) is left alone: a history
145
+ // that still differs from tmux is caught by the owner's size check.
146
+ if (
147
+ this.#collecting &&
148
+ limit > 0 &&
149
+ before !== null &&
150
+ before >= limit &&
151
+ buffer.ybase === before + 1
152
+ ) {
153
+ const trim = Math.min(buffer.ybase, Math.max(1, Math.floor(limit / 10)));
154
+ buffer.lines.trimStart(trim);
155
+ buffer.ybase -= trim;
156
+ buffer.ydisp = Math.max(0, buffer.ydisp - trim);
157
+ }
158
+ this.#lastYbase = buffer.ybase;
159
+ }
160
+
97
161
  get cols(): number {
98
162
  return this.#terminal.cols;
99
163
  }
@@ -1,4 +1,8 @@
1
- import { STOCK_CAPTURE_TAB_UNAVAILABLE } from "@tmux-ide/contracts";
1
+ import {
2
+ STOCK_CAPTURE_TAB_UNAVAILABLE,
3
+ TERMINAL_DELIVERY_MAX_PIPELINED,
4
+ TERMINAL_DELIVERY_PIPELINING_CAPABILITY_VERSION,
5
+ } from "@tmux-ide/contracts";
2
6
  import { randomUUID } from "node:crypto";
3
7
  import type {
4
8
  WindowLinkTopology,
@@ -413,6 +417,13 @@ class WireTerminalEndpoint {
413
417
  #pending: PendingDelivery | null = null;
414
418
  #rejectedTransactionId: string | null = null;
415
419
  #decodeToken: object | null = null;
420
+ /**
421
+ * Capability 124: patches the daemon pipelined behind the delivery that is
422
+ * still decoding or unsettled, each with its chunks, in arrival order. Each
423
+ * names the one before as its base; they are admitted once that one is ACKed.
424
+ */
425
+ #queued: TerminalDeliveryServerMessage[] = [];
426
+ #draining = false;
416
427
  #closed = false;
417
428
  readonly #ready: Promise<boolean>;
418
429
  #resolveReady!: (ready: boolean) => void;
@@ -505,6 +516,7 @@ class WireTerminalEndpoint {
505
516
  return;
506
517
  }
507
518
  if (message.type === "terminal.delivery.fault") {
519
+ this.#queued.length = 0;
508
520
  if (message.deliveryNonce !== this.#negotiated.deliveryNonce) {
509
521
  this.#failConnection(new Error("Terminal fault nonce does not match negotiation"));
510
522
  return;
@@ -532,6 +544,15 @@ class WireTerminalEndpoint {
532
544
  return;
533
545
  }
534
546
  if (this.#unavailable) return;
547
+ if ((this.#queued.length > 0 || this.#busy()) && this.#mayQueue(message)) {
548
+ this.#queued.push(message);
549
+ return;
550
+ }
551
+ return this.#acceptNow(message);
552
+ }
553
+
554
+ #acceptNow(message: TerminalDeliveryServerMessage): void | { readonly consumedOwnedChunk: true } {
555
+ if (message.type === "terminal.delivery.fault") return;
535
556
  if (message.type === "terminal.projection") {
536
557
  this.#failConnection(new Error("Unsolicited alternate-screen projection"));
537
558
  return;
@@ -543,9 +564,62 @@ class WireTerminalEndpoint {
543
564
  return this.#acceptChunk(message);
544
565
  }
545
566
 
567
+ /** A flight is decoding or waiting for its subscriber: it has not been ACKed. */
568
+ #busy(): boolean {
569
+ return this.#decodeToken !== null || this.#pending !== null;
570
+ }
571
+
572
+ /**
573
+ * Capability 124: only a patch based on the newest flight (decoding,
574
+ * unsettled or queued), within TERMINAL_DELIVERY_MAX_PIPELINED, and the
575
+ * chunks of the newest queued patch. Anything else overlapping a flight is
576
+ * still a protocol violation and takes the ordinary path.
577
+ */
578
+ #mayQueue(message: TerminalDeliveryServerMessage): boolean {
579
+ let newest: TerminalDeliveryEnvelope | null = this.#pending?.envelope ?? this.#envelope;
580
+ let envelopes = 1;
581
+ let chunks = 0;
582
+ for (const queued of this.#queued)
583
+ if (queued.type === "terminal.delivery") {
584
+ newest = queued;
585
+ envelopes += 1;
586
+ chunks = 0;
587
+ } else if (queued.type === "terminal.delivery.chunk") chunks += 1;
588
+ if (!newest) return false;
589
+ if (message.type === "terminal.delivery.chunk")
590
+ return (
591
+ envelopes > 1 &&
592
+ message.transactionId === newest.transactionId &&
593
+ chunks < newest.chunkCount
594
+ );
595
+ return (
596
+ message.type === "terminal.delivery" &&
597
+ message.frame === "patch" &&
598
+ message.baseRevision === newest.canonicalRevision &&
599
+ message.incarnation === newest.incarnation &&
600
+ envelopes < TERMINAL_DELIVERY_MAX_PIPELINED &&
601
+ (envelopes === 1 || chunks === newest.chunkCount)
602
+ );
603
+ }
604
+
605
+ /** Admit queued deliveries in order until one is decoding or unsettled again. */
606
+ #drain(): void {
607
+ if (this.#draining) return;
608
+ this.#draining = true;
609
+ try {
610
+ while (this.#queued.length > 0 && !this.#busy() && !this.#closed) {
611
+ const message = this.#queued.shift()!;
612
+ this.#acceptNow(message);
613
+ }
614
+ } finally {
615
+ this.#draining = false;
616
+ }
617
+ }
618
+
546
619
  close(): void {
547
620
  if (this.#closed) return;
548
621
  this.#closed = true;
622
+ this.#queued.length = 0;
549
623
  this.#assembler = null;
550
624
  this.#assemblyStorage = null;
551
625
  this.#envelope = null;
@@ -847,7 +921,9 @@ class WireTerminalEndpoint {
847
921
  });
848
922
  } catch (error) {
849
923
  this.#failConnection(error instanceof Error ? error : new Error(String(error)));
924
+ return;
850
925
  }
926
+ this.#drain();
851
927
  }
852
928
 
853
929
  #reject(
@@ -882,6 +958,9 @@ class WireTerminalEndpoint {
882
958
  this.#decodeToken = null;
883
959
  this.#rejectedTransactionId = attempted?.transactionId ?? transactionId;
884
960
  this.#reseedRequired = true;
961
+ // Patches queued behind the rejected flight are NACKed in turn ("gap");
962
+ // the daemon dropped them with the first NACK.
963
+ this.#drain();
885
964
  }
886
965
  }
887
966
 
@@ -1227,7 +1306,8 @@ export async function connectOpenTuiWorkspaceRuntimePort(
1227
1306
  panes: [...panes],
1228
1307
  viewerMode: "interactive",
1229
1308
  terminalDelivery: {
1230
- protocolVersions: [1],
1309
+ // 124: this endpoint holds patches pipelined behind a decoding one.
1310
+ protocolVersions: [1, TERMINAL_DELIVERY_PIPELINING_CAPABILITY_VERSION],
1231
1311
  encodings: ["semantic-compact-v1", "semantic-v1"],
1232
1312
  richPlacements: true,
1233
1313
  },
@@ -139,6 +139,9 @@ export interface SemanticThemeSnapshot extends SemanticThemeTokens {
139
139
  export interface ThemeConfigInput {
140
140
  mode?: ThemeModeSetting;
141
141
  preset?: string;
142
+ /** System mode's preset when the host is light, and when it is dark. */
143
+ light?: string;
144
+ dark?: string;
142
145
  userTheme?: unknown;
143
146
  projectTheme?: unknown;
144
147
  accessibility?: Partial<ThemeAccessibilityPreferences>;
@@ -900,10 +903,19 @@ export function createSemanticThemeSnapshot(
900
903
  config?.accessibility?.increasedContrast ?? DEFAULT_ACCESSIBILITY.increasedContrast,
901
904
  };
902
905
  const mode = resolvedMode(setting, rendererMode, hostDefaults);
906
+ // System mode with a chosen preset for each side (the Mac app's Match
907
+ // macOS writes theme.light / theme.dark): the side the host is on.
908
+ const side =
909
+ setting === "system"
910
+ ? findVisualThemePreset(mode === "light" ? config?.light : config?.dark)
911
+ : undefined;
903
912
  const resolved = resolveVisualTheme({
904
913
  appearance: mode,
905
914
  hostDefaults: setting === "system" ? (hostDefaults ?? undefined) : undefined,
906
- userTheme: config?.userTheme ?? findVisualThemePreset(config?.preset),
915
+ userTheme:
916
+ config?.userTheme ??
917
+ findVisualThemePreset(config?.preset) ??
918
+ (side?.appearance === mode ? side : undefined),
907
919
  projectTheme: config?.projectTheme,
908
920
  accessibility,
909
921
  });