tmux-ide 2.9.27 → 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 (55) hide show
  1. package/bin/cli.js +796 -97
  2. package/package.json +1 -1
  3. package/packages/contracts/src/pane-stream.ts +36 -0
  4. package/packages/daemon/dist/command-center/resources/terminal-runtime-inventory.js +17 -3
  5. package/packages/daemon/dist/command-center/tmux-servers.js +2 -1
  6. package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/Info.plist +2 -2
  7. package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/MacOS/tmux-ide-notifier +0 -0
  8. package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/Resources/Assets.car +0 -0
  9. package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/_CodeSignature/CodeResources +2 -2
  10. package/packages/daemon/dist/terminal/attachments/native-runtime.js +12 -8
  11. package/packages/daemon/dist/terminal/mirror/mirror-service.js +13 -0
  12. package/packages/daemon/dist/terminal/mirror/native-atomic-snapshot.js +17 -7
  13. package/packages/daemon/dist/terminal/mirror/native-grid-capture.js +129 -5
  14. package/packages/daemon/dist/terminal/mirror/pane-feed.js +4 -0
  15. package/packages/daemon/dist/terminal/mirror/pane-hold.js +13 -0
  16. package/packages/daemon/dist/terminal/mirror/session-channel.js +198 -27
  17. package/packages/daemon/dist/terminal/pane-stream/lease-manager.js +1 -0
  18. package/packages/daemon/dist/terminal/pane-stream/pane-stream-websocket.js +184 -12
  19. package/packages/daemon/dist/terminal/protocol/layout-parse.js +99 -10
  20. package/packages/daemon/dist/terminal/protocol/session-descriptor-discovery.js +5 -2
  21. package/packages/daemon/dist/terminal/session-runtime/terminal-interpreter-backend.js +2 -1
  22. package/packages/daemon/dist/terminal/session-runtime/terminal-replica-interpreter.js +46 -1
  23. package/packages/daemon/dist/terminal/session-runtime/terminal-replica-owner.js +128 -3
  24. package/packages/daemon/dist/terminal/session-runtime/xterm-terminal-interpreter-backend.js +115 -6
  25. package/packages/daemon/dist/tui/mirror/open-tui-workspace-runtime-port.js +19 -1
  26. package/packages/daemon/dist/tui/mirror/runtime/open-tui-generation-host.js +9 -1
  27. package/packages/daemon/dist/tui/mirror/workspace/connection-feedback.js +8 -0
  28. package/packages/daemon/src/command-center/resources/terminal-runtime-inventory.ts +20 -2
  29. package/packages/daemon/src/command-center/tmux-servers.ts +4 -1
  30. package/packages/daemon/src/terminal/attachments/native-runtime.ts +15 -1
  31. package/packages/daemon/src/terminal/mirror/events.ts +31 -1
  32. package/packages/daemon/src/terminal/mirror/mirror-service.ts +19 -0
  33. package/packages/daemon/src/terminal/mirror/native-atomic-snapshot.ts +16 -5
  34. package/packages/daemon/src/terminal/mirror/native-grid-capture.ts +164 -5
  35. package/packages/daemon/src/terminal/mirror/pane-feed.ts +5 -0
  36. package/packages/daemon/src/terminal/mirror/pane-hold.ts +16 -0
  37. package/packages/daemon/src/terminal/mirror/session-channel.ts +253 -38
  38. package/packages/daemon/src/terminal/mirror/trusted-inventory.ts +2 -0
  39. package/packages/daemon/src/terminal/pane-stream/lease-manager.ts +3 -0
  40. package/packages/daemon/src/terminal/pane-stream/pane-stream-websocket.ts +215 -12
  41. package/packages/daemon/src/terminal/protocol/layout-parse.ts +109 -10
  42. package/packages/daemon/src/terminal/protocol/session-descriptor-discovery.ts +10 -1
  43. package/packages/daemon/src/terminal/session-runtime/runtime-observability.ts +2 -1
  44. package/packages/daemon/src/terminal/session-runtime/terminal-interpreter-backend.ts +24 -1
  45. package/packages/daemon/src/terminal/session-runtime/terminal-replica-interpreter.ts +61 -5
  46. package/packages/daemon/src/terminal/session-runtime/terminal-replica-owner.ts +159 -32
  47. package/packages/daemon/src/terminal/session-runtime/xterm-terminal-interpreter-backend.ts +134 -11
  48. package/packages/daemon/src/tui/mirror/open-tui-workspace-runtime-port.ts +19 -0
  49. package/packages/daemon/src/tui/mirror/runtime/open-tui-generation-host.ts +13 -0
  50. package/packages/daemon/src/tui/mirror/workspace/connection-feedback.ts +13 -1
  51. package/packages/daemon-client/src/direct-application-shell-transport.ts +6 -2
  52. package/packages/daemon-client/src/pane-stream-client.ts +24 -6
  53. package/packages/daemon-client/src/workspace-client-types.ts +6 -0
  54. package/packages/daemon-client/src/workspace-client.ts +15 -9
  55. package/packages/daemon-client/src/workspace-event-supervisor.ts +3 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tmux-ide",
