tmux-ide 2.9.26 → 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/README.md +1 -1
- package/bin/cli.js +2046 -623
- package/package.json +2 -2
- package/packages/contracts/src/pane-stream.ts +45 -0
- package/packages/contracts/src/terminal-delivery.ts +114 -3
- package/packages/core/src/index.ts +1 -0
- package/packages/core/src/terminal-delivery-binary.ts +8 -7
- package/packages/core/src/terminal-delivery.ts +174 -3
- package/packages/core/src/terminal-partial-history.ts +152 -0
- package/packages/core/src/terminal-replica.ts +70 -1
- package/packages/daemon/dist/command-center/owner-keep-alive.js +30 -0
- package/packages/daemon/dist/command-center/resources/terminal-runtime-inventory.js +17 -3
- package/packages/daemon/dist/command-center/server.js +3 -0
- package/packages/daemon/dist/command-center/tmux-server-attach.js +51 -0
- package/packages/daemon/dist/command-center/tmux-servers.js +80 -1
- package/packages/daemon/dist/doctor.js +4 -4
- package/packages/daemon/dist/lib/app-config.js +7 -0
- package/packages/daemon/dist/lib/node-requirement.js +20 -0
- package/packages/daemon/dist/lib/require-supported-node.js +8 -0
- package/packages/daemon/dist/lib/tmux-server-session-open.js +38 -12
- package/packages/daemon/dist/lib/workspace-promotion.js +4 -4
- 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/server/pane-stream-upgrade.js +39 -1
- 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 +198 -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/registry.js +1 -0
- package/packages/daemon/dist/terminal/session-runtime/terminal-delivery-hub.js +465 -42
- 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 +94 -2
- package/packages/daemon/dist/tui/mirror/runtime/open-tui-generation-host.js +9 -1
- package/packages/daemon/dist/tui/mirror/theme.js +8 -1
- package/packages/daemon/dist/tui/mirror/workspace/connection-feedback.js +8 -0
- package/packages/daemon/src/command-center/attach-window-rule.cases.json +84 -0
- package/packages/daemon/src/command-center/owner-keep-alive.ts +38 -0
- package/packages/daemon/src/command-center/resources/terminal-runtime-inventory.ts +20 -2
- package/packages/daemon/src/command-center/server.ts +3 -0
- package/packages/daemon/src/command-center/tmux-server-attach.ts +75 -0
- package/packages/daemon/src/command-center/tmux-servers.ts +88 -1
- package/packages/daemon/src/doctor.ts +4 -4
- package/packages/daemon/src/lib/app-config.ts +15 -0
- package/packages/daemon/src/lib/node-requirement.ts +22 -0
- package/packages/daemon/src/lib/require-supported-node.ts +9 -0
- package/packages/daemon/src/lib/tmux-server-session-open.ts +53 -15
- package/packages/daemon/src/lib/workspace-promotion.ts +4 -4
- package/packages/daemon/src/server/pane-stream-upgrade.ts +41 -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 +240 -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/registry.ts +1 -0
- package/packages/daemon/src/terminal/session-runtime/runtime-observability.ts +2 -1
- package/packages/daemon/src/terminal/session-runtime/terminal-delivery-hub.ts +575 -39
- 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 +101 -2
- package/packages/daemon/src/tui/mirror/runtime/open-tui-generation-host.ts +13 -0
- package/packages/daemon/src/tui/mirror/theme.ts +13 -1
- 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 { STOCK_CAPTURE_TAB_UNAVAILABLE } 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)
|
|
@@ -244,6 +260,13 @@ class WireTerminalEndpoint {
|
|
|
244
260
|
#pending = null;
|
|
245
261
|
#rejectedTransactionId = null;
|
|
246
262
|
#decodeToken = null;
|
|
263
|
+
/**
|
|
264
|
+
* Capability 124: patches the daemon pipelined behind the delivery that is
|
|
265
|
+
* still decoding or unsettled, each with its chunks, in arrival order. Each
|
|
266
|
+
* names the one before as its base; they are admitted once that one is ACKed.
|
|
267
|
+
*/
|
|
268
|
+
#queued = [];
|
|
269
|
+
#draining = false;
|
|
247
270
|
#closed = false;
|
|
248
271
|
#ready;
|
|
249
272
|
#resolveReady;
|
|
@@ -311,6 +334,7 @@ class WireTerminalEndpoint {
|
|
|
311
334
|
return;
|
|
312
335
|
}
|
|
313
336
|
if (message.type === "terminal.delivery.fault") {
|
|
337
|
+
this.#queued.length = 0;
|
|
314
338
|
if (message.deliveryNonce !== this.#negotiated.deliveryNonce) {
|
|
315
339
|
this.#failConnection(new Error("Terminal fault nonce does not match negotiation"));
|
|
316
340
|
return;
|
|
@@ -335,6 +359,15 @@ class WireTerminalEndpoint {
|
|
|
335
359
|
}
|
|
336
360
|
if (this.#unavailable)
|
|
337
361
|
return;
|
|
362
|
+
if ((this.#queued.length > 0 || this.#busy()) && this.#mayQueue(message)) {
|
|
363
|
+
this.#queued.push(message);
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
return this.#acceptNow(message);
|
|
367
|
+
}
|
|
368
|
+
#acceptNow(message) {
|
|
369
|
+
if (message.type === "terminal.delivery.fault")
|
|
370
|
+
return;
|
|
338
371
|
if (message.type === "terminal.projection") {
|
|
339
372
|
this.#failConnection(new Error("Unsolicited alternate-screen projection"));
|
|
340
373
|
return;
|
|
@@ -345,10 +378,61 @@ class WireTerminalEndpoint {
|
|
|
345
378
|
}
|
|
346
379
|
return this.#acceptChunk(message);
|
|
347
380
|
}
|
|
381
|
+
/** A flight is decoding or waiting for its subscriber: it has not been ACKed. */
|
|
382
|
+
#busy() {
|
|
383
|
+
return this.#decodeToken !== null || this.#pending !== null;
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* Capability 124: only a patch based on the newest flight (decoding,
|
|
387
|
+
* unsettled or queued), within TERMINAL_DELIVERY_MAX_PIPELINED, and the
|
|
388
|
+
* chunks of the newest queued patch. Anything else overlapping a flight is
|
|
389
|
+
* still a protocol violation and takes the ordinary path.
|
|
390
|
+
*/
|
|
391
|
+
#mayQueue(message) {
|
|
392
|
+
let newest = this.#pending?.envelope ?? this.#envelope;
|
|
393
|
+
let envelopes = 1;
|
|
394
|
+
let chunks = 0;
|
|
395
|
+
for (const queued of this.#queued)
|
|
396
|
+
if (queued.type === "terminal.delivery") {
|
|
397
|
+
newest = queued;
|
|
398
|
+
envelopes += 1;
|
|
399
|
+
chunks = 0;
|
|
400
|
+
}
|
|
401
|
+
else if (queued.type === "terminal.delivery.chunk")
|
|
402
|
+
chunks += 1;
|
|
403
|
+
if (!newest)
|
|
404
|
+
return false;
|
|
405
|
+
if (message.type === "terminal.delivery.chunk")
|
|
406
|
+
return (envelopes > 1 &&
|
|
407
|
+
message.transactionId === newest.transactionId &&
|
|
408
|
+
chunks < newest.chunkCount);
|
|
409
|
+
return (message.type === "terminal.delivery" &&
|
|
410
|
+
message.frame === "patch" &&
|
|
411
|
+
message.baseRevision === newest.canonicalRevision &&
|
|
412
|
+
message.incarnation === newest.incarnation &&
|
|
413
|
+
envelopes < TERMINAL_DELIVERY_MAX_PIPELINED &&
|
|
414
|
+
(envelopes === 1 || chunks === newest.chunkCount));
|
|
415
|
+
}
|
|
416
|
+
/** Admit queued deliveries in order until one is decoding or unsettled again. */
|
|
417
|
+
#drain() {
|
|
418
|
+
if (this.#draining)
|
|
419
|
+
return;
|
|
420
|
+
this.#draining = true;
|
|
421
|
+
try {
|
|
422
|
+
while (this.#queued.length > 0 && !this.#busy() && !this.#closed) {
|
|
423
|
+
const message = this.#queued.shift();
|
|
424
|
+
this.#acceptNow(message);
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
finally {
|
|
428
|
+
this.#draining = false;
|
|
429
|
+
}
|
|
430
|
+
}
|
|
348
431
|
close() {
|
|
349
432
|
if (this.#closed)
|
|
350
433
|
return;
|
|
351
434
|
this.#closed = true;
|
|
435
|
+
this.#queued.length = 0;
|
|
352
436
|
this.#assembler = null;
|
|
353
437
|
this.#assemblyStorage = null;
|
|
354
438
|
this.#envelope = null;
|
|
@@ -595,7 +679,9 @@ class WireTerminalEndpoint {
|
|
|
595
679
|
}
|
|
596
680
|
catch (error) {
|
|
597
681
|
this.#failConnection(error instanceof Error ? error : new Error(String(error)));
|
|
682
|
+
return;
|
|
598
683
|
}
|
|
684
|
+
this.#drain();
|
|
599
685
|
}
|
|
600
686
|
#reject(reason, envelope, transactionId = null) {
|
|
601
687
|
const negotiated = this.#negotiated;
|
|
@@ -626,6 +712,9 @@ class WireTerminalEndpoint {
|
|
|
626
712
|
this.#decodeToken = null;
|
|
627
713
|
this.#rejectedTransactionId = attempted?.transactionId ?? transactionId;
|
|
628
714
|
this.#reseedRequired = true;
|
|
715
|
+
// Patches queued behind the rejected flight are NACKed in turn ("gap");
|
|
716
|
+
// the daemon dropped them with the first NACK.
|
|
717
|
+
this.#drain();
|
|
629
718
|
}
|
|
630
719
|
}
|
|
631
720
|
class WireTerminalSubscription {
|
|
@@ -710,6 +799,8 @@ class WireTerminalSubscription {
|
|
|
710
799
|
export async function connectOpenTuiWorkspaceRuntimePort(options) {
|
|
711
800
|
const { inventory, routing } = options;
|
|
712
801
|
const panes = canonicalPaneIds(inventory);
|
|
802
|
+
if (panes.length > PANE_STREAM_MAX_PANES)
|
|
803
|
+
throw new OpenTuiPaneLimitError(panes.length, PANE_STREAM_MAX_PANES);
|
|
713
804
|
const expected = {
|
|
714
805
|
daemonInstanceId: inventory.daemonGeneration,
|
|
715
806
|
workspaceName: inventory.workspaceName,
|
|
@@ -942,7 +1033,8 @@ export async function connectOpenTuiWorkspaceRuntimePort(options) {
|
|
|
942
1033
|
panes: [...panes],
|
|
943
1034
|
viewerMode: "interactive",
|
|
944
1035
|
terminalDelivery: {
|
|
945
|
-
|
|
1036
|
+
// 124: this endpoint holds patches pipelined behind a decoding one.
|
|
1037
|
+
protocolVersions: [1, TERMINAL_DELIVERY_PIPELINING_CAPABILITY_VERSION],
|
|
946
1038
|
encodings: ["semantic-compact-v1", "semantic-v1"],
|
|
947
1039
|
richPlacements: true,
|
|
948
1040
|
},
|
|
@@ -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", {
|
|
@@ -597,10 +597,17 @@ export function createSemanticThemeSnapshot(config = undefined, rendererMode = n
|
|
|
597
597
|
increasedContrast: config?.accessibility?.increasedContrast ?? DEFAULT_ACCESSIBILITY.increasedContrast,
|
|
598
598
|
};
|
|
599
599
|
const mode = resolvedMode(setting, rendererMode, hostDefaults);
|
|
600
|
+
// System mode with a chosen preset for each side (the Mac app's Match
|
|
601
|
+
// macOS writes theme.light / theme.dark): the side the host is on.
|
|
602
|
+
const side = setting === "system"
|
|
603
|
+
? findVisualThemePreset(mode === "light" ? config?.light : config?.dark)
|
|
604
|
+
: undefined;
|
|
600
605
|
const resolved = resolveVisualTheme({
|
|
601
606
|
appearance: mode,
|
|
602
607
|
hostDefaults: setting === "system" ? (hostDefaults ?? undefined) : undefined,
|
|
603
|
-
userTheme: config?.userTheme ??
|
|
608
|
+
userTheme: config?.userTheme ??
|
|
609
|
+
findVisualThemePreset(config?.preset) ??
|
|
610
|
+
(side?.appearance === mode ? side : undefined),
|
|
604
611
|
projectTheme: config?.projectTheme,
|
|
605
612
|
accessibility,
|
|
606
613
|
});
|
|
@@ -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) &&
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"name": "a session that fits streams whole, preferred pane selected",
|
|
4
|
+
"windows": [
|
|
5
|
+
{ "id": "window.a", "active": false, "panes": ["pane.1", "pane.2"] },
|
|
6
|
+
{ "id": "window.b", "active": true, "panes": ["pane.3"] }
|
|
7
|
+
],
|
|
8
|
+
"preferred": "pane.3",
|
|
9
|
+
"maxPanes": 3,
|
|
10
|
+
"expect": { "window": null, "panes": ["pane.1", "pane.2", "pane.3"], "selected": "pane.3" }
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
"name": "a whole session without a preferred pane selects the first",
|
|
14
|
+
"windows": [{ "id": "window.a", "active": true, "panes": ["pane.1", "pane.2"] }],
|
|
15
|
+
"preferred": null,
|
|
16
|
+
"maxPanes": 2,
|
|
17
|
+
"expect": { "window": null, "panes": ["pane.1", "pane.2"], "selected": "pane.1" }
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"name": "a preferred pane that is gone selects the first",
|
|
21
|
+
"windows": [{ "id": "window.a", "active": true, "panes": ["pane.1"] }],
|
|
22
|
+
"preferred": "pane.9",
|
|
23
|
+
"maxPanes": 24,
|
|
24
|
+
"expect": { "window": null, "panes": ["pane.1"], "selected": "pane.1" }
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"name": "too many panes: the window holding the preferred pane",
|
|
28
|
+
"windows": [
|
|
29
|
+
{ "id": "window.a", "active": true, "panes": ["pane.1", "pane.2"] },
|
|
30
|
+
{ "id": "window.b", "active": false, "panes": ["pane.3", "pane.4"] }
|
|
31
|
+
],
|
|
32
|
+
"preferred": "pane.4",
|
|
33
|
+
"maxPanes": 3,
|
|
34
|
+
"expect": { "window": "window.b", "panes": ["pane.3", "pane.4"], "selected": "pane.4" }
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
"name": "too many panes and no preferred pane: the active window",
|
|
38
|
+
"windows": [
|
|
39
|
+
{ "id": "window.a", "active": false, "panes": ["pane.1", "pane.2"] },
|
|
40
|
+
{ "id": "window.b", "active": true, "panes": ["pane.3", "pane.4"] }
|
|
41
|
+
],
|
|
42
|
+
"preferred": null,
|
|
43
|
+
"maxPanes": 3,
|
|
44
|
+
"expect": { "window": "window.b", "panes": ["pane.3", "pane.4"], "selected": "pane.3" }
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
"name": "the wanted window does not fit: the active one",
|
|
48
|
+
"windows": [
|
|
49
|
+
{ "id": "window.a", "active": false, "panes": ["pane.1", "pane.2", "pane.5"] },
|
|
50
|
+
{ "id": "window.b", "active": true, "panes": ["pane.3"] }
|
|
51
|
+
],
|
|
52
|
+
"preferred": "pane.2",
|
|
53
|
+
"maxPanes": 2,
|
|
54
|
+
"expect": { "window": "window.b", "panes": ["pane.3"], "selected": "pane.3" }
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
"name": "neither wanted nor active fits: the first that fits",
|
|
58
|
+
"windows": [
|
|
59
|
+
{ "id": "window.a", "active": true, "panes": ["pane.1", "pane.2", "pane.5"] },
|
|
60
|
+
{ "id": "window.b", "active": false, "panes": ["pane.3", "pane.6", "pane.7"] },
|
|
61
|
+
{ "id": "window.c", "active": false, "panes": ["pane.4"] }
|
|
62
|
+
],
|
|
63
|
+
"preferred": null,
|
|
64
|
+
"maxPanes": 2,
|
|
65
|
+
"expect": { "window": "window.c", "panes": ["pane.4"], "selected": "pane.4" }
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
"name": "nothing fits: no selection",
|
|
69
|
+
"windows": [
|
|
70
|
+
{ "id": "window.a", "active": true, "panes": ["pane.1", "pane.2"] },
|
|
71
|
+
{ "id": "window.b", "active": false, "panes": ["pane.3", "pane.4"] }
|
|
72
|
+
],
|
|
73
|
+
"preferred": null,
|
|
74
|
+
"maxPanes": 1,
|
|
75
|
+
"expect": null
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
"name": "no panes: no selection",
|
|
79
|
+
"windows": [],
|
|
80
|
+
"preferred": null,
|
|
81
|
+
"maxPanes": 24,
|
|
82
|
+
"expect": null
|
|
83
|
+
}
|
|
84
|
+
]
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
2
|
+
import type { MiddlewareHandler } from "hono";
|
|
3
|
+
import { ownerBearerMatches } from "./owner-authority.ts";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* How long an owner-authenticated HTTP connection may sit idle before the
|
|
7
|
+
* daemon closes it. Node's default is 5 s, so a native app that paused for
|
|
8
|
+
* longer found its proven connection gone; over SSH every replacement costs
|
|
9
|
+
* a channel open and an identity proof (attach-rtt). The app keeps an idle
|
|
10
|
+
* connection for at most 60 s, below this.
|
|
11
|
+
*/
|
|
12
|
+
export const OWNER_KEEP_ALIVE_MS = 65_000;
|
|
13
|
+
|
|
14
|
+
type NodeBindings = { incoming?: IncomingMessage; outgoing?: ServerResponse } | undefined;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* After a response to the owner bearer, keep that connection open for
|
|
18
|
+
* `timeoutMs` while idle. Every other connection keeps Node's default.
|
|
19
|
+
* Node arms its own keep-alive timer when the response finishes; this runs
|
|
20
|
+
* after it and replaces the bound for this socket only. The next request on
|
|
21
|
+
* the socket clears the timer as usual.
|
|
22
|
+
*/
|
|
23
|
+
export function ownerKeepAlive(
|
|
24
|
+
ownerToken: string | null,
|
|
25
|
+
timeoutMs: number = OWNER_KEEP_ALIVE_MS,
|
|
26
|
+
): MiddlewareHandler {
|
|
27
|
+
return async (c, next) => {
|
|
28
|
+
const bindings = c.env as NodeBindings;
|
|
29
|
+
const outgoing = bindings?.outgoing;
|
|
30
|
+
const socket = bindings?.incoming?.socket;
|
|
31
|
+
if (outgoing && socket && ownerBearerMatches(c.req.header("Authorization"), ownerToken)) {
|
|
32
|
+
outgoing.once("finish", () => {
|
|
33
|
+
if (!socket.destroyed && outgoing.shouldKeepAlive) socket.setTimeout(timeoutMs);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
await next();
|
|
37
|
+
};
|
|
38
|
+
}
|
|
@@ -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),
|
|
@@ -161,6 +161,7 @@ import { mountWorkspaceResourceRoutes } from "./resources/workspace-resource-rou
|
|
|
161
161
|
import { mountFleetResourceRoute } from "./resources/fleet-resource-route.ts";
|
|
162
162
|
import { mountWorkspaceMissionsRoute } from "./resources/workspace-missions-route.ts";
|
|
163
163
|
import { ownerAuthorityGate, requireOwnerAuthority } from "./owner-authority.ts";
|
|
164
|
+
import { ownerKeepAlive } from "./owner-keep-alive.ts";
|
|
164
165
|
import { mountDiagnosticsRoute } from "./diagnostics.ts";
|
|
165
166
|
import {
|
|
166
167
|
mountStartupReadinessRoute,
|
|
@@ -569,6 +570,8 @@ export function createApp(options: CreateAppOptions = {}): Hono {
|
|
|
569
570
|
|
|
570
571
|
// Allow cross-origin (Next.js dashboard, Tailscale, etc.)
|
|
571
572
|
app.use("/*", cors());
|
|
573
|
+
// An owner connection stays open while idle for longer than Node's 5 s.
|
|
574
|
+
app.use("/*", ownerKeepAlive(options.remoteAccess?.ownerToken ?? null));
|
|
572
575
|
|
|
573
576
|
if (options.tmuxServerOwners) {
|
|
574
577
|
mountAutomationRoutes(app, {
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* One request that opens a session, reads its inventory and issues its stream
|
|
5
|
+
* (attach-rtt). Before it the app sent three: open, inventory, issue. The app
|
|
6
|
+
* still checks the answer: it applies its own window rule to the returned
|
|
7
|
+
* inventory and uses the issued stream only when the daemon chose the same.
|
|
8
|
+
*
|
|
9
|
+
* `issue` is the body of an ordinary pane-stream issue request without the
|
|
10
|
+
* workspace name, the panes and the window, which only the daemon knows here.
|
|
11
|
+
*/
|
|
12
|
+
export const TmuxServerAttachRequestSchemaZ = z
|
|
13
|
+
.object({
|
|
14
|
+
version: z.literal(1),
|
|
15
|
+
preferredPane: z.string().min(1).max(128).nullable(),
|
|
16
|
+
maxPanes: z.number().int().min(1).max(256),
|
|
17
|
+
issue: z
|
|
18
|
+
.object({
|
|
19
|
+
expectedDaemonInstanceId: z.uuid(),
|
|
20
|
+
stream: z.record(z.string(), z.unknown()),
|
|
21
|
+
})
|
|
22
|
+
.catchall(z.unknown()),
|
|
23
|
+
})
|
|
24
|
+
.strict();
|
|
25
|
+
export type TmuxServerAttachRequest = z.infer<typeof TmuxServerAttachRequestSchemaZ>;
|
|
26
|
+
|
|
27
|
+
export interface AttachInventory {
|
|
28
|
+
readonly semanticPaneIds: readonly string[];
|
|
29
|
+
readonly windows: readonly {
|
|
30
|
+
readonly semanticWindowId: string;
|
|
31
|
+
readonly active: boolean;
|
|
32
|
+
readonly semanticPaneIds: readonly string[];
|
|
33
|
+
}[];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface AttachSelection {
|
|
37
|
+
/** The one window the stream carries, or null for the whole session. */
|
|
38
|
+
readonly semanticWindowId: string | null;
|
|
39
|
+
readonly panes: readonly string[];
|
|
40
|
+
readonly selectedPane: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* The app's rule (browser_native_local_window.rs `scope`), here so the open
|
|
45
|
+
* and the issue can be one request: a session that fits streams whole;
|
|
46
|
+
* otherwise the window holding the preferred pane (else the active one) when
|
|
47
|
+
* it fits, else the active one, else the first in tmux order that fits. No
|
|
48
|
+
* selection when there is no pane or nothing fits: the app decides then.
|
|
49
|
+
*/
|
|
50
|
+
export function chooseAttachSelection(
|
|
51
|
+
inventory: AttachInventory,
|
|
52
|
+
preferredPane: string | null,
|
|
53
|
+
maxPanes: number,
|
|
54
|
+
): AttachSelection | null {
|
|
55
|
+
const panes = inventory.semanticPaneIds;
|
|
56
|
+
if (panes.length === 0) return null;
|
|
57
|
+
let semanticWindowId: string | null = null;
|
|
58
|
+
let chosen = panes;
|
|
59
|
+
if (panes.length > maxPanes) {
|
|
60
|
+
const fits = (window: AttachInventory["windows"][number] | undefined) =>
|
|
61
|
+
window !== undefined && window.semanticPaneIds.length <= maxPanes;
|
|
62
|
+
const active = inventory.windows.find((window) => window.active);
|
|
63
|
+
const wanted =
|
|
64
|
+
(preferredPane !== null
|
|
65
|
+
? inventory.windows.find((window) => window.semanticPaneIds.includes(preferredPane))
|
|
66
|
+
: undefined) ?? active;
|
|
67
|
+
const window = [wanted, active].find(fits) ?? inventory.windows.find(fits);
|
|
68
|
+
if (!window) return null;
|
|
69
|
+
semanticWindowId = window.semanticWindowId;
|
|
70
|
+
chosen = window.semanticPaneIds;
|
|
71
|
+
}
|
|
72
|
+
const selectedPane =
|
|
73
|
+
preferredPane !== null && chosen.includes(preferredPane) ? preferredPane : chosen[0]!;
|
|
74
|
+
return { semanticWindowId, panes: chosen, selectedPane };
|
|
75
|
+
}
|
|
@@ -41,6 +41,7 @@ import { WorkspacePaneCreationError } from "../lib/workspace-pane-creation.ts";
|
|
|
41
41
|
import { ownerBearerMatches } from "./owner-authority.ts";
|
|
42
42
|
import { logger } from "../lib/log.ts";
|
|
43
43
|
import { mountPaneStreamIssueRoute } from "./pane-stream-issue.ts";
|
|
44
|
+
import { chooseAttachSelection, TmuxServerAttachRequestSchemaZ } from "./tmux-server-attach.ts";
|
|
44
45
|
import {
|
|
45
46
|
projectTerminalRuntimeInventory,
|
|
46
47
|
projectTerminalRuntimeInventoryV2,
|
|
@@ -295,6 +296,89 @@ export function mountTmuxServerRoutes(app: Hono, options: TmuxServerRoutesOption
|
|
|
295
296
|
return c.json({ version: 1, server, ...result });
|
|
296
297
|
}),
|
|
297
298
|
);
|
|
299
|
+
// attach-rtt: open, inventory and issue in one round trip. The stream is
|
|
300
|
+
// issued through the ordinary issue route with this request's headers, so
|
|
301
|
+
// it is checked exactly as a separate issue request would be.
|
|
302
|
+
app.post(
|
|
303
|
+
`${scoped}/sessions/:liveSessionId/attach`,
|
|
304
|
+
route(async (c) => {
|
|
305
|
+
const server = scope(c);
|
|
306
|
+
const liveSessionId = workspaceSchema.parse(c.req.param("liveSessionId"));
|
|
307
|
+
const request = TmuxServerAttachRequestSchemaZ.parse(await boundedJson(c.req.raw));
|
|
308
|
+
// The issue below checks the same, but only after the open: refuse a
|
|
309
|
+
// request for another generation before it can promote anything.
|
|
310
|
+
if (
|
|
311
|
+
request.issue.expectedDaemonInstanceId !== server.generation ||
|
|
312
|
+
c.req.header("X-Tmux-Ide-Expected-Daemon-Instance-Id") !== server.generation
|
|
313
|
+
)
|
|
314
|
+
throw new TmuxServerScopeError("stale-generation");
|
|
315
|
+
const result = await options.owners.withOwner(server, async (owner) => {
|
|
316
|
+
const opened = await owner.openSession(liveSessionId);
|
|
317
|
+
const workspace = owner.workspaceRegistry.get(opened.workspaceName);
|
|
318
|
+
if (!workspace || opened.liveSessionId !== liveSessionId)
|
|
319
|
+
throw new TmuxServerScopeError("stale-generation");
|
|
320
|
+
const snapshot = await owner.terminalInventoryRuntime.discoverTerminalRuntimeSession(
|
|
321
|
+
workspace.sessionName,
|
|
322
|
+
c.req.raw.signal,
|
|
323
|
+
);
|
|
324
|
+
if (!snapshot) return null;
|
|
325
|
+
const inventory = projectTerminalRuntimeInventoryV2(snapshot, 0);
|
|
326
|
+
const selection = chooseAttachSelection(inventory, request.preferredPane, request.maxPanes);
|
|
327
|
+
if (!selection)
|
|
328
|
+
return { kind: "attached" as const, opened, inventory, selection, issue: null };
|
|
329
|
+
// The window is the daemon's to choose, never the client's.
|
|
330
|
+
const stream = { ...request.issue.stream };
|
|
331
|
+
delete stream.semanticWindowId;
|
|
332
|
+
const body = {
|
|
333
|
+
...request.issue,
|
|
334
|
+
stream: {
|
|
335
|
+
...stream,
|
|
336
|
+
workspaceName: opened.workspaceName,
|
|
337
|
+
panes: selection.panes,
|
|
338
|
+
...(selection.semanticWindowId ? { semanticWindowId: selection.semanticWindowId } : {}),
|
|
339
|
+
},
|
|
340
|
+
};
|
|
341
|
+
const issueApp = new Hono();
|
|
342
|
+
mountPaneStreamIssueRoute(issueApp, {
|
|
343
|
+
daemonInstanceId: server.generation,
|
|
344
|
+
ownerToken: options.ownerToken,
|
|
345
|
+
workspaceRegistry: owner.workspaceRegistry,
|
|
346
|
+
backend: owner.paneStreamRuntime.coordinator,
|
|
347
|
+
});
|
|
348
|
+
const url = new URL(c.req.url);
|
|
349
|
+
url.pathname = PANE_STREAM_ISSUE_PATH;
|
|
350
|
+
url.search = "";
|
|
351
|
+
const headers = new Headers(c.req.raw.headers);
|
|
352
|
+
headers.delete("Content-Length");
|
|
353
|
+
headers.set("Content-Type", "application/json");
|
|
354
|
+
const issued = await issueApp.request(
|
|
355
|
+
new Request(url, { method: "POST", headers, body: JSON.stringify(body) }),
|
|
356
|
+
);
|
|
357
|
+
// The issue route answers a refused issue as 200 with an error
|
|
358
|
+
// envelope, which goes back in `issue` with the open and inventory
|
|
359
|
+
// (the app then issues again). A non-200 is an auth or body refusal.
|
|
360
|
+
if (issued.status !== 200) return { kind: "refused" as const, refused: issued };
|
|
361
|
+
return {
|
|
362
|
+
kind: "attached" as const,
|
|
363
|
+
opened,
|
|
364
|
+
inventory,
|
|
365
|
+
selection,
|
|
366
|
+
issue: (await issued.json()) as unknown,
|
|
367
|
+
};
|
|
368
|
+
});
|
|
369
|
+
if (!result) return c.json({ error: { code: "workspace-not-found" } }, 404);
|
|
370
|
+
if (result.kind === "refused") return result.refused;
|
|
371
|
+
return c.json({
|
|
372
|
+
version: 1,
|
|
373
|
+
server,
|
|
374
|
+
workspaceName: result.opened.workspaceName,
|
|
375
|
+
liveSessionId,
|
|
376
|
+
inventory: result.inventory,
|
|
377
|
+
selection: result.selection,
|
|
378
|
+
issue: result.issue,
|
|
379
|
+
});
|
|
380
|
+
}),
|
|
381
|
+
);
|
|
298
382
|
app.get(
|
|
299
383
|
`${scoped}/sessions`,
|
|
300
384
|
route(async (c) => {
|
|
@@ -513,7 +597,10 @@ export function mountTmuxServerRoutes(app: Hono, options: TmuxServerRoutesOption
|
|
|
513
597
|
() => undefined,
|
|
514
598
|
{
|
|
515
599
|
expectedRuntimeSessionId: identity.runtimeSessionId,
|
|
516
|
-
|
|
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
|
+
),
|
|
517
604
|
onAuthority(snapshot) {
|
|
518
605
|
if (snapshot.windowLinks.liveSessionId !== c.req.query("liveSessionId")) {
|
|
519
606
|
sessionReplaced = true;
|
|
@@ -17,6 +17,7 @@ import { findCompiledTui, hasDevelopmentTuiSource, isBunAvailable } from "./tui/
|
|
|
17
17
|
import { claudeSettingsPath } from "./tui/integrations/claude.ts";
|
|
18
18
|
import { readNotificationPrefs, resolveNativeMacosNotifierPath } from "./tui/chrome/notify.ts";
|
|
19
19
|
import { resolveConfig } from "./lib/resolved-config.ts";
|
|
20
|
+
import { MINIMUM_NODE_MAJOR, isSupportedNodeVersion } from "./lib/node-requirement.ts";
|
|
20
21
|
import {
|
|
21
22
|
collectDaemonProvenanceReport,
|
|
22
23
|
type DaemonProvenanceReport,
|
|
@@ -436,12 +437,11 @@ export function tmuxServerSocketRow(environment: NodeJS.ProcessEnv, uid: number)
|
|
|
436
437
|
}
|
|
437
438
|
|
|
438
439
|
export function nodeVersionRow(version: string): CheckResult {
|
|
439
|
-
const
|
|
440
|
-
const pass = Number.isInteger(major) && major >= 20;
|
|
440
|
+
const pass = isSupportedNodeVersion(version);
|
|
441
441
|
return {
|
|
442
|
-
label:
|
|
442
|
+
label: `Node.js ≥ ${MINIMUM_NODE_MAJOR}`,
|
|
443
443
|
pass,
|
|
444
|
-
detail: pass ? `v${version}` : `Node ${version} (need ≥
|
|
444
|
+
detail: pass ? `v${version}` : `Node ${version} (need ≥ ${MINIMUM_NODE_MAJOR})`,
|
|
445
445
|
optional: false,
|
|
446
446
|
};
|
|
447
447
|
}
|