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,5 +1,7 @@
|
|
|
1
|
+
import { MirrorPaneHeldError } from "../mirror/pane-hold.js";
|
|
1
2
|
import { HistoryAnchorOwner, } from "./history-anchor-owner.js";
|
|
2
3
|
import { layoutContentRows } from "../mirror/layout-content-rows.js";
|
|
4
|
+
import { nativeHistoryPieceRows } from "../mirror/native-grid-capture.js";
|
|
3
5
|
import { terminalReplicaRowsEqual } from "@tmux-ide/core";
|
|
4
6
|
import { projectNativeGridRow } from "../mirror/native-grid-projection.js";
|
|
5
7
|
import { TerminalReplicaInterpreter, } from "./terminal-replica-interpreter.js";
|
|
@@ -10,6 +12,20 @@ import { DISABLED_SESSION_RUNTIME_OBSERVABILITY } from "./runtime-observability.
|
|
|
10
12
|
* enough that switching away and back stays warm.
|
|
11
13
|
*/
|
|
12
14
|
export const PARK_AFTER_MS = 10_000;
|
|
15
|
+
/**
|
|
16
|
+
* #873 backfill: a native seed can leave out the oldest history rows; the
|
|
17
|
+
* owner then asks tmux for them piece by piece. A null answer (output crossed
|
|
18
|
+
* the read) or a piece that no longer fits is asked again after
|
|
19
|
+
* BACKFILL_FIRST_RETRY_MS, doubling up to BACKFILL_MAX_RETRY_MS. After
|
|
20
|
+
* BACKFILL_MAX_FAILURES in a row (about 48 s of a pane that never pauses) the
|
|
21
|
+
* owner stops until the next seed; the replica stays correct without the
|
|
22
|
+
* older rows, it only lacks them. While the alternate screen is active it
|
|
23
|
+
* checks again every BACKFILL_ALTERNATE_WAIT_MS without counting a failure.
|
|
24
|
+
*/
|
|
25
|
+
export const BACKFILL_FIRST_RETRY_MS = 250;
|
|
26
|
+
export const BACKFILL_MAX_RETRY_MS = 4_000;
|
|
27
|
+
export const BACKFILL_MAX_FAILURES = 16;
|
|
28
|
+
export const BACKFILL_ALTERNATE_WAIT_MS = 1_000;
|
|
13
29
|
/** One parser/replica owner for one semantic pane inside one SessionRuntime. */
|
|
14
30
|
export class SessionRuntimeTerminalReplicaOwner {
|
|
15
31
|
generation;
|
|
@@ -46,6 +62,14 @@ export class SessionRuntimeTerminalReplicaOwner {
|
|
|
46
62
|
#historyChecking = false;
|
|
47
63
|
#historyDirty = false;
|
|
48
64
|
#reconstructedHistoryGap = null;
|
|
65
|
+
// #873 backfill. A new seed, resize, park or disposal starts a new token;
|
|
66
|
+
// anything from an older token is ignored.
|
|
67
|
+
#backfillToken = 0;
|
|
68
|
+
// The token of each history request sent and not yet answered, oldest first.
|
|
69
|
+
// Answers arrive in request order, so each one belongs to the first entry.
|
|
70
|
+
#backfillAsked = [];
|
|
71
|
+
#backfillFailures = 0;
|
|
72
|
+
#backfillTimer = null;
|
|
49
73
|
constructor(generation, session, semanticPaneId, mirror, options) {
|
|
50
74
|
this.generation = generation;
|
|
51
75
|
this.session = session;
|
|
@@ -65,11 +89,13 @@ export class SessionRuntimeTerminalReplicaOwner {
|
|
|
65
89
|
rows: this.#rows,
|
|
66
90
|
scheduler: options.scheduler,
|
|
67
91
|
observability: options.observability,
|
|
92
|
+
...(options.historyRowCap !== undefined ? { historyRowCap: options.historyRowCap } : {}),
|
|
68
93
|
onNativeReseedRequired: () => {
|
|
69
94
|
if (this.#disposed || this.#reseed || this.#waitingForGeometryCapture)
|
|
70
95
|
return;
|
|
71
96
|
this.#waitingForGeometryCapture = true;
|
|
72
97
|
this.#historyAnchors.invalidate();
|
|
98
|
+
this.#cancelBackfill();
|
|
73
99
|
this.#supervise(this.#start.then(() => {
|
|
74
100
|
if (!this.#disposed && this.#waitingForGeometryCapture)
|
|
75
101
|
this.#upstream?.reseed();
|
|
@@ -196,6 +222,9 @@ export class SessionRuntimeTerminalReplicaOwner {
|
|
|
196
222
|
const initial = this.#interpreter.currentSeed();
|
|
197
223
|
if (!initial || this.#stale || this.#reseed || this.#waitingForGeometryCapture)
|
|
198
224
|
return { status: "changed" };
|
|
225
|
+
// #873: tmux holds older rows than the replica; its rows cannot line up.
|
|
226
|
+
if (this.#interpreter.omittedHistory() > 0)
|
|
227
|
+
return { status: "mismatch" };
|
|
199
228
|
const epoch = this.#subscriptionEpoch;
|
|
200
229
|
const captured = await upstream.captureNativeBacking();
|
|
201
230
|
if (captured.status !== "captured")
|
|
@@ -304,6 +333,7 @@ export class SessionRuntimeTerminalReplicaOwner {
|
|
|
304
333
|
return;
|
|
305
334
|
this.#parked = true;
|
|
306
335
|
this.#stale = true;
|
|
336
|
+
this.#cancelBackfill();
|
|
307
337
|
this.#upstream.freeze();
|
|
308
338
|
}, PARK_AFTER_MS);
|
|
309
339
|
}
|
|
@@ -359,6 +389,7 @@ export class SessionRuntimeTerminalReplicaOwner {
|
|
|
359
389
|
this.#historyTimer = null;
|
|
360
390
|
this.#parkTimer?.cancel();
|
|
361
391
|
this.#parkTimer = null;
|
|
392
|
+
this.#cancelBackfill();
|
|
362
393
|
this.#subscriptionEpoch += 1;
|
|
363
394
|
await this.#interpreter.enqueue({ type: "close", reason });
|
|
364
395
|
await this.#start.catch(() => undefined);
|
|
@@ -401,6 +432,8 @@ export class SessionRuntimeTerminalReplicaOwner {
|
|
|
401
432
|
const seed = this.#interpreter.currentSeed();
|
|
402
433
|
if (!seed)
|
|
403
434
|
return;
|
|
435
|
+
// A native seed can leave out tmux's oldest rows (#873): tmux then holds
|
|
436
|
+
// that many more than the replica, until the backfill prepends them.
|
|
404
437
|
const gap = size - seed.snapshot.history.length;
|
|
405
438
|
// A seed with reconstructed tabs can differ from tmux in row count, and
|
|
406
439
|
// a new capture would paint the same rows again. Accept the difference
|
|
@@ -415,7 +448,7 @@ export class SessionRuntimeTerminalReplicaOwner {
|
|
|
415
448
|
if (this.#reconstructedHistoryGap.gap === gap)
|
|
416
449
|
return;
|
|
417
450
|
}
|
|
418
|
-
else if (gap ===
|
|
451
|
+
else if (gap === this.#interpreter.omittedHistory())
|
|
419
452
|
return;
|
|
420
453
|
upstream.reseed();
|
|
421
454
|
}
|
|
@@ -429,6 +462,10 @@ export class SessionRuntimeTerminalReplicaOwner {
|
|
|
429
462
|
}
|
|
430
463
|
}
|
|
431
464
|
#observePane(event) {
|
|
465
|
+
if (event.type === "history") {
|
|
466
|
+
this.#observeHistoryPiece(event.piece);
|
|
467
|
+
return;
|
|
468
|
+
}
|
|
432
469
|
if (event.type === "delta") {
|
|
433
470
|
this.#historyDirty = true;
|
|
434
471
|
this.#scheduleHistoryCheck();
|
|
@@ -438,6 +475,7 @@ export class SessionRuntimeTerminalReplicaOwner {
|
|
|
438
475
|
// armed after reset belongs to the next post-capture delta, never to this
|
|
439
476
|
// already-started reseed.
|
|
440
477
|
this.#historyAnchors.invalidate();
|
|
478
|
+
this.#cancelBackfill();
|
|
441
479
|
this.#reseed = {
|
|
442
480
|
nativeCols: event.cols,
|
|
443
481
|
nativeRows: event.rows,
|
|
@@ -479,7 +517,8 @@ export class SessionRuntimeTerminalReplicaOwner {
|
|
|
479
517
|
this.#stale = false;
|
|
480
518
|
const lease = reseed ? this.#qualifyReseed(reseed, event.x, event.y) : null;
|
|
481
519
|
this.#supervise(reseed && lease
|
|
482
|
-
? this.#interpreter
|
|
520
|
+
? this.#interpreter
|
|
521
|
+
.enqueue({
|
|
483
522
|
type: "reseed",
|
|
484
523
|
nativeCols: reseed.nativeCols,
|
|
485
524
|
nativeRows: reseed.nativeRows,
|
|
@@ -502,6 +541,7 @@ export class SessionRuntimeTerminalReplicaOwner {
|
|
|
502
541
|
validateBeforeCommit: () => this.#leaseIsCurrent(lease, reseed.subscriptionEpoch),
|
|
503
542
|
onInvalidated: () => this.#retryReseedOrFault("terminal reseed layout lease crossed", reseed, "before-commit", "lease-crossed"),
|
|
504
543
|
})
|
|
544
|
+
.then(() => this.#startBackfill())
|
|
505
545
|
: reseed
|
|
506
546
|
? (this.#retryReseedOrFault(`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}`, reseed, "capture-qualification", this.#reseedRejection(reseed, event.x, event.y)),
|
|
507
547
|
Promise.resolve())
|
|
@@ -515,7 +555,9 @@ export class SessionRuntimeTerminalReplicaOwner {
|
|
|
515
555
|
}
|
|
516
556
|
else if (event.type === "fault") {
|
|
517
557
|
this.#noteLifecycle("upstream-fault");
|
|
518
|
-
const error =
|
|
558
|
+
const error = event.hold
|
|
559
|
+
? new MirrorPaneHeldError(event.hold)
|
|
560
|
+
: new Error("Native terminal recovery failed");
|
|
519
561
|
this.#interpreter.abort(error);
|
|
520
562
|
this.#onFault?.(error);
|
|
521
563
|
}
|
|
@@ -529,6 +571,87 @@ export class SessionRuntimeTerminalReplicaOwner {
|
|
|
529
571
|
}, () => undefined);
|
|
530
572
|
}
|
|
531
573
|
}
|
|
574
|
+
#cancelBackfill() {
|
|
575
|
+
this.#backfillToken += 1;
|
|
576
|
+
this.#backfillFailures = 0;
|
|
577
|
+
this.#backfillTimer?.cancel();
|
|
578
|
+
this.#backfillTimer = null;
|
|
579
|
+
}
|
|
580
|
+
/** After a seed commits: ask for the rows it left out, if any. */
|
|
581
|
+
#startBackfill() {
|
|
582
|
+
this.#cancelBackfill();
|
|
583
|
+
void this.#askForHistory(this.#backfillToken);
|
|
584
|
+
}
|
|
585
|
+
async #askForHistory(token) {
|
|
586
|
+
await this.#interpreter.whenIdle();
|
|
587
|
+
if (token !== this.#backfillToken ||
|
|
588
|
+
this.#disposed ||
|
|
589
|
+
this.#parked ||
|
|
590
|
+
this.#stale ||
|
|
591
|
+
this.#reseed ||
|
|
592
|
+
this.#waitingForGeometryCapture)
|
|
593
|
+
return;
|
|
594
|
+
const omitted = this.#interpreter.omittedHistory();
|
|
595
|
+
const upstream = this.#upstream;
|
|
596
|
+
if (omitted <= 0 || !upstream?.requestNativeHistory)
|
|
597
|
+
return;
|
|
598
|
+
const snapshot = this.#interpreter.currentSnapshot();
|
|
599
|
+
// tmux reads the normal screen's history; the piece is prepended there.
|
|
600
|
+
if (snapshot.modes.alternateScreen) {
|
|
601
|
+
this.#retryBackfill(token, false);
|
|
602
|
+
return;
|
|
603
|
+
}
|
|
604
|
+
// #873: the daemon holds at most the cap; rows past it stay in tmux, left
|
|
605
|
+
// out for good, and are never asked for.
|
|
606
|
+
const room = this.#interpreter.historyRowCap() - snapshot.history.length;
|
|
607
|
+
if (room <= 0)
|
|
608
|
+
return;
|
|
609
|
+
const sent = upstream.requestNativeHistory({
|
|
610
|
+
endRow: omitted,
|
|
611
|
+
rows: Math.min(room, nativeHistoryPieceRows(snapshot.cols)),
|
|
612
|
+
historySize: omitted + snapshot.history.length,
|
|
613
|
+
});
|
|
614
|
+
if (sent)
|
|
615
|
+
this.#backfillAsked.push(token);
|
|
616
|
+
else
|
|
617
|
+
this.#retryBackfill(token, true);
|
|
618
|
+
}
|
|
619
|
+
#observeHistoryPiece(piece) {
|
|
620
|
+
const token = this.#backfillAsked.shift();
|
|
621
|
+
if (token === undefined || token !== this.#backfillToken || this.#disposed)
|
|
622
|
+
return;
|
|
623
|
+
if (!piece) {
|
|
624
|
+
this.#retryBackfill(token, true);
|
|
625
|
+
return;
|
|
626
|
+
}
|
|
627
|
+
// Queued now, behind every delta tmux sent before it read the piece.
|
|
628
|
+
this.#supervise(this.#interpreter.prependNativeHistory(piece).then((applied) => {
|
|
629
|
+
if (token !== this.#backfillToken)
|
|
630
|
+
return;
|
|
631
|
+
if (applied) {
|
|
632
|
+
this.#backfillFailures = 0;
|
|
633
|
+
void this.#askForHistory(token);
|
|
634
|
+
}
|
|
635
|
+
else
|
|
636
|
+
this.#retryBackfill(token, true);
|
|
637
|
+
}));
|
|
638
|
+
}
|
|
639
|
+
#retryBackfill(token, failed) {
|
|
640
|
+
if (token !== this.#backfillToken || this.#disposed)
|
|
641
|
+
return;
|
|
642
|
+
let delay = BACKFILL_ALTERNATE_WAIT_MS;
|
|
643
|
+
if (failed) {
|
|
644
|
+
this.#backfillFailures += 1;
|
|
645
|
+
if (this.#backfillFailures >= BACKFILL_MAX_FAILURES)
|
|
646
|
+
return;
|
|
647
|
+
delay = Math.min(BACKFILL_MAX_RETRY_MS, BACKFILL_FIRST_RETRY_MS * 2 ** (this.#backfillFailures - 1));
|
|
648
|
+
}
|
|
649
|
+
this.#backfillTimer?.cancel();
|
|
650
|
+
this.#backfillTimer = this.#scheduler.timer(() => {
|
|
651
|
+
this.#backfillTimer = null;
|
|
652
|
+
void this.#askForHistory(token);
|
|
653
|
+
}, delay);
|
|
654
|
+
}
|
|
532
655
|
#observeLayout(event) {
|
|
533
656
|
const observed = this.#readLayoutLease(event);
|
|
534
657
|
if (observed.kind === "irrelevant")
|
|
@@ -555,6 +678,7 @@ export class SessionRuntimeTerminalReplicaOwner {
|
|
|
555
678
|
// One outstanding capture also coalesces geometry bursts; crossed leases
|
|
556
679
|
// request the latest capture through the normal qualification retry path.
|
|
557
680
|
this.#reseedRetryCount = 0;
|
|
681
|
+
this.#cancelBackfill();
|
|
558
682
|
if (!this.#bootstrapped || this.#reseed || this.#waitingForGeometryCapture)
|
|
559
683
|
return;
|
|
560
684
|
this.#waitingForGeometryCapture = true;
|
|
@@ -669,6 +793,7 @@ export class SessionRuntimeTerminalReplicaOwner {
|
|
|
669
793
|
this.#noteLifecycle("reseed-retry", diagnostic);
|
|
670
794
|
this.#reseedRetryCount += 1;
|
|
671
795
|
this.#waitingForGeometryCapture = true;
|
|
796
|
+
this.#cancelBackfill();
|
|
672
797
|
this.#historyAnchors.invalidate();
|
|
673
798
|
void this.#start.then(() => {
|
|
674
799
|
if (!this.#disposed)
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { isNativeBootstrapCapture } from "../mirror/native-grid-capture.js";
|
|
1
|
+
import { isNativeBootstrapCapture, } from "../mirror/native-grid-capture.js";
|
|
2
2
|
import { projectNativeGridRow } from "../mirror/native-grid-projection.js";
|
|
3
3
|
import { Terminal } from "@tmux-ide/xterm-headless";
|
|
4
4
|
import { Unicode11Addon } from "@xterm/addon-unicode11";
|
|
5
5
|
import { createProjectedTerminalReplicaRowBuilder } from "@tmux-ide/core";
|
|
6
|
+
import { DAEMON_HISTORY_ROW_CAP, } from "./terminal-interpreter-backend.js";
|
|
6
7
|
/** Pinned xterm 6 adapter and the rollback oracle for native backends. */
|
|
7
8
|
export class XtermTerminalInterpreterBackend {
|
|
8
9
|
kind = "xterm";
|
|
@@ -23,9 +24,14 @@ export class XtermTerminalInterpreterBackend {
|
|
|
23
24
|
#nativeModesObserved = false;
|
|
24
25
|
#historyProjectionInvalidated = false;
|
|
25
26
|
#scrollOnClear;
|
|
27
|
+
/** #873: tmux history rows older than the oldest row held (see omittedHistory). */
|
|
28
|
+
#omittedHistory = 0;
|
|
29
|
+
/** #873: the most history rows held; rows pushed past it count as left out. */
|
|
30
|
+
#historyRowCap;
|
|
26
31
|
constructor(options) {
|
|
27
32
|
const historyLimit = options.historyLimit ?? options.scrollback;
|
|
28
33
|
this.#historyLimit = historyLimit;
|
|
34
|
+
this.#historyRowCap = options.historyRowCap ?? DAEMON_HISTORY_ROW_CAP;
|
|
29
35
|
this.#terminal = new Terminal({
|
|
30
36
|
cols: options.cols,
|
|
31
37
|
rows: options.rows,
|
|
@@ -96,31 +102,78 @@ export class XtermTerminalInterpreterBackend {
|
|
|
96
102
|
*/
|
|
97
103
|
startHistoryCollection() {
|
|
98
104
|
this.#collecting = true;
|
|
105
|
+
this.#enforceRowCap();
|
|
99
106
|
this.#lastYbase = this.#normalBuffer()?.ybase ?? null;
|
|
100
107
|
}
|
|
108
|
+
historyRowCap() {
|
|
109
|
+
return this.#historyRowCap;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* #873: hold at most #historyRowCap history rows. The oldest rows past it
|
|
113
|
+
* are dropped here and counted as left out, so tmux's history size is still
|
|
114
|
+
* the rows held plus the rows left out. tmux itself keeps them.
|
|
115
|
+
*/
|
|
116
|
+
#enforceRowCap() {
|
|
117
|
+
const buffer = this.#normalBuffer();
|
|
118
|
+
if (!buffer || buffer.ybase <= this.#historyRowCap)
|
|
119
|
+
return;
|
|
120
|
+
const extra = buffer.ybase - this.#historyRowCap;
|
|
121
|
+
buffer.lines.trimStart(extra);
|
|
122
|
+
buffer.ybase -= extra;
|
|
123
|
+
buffer.ydisp = Math.max(0, buffer.ydisp - extra);
|
|
124
|
+
this.#setOmittedHistory(this.#omittedHistory + extra);
|
|
125
|
+
// No projection invalidation: the incremental projection reads a trim at
|
|
126
|
+
// the old end like tmux's own collection, so a scroll at the cap stays a
|
|
127
|
+
// one-row delta. Seeds and prepends invalidate on their own.
|
|
128
|
+
}
|
|
101
129
|
#normalBuffer() {
|
|
102
130
|
return this.#terminal._core?.buffers?.normal;
|
|
103
131
|
}
|
|
132
|
+
omittedHistory() {
|
|
133
|
+
return this.#omittedHistory;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* The parser's own erase-in-display collection counts only the rows held.
|
|
137
|
+
* While tmux holds older rows than these, turn it off: #collectHistory then
|
|
138
|
+
* collects after each of the erase's scrolls instead, which leaves the same
|
|
139
|
+
* rows as tmux's collection before it.
|
|
140
|
+
*/
|
|
141
|
+
#setOmittedHistory(count) {
|
|
142
|
+
this.#omittedHistory = count;
|
|
143
|
+
this.#terminal.options.tmuxHistoryLimit =
|
|
144
|
+
count > 0 ? Number.MAX_SAFE_INTEGER : this.#historyLimit;
|
|
145
|
+
}
|
|
104
146
|
#collectHistory() {
|
|
105
147
|
const buffer = this.#normalBuffer();
|
|
106
148
|
if (!buffer)
|
|
107
149
|
return;
|
|
108
150
|
const before = this.#lastYbase;
|
|
109
151
|
const limit = this.#historyLimit;
|
|
152
|
+
const omitted = this.#omittedHistory;
|
|
110
153
|
// Only a plain one-row scroll from at or above the limit is collected
|
|
111
154
|
// here. ED2 collects before its own scrolls (one-column.patch), and any
|
|
112
155
|
// other change (reset, resize, a capped ring) is left alone: a history
|
|
113
156
|
// that still differs from tmux is caught by the owner's size check.
|
|
157
|
+
// tmux's history size counts the rows a native seed left out, and its
|
|
158
|
+
// collection drops the oldest rows: those first, then rows held.
|
|
114
159
|
if (this.#collecting &&
|
|
115
160
|
limit > 0 &&
|
|
116
161
|
before !== null &&
|
|
117
|
-
before >= limit &&
|
|
162
|
+
omitted + before >= limit &&
|
|
118
163
|
buffer.ybase === before + 1) {
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
164
|
+
const collected = Math.min(omitted + buffer.ybase, Math.max(1, Math.floor(limit / 10)));
|
|
165
|
+
const fromOmitted = Math.min(omitted, collected);
|
|
166
|
+
if (fromOmitted > 0)
|
|
167
|
+
this.#setOmittedHistory(omitted - fromOmitted);
|
|
168
|
+
const trim = collected - fromOmitted;
|
|
169
|
+
if (trim > 0) {
|
|
170
|
+
buffer.lines.trimStart(trim);
|
|
171
|
+
buffer.ybase -= trim;
|
|
172
|
+
buffer.ydisp = Math.max(0, buffer.ydisp - trim);
|
|
173
|
+
}
|
|
123
174
|
}
|
|
175
|
+
if (this.#collecting)
|
|
176
|
+
this.#enforceRowCap();
|
|
124
177
|
this.#lastYbase = buffer.ybase;
|
|
125
178
|
}
|
|
126
179
|
get cols() {
|
|
@@ -180,6 +233,9 @@ export class XtermTerminalInterpreterBackend {
|
|
|
180
233
|
const cell = this.#terminal.buffer.active.getNullCell();
|
|
181
234
|
if (typeof cell.setFromCharData !== "function")
|
|
182
235
|
throw new Error("Unsupported @tmux-ide/xterm-headless 6 native cell shape");
|
|
236
|
+
const omitted = snapshot.omittedHistory ?? 0;
|
|
237
|
+
if (!Number.isSafeInteger(omitted) || omitted < 0)
|
|
238
|
+
return false;
|
|
183
239
|
if (buffer.lines.maxLength < snapshot.grid.length)
|
|
184
240
|
return false;
|
|
185
241
|
buffer.lines.length = 0;
|
|
@@ -220,9 +276,62 @@ export class XtermTerminalInterpreterBackend {
|
|
|
220
276
|
],
|
|
221
277
|
}, 1).cells[0];
|
|
222
278
|
[handler._curAttrData.fg, handler._curAttrData.bg] = nativeImportAttributes(current);
|
|
279
|
+
this.#setOmittedHistory(omitted);
|
|
223
280
|
this.#historyProjectionInvalidated = true;
|
|
224
281
|
return true;
|
|
225
282
|
}
|
|
283
|
+
prependNativeHistory(piece) {
|
|
284
|
+
const omitted = this.#omittedHistory;
|
|
285
|
+
const buffer = this.#normalBuffer();
|
|
286
|
+
if (!buffer ||
|
|
287
|
+
omitted <= 0 ||
|
|
288
|
+
this.#terminal.buffer.active.type !== "normal" ||
|
|
289
|
+
piece.cols !== this.cols ||
|
|
290
|
+
piece.historySize !== omitted + buffer.ybase ||
|
|
291
|
+
!Number.isSafeInteger(piece.firstRow) ||
|
|
292
|
+
piece.firstRow < 0 ||
|
|
293
|
+
piece.firstRow >= omitted ||
|
|
294
|
+
piece.firstRow + piece.rows.length < omitted ||
|
|
295
|
+
!this.canImportNativeGrid())
|
|
296
|
+
return false;
|
|
297
|
+
// Rows numbered below the oldest row held; a piece can overlap rows held.
|
|
298
|
+
const count = omitted - piece.firstRow;
|
|
299
|
+
if (buffer.lines.length + count > buffer.lines.maxLength)
|
|
300
|
+
return false;
|
|
301
|
+
const lines = piece.rows
|
|
302
|
+
.slice(0, count)
|
|
303
|
+
.map((row, index) => this.#nativeLine(row, index > 0 && (piece.rows[index - 1].flags & 1) !== 0));
|
|
304
|
+
// In slices: one call with every row as an argument can exceed the stack.
|
|
305
|
+
for (let offset = 0; offset < lines.length; offset += 4096)
|
|
306
|
+
buffer.lines.splice(offset, 0, ...lines.slice(offset, offset + 4096));
|
|
307
|
+
// The import marked the row that was oldest as unwrapped: it had no row before it.
|
|
308
|
+
const boundary = buffer.lines.get(count);
|
|
309
|
+
if (boundary)
|
|
310
|
+
boundary.isWrapped = (piece.rows[count - 1].flags & 1) !== 0;
|
|
311
|
+
buffer.ybase += count;
|
|
312
|
+
buffer.ydisp += count;
|
|
313
|
+
if (this.#lastYbase !== null)
|
|
314
|
+
this.#lastYbase += count;
|
|
315
|
+
this.#setOmittedHistory(piece.firstRow);
|
|
316
|
+
this.#enforceRowCap();
|
|
317
|
+
this.#historyProjectionInvalidated = true;
|
|
318
|
+
return true;
|
|
319
|
+
}
|
|
320
|
+
/** One native row as a parser line, as importNativeGrid writes it. */
|
|
321
|
+
#nativeLine(source, wrapped) {
|
|
322
|
+
const buffer = this.#terminal.buffer.active
|
|
323
|
+
._buffer;
|
|
324
|
+
const cell = this.#terminal.buffer.active.getNullCell();
|
|
325
|
+
const row = projectNativeGridRow(source, this.cols, 0, wrapped);
|
|
326
|
+
const line = buffer.getBlankLine(undefined, row.wrapped);
|
|
327
|
+
for (let column = 0; column < row.cells.length; column++) {
|
|
328
|
+
const projected = row.cells[column];
|
|
329
|
+
cell.setFromCharData([0, projected.grapheme, projected.width, 0]);
|
|
330
|
+
[cell.fg, cell.bg] = nativeImportAttributes(projected);
|
|
331
|
+
line.setCell(column, cell);
|
|
332
|
+
}
|
|
333
|
+
return line;
|
|
334
|
+
}
|
|
226
335
|
prioritizeNextWrite() {
|
|
227
336
|
this.#terminal.prioritizeNextWrite();
|
|
228
337
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { STOCK_CAPTURE_TAB_UNAVAILABLE, TERMINAL_DELIVERY_MAX_PIPELINED, TERMINAL_DELIVERY_PIPELINING_CAPABILITY_VERSION, } from "@tmux-ide/contracts";
|
|
1
|
+
import { PANE_STREAM_MAX_PANES, STOCK_CAPTURE_TAB_UNAVAILABLE, TERMINAL_DELIVERY_MAX_PIPELINED, TERMINAL_DELIVERY_PIPELINING_CAPABILITY_VERSION, } from "@tmux-ide/contracts";
|
|
2
2
|
import { randomUUID } from "node:crypto";
|
|
3
3
|
import { TerminalDeliveryAssembler, decodeVerifiedCompactSemanticTerminalUpdate, decodeVerifiedCompactSemanticTerminalUpdateCooperatively, decodeVerifiedLegacySemanticTerminalUpdate, terminalDeliveryEncodingAccepted, } from "@tmux-ide/core";
|
|
4
4
|
import { PaneStreamOperationError, } from "@tmux-ide/daemon-client/pane-stream-client";
|
|
@@ -173,6 +173,22 @@ function layoutExactlyCoversPanes(snapshot, expectedPanes) {
|
|
|
173
173
|
(observedPanes.length === expectedPanes.length ||
|
|
174
174
|
snapshot.windows.some((window) => window.zoomed)));
|
|
175
175
|
}
|
|
176
|
+
/**
|
|
177
|
+
* A session with more panes than one pane stream carries (#585). The daemon
|
|
178
|
+
* refuses such a stream on every try, so the runtime supervisor does not try
|
|
179
|
+
* again until the session's panes change (`code` is what it checks).
|
|
180
|
+
*/
|
|
181
|
+
export class OpenTuiPaneLimitError extends Error {
|
|
182
|
+
panes;
|
|
183
|
+
limit;
|
|
184
|
+
code = "pane-limit-exceeded";
|
|
185
|
+
constructor(panes, limit) {
|
|
186
|
+
super(`Session has ${panes} panes; one pane stream carries at most ${limit}`);
|
|
187
|
+
this.panes = panes;
|
|
188
|
+
this.limit = limit;
|
|
189
|
+
this.name = "OpenTuiPaneLimitError";
|
|
190
|
+
}
|
|
191
|
+
}
|
|
176
192
|
function canonicalPaneIds(inventory) {
|
|
177
193
|
const panes = [...new Set(inventory.semanticPaneIds)].sort((left, right) => left.localeCompare(right));
|
|
178
194
|
if (panes.length === 0)
|
|
@@ -783,6 +799,8 @@ class WireTerminalSubscription {
|
|
|
783
799
|
export async function connectOpenTuiWorkspaceRuntimePort(options) {
|
|
784
800
|
const { inventory, routing } = options;
|
|
785
801
|
const panes = canonicalPaneIds(inventory);
|
|
802
|
+
if (panes.length > PANE_STREAM_MAX_PANES)
|
|
803
|
+
throw new OpenTuiPaneLimitError(panes.length, PANE_STREAM_MAX_PANES);
|
|
786
804
|
const expected = {
|
|
787
805
|
daemonInstanceId: inventory.daemonGeneration,
|
|
788
806
|
workspaceName: inventory.workspaceName,
|
|
@@ -5,7 +5,7 @@ import { dispatchOwnerAction } from "@tmux-ide/daemon-client/owner-action-client
|
|
|
5
5
|
import { createWorkspaceClient } from "@tmux-ide/daemon-client/workspace-client";
|
|
6
6
|
import { canonicalDaemonUrl } from "../../../lib/canonical-daemon.js";
|
|
7
7
|
import { ensureOpenTuiSessionWorkspaceResult } from "../configless-session-bootstrap.js";
|
|
8
|
-
import { OPEN_TUI_HOST_CLIENT_ID, connectOpenTuiWorkspaceRuntimePort, } from "../open-tui-workspace-runtime-port.js";
|
|
8
|
+
import { OPEN_TUI_HOST_CLIENT_ID, OpenTuiPaneLimitError, connectOpenTuiWorkspaceRuntimePort, } from "../open-tui-workspace-runtime-port.js";
|
|
9
9
|
import { resolveOpenTuiApplicationShellConnection, } from "../application-shell-daemon-connection.js";
|
|
10
10
|
import { DaemonAuthorityRebindCoordinator } from "./daemon-authority-rebind.js";
|
|
11
11
|
import { TerminalFastLaneRendererAdapter } from "./terminal-fast-lane-renderer-adapter.js";
|
|
@@ -159,6 +159,7 @@ function buildProductionBundle(connection, callbacks, readDaemon = readCanonical
|
|
|
159
159
|
callbacks.didSuspendRuntime(runtime);
|
|
160
160
|
},
|
|
161
161
|
didRetireRuntime: callbacks.didRetireRuntime,
|
|
162
|
+
didFailRuntime: callbacks.didRefuseRuntime,
|
|
162
163
|
requestTerminalRuntimeInventoryRefresh: () => {
|
|
163
164
|
connection.transport.refreshTerminalRuntimeInventory();
|
|
164
165
|
},
|
|
@@ -552,6 +553,13 @@ export function createOpenTuiGenerationHost(sessionName, presentation, overrides
|
|
|
552
553
|
currentOwner.runtime = null;
|
|
553
554
|
publish({ ...snapshot, status: "rebinding" });
|
|
554
555
|
},
|
|
556
|
+
didRefuseRuntime(error) {
|
|
557
|
+
const details = error instanceof OpenTuiPaneLimitError
|
|
558
|
+
? { code: error.code, panes: error.panes, limit: error.limit }
|
|
559
|
+
: { message: error instanceof Error ? error.message : String(error) };
|
|
560
|
+
overrides.onConnectionProgress?.("runtime-refused", details);
|
|
561
|
+
diagnose?.("runtime-refused", details);
|
|
562
|
+
},
|
|
555
563
|
didRuntimeDiagnostic(phase, details) {
|
|
556
564
|
if (phase === "seed" || phase === "coherent")
|
|
557
565
|
overrides.onConnectionProgress?.("runtime-progress", {
|
|
@@ -175,6 +175,14 @@ export function createApplicationConnectionFeedback(onPublish = () => undefined)
|
|
|
175
175
|
update("Reading terminal layout");
|
|
176
176
|
else if (phase === "runtime-fault")
|
|
177
177
|
update("Connection interrupted — retrying");
|
|
178
|
+
else if (phase === "runtime-refused" &&
|
|
179
|
+
Number.isSafeInteger(details.panes) &&
|
|
180
|
+
Number.isSafeInteger(details.limit)) {
|
|
181
|
+
// #585: refused on every try, so the app stops here instead of retrying.
|
|
182
|
+
// Words approved by the owner on 25 Nov 2026.
|
|
183
|
+
stop();
|
|
184
|
+
update(`Session too large to stream here: ${String(details.panes)} panes, the limit is ${String(details.limit)}. Move some windows to another session, or open it in the Mac app.`, true);
|
|
185
|
+
}
|
|
178
186
|
else if (phase === "runtime-progress") {
|
|
179
187
|
if (details.runtimePhase === "seed" &&
|
|
180
188
|
Number.isSafeInteger(details.seededPanes) &&
|
|
@@ -11,12 +11,26 @@ import {
|
|
|
11
11
|
import type { NativeTerminalRuntimeSessionSnapshot } from "../../terminal/attachments/native-runtime.ts";
|
|
12
12
|
import { paneIdentities, projectApplicationShellResource } from "./application-shell.ts";
|
|
13
13
|
|
|
14
|
+
/**
|
|
15
|
+
* #882: floating panes (tmux 3.7+) are listed by the catalog but have no cell
|
|
16
|
+
* in the tiled layout a client attaches to. Until floats are drawn, the
|
|
17
|
+
* attachable inventory leaves them out, so a session holding one still opens.
|
|
18
|
+
*/
|
|
19
|
+
function floatingPaneIds(session: NativeTerminalRuntimeSessionSnapshot): ReadonlySet<string> {
|
|
20
|
+
return new Set(
|
|
21
|
+
session.panes.flatMap((pane) =>
|
|
22
|
+
pane.floating === true && pane.semanticPaneId !== null ? [pane.semanticPaneId] : [],
|
|
23
|
+
),
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
14
27
|
/** Pure, wire-safe agent-free topology projection. */
|
|
15
28
|
export function projectTerminalRuntimeInventory(
|
|
16
29
|
session: NativeTerminalRuntimeSessionSnapshot,
|
|
17
30
|
resourceRevision: number,
|
|
18
31
|
): TerminalRuntimeInventoryProjectionV1 {
|
|
19
32
|
const shell = projectApplicationShellResource(session);
|
|
33
|
+
const floating = floatingPaneIds(session);
|
|
20
34
|
return TerminalRuntimeInventoryProjectionV1SchemaZ.parse({
|
|
21
35
|
workspaceName: session.workspaceName,
|
|
22
36
|
workspaceId: shell.workspace.id,
|
|
@@ -25,7 +39,8 @@ export function projectTerminalRuntimeInventory(
|
|
|
25
39
|
semanticPaneIds: [
|
|
26
40
|
...new Set(
|
|
27
41
|
shell.terminalInventory.resources.flatMap((resource) =>
|
|
28
|
-
resource.attachability.status === "available"
|
|
42
|
+
resource.attachability.status === "available" &&
|
|
43
|
+
!floating.has(resource.attachability.semanticPaneId)
|
|
29
44
|
? [resource.attachability.semanticPaneId]
|
|
30
45
|
: [],
|
|
31
46
|
),
|
|
@@ -58,10 +73,13 @@ export function projectTerminalRuntimeInventoryV2(
|
|
|
58
73
|
complete: true,
|
|
59
74
|
};
|
|
60
75
|
windows.set(pane.windowId, entry);
|
|
76
|
+
if (pane.active) entry.active = true;
|
|
77
|
+
// #882: a floating pane is not part of its window's tiled pane set, but an
|
|
78
|
+
// active float (a modal pane takes the focus) still marks its window active.
|
|
79
|
+
if (pane.floating === true) return;
|
|
61
80
|
const attachability = identities[index]!.attachability;
|
|
62
81
|
if (attachability.status === "available") entry.panes.push(attachability.semanticPaneId);
|
|
63
82
|
else entry.complete = false;
|
|
64
|
-
if (pane.active) entry.active = true;
|
|
65
83
|
});
|
|
66
84
|
return TerminalRuntimeInventoryProjectionV2SchemaZ.parse({
|
|
67
85
|
...projectTerminalRuntimeInventory(session, resourceRevision),
|
|
@@ -597,7 +597,10 @@ export function mountTmuxServerRoutes(app: Hono, options: TmuxServerRoutesOption
|
|
|
597
597
|
() => undefined,
|
|
598
598
|
{
|
|
599
599
|
expectedRuntimeSessionId: identity.runtimeSessionId,
|
|
600
|
-
|
|
600
|
+
// #882: a floating pane has no tiled cell; the layout fence leaves it out.
|
|
601
|
+
expectedSemanticPaneIds: identity.description.panes.flatMap((pane) =>
|
|
602
|
+
pane.floating === true ? [] : [pane.semanticPaneId],
|
|
603
|
+
),
|
|
601
604
|
onAuthority(snapshot) {
|
|
602
605
|
if (snapshot.windowLinks.liveSessionId !== c.req.query("liveSessionId")) {
|
|
603
606
|
sessionReplaced = true;
|