tmux-ide 2.9.26 → 2.9.28

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 (89) hide show
  1. package/README.md +1 -1
  2. package/bin/cli.js +2046 -623
  3. package/package.json +2 -2
  4. package/packages/contracts/src/pane-stream.ts +45 -0
  5. package/packages/contracts/src/terminal-delivery.ts +114 -3
  6. package/packages/core/src/index.ts +1 -0
  7. package/packages/core/src/terminal-delivery-binary.ts +8 -7
  8. package/packages/core/src/terminal-delivery.ts +174 -3
  9. package/packages/core/src/terminal-partial-history.ts +152 -0
  10. package/packages/core/src/terminal-replica.ts +70 -1
  11. package/packages/daemon/dist/command-center/owner-keep-alive.js +30 -0
  12. package/packages/daemon/dist/command-center/resources/terminal-runtime-inventory.js +17 -3
  13. package/packages/daemon/dist/command-center/server.js +3 -0
  14. package/packages/daemon/dist/command-center/tmux-server-attach.js +51 -0
  15. package/packages/daemon/dist/command-center/tmux-servers.js +80 -1
  16. package/packages/daemon/dist/doctor.js +4 -4
  17. package/packages/daemon/dist/lib/app-config.js +7 -0
  18. package/packages/daemon/dist/lib/node-requirement.js +20 -0
  19. package/packages/daemon/dist/lib/require-supported-node.js +8 -0
  20. package/packages/daemon/dist/lib/tmux-server-session-open.js +38 -12
  21. package/packages/daemon/dist/lib/workspace-promotion.js +4 -4
  22. package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/Info.plist +2 -2
  23. package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/MacOS/tmux-ide-notifier +0 -0
  24. package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/Resources/Assets.car +0 -0
  25. package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/_CodeSignature/CodeResources +2 -2
  26. package/packages/daemon/dist/server/pane-stream-upgrade.js +39 -1
  27. package/packages/daemon/dist/terminal/attachments/native-runtime.js +12 -8
  28. package/packages/daemon/dist/terminal/mirror/mirror-service.js +13 -0
  29. package/packages/daemon/dist/terminal/mirror/native-atomic-snapshot.js +17 -7
  30. package/packages/daemon/dist/terminal/mirror/native-grid-capture.js +129 -5
  31. package/packages/daemon/dist/terminal/mirror/pane-feed.js +4 -0
  32. package/packages/daemon/dist/terminal/mirror/pane-hold.js +13 -0
  33. package/packages/daemon/dist/terminal/mirror/session-channel.js +198 -27
  34. package/packages/daemon/dist/terminal/pane-stream/lease-manager.js +1 -0
  35. package/packages/daemon/dist/terminal/pane-stream/pane-stream-websocket.js +198 -12
  36. package/packages/daemon/dist/terminal/protocol/layout-parse.js +99 -10
  37. package/packages/daemon/dist/terminal/protocol/session-descriptor-discovery.js +5 -2
  38. package/packages/daemon/dist/terminal/session-runtime/registry.js +1 -0
  39. package/packages/daemon/dist/terminal/session-runtime/terminal-delivery-hub.js +465 -42
  40. package/packages/daemon/dist/terminal/session-runtime/terminal-interpreter-backend.js +2 -1
  41. package/packages/daemon/dist/terminal/session-runtime/terminal-replica-interpreter.js +46 -1
  42. package/packages/daemon/dist/terminal/session-runtime/terminal-replica-owner.js +128 -3
  43. package/packages/daemon/dist/terminal/session-runtime/xterm-terminal-interpreter-backend.js +115 -6
  44. package/packages/daemon/dist/tui/mirror/open-tui-workspace-runtime-port.js +94 -2
  45. package/packages/daemon/dist/tui/mirror/runtime/open-tui-generation-host.js +9 -1
  46. package/packages/daemon/dist/tui/mirror/theme.js +8 -1
  47. package/packages/daemon/dist/tui/mirror/workspace/connection-feedback.js +8 -0
  48. package/packages/daemon/src/command-center/attach-window-rule.cases.json +84 -0
  49. package/packages/daemon/src/command-center/owner-keep-alive.ts +38 -0
  50. package/packages/daemon/src/command-center/resources/terminal-runtime-inventory.ts +20 -2
  51. package/packages/daemon/src/command-center/server.ts +3 -0
  52. package/packages/daemon/src/command-center/tmux-server-attach.ts +75 -0
  53. package/packages/daemon/src/command-center/tmux-servers.ts +88 -1
  54. package/packages/daemon/src/doctor.ts +4 -4
  55. package/packages/daemon/src/lib/app-config.ts +15 -0
  56. package/packages/daemon/src/lib/node-requirement.ts +22 -0
  57. package/packages/daemon/src/lib/require-supported-node.ts +9 -0
  58. package/packages/daemon/src/lib/tmux-server-session-open.ts +53 -15
  59. package/packages/daemon/src/lib/workspace-promotion.ts +4 -4
  60. package/packages/daemon/src/server/pane-stream-upgrade.ts +41 -1
  61. package/packages/daemon/src/terminal/attachments/native-runtime.ts +15 -1
  62. package/packages/daemon/src/terminal/mirror/events.ts +31 -1
  63. package/packages/daemon/src/terminal/mirror/mirror-service.ts +19 -0
  64. package/packages/daemon/src/terminal/mirror/native-atomic-snapshot.ts +16 -5
  65. package/packages/daemon/src/terminal/mirror/native-grid-capture.ts +164 -5
  66. package/packages/daemon/src/terminal/mirror/pane-feed.ts +5 -0
  67. package/packages/daemon/src/terminal/mirror/pane-hold.ts +16 -0
  68. package/packages/daemon/src/terminal/mirror/session-channel.ts +253 -38
  69. package/packages/daemon/src/terminal/mirror/trusted-inventory.ts +2 -0
  70. package/packages/daemon/src/terminal/pane-stream/lease-manager.ts +3 -0
  71. package/packages/daemon/src/terminal/pane-stream/pane-stream-websocket.ts +240 -12
  72. package/packages/daemon/src/terminal/protocol/layout-parse.ts +109 -10
  73. package/packages/daemon/src/terminal/protocol/session-descriptor-discovery.ts +10 -1
  74. package/packages/daemon/src/terminal/session-runtime/registry.ts +1 -0
  75. package/packages/daemon/src/terminal/session-runtime/runtime-observability.ts +2 -1
  76. package/packages/daemon/src/terminal/session-runtime/terminal-delivery-hub.ts +575 -39
  77. package/packages/daemon/src/terminal/session-runtime/terminal-interpreter-backend.ts +24 -1
  78. package/packages/daemon/src/terminal/session-runtime/terminal-replica-interpreter.ts +61 -5
  79. package/packages/daemon/src/terminal/session-runtime/terminal-replica-owner.ts +159 -32
  80. package/packages/daemon/src/terminal/session-runtime/xterm-terminal-interpreter-backend.ts +134 -11
  81. package/packages/daemon/src/tui/mirror/open-tui-workspace-runtime-port.ts +101 -2
  82. package/packages/daemon/src/tui/mirror/runtime/open-tui-generation-host.ts +13 -0
  83. package/packages/daemon/src/tui/mirror/theme.ts +13 -1
  84. package/packages/daemon/src/tui/mirror/workspace/connection-feedback.ts +13 -1
  85. package/packages/daemon-client/src/direct-application-shell-transport.ts +6 -2
  86. package/packages/daemon-client/src/pane-stream-client.ts +24 -6
  87. package/packages/daemon-client/src/workspace-client-types.ts +6 -0
  88. package/packages/daemon-client/src/workspace-client.ts +15 -9
  89. package/packages/daemon-client/src/workspace-event-supervisor.ts +3 -1
