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.
- package/bin/cli.js +796 -97
- package/package.json +1 -1
- package/packages/contracts/src/pane-stream.ts +36 -0
- package/packages/daemon/dist/command-center/resources/terminal-runtime-inventory.js +17 -3
- package/packages/daemon/dist/command-center/tmux-servers.js +2 -1
- package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/Info.plist +2 -2
- package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/MacOS/tmux-ide-notifier +0 -0
- package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/Resources/Assets.car +0 -0
- package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/_CodeSignature/CodeResources +2 -2
- package/packages/daemon/dist/terminal/attachments/native-runtime.js +12 -8
- package/packages/daemon/dist/terminal/mirror/mirror-service.js +13 -0
- package/packages/daemon/dist/terminal/mirror/native-atomic-snapshot.js +17 -7
- package/packages/daemon/dist/terminal/mirror/native-grid-capture.js +129 -5
- package/packages/daemon/dist/terminal/mirror/pane-feed.js +4 -0
- package/packages/daemon/dist/terminal/mirror/pane-hold.js +13 -0
- package/packages/daemon/dist/terminal/mirror/session-channel.js +198 -27
- package/packages/daemon/dist/terminal/pane-stream/lease-manager.js +1 -0
- package/packages/daemon/dist/terminal/pane-stream/pane-stream-websocket.js +184 -12
- package/packages/daemon/dist/terminal/protocol/layout-parse.js +99 -10
- package/packages/daemon/dist/terminal/protocol/session-descriptor-discovery.js +5 -2
- package/packages/daemon/dist/terminal/session-runtime/terminal-interpreter-backend.js +2 -1
- package/packages/daemon/dist/terminal/session-runtime/terminal-replica-interpreter.js +46 -1
- package/packages/daemon/dist/terminal/session-runtime/terminal-replica-owner.js +128 -3
- package/packages/daemon/dist/terminal/session-runtime/xterm-terminal-interpreter-backend.js +115 -6
- package/packages/daemon/dist/tui/mirror/open-tui-workspace-runtime-port.js +19 -1
- package/packages/daemon/dist/tui/mirror/runtime/open-tui-generation-host.js +9 -1
- package/packages/daemon/dist/tui/mirror/workspace/connection-feedback.js +8 -0
- package/packages/daemon/src/command-center/resources/terminal-runtime-inventory.ts +20 -2
- package/packages/daemon/src/command-center/tmux-servers.ts +4 -1
- package/packages/daemon/src/terminal/attachments/native-runtime.ts +15 -1
- package/packages/daemon/src/terminal/mirror/events.ts +31 -1
- package/packages/daemon/src/terminal/mirror/mirror-service.ts +19 -0
- package/packages/daemon/src/terminal/mirror/native-atomic-snapshot.ts +16 -5
- package/packages/daemon/src/terminal/mirror/native-grid-capture.ts +164 -5
- package/packages/daemon/src/terminal/mirror/pane-feed.ts +5 -0
- package/packages/daemon/src/terminal/mirror/pane-hold.ts +16 -0
- package/packages/daemon/src/terminal/mirror/session-channel.ts +253 -38
- package/packages/daemon/src/terminal/mirror/trusted-inventory.ts +2 -0
- package/packages/daemon/src/terminal/pane-stream/lease-manager.ts +3 -0
- package/packages/daemon/src/terminal/pane-stream/pane-stream-websocket.ts +215 -12
- package/packages/daemon/src/terminal/protocol/layout-parse.ts +109 -10
- package/packages/daemon/src/terminal/protocol/session-descriptor-discovery.ts +10 -1
- package/packages/daemon/src/terminal/session-runtime/runtime-observability.ts +2 -1
- package/packages/daemon/src/terminal/session-runtime/terminal-interpreter-backend.ts +24 -1
- package/packages/daemon/src/terminal/session-runtime/terminal-replica-interpreter.ts +61 -5
- package/packages/daemon/src/terminal/session-runtime/terminal-replica-owner.ts +159 -32
- package/packages/daemon/src/terminal/session-runtime/xterm-terminal-interpreter-backend.ts +134 -11
- package/packages/daemon/src/tui/mirror/open-tui-workspace-runtime-port.ts +19 -0
- package/packages/daemon/src/tui/mirror/runtime/open-tui-generation-host.ts +13 -0
- package/packages/daemon/src/tui/mirror/workspace/connection-feedback.ts +13 -1
- package/packages/daemon-client/src/direct-application-shell-transport.ts +6 -2
- package/packages/daemon-client/src/pane-stream-client.ts +24 -6
- package/packages/daemon-client/src/workspace-client-types.ts +6 -0
- package/packages/daemon-client/src/workspace-client.ts +15 -9
- package/packages/daemon-client/src/workspace-event-supervisor.ts +3 -1
|
@@ -498,6 +498,8 @@ export interface NativeTerminalInventoryPaneSnapshot extends TrustedSemanticPane
|
|
|
498
498
|
/** Durable `@tmux_ide_mission` creation stamp, or null when unset. */
|
|
499
499
|
readonly missionStamp: string | null;
|
|
500
500
|
readonly dir: string;
|
|
501
|
+
/** #882: a floating pane; present, but not in the tiled layout. */
|
|
502
|
+
readonly floating?: boolean;
|
|
501
503
|
}
|
|
502
504
|
|
|
503
505
|
export interface NativeTerminalInventorySnapshot {
|
|
@@ -600,6 +602,7 @@ function projectTrustedMirrorInventory(
|
|
|
600
602
|
type: nullable(pane.type),
|
|
601
603
|
missionStamp: nullable(pane.missionStamp),
|
|
602
604
|
dir: boundedWireValue(pane.dir, 4_096),
|
|
605
|
+
...(pane.floating === true ? { floating: true } : {}),
|
|
603
606
|
});
|
|
604
607
|
});
|
|
605
608
|
if (
|
|
@@ -633,6 +636,7 @@ function analyzeInventoryPanes(panes: readonly NativeTerminalInventoryPaneSnapsh
|
|
|
633
636
|
interactionEndpoint: _interactionEndpoint,
|
|
634
637
|
nativeIdentity: _nativeIdentity,
|
|
635
638
|
nativePaneBirthId: _nativePaneBirthId,
|
|
639
|
+
floating: _floating,
|
|
636
640
|
...row
|
|
637
641
|
}) => row,
|
|
638
642
|
),
|
|
@@ -725,6 +729,8 @@ const PANE_FORMAT = [
|
|
|
725
729
|
"#{@tmux_ide_window_id}",
|
|
726
730
|
"#{window_index}",
|
|
727
731
|
"#{pane_birth_id}",
|
|
732
|
+
// #882: a floating pane (tmux 3.7+) has no tiled cell; older tmux prints "".
|
|
733
|
+
"#{pane_floating_flag}",
|
|
728
734
|
PANE_WIRE_SENTINEL,
|
|
729
735
|
].join(WIRE_SEPARATOR);
|
|
730
736
|
|
|
@@ -786,7 +792,7 @@ function parsePaneSnapshot(
|
|
|
786
792
|
const links = new Map<number, { windowId: string; active: boolean; panes: Set<string> }>();
|
|
787
793
|
for (const line of strictLines(stdout, MAX_DISCOVERED_PANES)) {
|
|
788
794
|
const fields = line.split(WIRE_SEPARATOR);
|
|
789
|
-
if (fields.length !==
|
|
795
|
+
if (fields.length !== 22 || fields[21] !== PANE_WIRE_SENTINEL) {
|
|
790
796
|
throw new NativeTerminalAttachmentRuntimeError("invalid-tmux-output");
|
|
791
797
|
}
|
|
792
798
|
const [
|
|
@@ -810,6 +816,7 @@ function parsePaneSnapshot(
|
|
|
810
816
|
windowStampValue,
|
|
811
817
|
windowIndexValue,
|
|
812
818
|
nativePaneBirthId,
|
|
819
|
+
floating,
|
|
813
820
|
] = fields as [
|
|
814
821
|
string,
|
|
815
822
|
string,
|
|
@@ -832,6 +839,7 @@ function parsePaneSnapshot(
|
|
|
832
839
|
string,
|
|
833
840
|
string,
|
|
834
841
|
string,
|
|
842
|
+
string,
|
|
835
843
|
];
|
|
836
844
|
if (
|
|
837
845
|
sessionName !== expected.name ||
|
|
@@ -868,6 +876,7 @@ function parsePaneSnapshot(
|
|
|
868
876
|
// registered workspace remains the trusted application-shell root, so
|
|
869
877
|
// keep discovery available and carry the empty presentation value.
|
|
870
878
|
dir: boundedWireValue(dir, 4_096),
|
|
879
|
+
...(floating === "1" ? { floating: true } : {}),
|
|
871
880
|
};
|
|
872
881
|
const windowIndex = nonnegativeInteger(windowIndexValue);
|
|
873
882
|
const link = links.get(windowIndex) ?? {
|
|
@@ -1038,6 +1047,7 @@ export async function discoverWorkspaceRegistryTerminalInventory(
|
|
|
1038
1047
|
interactionEndpoint: _interactionEndpoint,
|
|
1039
1048
|
nativeIdentity: _nativeIdentity,
|
|
1040
1049
|
nativePaneBirthId: _nativePaneBirthId,
|
|
1050
|
+
floating: _floating,
|
|
1041
1051
|
...row
|
|
1042
1052
|
}) => row,
|
|
1043
1053
|
),
|
|
@@ -1068,6 +1078,7 @@ export async function discoverWorkspaceRegistrySemanticPanes(
|
|
|
1068
1078
|
interactionEndpoint: _interactionEndpoint,
|
|
1069
1079
|
nativeIdentity: _nativeIdentity,
|
|
1070
1080
|
nativePaneBirthId: _nativePaneBirthId,
|
|
1081
|
+
floating: _floating,
|
|
1071
1082
|
...row
|
|
1072
1083
|
}) => row,
|
|
1073
1084
|
);
|
|
@@ -1400,6 +1411,7 @@ export class WorkspaceTerminalInventoryRuntime {
|
|
|
1400
1411
|
interactionEndpoint: _interactionEndpoint,
|
|
1401
1412
|
nativeIdentity: _nativeIdentity,
|
|
1402
1413
|
nativePaneBirthId: _nativePaneBirthId,
|
|
1414
|
+
floating: _floating,
|
|
1403
1415
|
...row
|
|
1404
1416
|
}) => row,
|
|
1405
1417
|
);
|
|
@@ -2155,6 +2167,7 @@ export class NativeTerminalAttachmentRuntime {
|
|
|
2155
2167
|
interactionEndpoint: _interactionEndpoint,
|
|
2156
2168
|
nativeIdentity: _nativeIdentity,
|
|
2157
2169
|
nativePaneBirthId: _nativePaneBirthId,
|
|
2170
|
+
floating: _floating,
|
|
2158
2171
|
...row
|
|
2159
2172
|
}) => row,
|
|
2160
2173
|
);
|
|
@@ -2431,6 +2444,7 @@ export class NativeTerminalAttachmentRuntime {
|
|
|
2431
2444
|
interactionEndpoint: _interactionEndpoint,
|
|
2432
2445
|
nativeIdentity: _nativeIdentity,
|
|
2433
2446
|
nativePaneBirthId: _nativePaneBirthId,
|
|
2447
|
+
floating: _floating,
|
|
2434
2448
|
...row
|
|
2435
2449
|
}) => row,
|
|
2436
2450
|
),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { WindowLinkTopology } from "@tmux-ide/contracts";
|
|
2
|
-
import type { NativeGridCapture } from "./native-grid-capture.ts";
|
|
2
|
+
import type { NativeGridCapture, NativeHistoryPiece } from "./native-grid-capture.ts";
|
|
3
3
|
/**
|
|
4
4
|
* Public event contract of the daemon MirrorService (m43 card 1).
|
|
5
5
|
*
|
|
@@ -78,10 +78,26 @@ export type MirrorPaneEvent =
|
|
|
78
78
|
state: "paused" | "resumed";
|
|
79
79
|
reason: "backpressure" | "requested";
|
|
80
80
|
}
|
|
81
|
+
| {
|
|
82
|
+
/**
|
|
83
|
+
* #873: the answer to this subscriber's own `requestNativeHistory`, in
|
|
84
|
+
* stream order: every delta before it was read before tmux read the
|
|
85
|
+
* piece, every delta after it later. Null when the read failed or output
|
|
86
|
+
* crossed it; the requester may ask again.
|
|
87
|
+
*/
|
|
88
|
+
type: "history";
|
|
89
|
+
piece: NativeHistoryPiece | null;
|
|
90
|
+
}
|
|
81
91
|
| {
|
|
82
92
|
/** Native recovery exhausted its bounds; this is not evidence of pane deletion. */
|
|
83
93
|
type: "fault";
|
|
84
94
|
reason: "native-recovery-failed";
|
|
95
|
+
/**
|
|
96
|
+
* Present only when the pane's recoveries failed in a row and this one
|
|
97
|
+
* was refused without asking tmux (#869, #872): how long until the pane
|
|
98
|
+
* is asked again, and why its last real try failed.
|
|
99
|
+
*/
|
|
100
|
+
hold?: MirrorPaneHold;
|
|
85
101
|
}
|
|
86
102
|
| {
|
|
87
103
|
/** The pane is gone from tmux truth (a successful list-panes reply that
|
|
@@ -89,6 +105,15 @@ export type MirrorPaneEvent =
|
|
|
89
105
|
type: "closed";
|
|
90
106
|
};
|
|
91
107
|
|
|
108
|
+
/** Why a held pane's last real recovery failed: its capture was over the size cap, or anything else. */
|
|
109
|
+
export type MirrorPaneHoldWhy = "too-large" | "failed";
|
|
110
|
+
|
|
111
|
+
export interface MirrorPaneHold {
|
|
112
|
+
/** Whole milliseconds until a new recovery asks tmux again; at least 1. */
|
|
113
|
+
readonly retryInMs: number;
|
|
114
|
+
readonly why: MirrorPaneHoldWhy;
|
|
115
|
+
}
|
|
116
|
+
|
|
92
117
|
/** One visible pane rectangle inside a layout event, in window cells. */
|
|
93
118
|
export interface MirrorLayoutPane {
|
|
94
119
|
browserIcon?: string | null;
|
|
@@ -154,6 +179,11 @@ export interface MirrorPaneDescription {
|
|
|
154
179
|
displayNameSource: "manual" | "agent" | "process" | "title" | "generated";
|
|
155
180
|
windowName: string | null;
|
|
156
181
|
active: boolean;
|
|
182
|
+
/**
|
|
183
|
+
* #882: a floating pane (tmux 3.7 and later). It is listed, but it has no
|
|
184
|
+
* cell in the tiled layout, so no stream attaches to it or waits for it.
|
|
185
|
+
*/
|
|
186
|
+
floating?: true;
|
|
157
187
|
}
|
|
158
188
|
|
|
159
189
|
/** Identity-join diagnostic, stripped of runtime addresses at the boundary. */
|
|
@@ -55,6 +55,7 @@ import {
|
|
|
55
55
|
import type { TrustedMirrorSessionInventory } from "./trusted-inventory.ts";
|
|
56
56
|
import type { InputAction } from "../protocol/input-coalescer.ts";
|
|
57
57
|
import type { NativeGridReadResult } from "./native-grid-reader.ts";
|
|
58
|
+
import type { NativeHistoryRequest } from "./native-grid-capture.ts";
|
|
58
59
|
import {
|
|
59
60
|
controlModeAuthorityKey,
|
|
60
61
|
processControlModeOwnershipRegistry,
|
|
@@ -141,6 +142,12 @@ export interface MirrorSubscription {
|
|
|
141
142
|
captureNativeBacking?(): Promise<NativeGridReadResult>;
|
|
142
143
|
/** Native metadata on this exact retained pane; null means unavailable. */
|
|
143
144
|
readHistorySize?(): Promise<number | null>;
|
|
145
|
+
/**
|
|
146
|
+
* #873: read older native history rows. The answer is one `history` event on
|
|
147
|
+
* this subscription, in stream order. False when nothing was sent (no
|
|
148
|
+
* event follows).
|
|
149
|
+
*/
|
|
150
|
+
requestNativeHistory?(request: NativeHistoryRequest): boolean;
|
|
144
151
|
readonly session: string;
|
|
145
152
|
readonly semanticPaneId: string;
|
|
146
153
|
/** Park delivery for this subscriber (offscreen freeze). Siblings and other
|
|
@@ -383,6 +390,17 @@ export class MirrorService {
|
|
|
383
390
|
return identity;
|
|
384
391
|
}
|
|
385
392
|
|
|
393
|
+
/**
|
|
394
|
+
* #872: a person asked to retry these panes now. Each one's next recovery
|
|
395
|
+
* asks tmux even inside a hold after failed recoveries. A session without a
|
|
396
|
+
* channel has no hold to lift.
|
|
397
|
+
*/
|
|
398
|
+
liftRecoveryHolds(session: string, semanticPaneIds: readonly string[]): void {
|
|
399
|
+
const entry = this.channels.get(session);
|
|
400
|
+
if (!entry || entry.retired) return;
|
|
401
|
+
for (const semanticPaneId of semanticPaneIds) entry.channel.liftRecoveryHold(semanticPaneId);
|
|
402
|
+
}
|
|
403
|
+
|
|
386
404
|
async subscribe(request: MirrorSubscribeRequest): Promise<MirrorSubscription> {
|
|
387
405
|
const entry = await this.acquire(request.session);
|
|
388
406
|
let handle;
|
|
@@ -405,6 +423,7 @@ export class MirrorService {
|
|
|
405
423
|
thaw: () => handle.thaw(),
|
|
406
424
|
reseed: () => handle.reseed(),
|
|
407
425
|
readHistorySize: () => handle.readHistorySize(),
|
|
426
|
+
requestNativeHistory: (historyRequest) => handle.requestNativeHistory(historyRequest),
|
|
408
427
|
captureNativeBacking: () => handle.captureNativeBacking(),
|
|
409
428
|
sendText: (text) => {
|
|
410
429
|
this.assertWindowOwnership(request.session);
|
|
@@ -43,6 +43,7 @@ function validLimit(limit: number): boolean {
|
|
|
43
43
|
export function nativeAtomicSnapshotPlan(
|
|
44
44
|
target: NativeAtomicSnapshotTarget,
|
|
45
45
|
maxBytes = NATIVE_ATOMIC_SNAPSHOT_MAX_BYTES,
|
|
46
|
+
historyRows?: number,
|
|
46
47
|
): OwnedViewerRequest {
|
|
47
48
|
const validated = TargetSchema.parse(target);
|
|
48
49
|
const continuationBytes = `%continue ${validated.paneId}\n`.length;
|
|
@@ -61,7 +62,7 @@ export function nativeAtomicSnapshotPlan(
|
|
|
61
62
|
"-U",
|
|
62
63
|
String(maxBytes - continuationBytes),
|
|
63
64
|
"-S",
|
|
64
|
-
|
|
65
|
+
historyStart(historyRows),
|
|
65
66
|
"-t",
|
|
66
67
|
validated.paneId,
|
|
67
68
|
],
|
|
@@ -70,6 +71,13 @@ export function nativeAtomicSnapshotPlan(
|
|
|
70
71
|
limits: { maxBytes, maxLines: MAX_LINES },
|
|
71
72
|
};
|
|
72
73
|
}
|
|
74
|
+
/** #873: `-S -` reads all history; `-S -N` the newest N rows. */
|
|
75
|
+
function historyStart(historyRows: number | undefined): string {
|
|
76
|
+
if (historyRows === undefined) return "-";
|
|
77
|
+
if (!Number.isSafeInteger(historyRows) || historyRows < 0 || historyRows > 1_000_000)
|
|
78
|
+
throw new TypeError("Invalid atomic snapshot history rows");
|
|
79
|
+
return `-${historyRows}`;
|
|
80
|
+
}
|
|
73
81
|
const decimal = (value: string | undefined): number | null =>
|
|
74
82
|
value !== undefined && /^(0|[1-9][0-9]*)$/u.test(value) && Number.isSafeInteger(Number(value))
|
|
75
83
|
? Number(value)
|
|
@@ -84,7 +92,7 @@ function validModes(line: string, capture: NativeGridCapture): boolean {
|
|
|
84
92
|
numeric[1] !== capture.cursor[1] ||
|
|
85
93
|
numeric[2] !== capture.cols ||
|
|
86
94
|
numeric[3] !== capture.rows ||
|
|
87
|
-
numeric[4] !== capture.history ||
|
|
95
|
+
numeric[4] !== capture.history + (capture.omittedHistory ?? 0) ||
|
|
88
96
|
numeric[5] !== capture.limit
|
|
89
97
|
)
|
|
90
98
|
return false;
|
|
@@ -138,7 +146,9 @@ export function decodeNativeAtomicSnapshot(
|
|
|
138
146
|
// Native Q emits this notification inside its own child frame. It must be
|
|
139
147
|
// terminal and exact; a separate asynchronous notification proves nothing here.
|
|
140
148
|
if (reply.lines.at(-1) !== `%continue ${expected.paneId}`) return unknown;
|
|
141
|
-
const capture = decodeNativeGridCapture(reply.lines.slice(1, -1).join("\n") + "\n"
|
|
149
|
+
const capture = decodeNativeGridCapture(reply.lines.slice(1, -1).join("\n") + "\n", {
|
|
150
|
+
tail: true,
|
|
151
|
+
});
|
|
142
152
|
if (!capture || !isNativeBootstrapCapture(capture) || !validModes(metadata.cursor, capture))
|
|
143
153
|
return unknown;
|
|
144
154
|
return {
|
|
@@ -179,8 +189,9 @@ export type NativeAtomicDualSnapshotResult =
|
|
|
179
189
|
export function nativeAtomicDualSnapshotPlan(
|
|
180
190
|
target: NativeAtomicSnapshotTarget,
|
|
181
191
|
maxBytes = NATIVE_ATOMIC_SNAPSHOT_MAX_BYTES,
|
|
192
|
+
historyRows?: number,
|
|
182
193
|
): OwnedViewerRequest {
|
|
183
|
-
const plan = nativeAtomicSnapshotPlan(target, maxBytes);
|
|
194
|
+
const plan = nativeAtomicSnapshotPlan(target, maxBytes, historyRows);
|
|
184
195
|
return {
|
|
185
196
|
...plan,
|
|
186
197
|
commands: [
|
|
@@ -193,7 +204,7 @@ export function nativeAtomicDualSnapshotPlan(
|
|
|
193
204
|
"-U",
|
|
194
205
|
String(maxBytes),
|
|
195
206
|
"-S",
|
|
196
|
-
|
|
207
|
+
historyStart(historyRows),
|
|
197
208
|
"-t",
|
|
198
209
|
target.paneId,
|
|
199
210
|
],
|
|
@@ -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(
|
|
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
|
-
|
|
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
|
+
}
|