3
- "version": "2.9.27",
3
+ "version": "2.9.28",
4
4
  "description": "The open-source workspace for coding agents: run Claude Code, Codex and other agents in tmux with live status",
5
5
  "type": "module",
6
6
  "bin": {
@@ -145,10 +145,46 @@ export const PaneStreamLeaseRequestSchemaZ = z
145
145
  * Released daemons refuse the field: send it only to a daemon that has it.
146
146
  */
147
147
  semanticWindowId: TerminalAttachmentSemanticWindowIdSchemaZ.optional(),
148
+ /**
149
+ * #872: a person asked to retry now. The daemon asks tmux for the
150
+ * stream's panes even inside a hold after failed recoveries. Released
151
+ * daemons refuse the field: send it only to 2.9.28 or newer.
152
+ */
153
+ retryAskedByPerson: z.literal(true).optional(),
148
154
  })
149
155
  .strict();
150
156
  export type PaneStreamLeaseRequest = z.infer<typeof PaneStreamLeaseRequestSchemaZ>;
151
157
 
158
+ /**
159
+ * #872: the close of a stream whose pane the daemon holds back after its
160
+ * recoveries failed in a row: "try again later", with the reason
161
+ * `pane-held:<ms>:<why>`. `<ms>` is the whole milliseconds until the daemon
162
+ * asks tmux again; `<why>` is `too-large` when the last try's capture was over
163
+ * its size cap, else `failed`. A client that does not know the reason treats
164
+ * it as any other close and reconnects.
165
+ */
166
+ export const PANE_STREAM_PANE_HELD_CLOSE_CODE = 1013;
167
+ export type PaneStreamPaneHoldWhy = "too-large" | "failed";
168
+ export interface PaneStreamPaneHold {
169
+ readonly retryInMs: number;
170
+ readonly why: PaneStreamPaneHoldWhy;
171
+ }
172
+ const PANE_HELD_CLOSE_REASON = /^pane-held:([1-9][0-9]{0,5}):([a-z-]+)$/u;
173
+ /** The longest wait a reader takes; the daemon's hold is at most 30 s. */
174
+ const PANE_HELD_MAX_READ_MS = 600_000;
175
+
176
+ export function paneHeldCloseReason(hold: PaneStreamPaneHold): string {
177
+ return `pane-held:${Math.max(1, Math.ceil(hold.retryInMs))}:${hold.why}`;
178
+ }
179
+
180
+ export function readPaneHeldCloseReason(reason: string): PaneStreamPaneHold | null {
181
+ const match = PANE_HELD_CLOSE_REASON.exec(reason);
182
+ if (!match) return null;
183
+ const retryInMs = Number(match[1]);
184
+ if (retryInMs > PANE_HELD_MAX_READ_MS) return null;
185
+ return { retryInMs, why: match[2] === "too-large" ? "too-large" : "failed" };
186
+ }
187
+
152
188
  export const PaneStreamRedemptionTicketSchemaZ = z.string().regex(/^ps2_[A-Za-z0-9_-]{43}$/u);
153
189
 
154
190
  /** Same canonical loopback discipline as the terminal-attachment endpoint. */
@@ -1,15 +1,25 @@
1
1
  import { TERMINAL_RUNTIME_INVENTORY_RESOURCE_VERSION, TerminalRuntimeInventoryProjectionV1SchemaZ, TerminalRuntimeInventoryProjectionV2SchemaZ, } from "@tmux-ide/contracts";
2
2
  import { paneIdentities, projectApplicationShellResource } from "./application-shell.js";
3
+ /**
4
+ * #882: floating panes (tmux 3.7+) are listed by the catalog but have no cell
5
+ * in the tiled layout a client attaches to. Until floats are drawn, the
6
+ * attachable inventory leaves them out, so a session holding one still opens.
7
+ */
8
+ function floatingPaneIds(session) {
9
+ return new Set(session.panes.flatMap((pane) => pane.floating === true && pane.semanticPaneId !== null ? [pane.semanticPaneId] : []));
10
+ }
3
11
  /** Pure, wire-safe agent-free topology projection. */