@@ -9,6 +9,53 @@ export function isStockRawGridCapture(lines: readonly string[]): boolean {
9
9
  );
10
10
  }
11
11
 
12
+ /**
13
+ * The capability question, asked without reading the pane's history (#869).
14
+ * `-V` exists only in tmux-ide's build, in every revision of the patch that
15
+ * adds its `-R`, and tmux rejects an unknown flag while it parses the command.
16
+ * `-V` comes first, so an upstream server refuses the command at once whatever
17
+ * the pane holds: 3.7 and older lack both flags, and 3.8 has an `-R` of its own
18
+ * that dumps the whole grid as text and ignores `-S` (28 MB for 2,000 lines at
19
+ * 120 columns). tmux-ide's build honours `-S 0 -E 0` and answers with the
20
+ * header and one row.
21
+ */
22
+ export const NATIVE_BOOTSTRAP_PROBE_FLAGS: readonly string[] = ["-V", "-R", "-S", "0", "-E", "0"];
23
+ /** A header and one row; the row has at most one cell per column. */
24
+ export const NATIVE_BOOTSTRAP_PROBE_LIMITS = { maxBytes: 1024 * 1024, maxLines: 4 } as const;
25
+
26
+ export type NativeBootstrapProbeResult = "native" | "unsupported" | "unknown";
27
+
28
+ /**
29
+ * Read the probe's reply. Only a proven answer is "native" or "unsupported";
30
+ * a failed or malformed reply stays "unknown" so the caller can ask again
31
+ * instead of settling the server's capability on a bad read.
32
+ */
33
+ export function readNativeBootstrapProbe(
34
+ ok: boolean,
35
+ lines: readonly string[],
36
+ ): NativeBootstrapProbeResult {
37
+ if (!ok)
38
+ return lines.some((line) =>
39
+ /^(?:parse error: )?(?:command capture-pane: )?unknown flag -V$/.test(line.trim()),
40
+ )
41
+ ? "unsupported"
42
+ : "unknown";
43
+ if (isStockRawGridCapture(lines)) return "unsupported";
44
+ let header: unknown;
45
+ try {
46
+ header = JSON.parse(lines[0] ?? "");
47
+ } catch {
48
+ return "unknown";
49
+ }
50
+ // Every revision's header names the grid's width; a row record does not.
51
+ if (header === null || typeof header !== "object" || !("cols" in header)) return "unknown";
52
+ // With -V a pane in a mode reports that mode's screen, whose current
53
+ // rendition is null. A build that predates the field omits the key.
54
+ return "version" in header && header.version === 2 && "currentAttributes" in header
55
+ ? "native"
56
+ : "unsupported";
57
+ }
58
+
12
59
  /** Private native capture experiment; this is not the canonical renderer schema. */
