tmux-ide 2.9.22 → 2.9.23
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 +3434 -7568
- package/package.json +3 -3
- package/packages/contracts/src/index.ts +1 -0
- package/packages/contracts/src/websocket-heartbeat.ts +41 -0
- package/packages/daemon/dist/command-center/automation.js +1 -1
- package/packages/daemon/dist/command-center/daemon-fleet-facts-observer.js +37 -5
- package/packages/daemon/dist/command-center/discovery.js +28 -2
- package/packages/daemon/dist/command-center/server.js +8 -2
- package/packages/daemon/dist/command-center/tmux-servers.js +1 -1
- package/packages/daemon/dist/doctor.js +41 -0
- package/packages/daemon/dist/lib/bounded-tmux-read.js +34 -12
- package/packages/daemon/dist/lib/daemon-embed.js +111 -55
- package/packages/daemon/dist/lib/daemon-stop-progress.js +58 -0
- package/packages/daemon/dist/lib/embedded-daemon-lifecycle.js +11 -0
- package/packages/daemon/dist/lib/embedded-tmux-server-owners.js +88 -12
- package/packages/daemon/dist/lib/headless-daemon.js +177 -10
- package/packages/daemon/dist/lib/log.js +18 -1
- package/packages/daemon/dist/lib/tmux-external-interaction-observer.js +140 -19
- package/packages/daemon/dist/lib/tmux-native-browser.js +4 -2
- package/packages/daemon/dist/lib/tmux-pane-reader.js +4 -2
- package/packages/daemon/dist/lib/tmux-server-agent-admission.js +6 -1
- package/packages/daemon/dist/lib/tmux-server-owner-teardown.js +33 -0
- package/packages/daemon/dist/lib/tmux-server-owner.js +29 -37
- package/packages/daemon/dist/lib/tmux-server-owners.js +310 -20
- package/packages/daemon/dist/lib/tmux-server-registration.js +128 -9
- package/packages/daemon/dist/lib/unix-socket-authority.js +58 -3
- package/packages/daemon/dist/lib/workspace-pane-creation.js +10 -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/plugins/cli.js +1 -2
- package/packages/daemon/dist/server/pane-stream-upgrade.js +5 -1
- package/packages/daemon/dist/server/websocket-heartbeat.js +103 -0
- package/packages/daemon/dist/terminal/attachments/native-runtime.js +32 -14
- package/packages/daemon/dist/terminal/mirror/layout-content-rows.js +11 -0
- package/packages/daemon/dist/terminal/mirror/mirror-service.js +61 -3
- package/packages/daemon/dist/terminal/mirror/session-channel.js +9 -11
- package/packages/daemon/dist/terminal/pane-stream/pane-stream-websocket.js +111 -22
- package/packages/daemon/dist/terminal/pane-stream/runtime.js +3 -2
- package/packages/daemon/dist/terminal/protocol/session-descriptor-discovery.js +23 -0
- package/packages/daemon/dist/terminal/protocol/stock-split-resize.js +4 -1
- package/packages/daemon/dist/terminal/session-runtime/registry.js +17 -0
- package/packages/daemon/dist/terminal/session-runtime/terminal-replica-interpreter.js +81 -3
- package/packages/daemon/dist/terminal/session-runtime/terminal-replica-owner.js +60 -3
- package/packages/daemon/src/command-center/automation.ts +1 -1
- package/packages/daemon/src/command-center/daemon-fleet-facts-observer.ts +49 -8
- package/packages/daemon/src/command-center/discovery.ts +35 -2
- package/packages/daemon/src/command-center/server.ts +22 -8
- package/packages/daemon/src/command-center/tmux-servers.ts +1 -1
- package/packages/daemon/src/doctor.ts +46 -0
- package/packages/daemon/src/lib/bounded-tmux-read.ts +29 -9
- package/packages/daemon/src/lib/daemon-embed.ts +159 -64
- package/packages/daemon/src/lib/daemon-stop-progress.ts +78 -0
- package/packages/daemon/src/lib/embedded-daemon-lifecycle.ts +12 -0
- package/packages/daemon/src/lib/embedded-tmux-server-owners.ts +115 -11
- package/packages/daemon/src/lib/headless-daemon.ts +205 -12
- package/packages/daemon/src/lib/log.ts +18 -1
- package/packages/daemon/src/lib/tmux-external-interaction-observer.ts +163 -25
- package/packages/daemon/src/lib/tmux-native-browser.ts +4 -3
- package/packages/daemon/src/lib/tmux-pane-reader.ts +4 -3
- package/packages/daemon/src/lib/tmux-server-agent-admission.ts +6 -1
- package/packages/daemon/src/lib/tmux-server-owner-teardown.ts +54 -0
- package/packages/daemon/src/lib/tmux-server-owner.ts +32 -35
- package/packages/daemon/src/lib/tmux-server-owners.ts +427 -22
- package/packages/daemon/src/lib/tmux-server-registration.ts +155 -7
- package/packages/daemon/src/lib/unix-socket-authority.ts +72 -3
- package/packages/daemon/src/lib/workspace-pane-creation.ts +11 -1
- package/packages/daemon/src/plugins/cli.ts +1 -2
- package/packages/daemon/src/server/pane-stream-upgrade.ts +6 -0
- package/packages/daemon/src/server/websocket-heartbeat.ts +135 -0
- package/packages/daemon/src/terminal/attachments/native-runtime.ts +58 -14
- package/packages/daemon/src/terminal/mirror/layout-content-rows.ts +11 -0
- package/packages/daemon/src/terminal/mirror/mirror-service.ts +61 -2
- package/packages/daemon/src/terminal/mirror/session-channel.ts +9 -13
- package/packages/daemon/src/terminal/pane-stream/pane-stream-websocket.ts +125 -21
- package/packages/daemon/src/terminal/pane-stream/runtime.ts +4 -2
- package/packages/daemon/src/terminal/protocol/session-descriptor-discovery.ts +31 -0
- package/packages/daemon/src/terminal/protocol/stock-split-resize.ts +6 -1
- package/packages/daemon/src/terminal/session-runtime/registry.ts +23 -0
- package/packages/daemon/src/terminal/session-runtime/runtime-observability.ts +2 -0
- package/packages/daemon/src/terminal/session-runtime/terminal-replica-interpreter.ts +100 -3
- package/packages/daemon/src/terminal/session-runtime/terminal-replica-owner.ts +60 -3
- package/packages/daemon-client/src/direct-application-shell-transport.ts +21 -3
- package/packages/daemon-client/src/workspace-event-supervisor.ts +63 -2
|
@@ -25,6 +25,8 @@ import { execFile } from "node:child_process";
|
|
|
25
25
|
import { MirrorControlChannel, } from "./control-channel.js";
|
|
26
26
|
import { SessionChannel, } from "./session-channel.js";
|
|
27
27
|
import { controlModeAuthorityKey, processControlModeOwnershipRegistry, } from "./control-mode-ownership.js";
|
|
28
|
+
/** Backoff for re-reading registered windows after a failed read (#764). */
|
|
29
|
+
const OWNERSHIP_RETRY_MS = [100, 250, 500, 1_000];
|
|
28
30
|
export class MirrorService {
|
|
29
31
|
opts;
|
|
30
32
|
channels = new Map();
|
|
@@ -46,26 +48,74 @@ export class MirrorService {
|
|
|
46
48
|
};
|
|
47
49
|
}
|
|
48
50
|
invalidateRegisteredWindows() {
|
|
51
|
+
this.opts.onWindowOwnershipDiagnostic?.("guard-invalidate", {
|
|
52
|
+
wasPending: this.registeredWindows?.pending() ?? null,
|
|
53
|
+
});
|
|
49
54
|
this.registeredWindows?.invalidate();
|
|
50
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* #764: a failed re-read must not leave every session "being verified"
|
|
58
|
+
* for good. Nothing else re-reads until the next operation, so retry with
|
|
59
|
+
* a short bounded backoff while a channel is retained; success pushes
|
|
60
|
+
* any conflict as usual.
|
|
61
|
+
*/
|
|
62
|
+
ownershipRetries = 0;
|
|
63
|
+
ownershipRetry = null;
|
|
64
|
+
retryRegisteredWindows(guard) {
|
|
65
|
+
if (this.ownershipRetry || this.disposed || guard !== this.registeredWindows)
|
|
66
|
+
return;
|
|
67
|
+
if (this.channelSessions.size === 0)
|
|
68
|
+
return;
|
|
69
|
+
const delay = OWNERSHIP_RETRY_MS[Math.min(this.ownershipRetries, OWNERSHIP_RETRY_MS.length - 1)];
|
|
70
|
+
this.ownershipRetries += 1;
|
|
71
|
+
this.ownershipRetry = setTimeout(() => {
|
|
72
|
+
this.ownershipRetry = null;
|
|
73
|
+
if (this.disposed || guard !== this.registeredWindows || !guard.pending())
|
|
74
|
+
return;
|
|
75
|
+
void this.verifyRegisteredWindows().catch(() => { });
|
|
76
|
+
}, delay);
|
|
77
|
+
this.ownershipRetry.unref?.();
|
|
78
|
+
}
|
|
51
79
|
async verifyRegisteredWindows() {
|
|
52
80
|
const guard = this.registeredWindows;
|
|
53
81
|
if (!guard)
|
|
54
82
|
return;
|
|
55
|
-
|
|
83
|
+
const diagnostic = this.opts.onWindowOwnershipDiagnostic;
|
|
84
|
+
diagnostic?.("guard-verify-start", { pending: guard.pending() });
|
|
85
|
+
try {
|
|
86
|
+
await guard.verify();
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
const detail = error?.detail;
|
|
90
|
+
diagnostic?.("guard-verify-failed", {
|
|
91
|
+
reason: error instanceof Error ? error.message.slice(0, 200) : "unknown",
|
|
92
|
+
// Which origin of the failure it was, when the thrower said so.
|
|
93
|
+
...(typeof detail === "string" ? { detail: detail.slice(0, 80) } : {}),
|
|
94
|
+
});
|
|
95
|
+
this.retryRegisteredWindows(guard);
|
|
96
|
+
throw error;
|
|
97
|
+
}
|
|
98
|
+
this.ownershipRetries = 0;
|
|
56
99
|
if (guard !== this.registeredWindows || this.disposed)
|
|
57
100
|
throw new Error("Window ownership changed during discovery");
|
|
101
|
+
const blocked = [];
|
|
58
102
|
for (const [channel, session] of this.channelSessions) {
|
|
59
103
|
if (guard.blocked(session)) {
|
|
104
|
+
blocked.push(session);
|
|
60
105
|
channel.setGeometryParticipation(false);
|
|
61
106
|
if (!this.registeredConflicts.has(session)) {
|
|
62
107
|
this.registeredConflicts.add(session);
|
|
108
|
+
diagnostic?.("guard-conflict-push", { session });
|
|
63
109
|
this.opts.onSharedWindowConflict?.(session, true);
|
|
64
110
|
}
|
|
65
111
|
}
|
|
66
|
-
else
|
|
67
|
-
|
|
112
|
+
else if (this.registeredConflicts.delete(session)) {
|
|
113
|
+
// The registered-window conflict cleared: report it like a shared-window
|
|
114
|
+
// clear, so idle clients re-read the inventory (perf plan F13).
|
|
115
|
+
this.opts.onSharedWindowConflict?.(session, false);
|
|
116
|
+
}
|
|
68
117
|
}
|
|
118
|
+
diagnostic?.("guard-verify-ok", { blocked, channels: this.channelSessions.size });
|
|
69
119
|
}
|
|
70
120
|
pendingDisposals = new Set();
|
|
71
121
|
drainingChannels = new Map();
|
|
@@ -398,6 +448,7 @@ export class MirrorService {
|
|
|
398
448
|
continue;
|
|
399
449
|
if (conflict)
|
|
400
450
|
peer.setGeometryParticipation(false);
|
|
451
|
+
this.opts.onWindowOwnershipDiagnostic?.("membership-conflict-push", { session, conflict });
|
|
401
452
|
this.opts.onSharedWindowConflict?.(session, conflict);
|
|
402
453
|
}
|
|
403
454
|
}
|
|
@@ -512,6 +563,9 @@ export class MirrorService {
|
|
|
512
563
|
}
|
|
513
564
|
async dispose() {
|
|
514
565
|
this.disposed = true;
|
|
566
|
+
if (this.ownershipRetry)
|
|
567
|
+
clearTimeout(this.ownershipRetry);
|
|
568
|
+
this.ownershipRetry = null;
|
|
515
569
|
this.registeredWindows?.dispose();
|
|
516
570
|
this.sessionExitListeners.clear();
|
|
517
571
|
const entries = [...this.channels.values()];
|
|
@@ -569,6 +623,10 @@ export class MirrorService {
|
|
|
569
623
|
hasSharedWindowConflict: () => this.hasSharedWindowConflict(session),
|
|
570
624
|
beforeIdentityRepair: () => this.verifyRegisteredWindows(),
|
|
571
625
|
onWindowTopologyChanged: () => {
|
|
626
|
+
this.opts.onWindowOwnershipDiagnostic?.("topology-notification", {
|
|
627
|
+
session,
|
|
628
|
+
current: this.channelSessions.has(channel),
|
|
629
|
+
});
|
|
572
630
|
if (this.channelSessions.has(channel))
|
|
573
631
|
this.invalidateRegisteredWindows();
|
|
574
632
|
},
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { STOCK_SPLIT_OPTIONS_FORMAT } from "../protocol/stock-split-resize.js";
|
|
2
|
-
import { layoutContentRows } from "./layout-content-rows.js";
|
|
2
|
+
import { layoutContentRows, tiledPaneBorderStatus } from "./layout-content-rows.js";
|
|
3
3
|
import { decodeNativeAtomicSnapshot, decodeNativeAtomicDualSnapshot, nativeAtomicDualSnapshotPlan, nativeAtomicSnapshotPlan, } from "./native-atomic-snapshot.js";
|
|
4
4
|
import { boundedTmuxInteractionAppendCommand } from "../../lib/tmux-interaction-retention.js";
|
|
5
5
|
import { decodeNativeGridCapture, isStockRawGridCapture, isNativeBootstrapCapture, } from "./native-grid-capture.js";
|
|
@@ -38,7 +38,7 @@ import { textToHexKeys } from "../protocol/control.js";
|
|
|
38
38
|
import { InputCoalescer } from "../protocol/input-coalescer.js";
|
|
39
39
|
import { NativeGridCaptureReader } from "./native-grid-reader.js";
|
|
40
40
|
import { parseLayout, parseLayoutTree, parseLayoutChange, parseSessionWindowChanged, parseWindowPaneChanged, } from "../protocol/layout-parse.js";
|
|
41
|
-
import { SESSION_PANE_DESCRIPTOR_FORMAT, SessionDescriptorDiscovery, decodeControlReplyUtf8, decodeTmuxArgument, parseSessionPaneDescriptorReply, } from "../protocol/session-descriptor-discovery.js";
|
|
41
|
+
import { SESSION_PANE_DESCRIPTOR_FORMAT, sameSessionPaneInventory, SessionDescriptorDiscovery, decodeControlReplyUtf8, decodeTmuxArgument, parseSessionPaneDescriptorReply, } from "../protocol/session-descriptor-discovery.js";
|
|
42
42
|
import { resolvePaneDisplayName } from "../protocol/pane-display-name.js";
|
|
43
43
|
import { finalizeWorkspaceTmuxReconciliation, planWorkspaceTmuxReconciliation, } from "../protocol/workspace-tmux-adapter.js";
|
|
44
44
|
import { liveSessionIdForNativeIdentity } from "../protocol/live-session-identity.js";
|
|
@@ -2308,7 +2308,7 @@ export class SessionChannel {
|
|
|
2308
2308
|
}
|
|
2309
2309
|
}
|
|
2310
2310
|
const windowOptionHint = name === "subscription-changed"
|
|
2311
|
-
? (/^tmux-ide-pane-borders\s+\$[0-9]+\s+(@[0-9]+)\s+[0-9]+\s+-\s*:\s*(?:top|bottom|off)\s*$/u.exec(rest) ??
|
|
2311
|
+
? (/^tmux-ide-pane-borders\s+\$[0-9]+\s+(@[0-9]+)\s+[0-9]+\s+-\s*:\s*(?:top|bottom|off|top-floating|bottom-floating)\s*$/u.exec(rest) ??
|
|
2312
2312
|
/^tmux-ide-copy-keys\s+\$[0-9]+\s+(@[0-9]+)\s+[0-9]+\s+-\s*:\s*(?:emacs|vi)\s*$/u.exec(rest))
|
|
2313
2313
|
: null;
|
|
2314
2314
|
if (windowOptionHint) {
|
|
@@ -2454,11 +2454,9 @@ export class SessionChannel {
|
|
|
2454
2454
|
if (this.disposed ||
|
|
2455
2455
|
this.pendingLayoutOutput.get(change.windowId)?.layout !== pendingLayout)
|
|
2456
2456
|
return;
|
|
2457
|
-
const border = reply.lines[0];
|
|
2457
|
+
const border = tiledPaneBorderStatus(reply.lines[0]);
|
|
2458
2458
|
const window = this.windowsByRuntime.get(change.windowId);
|
|
2459
|
-
if (!reply.ok ||
|
|
2460
|
-
!window ||
|
|
2461
|
-
(border !== "top" && border !== "bottom" && border !== "off")) {
|
|
2459
|
+
if (!reply.ok || !window || border === null) {
|
|
2462
2460
|
this.scheduleSync();
|
|
2463
2461
|
return;
|
|
2464
2462
|
}
|
|
@@ -2846,8 +2844,7 @@ export class SessionChannel {
|
|
|
2846
2844
|
const repairedPanes = await this.repairTrustedPaneIdentity(descriptors, windowStage.layouts);
|
|
2847
2845
|
const afterLines = await this.io.request(`list-panes -s -t "${expectedRuntimeSessionId}" -F "${SESSION_PANE_DESCRIPTOR_FORMAT}"`);
|
|
2848
2846
|
const confirmedWindowStage = await this.stageWindows(expectedRuntimeSessionId);
|
|
2849
|
-
const coherent = beforeLines
|
|
2850
|
-
beforeLines.every((line, index) => line === afterLines[index]);
|
|
2847
|
+
const coherent = sameSessionPaneInventory(beforeLines, afterLines);
|
|
2851
2848
|
if (windowStage.repairedIdentity ||
|
|
2852
2849
|
confirmedWindowStage.repairedIdentity ||
|
|
2853
2850
|
repairedPanes ||
|
|
@@ -3106,15 +3103,16 @@ export class SessionChannel {
|
|
|
3106
3103
|
if (parts.length !== 10) {
|
|
3107
3104
|
throw new Error(`window layout truth for ${this.opts.session} is malformed`);
|
|
3108
3105
|
}
|
|
3109
|
-
const [runtimeId = "", stampRaw = "", nameRaw = "", active = "", visible = "", zoomed = "",
|
|
3106
|
+
const [runtimeId = "", stampRaw = "", nameRaw = "", active = "", visible = "", zoomed = "", borderStatusRaw = "off", full = visible, modeKeys, indexRaw = "",] = parts;
|
|
3110
3107
|
const index = Number(indexRaw);
|
|
3108
|
+
const borderStatus = tiledPaneBorderStatus(borderStatusRaw);
|
|
3111
3109
|
if (!/^@[0-9]+$/u.test(runtimeId) ||
|
|
3112
3110
|
!/^(?:0|[1-9][0-9]*)$/u.test(indexRaw) ||
|
|
3113
3111
|
!Number.isSafeInteger(index) ||
|
|
3114
3112
|
seenIndexes.has(index) ||
|
|
3115
3113
|
(active !== "0" && active !== "1") ||
|
|
3116
3114
|
(zoomed !== "0" && zoomed !== "1") ||
|
|
3117
|
-
|
|
3115
|
+
borderStatus === null ||
|
|
3118
3116
|
(modeKeys !== undefined && modeKeys !== "emacs" && modeKeys !== "vi")) {
|
|
3119
3117
|
throw new Error(`window layout truth for ${this.opts.session} is malformed`);
|
|
3120
3118
|
}
|
|
@@ -30,6 +30,37 @@ import { DEFAULT_PANE_STREAM_FLOW_BUDGETS, PaneStreamWireLedger, } from "./wire-
|
|
|
30
30
|
export { PANE_STREAM_REDEEM_PATH, PANE_STREAM_WEBSOCKET_SUBPROTOCOL };
|
|
31
31
|
export const PANE_STREAM_MAX_REDEMPTION_BYTES = 4 * 1024;
|
|
32
32
|
export const PANE_STREAM_MAX_CONTROL_BYTES = 4 * 1024;
|
|
33
|
+
/** The daemon process (or its whole generation) is going away. */
|
|
34
|
+
export const PANE_STREAM_DAEMON_SHUTDOWN_CLOSE = Object.freeze({
|
|
35
|
+
code: 1001,
|
|
36
|
+
reason: "daemon-shutdown",
|
|
37
|
+
});
|
|
38
|
+
/**
|
|
39
|
+
* Only this tmux server owner was retired; the daemon is still up. 1012
|
|
40
|
+
* (service restart) asks the client to list the servers again and reconnect
|
|
41
|
+
* now, without the backoff a vanished daemon deserves (#840).
|
|
42
|
+
*/
|
|
43
|
+
export const PANE_STREAM_OWNER_RETIRED_CLOSE = Object.freeze({
|
|
44
|
+
code: 1012,
|
|
45
|
+
reason: "tmux-server-retired",
|
|
46
|
+
});
|
|
47
|
+
/**
|
|
48
|
+
* The process restarts its daemon generation in place (tmux server replaced,
|
|
49
|
+
* settings restart). A new generation follows at once, possibly on another
|
|
50
|
+
* port: read daemon.json again and reconnect now.
|
|
51
|
+
*/
|
|
52
|
+
export const PANE_STREAM_DAEMON_RESTARTING_CLOSE = Object.freeze({
|
|
53
|
+
code: 1012,
|
|
54
|
+
reason: "daemon-restarting",
|
|
55
|
+
});
|
|
56
|
+
/** What an owner's streams are told when it is disposed for this reason. */
|
|
57
|
+
export function paneStreamCloseForRetirement(retirement) {
|
|
58
|
+
if (retirement === undefined || retirement === "shutdown")
|
|
59
|
+
return PANE_STREAM_DAEMON_SHUTDOWN_CLOSE;
|
|
60
|
+
return retirement === "generation-restart"
|
|
61
|
+
? PANE_STREAM_DAEMON_RESTARTING_CLOSE
|
|
62
|
+
: PANE_STREAM_OWNER_RETIRED_CLOSE;
|
|
63
|
+
}
|
|
33
64
|
export const PANE_STREAM_MAX_REDEMPTION_MS = 1_000;
|
|
34
65
|
const WS_OPEN = 1;
|
|
35
66
|
const CANONICAL_KEY_INPUT_FRAME_PREFIX = Buffer.from('{"kind":"key",', "utf8");
|
|
@@ -342,19 +373,34 @@ export class PaneStreamAdmissionCoordinator {
|
|
|
342
373
|
flowSnapshot() {
|
|
343
374
|
return this.#ledger.snapshot();
|
|
344
375
|
}
|
|
345
|
-
|
|
376
|
+
/**
|
|
377
|
+
* Close every stream and refuse new ones. The first caller decides what the
|
|
378
|
+
* clients are told: the daemon going away, or only this tmux server owner
|
|
379
|
+
* being retired while the daemon stays up (reconnect now).
|
|
380
|
+
*/
|
|
381
|
+
shutdown(close = PANE_STREAM_DAEMON_SHUTDOWN_CLOSE) {
|
|
346
382
|
if (this.#shutdownPromise)
|
|
347
383
|
return this.#shutdownPromise;
|
|
348
384
|
this.#shuttingDown = true;
|
|
349
|
-
|
|
385
|
+
// An idle daemon stopping is routine and stays out of the default log:
|
|
386
|
+
// `--headless --json` promises one status line on stdout. Streams that
|
|
387
|
+
// are actually closed, or an owner retired under a live daemon, are not.
|
|
388
|
+
const routine = close.reason === "daemon-shutdown" && this.#live.size === 0 && this.#preAuth.size === 0;
|
|
389
|
+
logger[routine ? "debug" : "info"]("pane-stream", "coordinator shutdown", {
|
|
390
|
+
code: close.code,
|
|
391
|
+
reason: close.reason,
|
|
392
|
+
liveStreams: this.#live.size,
|
|
393
|
+
unredeemed: this.#preAuth.size,
|
|
394
|
+
});
|
|
395
|
+
this.#shutdownPromise = this.#finishShutdown(close);
|
|
350
396
|
return this.#shutdownPromise;
|
|
351
397
|
}
|
|
352
|
-
async #finishShutdown() {
|
|
398
|
+
async #finishShutdown(close) {
|
|
353
399
|
for (const admission of [...this.#preAuth])
|
|
354
|
-
admission.close(
|
|
400
|
+
admission.close(close.code, close.reason);
|
|
355
401
|
await this.#exclusive(async () => {
|
|
356
402
|
for (const connection of [...this.#live])
|
|
357
|
-
connection.close(
|
|
403
|
+
connection.close(close.code, close.reason);
|
|
358
404
|
for (const pending of [...this.#pending.values()])
|
|
359
405
|
await this.#retirePending(pending);
|
|
360
406
|
});
|
|
@@ -685,6 +731,8 @@ export class PaneStreamLiveConnection {
|
|
|
685
731
|
#legacyInputActivated = false;
|
|
686
732
|
#legacyGeometryActivated = false;
|
|
687
733
|
#closed = false;
|
|
734
|
+
#closeCause = null;
|
|
735
|
+
#heldInput = null;
|
|
688
736
|
#releasePromise = null;
|
|
689
737
|
#stopAuthoritySnapshots = null;
|
|
690
738
|
#sharedClockOriginMicros = null;
|
|
@@ -707,6 +755,8 @@ export class PaneStreamLiveConnection {
|
|
|
707
755
|
"panes-closed",
|
|
708
756
|
"peer-closed",
|
|
709
757
|
"daemon-shutdown",
|
|
758
|
+
"tmux-server-retired",
|
|
759
|
+
"daemon-restarting",
|
|
710
760
|
"redemption-rejected",
|
|
711
761
|
"unknown",
|
|
712
762
|
]).has(closeReason ?? "")
|
|
@@ -827,6 +877,22 @@ export class PaneStreamLiveConnection {
|
|
|
827
877
|
this.#observeSurfaceDemand(this.#descriptor.panes);
|
|
828
878
|
void this.#subscribeAll();
|
|
829
879
|
}
|
|
880
|
+
/**
|
|
881
|
+
* 1011 "stream-unavailable" has ten different origins and the client is told
|
|
882
|
+
* none of them. The log says which one, with the error text, so a stream
|
|
883
|
+
* that "just closed" can be traced without a reproduction.
|
|
884
|
+
*/
|
|
885
|
+
#fail(cause, error) {
|
|
886
|
+
if (this.#closed)
|
|
887
|
+
return;
|
|
888
|
+
this.#closeCause = {
|
|
889
|
+
cause,
|
|
890
|
+
...(error === undefined
|
|
891
|
+
? {}
|
|
892
|
+
: { error: (error instanceof Error ? error.message : String(error)).slice(0, 300) }),
|
|
893
|
+
};
|
|
894
|
+
this.close(1011, "stream-unavailable");
|
|
895
|
+
}
|
|
830
896
|
close(code = 1000, reason = "stream-closed") {
|
|
831
897
|
if (this.#closed)
|
|
832
898
|
return;
|
|
@@ -834,8 +900,12 @@ export class PaneStreamLiveConnection {
|
|
|
834
900
|
logger.info("pane-stream", "stream closed", {
|
|
835
901
|
code,
|
|
836
902
|
reason,
|
|
903
|
+
...(this.#closeCause ?? {}),
|
|
837
904
|
session: this.#descriptor.sessionName,
|
|
838
905
|
clientId: this.#clientId,
|
|
906
|
+
// Whether this connection held input when it went: the next stream of
|
|
907
|
+
// the same client can only be granted input once that is released.
|
|
908
|
+
...(this.#heldInput === null ? {} : { heldInput: this.#heldInput }),
|
|
839
909
|
});
|
|
840
910
|
this.#closed = true;
|
|
841
911
|
for (const demand of this.#surfaceDemands.values())
|
|
@@ -906,8 +976,8 @@ export class PaneStreamLiveConnection {
|
|
|
906
976
|
try {
|
|
907
977
|
described = await this.#mirror.describeSession(this.#descriptor.sessionName);
|
|
908
978
|
}
|
|
909
|
-
catch {
|
|
910
|
-
this
|
|
979
|
+
catch (error) {
|
|
980
|
+
this.#fail("describe-session-failed", error);
|
|
911
981
|
return;
|
|
912
982
|
}
|
|
913
983
|
if (this.#closed)
|
|
@@ -926,8 +996,8 @@ export class PaneStreamLiveConnection {
|
|
|
926
996
|
}
|
|
927
997
|
this.#layoutSubscription = layoutSubscription;
|
|
928
998
|
}
|
|
929
|
-
catch {
|
|
930
|
-
this
|
|
999
|
+
catch (error) {
|
|
1000
|
+
this.#fail("layout-subscribe-failed", error);
|
|
931
1001
|
return;
|
|
932
1002
|
}
|
|
933
1003
|
}
|
|
@@ -953,8 +1023,8 @@ export class PaneStreamLiveConnection {
|
|
|
953
1023
|
}
|
|
954
1024
|
channel.sub = sub;
|
|
955
1025
|
}
|
|
956
|
-
catch {
|
|
957
|
-
this
|
|
1026
|
+
catch (error) {
|
|
1027
|
+
this.#fail("pane-subscribe-failed", error);
|
|
958
1028
|
return;
|
|
959
1029
|
}
|
|
960
1030
|
}
|
|
@@ -964,7 +1034,7 @@ export class PaneStreamLiveConnection {
|
|
|
964
1034
|
const binding = this.#sessionRuntimeBinding;
|
|
965
1035
|
const offer = this.#descriptor.terminalDelivery;
|
|
966
1036
|
if (!binding || !offer) {
|
|
967
|
-
this
|
|
1037
|
+
this.#fail("no-session-runtime-binding");
|
|
968
1038
|
return;
|
|
969
1039
|
}
|
|
970
1040
|
// Layout authority covers the whole session, while content leases may select
|
|
@@ -1031,7 +1101,7 @@ export class PaneStreamLiveConnection {
|
|
|
1031
1101
|
this.#failTopologyChanged();
|
|
1032
1102
|
return;
|
|
1033
1103
|
}
|
|
1034
|
-
this
|
|
1104
|
+
this.#fail("semantic-layout-subscribe-failed", cause);
|
|
1035
1105
|
return;
|
|
1036
1106
|
}
|
|
1037
1107
|
// Start visible sources first, preserving descriptor order within each
|
|
@@ -1071,8 +1141,10 @@ export class PaneStreamLiveConnection {
|
|
|
1071
1141
|
if (this.#closed ||
|
|
1072
1142
|
settled.some((result) => result.status === "rejected" || !result.value.delivery.negotiation.accepted)) {
|
|
1073
1143
|
await Promise.all(opened.map(({ delivery }) => delivery.close().catch(() => undefined)));
|
|
1074
|
-
if (!this.#closed)
|
|
1075
|
-
|
|
1144
|
+
if (!this.#closed) {
|
|
1145
|
+
const rejected = settled.find((result) => result.status === "rejected");
|
|
1146
|
+
this.#fail("delivery-negotiation-failed", rejected?.status === "rejected" ? rejected.reason : "a pane's delivery offer was refused");
|
|
1147
|
+
}
|
|
1076
1148
|
return;
|
|
1077
1149
|
}
|
|
1078
1150
|
const deliveryIdentityChanged = opened.some(({ channel, delivery, pending }) => {
|
|
@@ -1906,8 +1978,8 @@ export class PaneStreamLiveConnection {
|
|
|
1906
1978
|
try {
|
|
1907
1979
|
this.#socket.send(encoded, { binary });
|
|
1908
1980
|
}
|
|
1909
|
-
catch {
|
|
1910
|
-
this
|
|
1981
|
+
catch (error) {
|
|
1982
|
+
this.#fail("socket-send-failed", error);
|
|
1911
1983
|
return;
|
|
1912
1984
|
}
|
|
1913
1985
|
// Stall is judged on the drain tick, never synchronously at send: the
|
|
@@ -1949,7 +2021,7 @@ export class PaneStreamLiveConnection {
|
|
|
1949
2021
|
return;
|
|
1950
2022
|
const buffered = this.#socket.bufferedAmount ?? 0;
|
|
1951
2023
|
if (!Number.isSafeInteger(buffered) || buffered < 0) {
|
|
1952
|
-
this
|
|
2024
|
+
this.#fail("socket-buffer-invalid");
|
|
1953
2025
|
return;
|
|
1954
2026
|
}
|
|
1955
2027
|
if (buffered > this.#maxSocketBufferedBytes) {
|
|
@@ -2382,6 +2454,23 @@ export class PaneStreamLiveConnection {
|
|
|
2382
2454
|
return true;
|
|
2383
2455
|
}
|
|
2384
2456
|
#sendAuthoritySnapshot(snapshot) {
|
|
2457
|
+
// One line when this connection gains or loses input, and one for its
|
|
2458
|
+
// first snapshot: a stream that paints but never accepts keys shows up
|
|
2459
|
+
// here as "holdsInput false" with the client that holds it instead.
|
|
2460
|
+
const self = this.#sessionRuntimeBinding?.clientId ?? null;
|
|
2461
|
+
const holdsInput = self !== null && snapshot.owners.input === self;
|
|
2462
|
+
if (this.#heldInput !== holdsInput) {
|
|
2463
|
+
logger.info("pane-stream", "stream input authority", {
|
|
2464
|
+
session: this.#descriptor.sessionName,
|
|
2465
|
+
clientId: this.#clientId,
|
|
2466
|
+
connectionClientId: self,
|
|
2467
|
+
holdsInput,
|
|
2468
|
+
inputOwner: snapshot.owners.input,
|
|
2469
|
+
clients: snapshot.clients.length,
|
|
2470
|
+
revision: snapshot.revision,
|
|
2471
|
+
});
|
|
2472
|
+
this.#heldInput = holdsInput;
|
|
2473
|
+
}
|
|
2385
2474
|
this.#sendFrame(null, { type: "authority-snapshot", snapshot });
|
|
2386
2475
|
}
|
|
2387
2476
|
#prepareInputAuthority(geometry) {
|
|
@@ -2660,8 +2749,8 @@ export class PaneStreamLiveConnection {
|
|
|
2660
2749
|
}
|
|
2661
2750
|
}
|
|
2662
2751
|
}
|
|
2663
|
-
catch {
|
|
2664
|
-
this
|
|
2752
|
+
catch (error) {
|
|
2753
|
+
this.#fail("control-frame-handler-failed", error);
|
|
2665
2754
|
}
|
|
2666
2755
|
}
|
|
2667
2756
|
#failProtocol(code) {
|
|
@@ -2673,8 +2762,8 @@ export class PaneStreamLiveConnection {
|
|
|
2673
2762
|
retryable: false,
|
|
2674
2763
|
});
|
|
2675
2764
|
}
|
|
2676
|
-
catch {
|
|
2677
|
-
this
|
|
2765
|
+
catch (error) {
|
|
2766
|
+
this.#fail("error-frame-send-failed", error);
|
|
2678
2767
|
return;
|
|
2679
2768
|
}
|
|
2680
2769
|
this.close(1008, code);
|
|
@@ -48,11 +48,12 @@ export class PaneStreamRuntime {
|
|
|
48
48
|
},
|
|
49
49
|
});
|
|
50
50
|
}
|
|
51
|
-
|
|
51
|
+
/** `close` says what the streams are told; the default is a daemon shutdown. */
|
|
52
|
+
dispose(close) {
|
|
52
53
|
if (!this.#disposePromise) {
|
|
53
54
|
this.#disposePromise = (async () => {
|
|
54
55
|
this.nativeSurfaces?.close();
|
|
55
|
-
await this.coordinator.shutdown();
|
|
56
|
+
await this.coordinator.shutdown(close);
|
|
56
57
|
})();
|
|
57
58
|
}
|
|
58
59
|
return this.#disposePromise;
|
|
@@ -34,6 +34,29 @@ export const SESSION_PANE_DESCRIPTOR_FORMAT = [
|
|
|
34
34
|
// The reader option belongs to the pane only when its own process set it.
|
|
35
35
|
"#{pane_pid}",
|
|
36
36
|
].join("\t");
|
|
37
|
+
/**
|
|
38
|
+
* Descriptor fields the program in a pane changes whenever it likes: its
|
|
39
|
+
* command name, the window name tmux derives from it, and its title.
|
|
40
|
+
*/
|
|
41
|
+
const VOLATILE_DESCRIPTOR_FIELDS = new Set([
|
|
42
|
+
4, // pane_current_command
|
|
43
|
+
7, // window_name
|
|
44
|
+
9, // pane_title
|
|
45
|
+
]);
|
|
46
|
+
/**
|
|
47
|
+
* Whether two `list-panes` replies in SESSION_PANE_DESCRIPTOR_FORMAT describe
|
|
48
|
+
* the same panes. A busy pane changes its command and title between any two
|
|
49
|
+
* reads, which is not a pane set that is still changing: those fields are
|
|
50
|
+
* display text, read again on the next refresh (#730).
|
|
51
|
+
*/
|
|
52
|
+
export function sameSessionPaneInventory(before, after) {
|
|
53
|
+
const stable = (line) => line
|
|
54
|
+
.split("\t")
|
|
55
|
+
.map((field, index) => (VOLATILE_DESCRIPTOR_FIELDS.has(index) ? "" : field))
|
|
56
|
+
.join("\t");
|
|
57
|
+
return (before.length === after.length &&
|
|
58
|
+
before.every((line, index) => line === after[index] || stable(line) === stable(after[index])));
|
|
59
|
+
}
|
|
37
60
|
/** Decode the escapes emitted by tmux's `qa` format modifier. */
|
|
38
61
|
export function decodeTmuxArgument(value) {
|
|
39
62
|
const encoded = value.length >= 2 &&
|
|
@@ -119,7 +119,10 @@ export function stockSplitCommand(request, sessionCreated, plan, panes, options,
|
|
|
119
119
|
export const STOCK_SPLIT_OPTIONS_FORMAT = "#{pane-border-status}\t#{pane-scrollbars}\t#{pane-scrollbars-style}";
|
|
120
120
|
export function parseStockSplitOptions(line) {
|
|
121
121
|
const [borderStatus, scrollbars, style] = (line ?? "").split("\t");
|
|
122
|
-
|
|
122
|
+
// The raw value stays: the guarded command compares it with the option. A
|
|
123
|
+
// floating value leaves tiled panes without a status line, like "off".
|
|
124
|
+
if (!/^(off|top|bottom|top-floating|bottom-floating)$/u.test(borderStatus ?? "") ||
|
|
125
|
+
!/^[a-z]+$/u.test(scrollbars ?? ""))
|
|
123
126
|
return null;
|
|
124
127
|
const field = (name) => Number(new RegExp(`\\b${name}=(\\d+)`, "u").exec(style ?? "")?.[1] ?? 0);
|
|
125
128
|
return {
|
|
@@ -71,6 +71,15 @@ export class SessionRuntimeRegistry {
|
|
|
71
71
|
#scheduler;
|
|
72
72
|
#observability;
|
|
73
73
|
#createTraceCorrelator;
|
|
74
|
+
#onInventoryRecovered;
|
|
75
|
+
#announceInventory(session) {
|
|
76
|
+
try {
|
|
77
|
+
this.#onInventoryRecovered?.(session);
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
// A publication failure never changes qualification.
|
|
81
|
+
}
|
|
82
|
+
}
|
|
74
83
|
#sessions = new Map();
|
|
75
84
|
#listenerDisposal = null;
|
|
76
85
|
#proofPrewarmOwnership = new Map();
|
|
@@ -85,6 +94,7 @@ export class SessionRuntimeRegistry {
|
|
|
85
94
|
this.#observability = options.observability ?? DISABLED_SESSION_RUNTIME_OBSERVABILITY;
|
|
86
95
|
this.#createTraceCorrelator =
|
|
87
96
|
options.createTraceCorrelator ?? ((scheduler) => new RuntimeTraceCorrelator(scheduler));
|
|
97
|
+
this.#onInventoryRecovered = options.onInventoryRecovered ?? null;
|
|
88
98
|
const diagnosticMirrorOptions = {
|
|
89
99
|
onInputAccepted: (session, action, acceptedAtMicros, ok) => {
|
|
90
100
|
for (const traceId of action.traceIds ?? []) {
|
|
@@ -174,6 +184,10 @@ export class SessionRuntimeRegistry {
|
|
|
174
184
|
options.mirror?.onSharedWindowConflict?.(session, conflict);
|
|
175
185
|
if (conflict)
|
|
176
186
|
this.#sessions.get(session)?.invalidateSharedWindowAuthority();
|
|
187
|
+
// A cleared conflict is the trigger an idle client needs: nobody else
|
|
188
|
+
// may read the inventory, and the client's re-read re-qualifies it.
|
|
189
|
+
else if (!this.#mirror.hasSharedWindowConflict(session))
|
|
190
|
+
this.#announceInventory(session);
|
|
177
191
|
},
|
|
178
192
|
onNativeClientActivity: (session) => {
|
|
179
193
|
options.mirror?.onNativeClientActivity?.(session);
|
|
@@ -253,7 +267,10 @@ export class SessionRuntimeRegistry {
|
|
|
253
267
|
}
|
|
254
268
|
signal?.throwIfAborted();
|
|
255
269
|
await abortable(this.#mirror.verifyRegisteredWindows(), signal);
|
|
270
|
+
const wasQualified = runtime.trustedInventoryQualified();
|
|
256
271
|
runtime.qualifyTrustedInventory(runtimeSessionId);
|
|
272
|
+
if (!wasQualified && runtime.trustedInventoryQualified())
|
|
273
|
+
this.#announceInventory(session);
|
|
257
274
|
}
|
|
258
275
|
finally {
|
|
259
276
|
this.#releaseProofPrewarmRuntime(runtime);
|