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
|
@@ -89,6 +89,13 @@ export interface AppTheme {
|
|
|
89
89
|
/** Explicit palette mode or terminal-following mode. Defaults to following the terminal. */
|
|
90
90
|
mode: ThemeModeSetting;
|
|
91
91
|
preset?: string;
|
|
92
|
+
/**
|
|
93
|
+
* The presets `mode: "system"` uses when the terminal (or macOS, in the
|
|
94
|
+
* Mac app) is light or dark. Kept only when each names a preset of that
|
|
95
|
+
* appearance; unset, system mode follows the host palette as before.
|
|
96
|
+
*/
|
|
97
|
+
light?: string;
|
|
98
|
+
dark?: string;
|
|
92
99
|
/** Primary/brand accent (default `colour75`). */
|
|
93
100
|
accent: string;
|
|
94
101
|
/** Muted/secondary foreground for dim text (default `colour240`). */
|
|
@@ -368,6 +375,12 @@ function appThemeOverrideProvenance(
|
|
|
368
375
|
* back to its default, so partial and garbage configs both resolve to a complete,
|
|
369
376
|
* well-typed {@link AppConfig}. Never throws.
|
|
370
377
|
*/
|
|
378
|
+
/** `theme.light` / `theme.dark`, when the id names a preset of that appearance. */
|
|
379
|
+
function systemSide(value: unknown, appearance: "light" | "dark"): Partial<AppTheme> {
|
|
380
|
+
const preset = findVisualThemePreset(value);
|
|
381
|
+
return preset?.appearance === appearance ? { [appearance]: preset.id } : {};
|
|
382
|
+
}
|
|
383
|
+
|
|
371
384
|
export function parseAppConfig(input: unknown): AppConfig {
|
|
372
385
|
const D = DEFAULT_APP_CONFIG;
|
|
373
386
|
const root = asObject(input);
|
|
@@ -405,6 +418,8 @@ export function parseAppConfig(input: unknown): AppConfig {
|
|
|
405
418
|
findVisualThemePreset(theme.preset)?.appearance ?? D.theme.mode,
|
|
406
419
|
),
|
|
407
420
|
...(findVisualThemePreset(theme.preset) ? { preset: String(theme.preset) } : {}),
|
|
421
|
+
...systemSide(theme.light, "light"),
|
|
422
|
+
...systemSide(theme.dark, "dark"),
|
|
408
423
|
accent: pickString(theme.accent, D.theme.accent),
|
|
409
424
|
muted: pickString(theme.muted, D.theme.muted),
|
|
410
425
|
fg: pickString(theme.fg, D.theme.fg),
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** The oldest Node.js major an npm install of tmux-ide supports (package.json `engines`). */
|
|
2
|
+
export const MINIMUM_NODE_MAJOR = 24;
|
|
3
|
+
|
|
4
|
+
/** True when `version` (as in `process.versions.node`) is new enough. */
|
|
5
|
+
export function isSupportedNodeVersion(version: string): boolean {
|
|
6
|
+
const major = Number(version.split(".")[0]);
|
|
7
|
+
return Number.isInteger(major) && major >= MINIMUM_NODE_MAJOR;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The message the CLI prints before exiting on an unsupported Node.js, or null
|
|
12
|
+
* when the runtime is supported. Bun (dev runs, compiled surfaces) is exempt.
|
|
13
|
+
*/
|
|
14
|
+
export function unsupportedNodeMessage(versions: { node?: string; bun?: string }): string | null {
|
|
15
|
+
if (versions.bun !== undefined || versions.node === undefined) return null;
|
|
16
|
+
if (isSupportedNodeVersion(versions.node)) return null;
|
|
17
|
+
return (
|
|
18
|
+
`tmux-ide needs Node.js ${MINIMUM_NODE_MAJOR} or newer; this is Node.js ${versions.node}.\n` +
|
|
19
|
+
`Upgrade Node.js, or use the installer, which brings its own runtime:\n` +
|
|
20
|
+
` curl -fsSL https://tmux-ide.com/install.sh | sh\n`
|
|
21
|
+
);
|
|
22
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Imported first by bin/cli.ts so an unsupported Node.js stops with a clear
|
|
2
|
+
// message before any command code runs.
|
|
3
|
+
import { unsupportedNodeMessage } from "./node-requirement.ts";
|
|
4
|
+
|
|
5
|
+
const message = unsupportedNodeMessage(process.versions);
|
|
6
|
+
if (message !== null) {
|
|
7
|
+
process.stderr.write(message);
|
|
8
|
+
process.exit(1);
|
|
9
|
+
}
|
|
@@ -8,7 +8,13 @@ import { WorkspaceCatalogLiveSessionIdSchemaZ } from "@tmux-ide/contracts";
|
|
|
8
8
|
import { liveSessionIdForNativeIdentity } from "../terminal/protocol/live-session-identity.ts";
|
|
9
9
|
import { fleetSessionIdForName } from "../command-center/resources/fleet-catalog.ts";
|
|
10
10
|
import { isVisibleFleetSession } from "../command-center/discovery.ts";
|
|
11
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
ADOPTED_OPTION,
|
|
13
|
+
hasValidPaneStamp,
|
|
14
|
+
SEMANTIC_PANE_OPTION,
|
|
15
|
+
SEMANTIC_WINDOW_OPTION,
|
|
16
|
+
WorkspacePromotionAuthority,
|
|
17
|
+
} from "./workspace-promotion.ts";
|
|
12
18
|
import type { WorkspaceRegistry } from "./workspace-registry.ts";
|
|
13
19
|
import { shellEscape } from "./shell.ts";
|
|
14
20
|
|
|
@@ -28,30 +34,62 @@ export function createNativeTmuxSessionOpener(options: {
|
|
|
28
34
|
};
|
|
29
35
|
const open = async (liveSessionId: string, observed?: ObservedAgent) => {
|
|
30
36
|
assertOpen();
|
|
37
|
+
// One row per pane: the session's identity, whether it is adopted, and
|
|
38
|
+
// each window's and pane's stamp. tmux rejects tabs in session names, so
|
|
39
|
+
// the name is the last field; a pane stamp with a tab is invalid anyway.
|
|
31
40
|
const records = await options.run([
|
|
32
|
-
"list-
|
|
41
|
+
"list-panes",
|
|
42
|
+
"-a",
|
|
33
43
|
"-F",
|
|
34
|
-
|
|
44
|
+
`#{pid}\t#{session_id}\t#{session_created}\t#{${ADOPTED_OPTION}}\t#{${SEMANTIC_WINDOW_OPTION}}\t#{${SEMANTIC_PANE_OPTION}}\t#{session_name}`,
|
|
35
45
|
]);
|
|
36
|
-
|
|
37
|
-
const matches = records
|
|
46
|
+
const rows = records
|
|
38
47
|
.replace(/\n+$/u, "")
|
|
39
48
|
.split("\n")
|
|
40
49
|
.map((line) => line.split("\t"))
|
|
50
|
+
.filter((fields) => fields.length >= 7)
|
|
51
|
+
.map((fields) => ({
|
|
52
|
+
// A tab can only come from a window or pane stamp: such a row never
|
|
53
|
+
// takes the fast path below.
|
|
54
|
+
exact: fields.length === 7,
|
|
55
|
+
pid: fields[0]!,
|
|
56
|
+
id: fields[1]!,
|
|
57
|
+
created: fields[2]!,
|
|
58
|
+
adopted: fields[3]!,
|
|
59
|
+
window: fields.slice(4, -2).join("\t"),
|
|
60
|
+
pane: fields.at(-2)!,
|
|
61
|
+
name: fields.at(-1)!,
|
|
62
|
+
}))
|
|
41
63
|
.filter(
|
|
42
|
-
(
|
|
43
|
-
pid &&
|
|
64
|
+
({ pid, id, created, name }) =>
|
|
44
65
|
/^\d+$/.test(pid) &&
|
|
45
|
-
id &&
|
|
46
66
|
/^\$\d+$/.test(id) &&
|
|
47
|
-
created &&
|
|
48
67
|
/^\d+$/.test(created) &&
|
|
49
68
|
name &&
|
|
50
69
|
isVisibleFleetSession(name) &&
|
|
51
70
|
liveSessionIdForNativeIdentity(pid, id, created) === liveSessionId,
|
|
52
71
|
);
|
|
53
|
-
if (
|
|
54
|
-
|
|
72
|
+
if (new Set(rows.map((row) => row.id)).size !== 1)
|
|
73
|
+
throw new Error("Selected live tmux session is no longer available");
|
|
74
|
+
const { id: nativeSessionId, created, name } = rows[0]!;
|
|
75
|
+
// Re-opening a session that an earlier open already finished changes
|
|
76
|
+
// nothing: it is adopted, has exactly one durable alias, and every window
|
|
77
|
+
// and pane already carries a stamp. Promotion would only read it again
|
|
78
|
+
// (seven tmux commands), so skip it. Anything else promotes as before,
|
|
79
|
+
// which also stamps panes split since the last open.
|
|
80
|
+
const aliases = options.registry.list().filter((entry) => entry.sessionName === name);
|
|
81
|
+
if (
|
|
82
|
+
!observed &&
|
|
83
|
+
aliases.length === 1 &&
|
|
84
|
+
!options.registry.isVolatile(aliases[0]!.name) &&
|
|
85
|
+
rows.every(
|
|
86
|
+
(row) =>
|
|
87
|
+
row.exact && row.adopted === "1" && row.window.length > 0 && hasValidPaneStamp(row.pane),
|
|
88
|
+
)
|
|
89
|
+
) {
|
|
90
|
+
assertOpen();
|
|
91
|
+
return { workspaceName: aliases[0]!.name, liveSessionId };
|
|
92
|
+
}
|
|
55
93
|
// Each command checks the exact native session on the server accepting it.
|
|
56
94
|
// A name-only validation followed by stamping would cross a session replacement.
|
|
57
95
|
const run = async (args: readonly string[]) => {
|
|
@@ -62,7 +100,7 @@ export function createNativeTmuxSessionOpener(options: {
|
|
|
62
100
|
const output = await options.run([
|
|
63
101
|
"if-shell",
|
|
64
102
|
"-t",
|
|
65
|
-
nativeSessionId
|
|
103
|
+
nativeSessionId,
|
|
66
104
|
"-F",
|
|
67
105
|
condition,
|
|
68
106
|
command,
|
|
@@ -74,7 +112,7 @@ export function createNativeTmuxSessionOpener(options: {
|
|
|
74
112
|
return output;
|
|
75
113
|
};
|
|
76
114
|
const agent = observed
|
|
77
|
-
? await captureAgentAdmission(run, { id: nativeSessionId
|
|
115
|
+
? await captureAgentAdmission(run, { id: nativeSessionId, name }, observed)
|
|
78
116
|
: null;
|
|
79
117
|
await agent?.verify(false);
|
|
80
118
|
const promotion = new WorkspacePromotionAuthority({
|
|
@@ -86,9 +124,9 @@ export function createNativeTmuxSessionOpener(options: {
|
|
|
86
124
|
const result = await promotion.promote({
|
|
87
125
|
operationId: randomUUID(),
|
|
88
126
|
expectedDaemonInstanceId: options.generation,
|
|
89
|
-
intent: { sessionId: fleetSessionIdForName(name
|
|
127
|
+
intent: { sessionId: fleetSessionIdForName(name) },
|
|
90
128
|
});
|
|
91
|
-
await run(["display-message", "-p", "-t", nativeSessionId
|
|
129
|
+
await run(["display-message", "-p", "-t", nativeSessionId, "#{session_id}"]);
|
|
92
130
|
const semanticPaneId = await agent?.verify(true);
|
|
93
131
|
return {
|
|
94
132
|
workspaceName: result.resource.workspaceName,
|
|
@@ -69,12 +69,12 @@ const MAX_TMUX_OUTPUT_BYTES = 128 * 1024;
|
|
|
69
69
|
// is proven, immediately before registry admission. The promotion marker is
|
|
70
70
|
// DELIBERATELY distinct from the m32 open marker so a promoted session is a
|
|
71
71
|
// separate provenance.
|
|
72
|
-
const ADOPTED_OPTION = "@tmux_ide_adopted";
|
|
72
|
+
export const ADOPTED_OPTION = "@tmux_ide_adopted";
|
|
73
73
|
const SESSION_PROMOTED_MARKER_OPTION = "@tmux_ide_workspace_promoted_v1";
|
|
74
74
|
const SESSION_WORKSPACE_OPTION = "@tmux_ide_workspace_name";
|
|
75
75
|
const SESSION_OPERATION_OPTION = "@tmux_ide_workspace_promote_operation";
|
|
76
|
-
const SEMANTIC_PANE_OPTION = "@tmux_ide_pane_id";
|
|
77
|
-
const SEMANTIC_WINDOW_OPTION = "@tmux_ide_window_id";
|
|
76
|
+
export const SEMANTIC_PANE_OPTION = "@tmux_ide_pane_id";
|
|
77
|
+
export const SEMANTIC_WINDOW_OPTION = "@tmux_ide_window_id";
|
|
78
78
|
|
|
79
79
|
// Distinctive multi-char field/line delimiters — collision-resistant against
|
|
80
80
|
// arbitrary pane paths, window names and user-controlled `@agent_*` values,
|
|
@@ -301,7 +301,7 @@ function isInternalSession(name: string): boolean {
|
|
|
301
301
|
const VALID_SEMANTIC_PANE_ID = /^[A-Za-z0-9][A-Za-z0-9._-]*$/u;
|
|
302
302
|
const RESERVED_DISCOVERED_PREFIX = "terminal.discovered.";
|
|
303
303
|
|
|
304
|
-
function hasValidPaneStamp(value: string): boolean {
|
|
304
|
+
export function hasValidPaneStamp(value: string): boolean {
|
|
305
305
|
return (
|
|
306
306
|
value.length > 0 &&
|
|
307
307
|
value.length <= 128 &&
|
|
@@ -28,6 +28,35 @@ function rawHeaderValues(
|
|
|
28
28
|
return values;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
+
/**
|
|
32
|
+
* attach-rtt: the client may carry its redeem frame in the upgrade request
|
|
33
|
+
* (base64url of the frame's JSON text), so the daemon answers the 101 and the
|
|
34
|
+
* seed without waiting a round trip for the frame. The 101 says so with
|
|
35
|
+
* `X-Tmux-Ide-Redeem: accepted`; a client that sees no such header sends the
|
|
36
|
+
* frame as before. Absent, the upgrade is exactly as it was.
|
|
37
|
+
*/
|
|
38
|
+
export const PANE_STREAM_REDEEM_HEADER = "x-tmux-ide-redeem";
|
|
39
|
+
|
|
40
|
+
/** The frame a redeem header carries, `null` for none, or "invalid". */
|
|
41
|
+
function upgradeRedeemFrame(
|
|
42
|
+
request: import("node:http").IncomingMessage,
|
|
43
|
+
): Buffer | null | "invalid" {
|
|
44
|
+
const values = rawHeaderValues(request, PANE_STREAM_REDEEM_HEADER);
|
|
45
|
+
if (values.length === 0) return null;
|
|
46
|
+
const value = values[0]!;
|
|
47
|
+
if (
|
|
48
|
+
values.length > 1 ||
|
|
49
|
+
value.length === 0 ||
|
|
50
|
+
value.length > Math.ceil((PANE_STREAM_MAX_REDEMPTION_BYTES * 4) / 3) ||
|
|
51
|
+
!/^[A-Za-z0-9_-]+$/u.test(value)
|
|
52
|
+
)
|
|
53
|
+
return "invalid";
|
|
54
|
+
const frame = Buffer.from(value, "base64url");
|
|
55
|
+
return frame.byteLength === 0 || frame.byteLength > PANE_STREAM_MAX_REDEMPTION_BYTES
|
|
56
|
+
? "invalid"
|
|
57
|
+
: frame;
|
|
58
|
+
}
|
|
59
|
+
|
|
31
60
|
function rejectUpgrade(socket: Socket, status: number): void {
|
|
32
61
|
const phrase =
|
|
33
62
|
status === 403
|
|
@@ -77,7 +106,11 @@ export function attachPaneStreamWebSocket(
|
|
|
77
106
|
});
|
|
78
107
|
|
|
79
108
|
// Old clients ignore the header and answer the pings by protocol.
|
|
80
|
-
|
|
109
|
+
const redeemed = new WeakSet<import("node:http").IncomingMessage>();
|
|
110
|
+
wss.on("headers", (headers, request) => {
|
|
111
|
+
heartbeat.advertise(headers);
|
|
112
|
+
if (redeemed.has(request)) headers.push("X-Tmux-Ide-Redeem: accepted");
|
|
113
|
+
});
|
|
81
114
|
|
|
82
115
|
const upgrade = (
|
|
83
116
|
request: import("node:http").IncomingMessage,
|
|
@@ -123,6 +156,11 @@ export function attachPaneStreamWebSocket(
|
|
|
123
156
|
rejectUpgrade(socket, 403);
|
|
124
157
|
return;
|
|
125
158
|
}
|
|
159
|
+
const redeemFrame = upgradeRedeemFrame(request);
|
|
160
|
+
if (redeemFrame === "invalid") {
|
|
161
|
+
rejectUpgrade(socket, 403);
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
126
164
|
if (!isCurrent()) {
|
|
127
165
|
rejectUpgrade(socket, 410);
|
|
128
166
|
return;
|
|
@@ -141,12 +179,14 @@ export function attachPaneStreamWebSocket(
|
|
|
141
179
|
const cancelUnbound = (): void => decision.admission.cancelBeforeBind();
|
|
142
180
|
socket.once("close", cancelUnbound);
|
|
143
181
|
socket.once("error", cancelUnbound);
|
|
182
|
+
if (redeemFrame) redeemed.add(request);
|
|
144
183
|
try {
|
|
145
184
|
wss.handleUpgrade(request, socket, head, (ws) => {
|
|
146
185
|
socket.off("close", cancelUnbound);
|
|
147
186
|
socket.off("error", cancelUnbound);
|
|
148
187
|
heartbeat.watch(ws, `pane-stream ${redemptionPath}`);
|
|
149
188
|
decision.admission.bind(ws as unknown as DirectTerminalSocket);
|
|
189
|
+
if (redeemFrame) decision.admission.redeemFromUpgrade(redeemFrame);
|
|
150
190
|
});
|
|
151
191
|
} catch {
|
|
152
192
|
socket.off("close", cancelUnbound);
|
|
@@ -498,6 +498,8 @@ export interface NativeTerminalInventoryPaneSnapshot extends TrustedSemanticPane
|
|
|
498
498
|
/** Durable `@tmux_ide_mission` creation stamp, or null when unset. */
|
|
499
499
|
readonly missionStamp: string | null;
|
|
500
500
|
readonly dir: string;
|
|
501
|
+
/** #882: a floating pane; present, but not in the tiled layout. */
|
|
502
|
+
readonly floating?: boolean;
|
|
501
503
|
}
|
|
502
504
|
|
|
503
505
|
export interface NativeTerminalInventorySnapshot {
|
|
@@ -600,6 +602,7 @@ function projectTrustedMirrorInventory(
|
|
|
600
602
|
type: nullable(pane.type),
|
|
601
603
|
missionStamp: nullable(pane.missionStamp),
|
|
602
604
|
dir: boundedWireValue(pane.dir, 4_096),
|
|
605
|
+
...(pane.floating === true ? { floating: true } : {}),
|
|
603
606
|
});
|
|
604
607
|
});
|
|
605
608
|
if (
|
|
@@ -633,6 +636,7 @@ function analyzeInventoryPanes(panes: readonly NativeTerminalInventoryPaneSnapsh
|
|
|
633
636
|
interactionEndpoint: _interactionEndpoint,
|
|
634
637
|
nativeIdentity: _nativeIdentity,
|
|
635
638
|
nativePaneBirthId: _nativePaneBirthId,
|
|
639
|
+
floating: _floating,
|
|
636
640
|
...row
|
|
637
641
|
}) => row,
|
|
638
642
|
),
|
|
@@ -725,6 +729,8 @@ const PANE_FORMAT = [
|
|
|
725
729
|
"#{@tmux_ide_window_id}",
|
|
726
730
|
"#{window_index}",
|
|
727
731
|
"#{pane_birth_id}",
|
|
732
|
+
// #882: a floating pane (tmux 3.7+) has no tiled cell; older tmux prints "".
|
|
733
|
+
"#{pane_floating_flag}",
|
|
728
734
|
PANE_WIRE_SENTINEL,
|
|
729
735
|
].join(WIRE_SEPARATOR);
|
|
730
736
|
|
|
@@ -786,7 +792,7 @@ function parsePaneSnapshot(
|
|
|
786
792
|
const links = new Map<number, { windowId: string; active: boolean; panes: Set<string> }>();
|
|
787
793
|
for (const line of strictLines(stdout, MAX_DISCOVERED_PANES)) {
|
|
788
794
|
const fields = line.split(WIRE_SEPARATOR);
|
|
789
|
-
if (fields.length !==
|
|
795
|
+
if (fields.length !== 22 || fields[21] !== PANE_WIRE_SENTINEL) {
|
|
790
796
|
throw new NativeTerminalAttachmentRuntimeError("invalid-tmux-output");
|
|
791
797
|
}
|
|
792
798
|
const [
|
|
@@ -810,6 +816,7 @@ function parsePaneSnapshot(
|
|
|
810
816
|
windowStampValue,
|
|
811
817
|
windowIndexValue,
|
|
812
818
|
nativePaneBirthId,
|
|
819
|
+
floating,
|
|
813
820
|
] = fields as [
|
|
814
821
|
string,
|
|
815
822
|
string,
|
|
@@ -832,6 +839,7 @@ function parsePaneSnapshot(
|
|
|
832
839
|
string,
|
|
833
840
|
string,
|
|
834
841
|
string,
|
|
842
|
+
string,
|
|
835
843
|
];
|
|
836
844
|
if (
|
|
837
845
|
sessionName !== expected.name ||
|
|
@@ -868,6 +876,7 @@ function parsePaneSnapshot(
|
|
|
868
876
|
// registered workspace remains the trusted application-shell root, so
|
|
869
877
|
// keep discovery available and carry the empty presentation value.
|
|
870
878
|
dir: boundedWireValue(dir, 4_096),
|
|
879
|
+
...(floating === "1" ? { floating: true } : {}),
|
|
871
880
|
};
|
|
872
881
|
const windowIndex = nonnegativeInteger(windowIndexValue);
|
|
873
882
|
const link = links.get(windowIndex) ?? {
|
|
@@ -1038,6 +1047,7 @@ export async function discoverWorkspaceRegistryTerminalInventory(
|
|
|
1038
1047
|
interactionEndpoint: _interactionEndpoint,
|
|
1039
1048
|
nativeIdentity: _nativeIdentity,
|
|
1040
1049
|
nativePaneBirthId: _nativePaneBirthId,
|
|
1050
|
+
floating: _floating,
|
|
1041
1051
|
...row
|
|
1042
1052
|
}) => row,
|
|
1043
1053
|
),
|
|
@@ -1068,6 +1078,7 @@ export async function discoverWorkspaceRegistrySemanticPanes(
|
|
|
1068
1078
|
interactionEndpoint: _interactionEndpoint,
|
|
1069
1079
|
nativeIdentity: _nativeIdentity,
|
|
1070
1080
|
nativePaneBirthId: _nativePaneBirthId,
|
|
1081
|
+
floating: _floating,
|
|
1071
1082
|
...row
|
|
1072
1083
|
}) => row,
|
|
1073
1084
|
);
|
|
@@ -1400,6 +1411,7 @@ export class WorkspaceTerminalInventoryRuntime {
|
|
|
1400
1411
|
interactionEndpoint: _interactionEndpoint,
|
|
1401
1412
|
nativeIdentity: _nativeIdentity,
|
|
1402
1413
|
nativePaneBirthId: _nativePaneBirthId,
|
|
1414
|
+
floating: _floating,
|
|
1403
1415
|
...row
|
|
1404
1416
|
}) => row,
|
|
1405
1417
|
);
|
|
@@ -2155,6 +2167,7 @@ export class NativeTerminalAttachmentRuntime {
|
|
|
2155
2167
|
interactionEndpoint: _interactionEndpoint,
|
|
2156
2168
|
nativeIdentity: _nativeIdentity,
|
|
2157
2169
|
nativePaneBirthId: _nativePaneBirthId,
|
|
2170
|
+
floating: _floating,
|
|
2158
2171
|
...row
|
|
2159
2172
|
}) => row,
|
|
2160
2173
|
);
|
|
@@ -2431,6 +2444,7 @@ export class NativeTerminalAttachmentRuntime {
|
|
|
2431
2444
|
interactionEndpoint: _interactionEndpoint,
|
|
2432
2445
|
nativeIdentity: _nativeIdentity,
|
|
2433
2446
|
nativePaneBirthId: _nativePaneBirthId,
|
|
2447
|
+
floating: _floating,
|
|
2434
2448
|
...row
|
|
2435
2449
|
}) => row,
|
|
2436
2450
|
),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { WindowLinkTopology } from "@tmux-ide/contracts";
|
|
2
|
-
import type { NativeGridCapture } from "./native-grid-capture.ts";
|
|
2
|
+
import type { NativeGridCapture, NativeHistoryPiece } from "./native-grid-capture.ts";
|
|
3
3
|
/**
|
|
4
4
|
* Public event contract of the daemon MirrorService (m43 card 1).
|
|
5
5
|
*
|
|
@@ -78,10 +78,26 @@ export type MirrorPaneEvent =
|
|
|
78
78
|
state: "paused" | "resumed";
|
|
79
79
|
reason: "backpressure" | "requested";
|
|
80
80
|
}
|
|
81
|
+
| {
|
|
82
|
+
/**
|
|
83
|
+
* #873: the answer to this subscriber's own `requestNativeHistory`, in
|
|
84
|
+
* stream order: every delta before it was read before tmux read the
|
|
85
|
+
* piece, every delta after it later. Null when the read failed or output
|
|
86
|
+
* crossed it; the requester may ask again.
|
|
87
|
+
*/
|
|
88
|
+
type: "history";
|
|
89
|
+
piece: NativeHistoryPiece | null;
|
|
90
|
+
}
|
|
81
91
|
| {
|
|
82
92
|
/** Native recovery exhausted its bounds; this is not evidence of pane deletion. */
|
|
83
93
|
type: "fault";
|
|
84
94
|
reason: "native-recovery-failed";
|
|
95
|
+
/**
|
|
96
|
+
* Present only when the pane's recoveries failed in a row and this one
|
|
97
|
+
* was refused without asking tmux (#869, #872): how long until the pane
|
|
98
|
+
* is asked again, and why its last real try failed.
|
|
99
|
+
*/
|
|
100
|
+
hold?: MirrorPaneHold;
|
|
85
101
|
}
|
|
86
102
|
| {
|
|
87
103
|
/** The pane is gone from tmux truth (a successful list-panes reply that
|
|
@@ -89,6 +105,15 @@ export type MirrorPaneEvent =
|
|
|
89
105
|
type: "closed";
|
|
90
106
|
};
|
|
91
107
|
|
|
108
|
+
/** Why a held pane's last real recovery failed: its capture was over the size cap, or anything else. */
|
|
109
|
+
export type MirrorPaneHoldWhy = "too-large" | "failed";
|
|
110
|
+
|
|
111
|
+
export interface MirrorPaneHold {
|
|
112
|
+
/** Whole milliseconds until a new recovery asks tmux again; at least 1. */
|
|
113
|
+
readonly retryInMs: number;
|
|
114
|
+
readonly why: MirrorPaneHoldWhy;
|
|
115
|
+
}
|
|
116
|
+
|
|
92
117
|
/** One visible pane rectangle inside a layout event, in window cells. */
|
|
93
118
|
export interface MirrorLayoutPane {
|
|
94
119
|
browserIcon?: string | null;
|
|
@@ -154,6 +179,11 @@ export interface MirrorPaneDescription {
|
|
|
154
179
|
displayNameSource: "manual" | "agent" | "process" | "title" | "generated";
|
|
155
180
|
windowName: string | null;
|
|
156
181
|
active: boolean;
|
|
182
|
+
/**
|
|
183
|
+
* #882: a floating pane (tmux 3.7 and later). It is listed, but it has no
|
|
184
|
+
* cell in the tiled layout, so no stream attaches to it or waits for it.
|
|
185
|
+
*/
|
|
186
|
+
floating?: true;
|
|
157
187
|
}
|
|
158
188
|
|
|
159
189
|
/** Identity-join diagnostic, stripped of runtime addresses at the boundary. */
|
|
@@ -55,6 +55,7 @@ import {
|
|
|
55
55
|
import type { TrustedMirrorSessionInventory } from "./trusted-inventory.ts";
|
|
56
56
|
import type { InputAction } from "../protocol/input-coalescer.ts";
|
|
57
57
|
import type { NativeGridReadResult } from "./native-grid-reader.ts";
|
|
58
|
+
import type { NativeHistoryRequest } from "./native-grid-capture.ts";
|
|
58
59
|
import {
|
|
59
60
|
controlModeAuthorityKey,
|
|
60
61
|
processControlModeOwnershipRegistry,
|
|
@@ -141,6 +142,12 @@ export interface MirrorSubscription {
|
|
|
141
142
|
captureNativeBacking?(): Promise<NativeGridReadResult>;
|
|
142
143
|
/** Native metadata on this exact retained pane; null means unavailable. */
|
|
143
144
|
readHistorySize?(): Promise<number | null>;
|
|
145
|
+
/**
|
|
146
|
+
* #873: read older native history rows. The answer is one `history` event on
|
|
147
|
+
* this subscription, in stream order. False when nothing was sent (no
|
|
148
|
+
* event follows).
|
|
149
|
+
*/
|
|
150
|
+
requestNativeHistory?(request: NativeHistoryRequest): boolean;
|
|
144
151
|
readonly session: string;
|
|
145
152
|
readonly semanticPaneId: string;
|
|
146
153
|
/** Park delivery for this subscriber (offscreen freeze). Siblings and other
|
|
@@ -383,6 +390,17 @@ export class MirrorService {
|
|
|
383
390
|
return identity;
|
|
384
391
|
}
|
|
385
392
|
|
|
393
|
+
/**
|
|
394
|
+
* #872: a person asked to retry these panes now. Each one's next recovery
|
|
395
|
+
* asks tmux even inside a hold after failed recoveries. A session without a
|
|
396
|
+
* channel has no hold to lift.
|
|
397
|
+
*/
|
|
398
|
+
liftRecoveryHolds(session: string, semanticPaneIds: readonly string[]): void {
|
|
399
|
+
const entry = this.channels.get(session);
|
|
400
|
+
if (!entry || entry.retired) return;
|
|
401
|
+
for (const semanticPaneId of semanticPaneIds) entry.channel.liftRecoveryHold(semanticPaneId);
|
|
402
|
+
}
|
|
403
|
+
|
|
386
404
|
async subscribe(request: MirrorSubscribeRequest): Promise<MirrorSubscription> {
|
|
387
405
|
const entry = await this.acquire(request.session);
|
|
388
406
|
let handle;
|
|
@@ -405,6 +423,7 @@ export class MirrorService {
|
|
|
405
423
|
thaw: () => handle.thaw(),
|
|
406
424
|
reseed: () => handle.reseed(),
|
|
407
425
|
readHistorySize: () => handle.readHistorySize(),
|
|
426
|
+
requestNativeHistory: (historyRequest) => handle.requestNativeHistory(historyRequest),
|
|
408
427
|
captureNativeBacking: () => handle.captureNativeBacking(),
|
|
409
428
|
sendText: (text) => {
|
|
410
429
|
this.assertWindowOwnership(request.session);
|
|
@@ -43,6 +43,7 @@ function validLimit(limit: number): boolean {
|
|
|
43
43
|
export function nativeAtomicSnapshotPlan(
|
|
44
44
|
target: NativeAtomicSnapshotTarget,
|
|
45
45
|
maxBytes = NATIVE_ATOMIC_SNAPSHOT_MAX_BYTES,
|
|
46
|
+
historyRows?: number,
|
|
46
47
|
): OwnedViewerRequest {
|
|
47
48
|
const validated = TargetSchema.parse(target);
|
|
48
49
|
const continuationBytes = `%continue ${validated.paneId}\n`.length;
|
|
@@ -61,7 +62,7 @@ export function nativeAtomicSnapshotPlan(
|
|
|
61
62
|
"-U",
|
|
62
63
|
String(maxBytes - continuationBytes),
|
|
63
64
|
"-S",
|
|
64
|
-
|
|
65
|
+
historyStart(historyRows),
|
|
65
66
|
"-t",
|
|
66
67
|
validated.paneId,
|
|
67
68
|
],
|
|
@@ -70,6 +71,13 @@ export function nativeAtomicSnapshotPlan(
|
|
|
70
71
|
limits: { maxBytes, maxLines: MAX_LINES },
|
|
71
72
|
};
|
|
72
73
|
}
|
|
74
|
+
/** #873: `-S -` reads all history; `-S -N` the newest N rows. */
|
|
75
|
+
function historyStart(historyRows: number | undefined): string {
|
|
76
|
+
if (historyRows === undefined) return "-";
|
|
77
|
+
if (!Number.isSafeInteger(historyRows) || historyRows < 0 || historyRows > 1_000_000)
|
|
78
|
+
throw new TypeError("Invalid atomic snapshot history rows");
|
|
79
|
+
return `-${historyRows}`;
|
|
80
|
+
}
|
|
73
81
|
const decimal = (value: string | undefined): number | null =>
|
|
74
82
|
value !== undefined && /^(0|[1-9][0-9]*)$/u.test(value) && Number.isSafeInteger(Number(value))
|
|
75
83
|
? Number(value)
|
|
@@ -84,7 +92,7 @@ function validModes(line: string, capture: NativeGridCapture): boolean {
|
|
|
84
92
|
numeric[1] !== capture.cursor[1] ||
|
|
85
93
|
numeric[2] !== capture.cols ||
|
|
86
94
|
numeric[3] !== capture.rows ||
|
|
87
|
-
numeric[4] !== capture.history ||
|
|
95
|
+
numeric[4] !== capture.history + (capture.omittedHistory ?? 0) ||
|
|
88
96
|
numeric[5] !== capture.limit
|
|
89
97
|
)
|
|
90
98
|
return false;
|
|
@@ -138,7 +146,9 @@ export function decodeNativeAtomicSnapshot(
|
|
|
138
146
|
// Native Q emits this notification inside its own child frame. It must be
|
|
139
147
|
// terminal and exact; a separate asynchronous notification proves nothing here.
|
|
140
148
|
if (reply.lines.at(-1) !== `%continue ${expected.paneId}`) return unknown;
|
|
141
|
-
const capture = decodeNativeGridCapture(reply.lines.slice(1, -1).join("\n") + "\n"
|
|
149
|
+
const capture = decodeNativeGridCapture(reply.lines.slice(1, -1).join("\n") + "\n", {
|
|
150
|
+
tail: true,
|
|
151
|
+
});
|
|
142
152
|
if (!capture || !isNativeBootstrapCapture(capture) || !validModes(metadata.cursor, capture))
|
|
143
153
|
return unknown;
|
|
144
154
|
return {
|
|
@@ -179,8 +189,9 @@ export type NativeAtomicDualSnapshotResult =
|
|
|
179
189
|
export function nativeAtomicDualSnapshotPlan(
|
|
180
190
|
target: NativeAtomicSnapshotTarget,
|
|
181
191
|
maxBytes = NATIVE_ATOMIC_SNAPSHOT_MAX_BYTES,
|
|
192
|
+
historyRows?: number,
|
|
182
193
|
): OwnedViewerRequest {
|
|
183
|
-
const plan = nativeAtomicSnapshotPlan(target, maxBytes);
|
|
194
|
+
const plan = nativeAtomicSnapshotPlan(target, maxBytes, historyRows);
|
|
184
195
|
return {
|
|
185
196
|
...plan,
|
|
186
197
|
commands: [
|
|
@@ -193,7 +204,7 @@ export function nativeAtomicDualSnapshotPlan(
|
|
|
193
204
|
"-U",
|
|
194
205
|
String(maxBytes),
|
|
195
206
|
"-S",
|
|
196
|
-
|
|
207
|
+
historyStart(historyRows),
|
|
197
208
|
"-t",
|
|
198
209
|
target.paneId,
|
|
199
210
|
],
|