13
60
  export interface NativeGridCaptureCell {
14
61
  readonly flags: number;
@@ -37,7 +84,14 @@ export interface NativeGridCapture {
37
84
  readonly currentAttributes?: readonly [number, number, number, number];
38
85
  readonly cols: number;
39
86
  readonly rows: number;
87
+ /** History rows in `grid`, which holds `history + rows` rows. */
40
88
  readonly history: number;
89
+ /**
90
+ * #873: tmux history rows older than `grid[0]` that this capture left out.
91
+ * tmux's history_size is `history + omittedHistory`. Absent on a capture of
92
+ * the whole history.
93
+ */
94
+ readonly omittedHistory?: number;
41
95
  readonly hscrolled: number;
42
96
  readonly limit: number;
43
97
  readonly cursor: readonly [number, number];
@@ -48,6 +102,47 @@ const MAX_BYTES = 16 * 1024 * 1024;
48
102
  const MAX_ROWS = MAX_BYTES / 64;
49
103
  const MAX_CELLS = 1_000_000;
50
104
 
105
+ /**
106
+ * #873: the first open reads the screen and the newest history that fits this
107
+ * many cells; older rows follow in pieces of the same size. A cell is 25 to 45
108
+ * bytes of the native JSON, so a piece stays well under the 16 MiB reply cap.
109
+ */
110
+ export const NATIVE_SEED_CELL_BUDGET = 262_144;
111
+ export const NATIVE_HISTORY_PIECE_CELL_BUDGET = 262_144;
112
+
113
+ /** History rows a first-open capture asks for at this pane size; never below zero. */
114
+ export function nativeSeedHistoryRows(cols: number, rows: number): number {
115
+ if (!Number.isSafeInteger(cols) || cols < 1 || !Number.isSafeInteger(rows) || rows < 1) return 0;
116
+ return Math.max(0, Math.floor(NATIVE_SEED_CELL_BUDGET / cols) - rows);
117
+ }
118
+
119
+ /** Rows one history piece holds at this width; at least one. */
120
+ export function nativeHistoryPieceRows(cols: number): number {
121
+ if (!Number.isSafeInteger(cols) || cols < 1) return 1;
122
+ return Math.max(1, Math.floor(NATIVE_HISTORY_PIECE_CELL_BUDGET / cols));
123
+ }
124
+
125
+ /**
126
+ * #873: older history rows read from tmux after the first open, oldest first.
127
+ * tmux numbers rows from its oldest history row; `firstRow` is that number for
128
+ * `rows[0]`, read at the instant tmux's history held `historySize` rows.
129
+ */
130
+ export interface NativeHistoryRequest {
131
+ /** tmux's number for the requester's oldest row; the piece ends just before it. */
132
+ readonly endRow: number;
133
+ /** Rows wanted, the newest at `endRow - 1`. */
134
+ readonly rows: number;
135
+ /** The requester's history_size, to turn row numbers into `-S`/`-E` offsets. */
136
+ readonly historySize: number;
137
+ }
138
+
139
+ export interface NativeHistoryPiece {
140
+ readonly cols: number;
141
+ readonly historySize: number;
142
+ readonly firstRow: number;
143
+ readonly rows: readonly NativeGridCaptureRow[];
144
+ }
145
+
51
146
  /** Dense parser import must also fit the cell budget, even for sparse exports. */
52
147
  export function isNativeBootstrapCapture(snapshot: NativeGridCapture): boolean {
53
148
  return (
@@ -118,7 +213,10 @@ const object = (value: unknown): value is Record<string, unknown> =>
118
213
  * captures and oversized payloads produce no state. Iterate NDJSON records
119
214
  * without first allocating an unbounded array of lines.
120
215
  */
121
- export function decodeNativeGridCapture(text: string): NativeGridCapture | null {
216
+ export function decodeNativeGridCapture(
217
+ text: string,
218
+ options: { readonly tail?: boolean } = {},
219
+ ): NativeGridCapture | null {
122
220
  if (text.length > MAX_BYTES || Buffer.byteLength(text, "utf8") > MAX_BYTES) return null;
123
221
  let offset = 0;
124
222
  const next = (): unknown => {
@@ -138,8 +236,8 @@ export function decodeNativeGridCapture(text: string): NativeGridCapture | null
138
236
  header.cols === 0 ||
139
237
  !uint(header.rows, MAX_ROWS) ||
140
238
  header.rows === 0 ||
141
- !uint(header.history, MAX_ROWS) ||
142
- header.history + header.rows > MAX_ROWS ||
239
+ !uint(header.history, options.tail ? 0xffffffff : MAX_ROWS) ||
240
+ (!options.tail && header.history + header.rows > MAX_ROWS) ||
143
241
  !uint(header.hscrolled, header.history) ||
144
242
  !uint(header.limit) ||
145
243
  !Array.isArray(header.cursor) ||
@@ -164,7 +262,16 @@ export function decodeNativeGridCapture(text: string): NativeGridCapture | null
164
262
  return null;
165
263
  const grid: NativeGridCaptureRow[] = [];
166
264
  let count = 0;
167
- for (let index = 0; index < header.history + header.rows; index++) {
265
+ // #873: a tail capture (`-S -N`) starts at the oldest row it read. tmux
266
+ // numbers rows from its oldest history row, so the first row's number is
267
+ // how many older rows the capture left out.
268
+ const savedOffset = offset;
269
+ const first = options.tail ? next() : null;
270
+ offset = savedOffset;
271
+ const omitted =
272
+ options.tail && object(first) && uint(first.row, header.history) ? first.row : 0;
273
+ if (header.history - omitted + header.rows > MAX_ROWS) return null;
274
+ for (let index = omitted; index < header.history + header.rows; index++) {
168
275
  const row = next();
169
276
  if (
170
277
  !object(row) ||
@@ -234,7 +341,8 @@ export function decodeNativeGridCapture(text: string): NativeGridCapture | null
234
341
  : {}),
235
342
  cols: header.cols,
236
343
  rows: header.rows,
237
- history: header.history,
344
+ history: header.history - omitted,
345
+ ...(omitted > 0 ? { omittedHistory: omitted } : {}),
238
346
  hscrolled: header.hscrolled,
239
347
  limit: header.limit,
240
348
  cursor: Object.freeze([header.cursor[0], header.cursor[1]]) as readonly [number, number],
@@ -244,3 +352,54 @@ export function decodeNativeGridCapture(text: string): NativeGridCapture | null
244
352
  return null;
245
353
  }
246
354
  }
355
+
356
+ /**
357
+ * #873: decode a `capture-pane -R -S <a> -E <b>` reply that holds history rows
358
+ * only. Rows must be contiguous and older than the screen. A malformed reply,
359
+ * an empty one or one with a screen row is null.
360
+ */
361
+ export function decodeNativeHistoryPiece(text: string): NativeHistoryPiece | null {
362
+ const newline = text.indexOf("\n");
363
+ if (newline < 0) return null;
364
+ let header: unknown;
365
+ let first: unknown;
366
+ try {
367
+ header = JSON.parse(text.slice(0, newline));
368
+ const second = text.indexOf("\n", newline + 1);
369
+ first = JSON.parse(text.slice(newline + 1, second < 0 ? text.length : second));
370
+ } catch {
371
+ return null;
372
+ }
373
+ if (!object(header) || !object(first) || !uint(first.row) || !uint(header.history)) return null;
374
+ const firstRow = first.row;
375
+ // Rewrite the header as a capture whose history ends at the piece's last row
376
+ // and whose screen is empty, then reuse the full decoder's checks: re-number
377
+ // the rows from zero so its contiguity check applies to the piece.
378
+ const lines = text.endsWith("\n") ? text.slice(0, -1).split("\n") : text.split("\n");
379
+ const count = lines.length - 1;
380
+ if (firstRow + count > header.history) return null;
381
+ const renumbered: string[] = [];
382
+ for (let index = 0; index < count; index++) {
383
+ const line = lines[index + 1]!;
384
+ const prefix = `{"row":${firstRow + index},`;
385
+ if (!line.startsWith(prefix)) return null;
386
+ renumbered.push(`{"row":${index},` + line.slice(prefix.length));
387
+ }
388
+ const synthetic = {
389
+ ...header,
390
+ history: count - 1,
391
+ rows: 1,
392
+ hscrolled: 0,
393
+ cursor: [0, 0],
394
+ };
395
+ const capture = decodeNativeGridCapture(
396
+ JSON.stringify(synthetic) + "\n" + renumbered.join("\n") + "\n",
397
+ );
398
+ if (!capture || capture.version !== 2) return null;
399
+ return Object.freeze({
400
+ cols: capture.cols,
401
+ historySize: header.history,
402
+ firstRow,
403
+ rows: capture.grid,
404
+ });
405
+ }
@@ -93,6 +93,11 @@ export class PaneFeed {
93
93
  return this.state;
94
94
  }
95
95
 
96
+ /** Changes with every `beginReseed`; a reply read under another value is stale. */
97
+ reseedEpoch(): number {
98
+ return this.epoch;
99
+ }
100
+
96
101
  /** Arm a reseed. Returns the epoch token the two reply hooks must present;
97
102
  * an in-flight older reseed is invalidated wholesale. */
98
103
  beginReseed(): number {
@@ -0,0 +1,16 @@
1
+ import type { MirrorPaneHold } from "./events.ts";
2
+
3
+ /**
4
+ * A pane's open refused because its recoveries failed in a row (#869, #872):
5
+ * not a try that failed. It carries the time until tmux is asked again and
6
+ * why the last try failed, so the stream can close with both.
7
+ */
8
+ export class MirrorPaneHeldError extends Error {
9
+ readonly hold: MirrorPaneHold;
10
+
11
+ constructor(hold: MirrorPaneHold) {
12
+ super("Native terminal recovery held after failed recoveries");
13
+ this.name = "MirrorPaneHeldError";
14
+ this.hold = hold;
15
+ }
16
+ }