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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { NativeGridCapture } from "../mirror/native-grid-capture.ts";
|
|
1
|
+
import type { NativeGridCapture, NativeHistoryPiece } from "../mirror/native-grid-capture.ts";
|
|
2
2
|
import type { MirrorObservedTerminalModes } from "../mirror/events.ts";
|
|
3
3
|
import type {
|
|
4
4
|
TerminalReplicaCursor,
|
|
@@ -32,6 +32,21 @@ export interface TerminalInterpreterBackend {
|
|
|
32
32
|
/** Exact native painted state; false means this parser cannot import it. */
|
|
33
33
|
canImportNativeGrid?(): boolean;
|
|
34
34
|
importNativeGrid?(snapshot: NativeGridCapture): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* #873: tmux history rows older than the oldest row held, left out by the
|
|
37
|
+
* last native import and not yet prepended or collected. tmux's history
|
|
38
|
+
* size is this plus the history rows held. Zero after any other start.
|
|
39
|
+
*/
|
|
40
|
+
omittedHistory?(): number;
|
|
41
|
+
/** #873: the most history rows this parser holds (DAEMON_HISTORY_ROW_CAP unless set). */
|
|
42
|
+
historyRowCap?(): number;
|
|
43
|
+
/**
|
|
44
|
+
* #873: prepend the piece's rows that are older than the oldest row held.
|
|
45
|
+
* Applies only on the normal screen, at the piece's width, when the piece
|
|
46
|
+
* was read at this history size and reaches the oldest row held; otherwise
|
|
47
|
+
* changes nothing and returns false.
|
|
48
|
+
*/
|
|
49
|
+
prependNativeHistory?(piece: NativeHistoryPiece): boolean;
|
|
35
50
|
resize(cols: number, rows: number): void;
|
|
36
51
|
/** x === cols preserves native wrap-pending state; project() returns a cell position. */
|
|
37
52
|
setAuthoritativeCursor(x: number, y: number): void;
|
|
@@ -81,8 +96,16 @@ export interface TerminalInterpreterBackendFactoryOptions {
|
|
|
81
96
|
readonly scrollback: number;
|
|
82
97
|
/** Native collection policy; retained capacity can be larger after tmux reflow. */
|
|
83
98
|
readonly historyLimit?: number;
|
|
99
|
+
/**
|
|
100
|
+
* #873: the most history rows the daemon holds for a pane, whatever tmux's
|
|
101
|
+
* history-limit. Older rows stay in tmux and count as left out.
|
|
102
|
+
*/
|
|
103
|
+
readonly historyRowCap?: number;
|
|
84
104
|
}
|
|
85
105
|
|
|
106
|
+
/** #873, owner decision of 25 Nov 2026: the daemon holds at most this many history rows per pane. */
|
|
107
|
+
export const DAEMON_HISTORY_ROW_CAP = 10_000;
|
|
108
|
+
|
|
86
109
|
export type TerminalInterpreterBackendFactory = (
|
|
87
110
|
options: TerminalInterpreterBackendFactoryOptions,
|
|
88
111
|
) => TerminalInterpreterBackend;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { assertStockCaptureRepresentable } from "./stock-capture-fidelity.ts";
|
|
2
2
|
import { logger } from "../../lib/log.ts";
|
|
3
3
|
import { rememberNativeSeedBacking } from "./native-seed-backing.ts";
|
|
4
|
-
import type { NativeGridCapture } from "../mirror/native-grid-capture.ts";
|
|
4
|
+
import type { NativeGridCapture, NativeHistoryPiece } from "../mirror/native-grid-capture.ts";
|
|
5
5
|
import type { MirrorObservedTerminalModes } from "../mirror/events.ts";
|
|
6
6
|
import {
|
|
7
7
|
detectWidgetMarkerFromReplicaRows,
|
|
@@ -34,9 +34,10 @@ import {
|
|
|
34
34
|
type SessionRuntimeObservability,
|
|
35
35
|
type SessionRuntimeTraceContext,
|
|
36
36
|
} from "./runtime-observability.ts";
|
|
37
|
-
import
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
import {
|
|
38
|
+
DAEMON_HISTORY_ROW_CAP,
|
|
39
|
+
type TerminalInterpreterBackend,
|
|
40
|
+
type TerminalInterpreterBackendFactory,
|
|
40
41
|
} from "./terminal-interpreter-backend.ts";
|
|
41
42
|
import { createXtermTerminalInterpreterBackend } from "./xterm-terminal-interpreter-backend.ts";
|
|
42
43
|
import {
|
|
@@ -148,6 +149,8 @@ export interface TerminalReplicaInterpreterOptions {
|
|
|
148
149
|
readonly cols: number;
|
|
149
150
|
readonly rows: number;
|
|
150
151
|
readonly scrollback?: number;
|
|
152
|
+
/** #873: the most history rows held per pane; DAEMON_HISTORY_ROW_CAP by default. */
|
|
153
|
+
readonly historyRowCap?: number;
|
|
151
154
|
readonly onUpdate?: (
|
|
152
155
|
update: CanonicalTerminalReplicaUpdate,
|
|
153
156
|
trace: SessionRuntimeTraceContext | null,
|
|
@@ -191,6 +194,7 @@ export class TerminalReplicaInterpreter {
|
|
|
191
194
|
readonly #semanticPaneId: string;
|
|
192
195
|
readonly #incarnation: string;
|
|
193
196
|
#scrollback: number;
|
|
197
|
+
readonly #historyRowCap: number;
|
|
194
198
|
readonly #listeners = new Set<
|
|
195
199
|
(update: CanonicalTerminalReplicaUpdate, trace: SessionRuntimeTraceContext | null) => void
|
|
196
200
|
>();
|
|
@@ -260,6 +264,7 @@ export class TerminalReplicaInterpreter {
|
|
|
260
264
|
this.#incarnation = options.incarnation;
|
|
261
265
|
this.#revision = options.initialRevision ?? 0;
|
|
262
266
|
this.#scrollback = options.scrollback ?? 5000;
|
|
267
|
+
this.#historyRowCap = options.historyRowCap ?? DAEMON_HISTORY_ROW_CAP;
|
|
263
268
|
this.#onRawCommit = options.onRawCommit;
|
|
264
269
|
this.#onNativeReseedRequired = options.onNativeReseedRequired;
|
|
265
270
|
this.#scheduler = options.scheduler ?? SYSTEM_SESSION_RUNTIME_SCHEDULER;
|
|
@@ -269,6 +274,7 @@ export class TerminalReplicaInterpreter {
|
|
|
269
274
|
cols: options.cols,
|
|
270
275
|
rows: options.rows,
|
|
271
276
|
scrollback: this.#scrollback,
|
|
277
|
+
historyRowCap: this.#historyRowCap,
|
|
272
278
|
});
|
|
273
279
|
this.#backend.startHistoryCollection?.();
|
|
274
280
|
this.#kitty = new KittyImageStore(
|
|
@@ -336,6 +342,36 @@ export class TerminalReplicaInterpreter {
|
|
|
336
342
|
return this.#append(admitted);
|
|
337
343
|
}
|
|
338
344
|
|
|
345
|
+
/**
|
|
346
|
+
* #873: prepend the older history rows of a piece read from tmux, in order
|
|
347
|
+
* with the writes queued before it. True when the rows were prepended and a
|
|
348
|
+
* new revision published; false when the piece does not fit the replica as
|
|
349
|
+
* it is at that point of the stream (see the backend's prependNativeHistory).
|
|
350
|
+
*/
|
|
351
|
+
prependNativeHistory(piece: NativeHistoryPiece): Promise<boolean> {
|
|
352
|
+
this.#flushWrites();
|
|
353
|
+
const run = this.#tail.then(() => this.#applyHistoryPiece(piece));
|
|
354
|
+
this.#tail = run.then(
|
|
355
|
+
() => undefined,
|
|
356
|
+
() => undefined,
|
|
357
|
+
);
|
|
358
|
+
return run;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* #873: tmux history rows older than the replica's oldest history row; tmux's
|
|
363
|
+
* history size is this plus the replica's history rows. Set by a native seed
|
|
364
|
+
* that left them out, zero after any other seed.
|
|
365
|
+
*/
|
|
366
|
+
omittedHistory(): number {
|
|
367
|
+
return this.#backend.omittedHistory?.() ?? 0;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
/** #873: the most history rows the replica holds; the backfill stops there. */
|
|
371
|
+
historyRowCap(): number {
|
|
372
|
+
return this.#historyRowCap;
|
|
373
|
+
}
|
|
374
|
+
|
|
339
375
|
whenIdle(): Promise<void> {
|
|
340
376
|
this.#flushWrites();
|
|
341
377
|
return this.#tail;
|
|
@@ -455,13 +491,14 @@ export class TerminalReplicaInterpreter {
|
|
|
455
491
|
const scrollback = Math.max(
|
|
456
492
|
operation.historyLimit ?? this.#scrollback,
|
|
457
493
|
operation.historySize ?? 0,
|
|
458
|
-
operation.native?.history ?? 0,
|
|
494
|
+
(operation.native?.history ?? 0) + (operation.native?.omittedHistory ?? 0),
|
|
459
495
|
);
|
|
460
496
|
const replacement = this.#backendFactory({
|
|
461
497
|
cols: nativeCols,
|
|
462
498
|
rows: nativeRows,
|
|
463
499
|
scrollback,
|
|
464
500
|
historyLimit: operation.historyLimit ?? scrollback,
|
|
501
|
+
historyRowCap: this.#historyRowCap,
|
|
465
502
|
});
|
|
466
503
|
try {
|
|
467
504
|
if (operation.native && !replacement.importNativeGrid?.(operation.native))
|
|
@@ -594,6 +631,25 @@ export class TerminalReplicaInterpreter {
|
|
|
594
631
|
this.#emit(update);
|
|
595
632
|
}
|
|
596
633
|
|
|
634
|
+
#applyHistoryPiece(piece: NativeHistoryPiece): boolean {
|
|
635
|
+
if (
|
|
636
|
+
this.#closed ||
|
|
637
|
+
this.#needsSeed ||
|
|
638
|
+
this.#nativeReseedRequested ||
|
|
639
|
+
this.#pendingResize !== null ||
|
|
640
|
+
this.#backend.requiresNativeReseed() ||
|
|
641
|
+
// A synchronized update publishes nothing until it ends.
|
|
642
|
+
this.#backend.modes().synchronizedOutput ||
|
|
643
|
+
!this.#backend.prependNativeHistory?.(piece)
|
|
644
|
+
)
|
|
645
|
+
return false;
|
|
646
|
+
// Image anchors are absolute buffer lines; prepended rows moved them all.
|
|
647
|
+
this.#kitty.dropCursorPlacements();
|
|
648
|
+
this.#commit(false);
|
|
649
|
+
this.#publishGraphics();
|
|
650
|
+
return true;
|
|
651
|
+
}
|
|
652
|
+
|
|
597
653
|
async #write(
|
|
598
654
|
data: Uint8Array,
|
|
599
655
|
continuedTrace: SessionRuntimeTraceContext | null,
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { MirrorPaneHeldError } from "../mirror/pane-hold.ts";
|
|
1
2
|
import {
|
|
2
3
|
HistoryAnchorOwner,
|
|
3
4
|
type HistoryAnchorIdentity,
|
|
4
5
|
type HistoryAnchorProof,
|
|
5
6
|
} from "./history-anchor-owner.ts";
|
|
6
7
|
import { layoutContentRows } from "../mirror/layout-content-rows.ts";
|
|
7
|
-
import type
|
|
8
|
+
import { nativeHistoryPieceRows, type NativeGridCapture } from "../mirror/native-grid-capture.ts";
|
|
8
9
|
import type {
|
|
9
10
|
CanonicalTerminalReplicaUpdate,
|
|
10
11
|
CausalCellFailureReasonV1,
|
|
@@ -47,6 +48,20 @@ export type TerminalReplicaSourceSubscription = TerminalReplicaSubscription;
|
|
|
47
48
|
* enough that switching away and back stays warm.
|
|
48
49
|
*/
|
|
49
50
|
export const PARK_AFTER_MS = 10_000;
|
|
51
|
+
/**
|
|
52
|
+
* #873 backfill: a native seed can leave out the oldest history rows; the
|
|
53
|
+
* owner then asks tmux for them piece by piece. A null answer (output crossed
|
|
54
|
+
* the read) or a piece that no longer fits is asked again after
|
|
55
|
+
* BACKFILL_FIRST_RETRY_MS, doubling up to BACKFILL_MAX_RETRY_MS. After
|
|
56
|
+
* BACKFILL_MAX_FAILURES in a row (about 48 s of a pane that never pauses) the
|
|
57
|
+
* owner stops until the next seed; the replica stays correct without the
|
|
58
|
+
* older rows, it only lacks them. While the alternate screen is active it
|
|
59
|
+
* checks again every BACKFILL_ALTERNATE_WAIT_MS without counting a failure.
|
|
60
|
+
*/
|
|
61
|
+
export const BACKFILL_FIRST_RETRY_MS = 250;
|
|
62
|
+
export const BACKFILL_MAX_RETRY_MS = 4_000;
|
|
63
|
+
export const BACKFILL_MAX_FAILURES = 16;
|
|
64
|
+
export const BACKFILL_ALTERNATE_WAIT_MS = 1_000;
|
|
50
65
|
|
|
51
66
|
export interface TerminalReplicaCommittedRaw {
|
|
52
67
|
readonly baseRevision: number;
|
|
@@ -129,6 +144,14 @@ export class SessionRuntimeTerminalReplicaOwner {
|
|
|
129
144
|
#historyChecking = false;
|
|
130
145
|
#historyDirty = false;
|
|
131
146
|
#reconstructedHistoryGap: { readonly seed: number; readonly gap: number } | null = null;
|
|
147
|
+
// #873 backfill. A new seed, resize, park or disposal starts a new token;
|
|
148
|
+
// anything from an older token is ignored.
|
|
149
|
+
#backfillToken = 0;
|
|
150
|
+
// The token of each history request sent and not yet answered, oldest first.
|
|
151
|
+
// Answers arrive in request order, so each one belongs to the first entry.
|
|
152
|
+
readonly #backfillAsked: number[] = [];
|
|
153
|
+
#backfillFailures = 0;
|
|
154
|
+
#backfillTimer: SessionRuntimeTimer | null = null;
|
|
132
155
|
|
|
133
156
|
constructor(
|
|
134
157
|
readonly generation: SessionRuntimeGeneration,
|
|
@@ -144,6 +167,8 @@ export class SessionRuntimeTerminalReplicaOwner {
|
|
|
144
167
|
readonly scheduler?: SessionRuntimeScheduler;
|
|
145
168
|
readonly observability?: SessionRuntimeObservability;
|
|
146
169
|
readonly takeOutputTrace?: () => SessionRuntimeTraceContext | null;
|
|
170
|
+
/** #873: the most history rows held for this pane (DAEMON_HISTORY_ROW_CAP). */
|
|
171
|
+
readonly historyRowCap?: number;
|
|
147
172
|
},
|
|
148
173
|
) {
|
|
149
174
|
this.#onClosed = options.onClosed;
|
|
@@ -161,10 +186,12 @@ export class SessionRuntimeTerminalReplicaOwner {
|
|
|
161
186
|
rows: this.#rows,
|
|
162
187
|
scheduler: options.scheduler,
|
|
163
188
|
observability: options.observability,
|
|
189
|
+
...(options.historyRowCap !== undefined ? { historyRowCap: options.historyRowCap } : {}),
|
|
164
190
|
onNativeReseedRequired: () => {
|
|
165
191
|
if (this.#disposed || this.#reseed || this.#waitingForGeometryCapture) return;
|
|
166
192
|
this.#waitingForGeometryCapture = true;
|
|
167
193
|
this.#historyAnchors.invalidate();
|
|
194
|
+
this.#cancelBackfill();
|
|
168
195
|
this.#supervise(
|
|
169
196
|
this.#start.then(() => {
|
|
170
197
|
if (!this.#disposed && this.#waitingForGeometryCapture) this.#upstream?.reseed();
|
|
@@ -301,6 +328,8 @@ export class SessionRuntimeTerminalReplicaOwner {
|
|
|
301
328
|
const initial = this.#interpreter.currentSeed();
|
|
302
329
|
if (!initial || this.#stale || this.#reseed || this.#waitingForGeometryCapture)
|
|
303
330
|
return { status: "changed" };
|
|
331
|
+
// #873: tmux holds older rows than the replica; its rows cannot line up.
|
|
332
|
+
if (this.#interpreter.omittedHistory() > 0) return { status: "mismatch" };
|
|
304
333
|
const epoch = this.#subscriptionEpoch;
|
|
305
334
|
const captured = await upstream.captureNativeBacking();
|
|
306
335
|
if (captured.status !== "captured") return captured;
|
|
@@ -414,6 +443,7 @@ export class SessionRuntimeTerminalReplicaOwner {
|
|
|
414
443
|
if (this.#disposed || this.#parked || this.#listeners.size > 0 || !this.#upstream) return;
|
|
415
444
|
this.#parked = true;
|
|
416
445
|
this.#stale = true;
|
|
446
|
+
this.#cancelBackfill();
|
|
417
447
|
this.#upstream.freeze();
|
|
418
448
|
}, PARK_AFTER_MS);
|
|
419
449
|
}
|
|
@@ -480,6 +510,7 @@ export class SessionRuntimeTerminalReplicaOwner {
|
|
|
480
510
|
this.#historyTimer = null;
|
|
481
511
|
this.#parkTimer?.cancel();
|
|
482
512
|
this.#parkTimer = null;
|
|
513
|
+
this.#cancelBackfill();
|
|
483
514
|
this.#subscriptionEpoch += 1;
|
|
484
515
|
await this.#interpreter.enqueue({ type: "close", reason });
|
|
485
516
|
await this.#start.catch(() => undefined);
|
|
@@ -522,6 +553,8 @@ export class SessionRuntimeTerminalReplicaOwner {
|
|
|
522
553
|
return;
|
|
523
554
|
const seed = this.#interpreter.currentSeed();
|
|
524
555
|
if (!seed) return;
|
|
556
|
+
// A native seed can leave out tmux's oldest rows (#873): tmux then holds
|
|
557
|
+
// that many more than the replica, until the backfill prepends them.
|
|
525
558
|
const gap = size - seed.snapshot.history.length;
|
|
526
559
|
// A seed with reconstructed tabs can differ from tmux in row count, and
|
|
527
560
|
// a new capture would paint the same rows again. Accept the difference
|
|
@@ -534,7 +567,7 @@ export class SessionRuntimeTerminalReplicaOwner {
|
|
|
534
567
|
return;
|
|
535
568
|
}
|
|
536
569
|
if (this.#reconstructedHistoryGap.gap === gap) return;
|
|
537
|
-
} else if (gap ===
|
|
570
|
+
} else if (gap === this.#interpreter.omittedHistory()) return;
|
|
538
571
|
upstream.reseed();
|
|
539
572
|
} catch {
|
|
540
573
|
// Unavailable metadata is not evidence that history disappeared.
|
|
@@ -545,6 +578,10 @@ export class SessionRuntimeTerminalReplicaOwner {
|
|
|
545
578
|
}
|
|
546
579
|
|
|
547
580
|
#observePane(event: MirrorPaneEvent): void {
|
|
581
|
+
if (event.type === "history") {
|
|
582
|
+
this.#observeHistoryPiece(event.piece);
|
|
583
|
+
return;
|
|
584
|
+
}
|
|
548
585
|
if (event.type === "delta") {
|
|
549
586
|
this.#historyDirty = true;
|
|
550
587
|
this.#scheduleHistoryCheck();
|
|
@@ -554,6 +591,7 @@ export class SessionRuntimeTerminalReplicaOwner {
|
|
|
554
591
|
// armed after reset belongs to the next post-capture delta, never to this
|
|
555
592
|
// already-started reseed.
|
|
556
593
|
this.#historyAnchors.invalidate();
|
|
594
|
+
this.#cancelBackfill();
|
|
557
595
|
this.#reseed = {
|
|
558
596
|
nativeCols: event.cols,
|
|
559
597
|
nativeRows: event.rows,
|
|
@@ -591,35 +629,37 @@ export class SessionRuntimeTerminalReplicaOwner {
|
|
|
591
629
|
const lease = reseed ? this.#qualifyReseed(reseed, event.x, event.y) : null;
|
|
592
630
|
this.#supervise(
|
|
593
631
|
reseed && lease
|
|
594
|
-
? this.#interpreter
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
632
|
+
? this.#interpreter
|
|
633
|
+
.enqueue({
|
|
634
|
+
type: "reseed",
|
|
635
|
+
nativeCols: reseed.nativeCols,
|
|
636
|
+
nativeRows: reseed.nativeRows,
|
|
637
|
+
cols: reseed.nativeCols,
|
|
638
|
+
rows: reseed.nativeRows,
|
|
639
|
+
chunks: reseed.chunks,
|
|
640
|
+
captureChunks: reseed.captureChunks,
|
|
641
|
+
native: reseed.native,
|
|
642
|
+
historyLimit: event.historyLimit,
|
|
643
|
+
historySize: event.historySize,
|
|
644
|
+
trace: reseed.trace,
|
|
645
|
+
// tmux can retain an offscreen x after a non-reflow width shrink
|
|
646
|
+
// (screen_resize_cursor), as well as x === cols for wrap pending.
|
|
647
|
+
// Preserve wrap pending in the parser. The backend's canonical
|
|
648
|
+
// projection, not its input cursor, clamps to the final cell.
|
|
649
|
+
cursor: { x: event.x, y: event.y },
|
|
650
|
+
wraparound: event.wraparound,
|
|
651
|
+
observedModes: event.observedModes,
|
|
652
|
+
bootstrap: "painted-capture",
|
|
653
|
+
validateBeforeCommit: () => this.#leaseIsCurrent(lease, reseed.subscriptionEpoch),
|
|
654
|
+
onInvalidated: () =>
|
|
655
|
+
this.#retryReseedOrFault(
|
|
656
|
+
"terminal reseed layout lease crossed",
|
|
657
|
+
reseed,
|
|
658
|
+
"before-commit",
|
|
659
|
+
"lease-crossed",
|
|
660
|
+
),
|
|
661
|
+
})
|
|
662
|
+
.then(() => this.#startBackfill())
|
|
623
663
|
: reseed
|
|
624
664
|
? (this.#retryReseedOrFault(
|
|
625
665
|
`terminal reseed geometry is incompatible: capture ${reseed.nativeCols}x${reseed.nativeRows}, layout ${reseed.layoutLease?.pane.width}x${reseed.layoutLease?.pane.height}, border ${reseed.layoutLease?.paneBorderStatus}`,
|
|
@@ -638,7 +678,9 @@ export class SessionRuntimeTerminalReplicaOwner {
|
|
|
638
678
|
);
|
|
639
679
|
} else if (event.type === "fault") {
|
|
640
680
|
this.#noteLifecycle("upstream-fault");
|
|
641
|
-
const error =
|
|
681
|
+
const error = event.hold
|
|
682
|
+
? new MirrorPaneHeldError(event.hold)
|
|
683
|
+
: new Error("Native terminal recovery failed");
|
|
642
684
|
this.#interpreter.abort(error);
|
|
643
685
|
this.#onFault?.(error);
|
|
644
686
|
} else if (event.type === "closed") {
|
|
@@ -655,6 +697,89 @@ export class SessionRuntimeTerminalReplicaOwner {
|
|
|
655
697
|
}
|
|
656
698
|
}
|
|
657
699
|
|
|
700
|
+
#cancelBackfill(): void {
|
|
701
|
+
this.#backfillToken += 1;
|
|
702
|
+
this.#backfillFailures = 0;
|
|
703
|
+
this.#backfillTimer?.cancel();
|
|
704
|
+
this.#backfillTimer = null;
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
/** After a seed commits: ask for the rows it left out, if any. */
|
|
708
|
+
#startBackfill(): void {
|
|
709
|
+
this.#cancelBackfill();
|
|
710
|
+
void this.#askForHistory(this.#backfillToken);
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
async #askForHistory(token: number): Promise<void> {
|
|
714
|
+
await this.#interpreter.whenIdle();
|
|
715
|
+
if (
|
|
716
|
+
token !== this.#backfillToken ||
|
|
717
|
+
this.#disposed ||
|
|
718
|
+
this.#parked ||
|
|
719
|
+
this.#stale ||
|
|
720
|
+
this.#reseed ||
|
|
721
|
+
this.#waitingForGeometryCapture
|
|
722
|
+
)
|
|
723
|
+
return;
|
|
724
|
+
const omitted = this.#interpreter.omittedHistory();
|
|
725
|
+
const upstream = this.#upstream;
|
|
726
|
+
if (omitted <= 0 || !upstream?.requestNativeHistory) return;
|
|
727
|
+
const snapshot = this.#interpreter.currentSnapshot();
|
|
728
|
+
// tmux reads the normal screen's history; the piece is prepended there.
|
|
729
|
+
if (snapshot.modes.alternateScreen) {
|
|
730
|
+
this.#retryBackfill(token, false);
|
|
731
|
+
return;
|
|
732
|
+
}
|
|
733
|
+
// #873: the daemon holds at most the cap; rows past it stay in tmux, left
|
|
734
|
+
// out for good, and are never asked for.
|
|
735
|
+
const room = this.#interpreter.historyRowCap() - snapshot.history.length;
|
|
736
|
+
if (room <= 0) return;
|
|
737
|
+
const sent = upstream.requestNativeHistory({
|
|
738
|
+
endRow: omitted,
|
|
739
|
+
rows: Math.min(room, nativeHistoryPieceRows(snapshot.cols)),
|
|
740
|
+
historySize: omitted + snapshot.history.length,
|
|
741
|
+
});
|
|
742
|
+
if (sent) this.#backfillAsked.push(token);
|
|
743
|
+
else this.#retryBackfill(token, true);
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
#observeHistoryPiece(piece: Extract<MirrorPaneEvent, { type: "history" }>["piece"]): void {
|
|
747
|
+
const token = this.#backfillAsked.shift();
|
|
748
|
+
if (token === undefined || token !== this.#backfillToken || this.#disposed) return;
|
|
749
|
+
if (!piece) {
|
|
750
|
+
this.#retryBackfill(token, true);
|
|
751
|
+
return;
|
|
752
|
+
}
|
|
753
|
+
// Queued now, behind every delta tmux sent before it read the piece.
|
|
754
|
+
this.#supervise(
|
|
755
|
+
this.#interpreter.prependNativeHistory(piece).then((applied) => {
|
|
756
|
+
if (token !== this.#backfillToken) return;
|
|
757
|
+
if (applied) {
|
|
758
|
+
this.#backfillFailures = 0;
|
|
759
|
+
void this.#askForHistory(token);
|
|
760
|
+
} else this.#retryBackfill(token, true);
|
|
761
|
+
}),
|
|
762
|
+
);
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
#retryBackfill(token: number, failed: boolean): void {
|
|
766
|
+
if (token !== this.#backfillToken || this.#disposed) return;
|
|
767
|
+
let delay = BACKFILL_ALTERNATE_WAIT_MS;
|
|
768
|
+
if (failed) {
|
|
769
|
+
this.#backfillFailures += 1;
|
|
770
|
+
if (this.#backfillFailures >= BACKFILL_MAX_FAILURES) return;
|
|
771
|
+
delay = Math.min(
|
|
772
|
+
BACKFILL_MAX_RETRY_MS,
|
|
773
|
+
BACKFILL_FIRST_RETRY_MS * 2 ** (this.#backfillFailures - 1),
|
|
774
|
+
);
|
|
775
|
+
}
|
|
776
|
+
this.#backfillTimer?.cancel();
|
|
777
|
+
this.#backfillTimer = this.#scheduler.timer(() => {
|
|
778
|
+
this.#backfillTimer = null;
|
|
779
|
+
void this.#askForHistory(token);
|
|
780
|
+
}, delay);
|
|
781
|
+
}
|
|
782
|
+
|
|
658
783
|
#observeLayout(event: MirrorLayoutEvent): void {
|
|
659
784
|
const observed = this.#readLayoutLease(event);
|
|
660
785
|
if (observed.kind === "irrelevant") return;
|
|
@@ -678,6 +803,7 @@ export class SessionRuntimeTerminalReplicaOwner {
|
|
|
678
803
|
// One outstanding capture also coalesces geometry bursts; crossed leases
|
|
679
804
|
// request the latest capture through the normal qualification retry path.
|
|
680
805
|
this.#reseedRetryCount = 0;
|
|
806
|
+
this.#cancelBackfill();
|
|
681
807
|
if (!this.#bootstrapped || this.#reseed || this.#waitingForGeometryCapture) return;
|
|
682
808
|
this.#waitingForGeometryCapture = true;
|
|
683
809
|
this.#historyAnchors.invalidate();
|
|
@@ -810,6 +936,7 @@ export class SessionRuntimeTerminalReplicaOwner {
|
|
|
810
936
|
this.#noteLifecycle("reseed-retry", diagnostic);
|
|
811
937
|
this.#reseedRetryCount += 1;
|
|
812
938
|
this.#waitingForGeometryCapture = true;
|
|
939
|
+
this.#cancelBackfill();
|
|
813
940
|
this.#historyAnchors.invalidate();
|
|
814
941
|
void this.#start.then(() => {
|
|
815
942
|
if (!this.#disposed) this.#upstream?.reseed();
|