4
12
  export function projectTerminalRuntimeInventory(session, resourceRevision) {
5
13
  const shell = projectApplicationShellResource(session);
14
+ const floating = floatingPaneIds(session);
6
15
  return TerminalRuntimeInventoryProjectionV1SchemaZ.parse({
7
16
  workspaceName: session.workspaceName,
8
17
  workspaceId: shell.workspace.id,
9
18
  sessionId: shell.workspace.session.id,
10
19
  resourceRevision,
11
20
  semanticPaneIds: [
12
- ...new Set(shell.terminalInventory.resources.flatMap((resource) => resource.attachability.status === "available"
21
+ ...new Set(shell.terminalInventory.resources.flatMap((resource) => resource.attachability.status === "available" &&
22
+ !floating.has(resource.attachability.semanticPaneId)
13
23
  ? [resource.attachability.semanticPaneId]
14
24
  : [])),
15
25
  ].sort(),
@@ -34,13 +44,17 @@ export function projectTerminalRuntimeInventoryV2(session, resourceRevision) {
34
44
  complete: true,
35
45
  };
36
46
  windows.set(pane.windowId, entry);
47
+ if (pane.active)
48
+ entry.active = true;
49
+ // #882: a floating pane is not part of its window's tiled pane set, but an
50
+ // active float (a modal pane takes the focus) still marks its window active.
51
+ if (pane.floating === true)
52
+ return;
37
53
  const attachability = identities[index].attachability;
38
54
  if (attachability.status === "available")
39
55
  entry.panes.push(attachability.semanticPaneId);
40
56
  else
41
57
  entry.complete = false;
42
- if (pane.active)
43
- entry.active = true;
44
58
  });
45
59
  return TerminalRuntimeInventoryProjectionV2SchemaZ.parse({
46
60
  ...projectTerminalRuntimeInventory(session, resourceRevision),
@@ -446,7 +446,8 @@ export function mountTmuxServerRoutes(app, options) {
446
446
  let sessionReplaced = false;
447
447
  const subscription = await owner.sessionRuntimeRegistry.subscribeLayout(workspace.sessionName, () => undefined, {
448
448
  expectedRuntimeSessionId: identity.runtimeSessionId,
449
- expectedSemanticPaneIds: identity.description.panes.map((pane) => pane.semanticPaneId),
449
+ // #882: a floating pane has no tiled cell; the layout fence leaves it out.
450
+ expectedSemanticPaneIds: identity.description.panes.flatMap((pane) => pane.floating === true ? [] : [pane.semanticPaneId]),
450
451
  onAuthority(snapshot) {
451
452
  if (snapshot.windowLinks.liveSessionId !== c.req.query("liveSessionId")) {
452
453
  sessionReplaced = true;
@@ -21,9 +21,9 @@
21
21
  <key>CFBundlePackageType</key>
22
22
  <string>APPL</string>
23
23
  <key>CFBundleShortVersionString</key>
24
- <string>2.9.27</string>
24
+ <string>2.9.28</string>
25
25
  <key>CFBundleVersion</key>
26
- <string>2.9.27</string>
26
+ <string>2.9.28</string>
27
27
  <key>LSMinimumSystemVersion</key>
28
28
  <string>11.0</string>
29
29
  <key>LSUIElement</key>
@@ -10,7 +10,7 @@
10
10
  </data>
11
11
  <key>Resources/Assets.car</key>
12
12
  <data>
13
- 7/c5M7HIcG2L8zbGq7f5hfd3b+k=
13
+ RP7qh+buOFIHWTXCC8Ce4QEUV4A=
14
14
  </data>
15
15
  </dict>
16
16
  <key>files2</key>
@@ -26,7 +26,7 @@
26
26
  <dict>
27
27
  <key>hash2</key>
28
28
  <data>
29
- lInayHTe0NipJWAju3yVQdmkOMR8qipP8gNMy+AgXt4=
29
+ zct9eeYLwHf/RR6FjRX5S/gPsvyLch7dr664mnX4Z2I=
30
30
  </data>
31
31
  </dict>
32
32
  </dict>
@@ -374,6 +374,7 @@ function projectTrustedMirrorInventory(trusted, workspaceName, expectedSessionNa
374
374
  type: nullable(pane.type),
375
375
  missionStamp: nullable(pane.missionStamp),
376
376
  dir: boundedWireValue(pane.dir, 4_096),
377
+ ...(pane.floating === true ? { floating: true } : {}),
377
378
  });
378
379
  });
379
380
  if (activeCount !== 1 ||
@@ -384,7 +385,7 @@ function projectTrustedMirrorInventory(trusted, workspaceName, expectedSessionNa
384
385
  return Object.freeze(panes);
385
386
  }
386
387
  function analyzeInventoryPanes(panes) {
387
- return analyzeTrustedSemanticPaneCatalog(panes.map(({ sessionName: _sessionName, index: _index, title: _title, currentCommand: _currentCommand, active: _active, role: _role, name: _name, nameSource: _nameSource, type: _type, missionStamp: _missionStamp, dir: _dir, interactionEndpoint: _interactionEndpoint, nativeIdentity: _nativeIdentity, nativePaneBirthId: _nativePaneBirthId, ...row }) => row));
388
+ return analyzeTrustedSemanticPaneCatalog(panes.map(({ sessionName: _sessionName, index: _index, title: _title, currentCommand: _currentCommand, active: _active, role: _role, name: _name, nameSource: _nameSource, type: _type, missionStamp: _missionStamp, dir: _dir, interactionEndpoint: _interactionEndpoint, nativeIdentity: _nativeIdentity, nativePaneBirthId: _nativePaneBirthId, floating: _floating, ...row }) => row));
388
389
  }
389
390
  function hasWindowStampCollision(rows) {
390
391
  const windows = new Map();
@@ -462,6 +463,8 @@ const PANE_FORMAT = [
462
463
  "#{@tmux_ide_window_id}",
463
464
  "#{window_index}",
464
465
  "#{pane_birth_id}",
466
+ // #882: a floating pane (tmux 3.7+) has no tiled cell; older tmux prints "".
467
+ "#{pane_floating_flag}",
465
468
  PANE_WIRE_SENTINEL,
466
469
  ].join(WIRE_SEPARATOR);
467
470
  async function requiredTmuxResult(runner, argv, signal) {
@@ -502,10 +505,10 @@ function parsePaneSnapshot(stdout, expected) {
502
505
  const links = new Map();
503
506
  for (const line of strictLines(stdout, MAX_DISCOVERED_PANES)) {
504
507
  const fields = line.split(WIRE_SEPARATOR);
505
- if (fields.length !== 21 || fields[20] !== PANE_WIRE_SENTINEL) {
508
+ if (fields.length !== 22 || fields[21] !== PANE_WIRE_SENTINEL) {
506
509
  throw new NativeTerminalAttachmentRuntimeError("invalid-tmux-output");
507
510
  }
508
- const [sessionName, sessionId, windowId, runtimePaneId, paneCountValue, windowCountValue, stamp, indexValue, title, currentCommand, windowActive, paneActive, role, name, type, missionStamp, dir, windowStampValue, windowIndexValue, nativePaneBirthId,] = fields;
511
+ const [sessionName, sessionId, windowId, runtimePaneId, paneCountValue, windowCountValue, stamp, indexValue, title, currentCommand, windowActive, paneActive, role, name, type, missionStamp, dir, windowStampValue, windowIndexValue, nativePaneBirthId, floating,] = fields;
509
512
  if (sessionName !== expected.name ||
510
513
  sessionId !== expected.id ||
511
514
  !RUNTIME_WINDOW_ID.test(windowId) ||
@@ -538,6 +541,7 @@ function parsePaneSnapshot(stdout, expected) {
538
541
  // registered workspace remains the trusted application-shell root, so
539
542
  // keep discovery available and carry the empty presentation value.
540
543
  dir: boundedWireValue(dir, 4_096),
544
+ ...(floating === "1" ? { floating: true } : {}),
541
545
  };
542
546
  const windowIndex = nonnegativeInteger(windowIndexValue);
543
547
  const link = links.get(windowIndex) ?? {
@@ -672,13 +676,13 @@ export async function discoverWorkspaceRegistryTerminalInventory(registry, runne
672
676
  }
673
677
  }
674
678
  }
675
- const catalog = analyzeTrustedSemanticPaneCatalog(panes.map(({ sessionName: _sessionName, index: _index, title: _title, currentCommand: _currentCommand, active: _active, role: _role, name: _name, nameSource: _nameSource, type: _type, missionStamp: _missionStamp, dir: _dir, interactionEndpoint: _interactionEndpoint, nativeIdentity: _nativeIdentity, nativePaneBirthId: _nativePaneBirthId, ...row }) => row));
679
+ const catalog = analyzeTrustedSemanticPaneCatalog(panes.map(({ sessionName: _sessionName, index: _index, title: _title, currentCommand: _currentCommand, active: _active, role: _role, name: _name, nameSource: _nameSource, type: _type, missionStamp: _missionStamp, dir: _dir, interactionEndpoint: _interactionEndpoint, nativeIdentity: _nativeIdentity, nativePaneBirthId: _nativePaneBirthId, floating: _floating, ...row }) => row));
676
680
  return Object.freeze({ panes: Object.freeze(panes), catalog });
677
681
  }
678
682
  /** Internal raw-id discovery; callers expose only SemanticPaneCatalog resolution. */
679
683
  export async function discoverWorkspaceRegistrySemanticPanes(registry, runner, signal) {
680
684
  const inventory = await discoverWorkspaceRegistryTerminalInventory(registry, runner, signal);
681
- return inventory.panes.map(({ sessionName: _sessionName, index: _index, title: _title, currentCommand: _currentCommand, active: _active, role: _role, name: _name, nameSource: _nameSource, type: _type, missionStamp: _missionStamp, dir: _dir, interactionEndpoint: _interactionEndpoint, nativeIdentity: _nativeIdentity, nativePaneBirthId: _nativePaneBirthId, ...row }) => row);
685
+ return inventory.panes.map(({ sessionName: _sessionName, index: _index, title: _title, currentCommand: _currentCommand, active: _active, role: _role, name: _name, nameSource: _nameSource, type: _type, missionStamp: _missionStamp, dir: _dir, interactionEndpoint: _interactionEndpoint, nativeIdentity: _nativeIdentity, nativePaneBirthId: _nativePaneBirthId, floating: _floating, ...row }) => row);
682
686
  }
683
687
  function quoteArgument(value) {
684
688
  if (/\0|\r|\n/u.test(value)) {
@@ -878,7 +882,7 @@ export class WorkspaceTerminalInventoryRuntime {
878
882
  new SemanticPaneCatalog({
879
883
  discover: async () => {
880
884
  const inventory = await this.#discoverTerminalInventory();
881
- return inventory.panes.map(({ sessionName: _sessionName, index: _index, title: _title, currentCommand: _currentCommand, active: _active, role: _role, name: _name, nameSource: _nameSource, type: _type, missionStamp: _missionStamp, dir: _dir, interactionEndpoint: _interactionEndpoint, nativeIdentity: _nativeIdentity, nativePaneBirthId: _nativePaneBirthId, ...row }) => row);
885
+ return inventory.panes.map(({ sessionName: _sessionName, index: _index, title: _title, currentCommand: _currentCommand, active: _active, role: _role, name: _name, nameSource: _nameSource, type: _type, missionStamp: _missionStamp, dir: _dir, interactionEndpoint: _interactionEndpoint, nativeIdentity: _nativeIdentity, nativePaneBirthId: _nativePaneBirthId, floating: _floating, ...row }) => row);
882
886
  },
883
887
  });
884
888
  const orphanExecutor = new TmuxAttachmentViewExecutor({ runner: this.runner });
@@ -1445,7 +1449,7 @@ export class NativeTerminalAttachmentRuntime {
1445
1449
  new SemanticPaneCatalog({
1446
1450
  discover: async () => {
1447
1451
  const inventory = await discoverTerminalInventory();
1448
- return inventory.panes.map(({ sessionName: _sessionName, index: _index, title: _title, currentCommand: _currentCommand, active: _active, role: _role, name: _name, nameSource: _nameSource, type: _type, missionStamp: _missionStamp, dir: _dir, interactionEndpoint: _interactionEndpoint, nativeIdentity: _nativeIdentity, nativePaneBirthId: _nativePaneBirthId, ...row }) => row);
1452
+ return inventory.panes.map(({ sessionName: _sessionName, index: _index, title: _title, currentCommand: _currentCommand, active: _active, role: _role, name: _name, nameSource: _nameSource, type: _type, missionStamp: _missionStamp, dir: _dir, interactionEndpoint: _interactionEndpoint, nativeIdentity: _nativeIdentity, nativePaneBirthId: _nativePaneBirthId, floating: _floating, ...row }) => row);
1449
1453
  },
1450
1454
  });
1451
1455
  const launcher = new PtyTmuxAttachmentLauncher({
@@ -1689,7 +1693,7 @@ export class NativeTerminalAttachmentRuntime {
1689
1693
  if (panes.length === 0)
1690
1694
  return null;
1691
1695
  const active = panes.find((pane) => pane.active) ?? panes[0];
1692
- const sessionCatalog = analyzeTrustedSemanticPaneCatalog(panes.map(({ sessionName: _sessionName, index: _index, title: _title, currentCommand: _currentCommand, active: _active, role: _role, name: _name, nameSource: _nameSource, type: _type, missionStamp: _missionStamp, dir: _dir, interactionEndpoint: _interactionEndpoint, nativeIdentity: _nativeIdentity, nativePaneBirthId: _nativePaneBirthId, ...row }) => row));
1696
+ const sessionCatalog = analyzeTrustedSemanticPaneCatalog(panes.map(({ sessionName: _sessionName, index: _index, title: _title, currentCommand: _currentCommand, active: _active, role: _role, name: _name, nameSource: _nameSource, type: _type, missionStamp: _missionStamp, dir: _dir, interactionEndpoint: _interactionEndpoint, nativeIdentity: _nativeIdentity, nativePaneBirthId: _nativePaneBirthId, floating: _floating, ...row }) => row));
1693
1697
  const windowStamps = new Map();
1694
1698
  let windowIdentityReady = true;
1695
1699
  for (const pane of sessionCatalog.rows) {
@@ -210,6 +210,18 @@ export class MirrorService {
210
210
  return null;
211
211
  return identity;
212
212
  }
213
+ /**
214
+ * #872: a person asked to retry these panes now. Each one's next recovery
215
+ * asks tmux even inside a hold after failed recoveries. A session without a
216
+ * channel has no hold to lift.
217
+ */
218
+ liftRecoveryHolds(session, semanticPaneIds) {
219
+ const entry = this.channels.get(session);
220
+ if (!entry || entry.retired)
221
+ return;
222
+ for (const semanticPaneId of semanticPaneIds)
223
+ entry.channel.liftRecoveryHold(semanticPaneId);
224
+ }
213
225
  async subscribe(request) {
214
226
  const entry = await this.acquire(request.session);
215
227
  let handle;
@@ -228,6 +240,7 @@ export class MirrorService {
228
240
  thaw: () => handle.thaw(),
229
241
  reseed: () => handle.reseed(),
230
242
  readHistorySize: () => handle.readHistorySize(),
243
+ requestNativeHistory: (historyRequest) => handle.requestNativeHistory(historyRequest),
231
244
  captureNativeBacking: () => handle.captureNativeBacking(),
232
245
  sendText: (text) => {
233
246
  this.assertWindowOwnership(request.session);
@@ -23,7 +23,7 @@ function validLimit(limit) {
23
23
  return Number.isSafeInteger(limit) && limit > 0 && limit <= NATIVE_ATOMIC_SNAPSHOT_MAX_BYTES;
24
24
  }
25
25
  /** One direct child is our admission policy; native Q itself permits other wrapper siblings. */
26
- export function nativeAtomicSnapshotPlan(target, maxBytes = NATIVE_ATOMIC_SNAPSHOT_MAX_BYTES) {
26
+ export function nativeAtomicSnapshotPlan(target, maxBytes = NATIVE_ATOMIC_SNAPSHOT_MAX_BYTES, historyRows) {
27
27
  const validated = TargetSchema.parse(target);
28
28
  const continuationBytes = `%continue ${validated.paneId}\n`.length;
29
29
  if (!validLimit(maxBytes) || maxBytes <= continuationBytes)
@@ -41,7 +41,7 @@ export function nativeAtomicSnapshotPlan(target, maxBytes = NATIVE_ATOMIC_SNAPSH
41
41
  "-U",
42
42
  String(maxBytes - continuationBytes),
43
43
  "-S",
44
- "-",
44
+ historyStart(historyRows),
45
45
  "-t",
46
46
  validated.paneId,
47
47
  ],
@@ -50,6 +50,14 @@ export function nativeAtomicSnapshotPlan(target, maxBytes = NATIVE_ATOMIC_SNAPSH
50
50
  limits: { maxBytes, maxLines: MAX_LINES },
51
51
  };
52
52
  }
53
+ /** #873: `-S -` reads all history; `-S -N` the newest N rows. */
54
+ function historyStart(historyRows) {
55
+ if (historyRows === undefined)
56
+ return "-";
57
+ if (!Number.isSafeInteger(historyRows) || historyRows < 0 || historyRows > 1_000_000)
58
+ throw new TypeError("Invalid atomic snapshot history rows");
59
+ return `-${historyRows}`;
60
+ }
53
61
  const decimal = (value) => value !== undefined && /^(0|[1-9][0-9]*)$/u.test(value) && Number.isSafeInteger(Number(value))
54
62
  ? Number(value)
55
63
  : null;
@@ -64,7 +72,7 @@ function validModes(line, capture) {
64
72
  numeric[1] !== capture.cursor[1] ||
65
73
  numeric[2] !== capture.cols ||
66
74
  numeric[3] !== capture.rows ||
67
- numeric[4] !== capture.history ||
75
+ numeric[4] !== capture.history + (capture.omittedHistory ?? 0) ||
68
76
  numeric[5] !== capture.limit)
69
77
  return false;
70
78
  for (const index of [4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16, 17, 18, 19])
@@ -109,7 +117,9 @@ export function decodeNativeAtomicSnapshot(reply, expected, maxBytes = NATIVE_AT
109
117
  // terminal and exact; a separate asynchronous notification proves nothing here.
110
118
  if (reply.lines.at(-1) !== `%continue ${expected.paneId}`)
111
119
  return unknown;
112
- const capture = decodeNativeGridCapture(reply.lines.slice(1, -1).join("\n") + "\n");
120
+ const capture = decodeNativeGridCapture(reply.lines.slice(1, -1).join("\n") + "\n", {
121
+ tail: true,
122
+ });
113
123
  if (!capture || !isNativeBootstrapCapture(capture) || !validModes(metadata.cursor, capture))
114
124
  return unknown;
115
125
  return {
@@ -143,8 +153,8 @@ const AnsiEndSchema = z
143
153
  })
144
154
  .strict();
145
155
  /** V2's -U includes the continuation; v1's existing budget semantics stay unchanged. */
146
- export function nativeAtomicDualSnapshotPlan(target, maxBytes = NATIVE_ATOMIC_SNAPSHOT_MAX_BYTES) {
147
- const plan = nativeAtomicSnapshotPlan(target, maxBytes);
156
+ export function nativeAtomicDualSnapshotPlan(target, maxBytes = NATIVE_ATOMIC_SNAPSHOT_MAX_BYTES, historyRows) {
157
+ const plan = nativeAtomicSnapshotPlan(target, maxBytes, historyRows);
148
158
  return {
149
159
  ...plan,
150
160
  commands: [
@@ -157,7 +167,7 @@ export function nativeAtomicDualSnapshotPlan(target, maxBytes = NATIVE_ATOMIC_SN
157
167
  "-U",
158
168
  String(maxBytes),
159
169
  "-S",
160
- "-",
170
+ historyStart(historyRows),
161
171
  "-t",
162
172
  target.paneId,
163
173
  ],
@@ -6,9 +6,69 @@ export function isStockRawGridCapture(lines) {
6
6
  return (/^G [1-9][0-9]*x[1-9][0-9]* \([0-9]+\/[0-9]+\)$/.test(lines[0] ?? "") &&
7
7
  /^\tL 0 \((?:-|0)\) flags=/.test(lines[1] ?? ""));
8
8
  }
9
+ /**
10
+ * The capability question, asked without reading the pane's history (#869).
11
+ * `-V` exists only in tmux-ide's build, in every revision of the patch that
12
+ * adds its `-R`, and tmux rejects an unknown flag while it parses the command.
13
+ * `-V` comes first, so an upstream server refuses the command at once whatever
14
+ * the pane holds: 3.7 and older lack both flags, and 3.8 has an `-R` of its own
15
+ * that dumps the whole grid as text and ignores `-S` (28 MB for 2,000 lines at
16
+ * 120 columns). tmux-ide's build honours `-S 0 -E 0` and answers with the
17
+ * header and one row.
18
+ */
19
+ export const NATIVE_BOOTSTRAP_PROBE_FLAGS = ["-V", "-R", "-S", "0", "-E", "0"];
20
+ /** A header and one row; the row has at most one cell per column. */
21
+ export const NATIVE_BOOTSTRAP_PROBE_LIMITS = { maxBytes: 1024 * 1024, maxLines: 4 };
22
+ /**
23
+ * Read the probe's reply. Only a proven answer is "native" or "unsupported";
24
+ * a failed or malformed reply stays "unknown" so the caller can ask again
25
+ * instead of settling the server's capability on a bad read.
26
+ */
27
+ export function readNativeBootstrapProbe(ok, lines) {
28
+ if (!ok)
29
+ return lines.some((line) => /^(?:parse error: )?(?:command capture-pane: )?unknown flag -V$/.test(line.trim()))
30
+ ? "unsupported"
31
+ : "unknown";
32
+ if (isStockRawGridCapture(lines))
33
+ return "unsupported";
34
+ let header;
35
+ try {
36
+ header = JSON.parse(lines[0] ?? "");
37
+ }
38
+ catch {
39
+ return "unknown";
40
+ }
41
+ // Every revision's header names the grid's width; a row record does not.
42
+ if (header === null || typeof header !== "object" || !("cols" in header))
43
+ return "unknown";
44
+ // With -V a pane in a mode reports that mode's screen, whose current
45
+ // rendition is null. A build that predates the field omits the key.
46
+ return "version" in header && header.version === 2 && "currentAttributes" in header
47
+ ? "native"
48
+ : "unsupported";
49
+ }
9
50
  const MAX_BYTES = 16 * 1024 * 1024;
10
51
  const MAX_ROWS = MAX_BYTES / 64;
11
52
  const MAX_CELLS = 1_000_000;
53
+ /**
54
+ * #873: the first open reads the screen and the newest history that fits this
55
+ * many cells; older rows follow in pieces of the same size. A cell is 25 to 45
56
+ * bytes of the native JSON, so a piece stays well under the 16 MiB reply cap.
57
+ */
58
+ export const NATIVE_SEED_CELL_BUDGET = 262_144;
59
+ export const NATIVE_HISTORY_PIECE_CELL_BUDGET = 262_144;
60
+ /** History rows a first-open capture asks for at this pane size; never below zero. */
61
+ export function nativeSeedHistoryRows(cols, rows) {
62
+ if (!Number.isSafeInteger(cols) || cols < 1 || !Number.isSafeInteger(rows) || rows < 1)
63
+ return 0;
64
+ return Math.max(0, Math.floor(NATIVE_SEED_CELL_BUDGET / cols) - rows);
65
+ }
66
+ /** Rows one history piece holds at this width; at least one. */
67
+ export function nativeHistoryPieceRows(cols) {
68
+ if (!Number.isSafeInteger(cols) || cols < 1)
69
+ return 1;
70
+ return Math.max(1, Math.floor(NATIVE_HISTORY_PIECE_CELL_BUDGET / cols));
71
+ }
12
72
  /** Dense parser import must also fit the cell budget, even for sparse exports. */
13
73
  export function isNativeBootstrapCapture(snapshot) {
14
74
  return (uint(snapshot.cols, 16384) &&
@@ -72,7 +132,7 @@ const object = (value) => value !== null && typeof value === "object" && !Array.
72
132
  * captures and oversized payloads produce no state. Iterate NDJSON records
73
133
  * without first allocating an unbounded array of lines.
74
134
  */
75
- export function decodeNativeGridCapture(text) {
135
+ export function decodeNativeGridCapture(text, options = {}) {
76
136
  if (text.length > MAX_BYTES || Buffer.byteLength(text, "utf8") > MAX_BYTES)
77
137
  return null;
78
138
  let offset = 0;
@@ -93,8 +153,8 @@ export function decodeNativeGridCapture(text) {
93
153
  header.cols === 0 ||
94
154
  !uint(header.rows, MAX_ROWS) ||
95
155
  header.rows === 0 ||
96
- !uint(header.history, MAX_ROWS) ||
97
- header.history + header.rows > MAX_ROWS ||
156
+ !uint(header.history, options.tail ? 0xffffffff : MAX_ROWS) ||
157
+ (!options.tail && header.history + header.rows > MAX_ROWS) ||
98
158
  !uint(header.hscrolled, header.history) ||
99
159
  !uint(header.limit) ||
100
160
  !Array.isArray(header.cursor) ||
@@ -116,7 +176,16 @@ export function decodeNativeGridCapture(text) {
116
176
  return null;
117
177
  const grid = [];
118
178
  let count = 0;
119
- for (let index = 0; index < header.history + header.rows; index++) {
179
+ // #873: a tail capture (`-S -N`) starts at the oldest row it read. tmux
180
+ // numbers rows from its oldest history row, so the first row's number is
181
+ // how many older rows the capture left out.
182
+ const savedOffset = offset;
183
+ const first = options.tail ? next() : null;
184
+ offset = savedOffset;
185
+ const omitted = options.tail && object(first) && uint(first.row, header.history) ? first.row : 0;
186
+ if (header.history - omitted + header.rows > MAX_ROWS)
187
+ return null;
188
+ for (let index = omitted; index < header.history + header.rows; index++) {
120
189
  const row = next();
121
190
  if (!object(row) ||
122
191
  row.row !== index ||
@@ -174,7 +243,8 @@ export function decodeNativeGridCapture(text) {
174
243
  : {}),
175
244
  cols: header.cols,
176
245
  rows: header.rows,
177
- history: header.history,
246
+ history: header.history - omitted,
247
+ ...(omitted > 0 ? { omittedHistory: omitted } : {}),
178
248
  hscrolled: header.hscrolled,
179
249
  limit: header.limit,
180
250
  cursor: Object.freeze([header.cursor[0], header.cursor[1]]),
@@ -185,3 +255,57 @@ export function decodeNativeGridCapture(text) {
185
255
  return null;
186
256
  }
187
257
  }
258
+ /**
259
+ * #873: decode a `capture-pane -R -S <a> -E <b>` reply that holds history rows
260
+ * only. Rows must be contiguous and older than the screen. A malformed reply,
261
+ * an empty one or one with a screen row is null.
262
+ */
263
+ export function decodeNativeHistoryPiece(text) {
264
+ const newline = text.indexOf("\n");
265
+ if (newline < 0)
266
+ return null;
267
+ let header;
268
+ let first;
269
+ try {
270
+ header = JSON.parse(text.slice(0, newline));
271
+ const second = text.indexOf("\n", newline + 1);
272
+ first = JSON.parse(text.slice(newline + 1, second < 0 ? text.length : second));
273
+ }
274
+ catch {
275
+ return null;
276
+ }
277
+ if (!object(header) || !object(first) || !uint(first.row) || !uint(header.history))
278
+ return null;
279
+ const firstRow = first.row;
280
+ // Rewrite the header as a capture whose history ends at the piece's last row
281
+ // and whose screen is empty, then reuse the full decoder's checks: re-number
282
+ // the rows from zero so its contiguity check applies to the piece.
283
+ const lines = text.endsWith("\n") ? text.slice(0, -1).split("\n") : text.split("\n");
284
+ const count = lines.length - 1;
285
+ if (firstRow + count > header.history)
286
+ return null;
287
+ const renumbered = [];
288
+ for (let index = 0; index < count; index++) {
289
+ const line = lines[index + 1];
290
+ const prefix = `{"row":${firstRow + index},`;
291
+ if (!line.startsWith(prefix))
292
+ return null;
293
+ renumbered.push(`{"row":${index},` + line.slice(prefix.length));
294
+ }
295
+ const synthetic = {
296
+ ...header,
297
+ history: count - 1,
298
+ rows: 1,
299
+ hscrolled: 0,
300
+ cursor: [0, 0],
301
+ };
302
+ const capture = decodeNativeGridCapture(JSON.stringify(synthetic) + "\n" + renumbered.join("\n") + "\n");
303
+ if (!capture || capture.version !== 2)
304
+ return null;
305
+ return Object.freeze({
306
+ cols: capture.cols,
307
+ historySize: header.history,
308
+ firstRow,
309
+ rows: capture.grid,
310
+ });
311
+ }
@@ -37,6 +37,10 @@ export class PaneFeed {
37
37
  currentState() {
38
38
  return this.state;
39
39
  }
40
+ /** Changes with every `beginReseed`; a reply read under another value is stale. */
41
+ reseedEpoch() {
42
+ return this.epoch;
43
+ }
40
44
  /** Arm a reseed. Returns the epoch token the two reply hooks must present;
41
45
  * an in-flight older reseed is invalidated wholesale. */
42
46
  beginReseed() {
@@ -0,0 +1,13 @@
1
+ /**
2
+ * A pane's open refused because its recoveries failed in a row (#869, #872):
3
+ * not a try that failed. It carries the time until tmux is asked again and
4
+ * why the last try failed, so the stream can close with both.
5
+ */
6
+ export class MirrorPaneHeldError extends Error {
7
+ hold;
8
+ constructor(hold) {
9
+ super("Native terminal recovery held after failed recoveries");
10
+ this.name = "MirrorPaneHeldError";
11
+ this.hold = hold;
12
+ }
13
+ }