tmux-ide 2.9.17 → 2.9.18
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 +629 -320
- package/package.json +1 -1
- package/packages/daemon/dist/doctor.js +101 -2
- package/packages/daemon/dist/lib/daemon-embed.js +4 -1
- package/packages/daemon/dist/lib/native-split-capability.js +20 -0
- package/packages/daemon/dist/lib/tmux-server-owner.js +2 -1
- package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/Info.plist +2 -2
- package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/MacOS/tmux-ide-notifier +0 -0
- package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/Resources/Assets.car +0 -0
- package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/_CodeSignature/CodeResources +2 -2
- package/packages/daemon/dist/terminal/mirror/control-channel.js +3 -2
- package/packages/daemon/dist/terminal/mirror/mirror-service.js +47 -11
- package/packages/daemon/dist/terminal/mirror/session-channel.js +19 -4
- package/packages/daemon/dist/terminal/mirror/window-split-authority.js +9 -2
- package/packages/daemon/dist/terminal/protocol/native-split-resize.js +16 -16
- package/packages/daemon/dist/terminal/protocol/stock-split-resize.js +194 -0
- package/packages/daemon/src/doctor.ts +104 -2
- package/packages/daemon/src/lib/daemon-embed.ts +4 -0
- package/packages/daemon/src/lib/native-split-capability.ts +21 -0
- package/packages/daemon/src/lib/tmux-server-owner.ts +2 -0
- package/packages/daemon/src/terminal/mirror/control-channel.ts +3 -2
- package/packages/daemon/src/terminal/mirror/mirror-service.ts +51 -12
- package/packages/daemon/src/terminal/mirror/session-channel.ts +23 -4
- package/packages/daemon/src/terminal/mirror/window-split-authority.ts +15 -4
- package/packages/daemon/src/terminal/protocol/native-split-resize.ts +16 -16
- package/packages/daemon/src/terminal/protocol/stock-split-resize.ts +268 -0
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Moves one split boundary on a stock tmux server, which has neither
|
|
3
|
+
* `tmux-ide-resize-split` nor the operation journal.
|
|
4
|
+
*
|
|
5
|
+
* `resize-pane` names a pane, and tmux applies it to that pane's nearest
|
|
6
|
+
* same-axis ancestor, so the target is a leaf that reaches the split's parent
|
|
7
|
+
* through opposite-axis splits only. The boundary is clamped to its two
|
|
8
|
+
* neighbours, because tmux takes space from further siblings once they run out.
|
|
9
|
+
* The move is relative, because an absolute -y adds one on the status line's edge.
|
|
10
|
+
*
|
|
11
|
+
* The guard and the resize are one `if-shell -F`: tmux evaluates the format
|
|
12
|
+
* inline and runs the commands it queues before any other client's command, so
|
|
13
|
+
* a change from outside cannot land between the comparison and the resize. Send
|
|
14
|
+
* it on a control connection, where if-shell and each branch command answer in
|
|
15
|
+
* their own block, three in all, the last holding the answer. On tmux 3.8 only control clients read
|
|
16
|
+
* `#{window_layout}` in the format the mirror holds; other clients read JSON.
|
|
17
|
+
*/
|
|
18
|
+
import { randomUUID } from "node:crypto";
|
|
19
|
+
import { parseLayoutTree } from "./layout-parse.js";
|
|
20
|
+
import { locateSplit, preservesSplitTree, splitEdge, validSplitTree, } from "./native-split-resize.js";
|
|
21
|
+
const span = (node, axis) => (axis === "cols" ? node.width : node.height);
|
|
22
|
+
const start = (node, axis) => (axis === "cols" ? node.left : node.top);
|
|
23
|
+
/** tmux's own minimum (`layout_resize_check`): a leaf holds one cell, plus the pane
|
|
24
|
+
* status line on the window's top or bottom edge, and any scrollbar. */
|
|
25
|
+
function minimum(node, axis, sizes, root) {
|
|
26
|
+
if (node.kind === "leaf") {
|
|
27
|
+
if (axis === "cols")
|
|
28
|
+
return 1 + sizes.scrollbar;
|
|
29
|
+
const onEdge = (sizes.borderStatus === "top" && node.top === root.top) ||
|
|
30
|
+
(sizes.borderStatus === "bottom" && node.top + node.height === root.top + root.height);
|
|
31
|
+
return onEdge ? 2 : 1;
|
|
32
|
+
}
|
|
33
|
+
const mins = node.children.map((child) => minimum(child, axis, sizes, root));
|
|
34
|
+
return node.axis === axis
|
|
35
|
+
? mins.reduce((sum, size) => sum + size, node.children.length - 1)
|
|
36
|
+
: Math.max(...mins);
|
|
37
|
+
}
|
|
38
|
+
/** A pane whose nearest ancestor on `axis` is the cell directly above `node`. */
|
|
39
|
+
function reachingLeaf(node, axis) {
|
|
40
|
+
if (node.kind === "leaf")
|
|
41
|
+
return node.id;
|
|
42
|
+
if (node.axis === axis)
|
|
43
|
+
return null;
|
|
44
|
+
for (const child of node.children) {
|
|
45
|
+
const leaf = reachingLeaf(child, axis);
|
|
46
|
+
if (leaf)
|
|
47
|
+
return leaf;
|
|
48
|
+
}
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
/** The pane to name in `resize-pane` for the boundary after the cell at `path`.
|
|
52
|
+
* Null means tmux has no way to address that boundary. In its last cell a pane
|
|
53
|
+
* acts on the boundary before it, so either side's pane moves it the same way. */
|
|
54
|
+
export function stockSplitTarget(tree, path, axis) {
|
|
55
|
+
const located = locateSplit(tree, path);
|
|
56
|
+
if (!located || located.parent.axis !== axis)
|
|
57
|
+
return null;
|
|
58
|
+
const leading = reachingLeaf(located.node, axis);
|
|
59
|
+
if (leading)
|
|
60
|
+
return leading;
|
|
61
|
+
const index = path.at(-1);
|
|
62
|
+
if (index + 1 !== located.parent.children.length - 1)
|
|
63
|
+
return null;
|
|
64
|
+
return reachingLeaf(located.parent.children[index + 1], axis);
|
|
65
|
+
}
|
|
66
|
+
/** Where the boundary may go without tmux taking space from further siblings. */
|
|
67
|
+
export function stockSplitRange(tree, path, axis, sizes) {
|
|
68
|
+
const located = locateSplit(tree, path);
|
|
69
|
+
if (!located)
|
|
70
|
+
return null;
|
|
71
|
+
const after = located.parent.children[path.at(-1) + 1];
|
|
72
|
+
const low = start(located.node, axis) + minimum(located.node, axis, sizes, tree);
|
|
73
|
+
const high = start(after, axis) + span(after, axis) - minimum(after, axis, sizes, tree) - 1;
|
|
74
|
+
return { low, high };
|
|
75
|
+
}
|
|
76
|
+
/** Whether a handle on this boundary could move it at all. */
|
|
77
|
+
export function stockSplitMovable(tree, path, axis, sizes) {
|
|
78
|
+
const range = stockSplitRange(tree, path, axis, sizes);
|
|
79
|
+
return stockSplitTarget(tree, path, axis) !== null && range !== null && range.high > range.low;
|
|
80
|
+
}
|
|
81
|
+
export function planStockSplitResize(tree, path, axis, boundary, sizes) {
|
|
82
|
+
const paneId = stockSplitTarget(tree, path, axis);
|
|
83
|
+
const range = stockSplitRange(tree, path, axis, sizes);
|
|
84
|
+
const located = locateSplit(tree, path);
|
|
85
|
+
if (!paneId || !range || !located || range.high < range.low)
|
|
86
|
+
return null;
|
|
87
|
+
const clamped = Math.min(range.high, Math.max(range.low, boundary));
|
|
88
|
+
return { paneId, boundary: clamped, delta: clamped - splitEdge(located.node, axis) };
|
|
89
|
+
}
|
|
90
|
+
/** Escapes a layout for the right side of a format comparison. */
|
|
91
|
+
function formatLiteral(layout) {
|
|
92
|
+
return layout.replaceAll(",", "#,").replaceAll("}", "#}");
|
|
93
|
+
}
|
|
94
|
+
function leafCount(node) {
|
|
95
|
+
return node.kind === "leaf" ? 1 : node.children.reduce((sum, child) => sum + leafCount(child), 0);
|
|
96
|
+
}
|
|
97
|
+
export function stockSplitCommand(request, sessionCreated, plan, panes, options, marker) {
|
|
98
|
+
const equal = (name, value) => `#{==:#{${name}},${value}}`;
|
|
99
|
+
const condition = [
|
|
100
|
+
equal("window_id", request.windowId),
|
|
101
|
+
equal("session_id", request.sessionId),
|
|
102
|
+
equal("session_created", sessionCreated),
|
|
103
|
+
equal("window_zoomed_flag", 0),
|
|
104
|
+
// Control clients' layouts leave out floating panes; this count includes them.
|
|
105
|
+
equal("window_panes", panes),
|
|
106
|
+
equal("pane-border-status", options.borderStatus),
|
|
107
|
+
equal("pane-scrollbars", options.scrollbars),
|
|
108
|
+
equal("window_layout", formatLiteral(request.expectedLayout)),
|
|
109
|
+
].reduceRight((rest, next) => `#{&&:${next},${rest}}`);
|
|
110
|
+
// Relative, because tmux adds one to an absolute -y on the status line's edge.
|
|
111
|
+
const flag = request.axis === "cols" ? (plan.delta > 0 ? "-R" : "-L") : plan.delta > 0 ? "-D" : "-U";
|
|
112
|
+
const move = plan.delta === 0
|
|
113
|
+
? `display-message -p ""`
|
|
114
|
+
: `resize-pane -t ${plan.paneId} ${flag} ${Math.abs(plan.delta)}`;
|
|
115
|
+
const readback = `display-message -p -t ${request.windowId} "${marker} #{window_layout}"`;
|
|
116
|
+
return `if-shell -F -t '${request.sessionId}:${request.windowId}' '${condition}' '${move} ; ${readback}' 'display-message -p ${marker} ; display-message -p ${marker}'`;
|
|
117
|
+
}
|
|
118
|
+
/** The format that reads a window's sizing options, and its parser. */
|
|
119
|
+
export const STOCK_SPLIT_OPTIONS_FORMAT = "#{pane-border-status}\t#{pane-scrollbars}\t#{pane-scrollbars-style}";
|
|
120
|
+
export function parseStockSplitOptions(line) {
|
|
121
|
+
const [borderStatus, scrollbars, style] = (line ?? "").split("\t");
|
|
122
|
+
if (!/^(off|top|bottom)$/u.test(borderStatus ?? "") || !/^[a-z]+$/u.test(scrollbars ?? ""))
|
|
123
|
+
return null;
|
|
124
|
+
const field = (name) => Number(new RegExp(`\\b${name}=(\\d+)`, "u").exec(style ?? "")?.[1] ?? 0);
|
|
125
|
+
return {
|
|
126
|
+
borderStatus: borderStatus,
|
|
127
|
+
scrollbars: scrollbars,
|
|
128
|
+
scrollbar: scrollbars === "off" ? 0 : Math.max(field("width"), 1) + field("pad"),
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
/** Authorizes, then sends the command without awaiting in between. A sent command
|
|
132
|
+
* that does not answer as expected is uncertain: the caller must not retry it. */
|
|
133
|
+
export async function resizeStockSplit(request, sessionCreated, authorizeBeforeEffect, io) {
|
|
134
|
+
const before = parseLayoutTree(request.expectedLayout);
|
|
135
|
+
if (!before ||
|
|
136
|
+
!validSplitTree(before) ||
|
|
137
|
+
!/^\$\d+$/u.test(request.sessionId) ||
|
|
138
|
+
!/^@\d+$/u.test(request.windowId) ||
|
|
139
|
+
!/^[1-9]\d*$/u.test(sessionCreated))
|
|
140
|
+
return { status: "refused", reason: "invalid-request" };
|
|
141
|
+
let options;
|
|
142
|
+
try {
|
|
143
|
+
options = parseStockSplitOptions((await io.readOptions(request.windowId))[0]);
|
|
144
|
+
}
|
|
145
|
+
catch {
|
|
146
|
+
return { status: "refused", reason: "unsupported" };
|
|
147
|
+
}
|
|
148
|
+
if (!options)
|
|
149
|
+
return { status: "refused", reason: "unsupported" };
|
|
150
|
+
const plan = planStockSplitResize(before, request.path, request.axis, request.boundary, options);
|
|
151
|
+
if (!plan)
|
|
152
|
+
return { status: "refused", reason: "invalid-request" };
|
|
153
|
+
const marker = `tmux-ide-split-${randomUUID()}`;
|
|
154
|
+
const command = stockSplitCommand(request, sessionCreated, plan, leafCount(before), options, marker);
|
|
155
|
+
authorizeBeforeEffect();
|
|
156
|
+
let reply;
|
|
157
|
+
try {
|
|
158
|
+
reply = await io.send(command);
|
|
159
|
+
}
|
|
160
|
+
catch {
|
|
161
|
+
return { status: "uncertain", reason: "command-failed" };
|
|
162
|
+
}
|
|
163
|
+
const answer = reply.join("\n");
|
|
164
|
+
if (answer === marker)
|
|
165
|
+
return { status: "refused", reason: "stale-layout" };
|
|
166
|
+
if (reply.length !== 1 || !answer.startsWith(`${marker} `))
|
|
167
|
+
return { status: "uncertain", reason: "invalid-receipt" };
|
|
168
|
+
const layout = answer.slice(marker.length + 1);
|
|
169
|
+
const after = parseLayoutTree(layout);
|
|
170
|
+
const original = locateSplit(before, request.path);
|
|
171
|
+
const actual = after && locateSplit(after, request.path);
|
|
172
|
+
if (!after ||
|
|
173
|
+
!validSplitTree(after) ||
|
|
174
|
+
!actual ||
|
|
175
|
+
!preservesSplitTree(before, after, original.parent, request.axis))
|
|
176
|
+
return { status: "uncertain", reason: "invalid-receipt" };
|
|
177
|
+
// Only this boundary may have moved: its parent's other children keep their edges.
|
|
178
|
+
const edges = (parent) => parent.children.map((child) => splitEdge(child, request.axis));
|
|
179
|
+
const moved = request.path.at(-1);
|
|
180
|
+
const others = edges(actual.parent);
|
|
181
|
+
if (edges(original.parent).some((edge, index) => index !== moved && edge !== others[index]))
|
|
182
|
+
return { status: "uncertain", reason: "invalid-receipt" };
|
|
183
|
+
const boundary = splitEdge(actual.node, request.axis);
|
|
184
|
+
const previous = splitEdge(original.node, request.axis);
|
|
185
|
+
if (boundary < Math.min(previous, plan.boundary) || boundary > Math.max(previous, plan.boundary))
|
|
186
|
+
return { status: "uncertain", reason: "invalid-receipt" };
|
|
187
|
+
return {
|
|
188
|
+
status: "applied",
|
|
189
|
+
boundary,
|
|
190
|
+
layout,
|
|
191
|
+
tree: after,
|
|
192
|
+
changed: layout !== request.expectedLayout,
|
|
193
|
+
};
|
|
194
|
+
}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { requireSupportedTmuxVersion } from "./lib/tmux-version.ts";
|
|
2
2
|
import { resolveTmuxExecutable } from "./lib/tmux-client-execution.ts";
|
|
3
|
+
import { TMUX_SOCKET_PATH_ENV } from "./lib/runtime-namespace.ts";
|
|
3
4
|
import { execSync, execFileSync } from "node:child_process";
|
|
4
|
-
import { accessSync, constants, existsSync } from "node:fs";
|
|
5
|
-
import {
|
|
5
|
+
import { accessSync, constants, existsSync, mkdtempSync, rmSync } from "node:fs";
|
|
6
|
+
import { tmpdir } from "node:os";
|
|
7
|
+
import { resolve, dirname, join } from "node:path";
|
|
8
|
+
import { nativeSplitCapability } from "./terminal/protocol/native-split-resize.ts";
|
|
6
9
|
import { fileURLToPath } from "node:url";
|
|
7
10
|
import { getCurrentVersion, getUpdateStatus } from "./lib/update-check.ts";
|
|
8
11
|
import { installedSkillVersion } from "./lib/skill-sync.ts";
|
|
@@ -176,6 +179,99 @@ function check(
|
|
|
176
179
|
}
|
|
177
180
|
}
|
|
178
181
|
|
|
182
|
+
type TmuxProbe = (args: readonly string[]) => string;
|
|
183
|
+
const UNKNOWN = (command: string) => new RegExp(`^unknown command: ${command}$`, "mu");
|
|
184
|
+
|
|
185
|
+
type NativeAnswer = "full" | "stock" | "partial" | "no-server" | "unknown";
|
|
186
|
+
/** The same reading of the server as the mirror's: stock only when it refuses both
|
|
187
|
+
* native commands by name, and full only with the split capability it requires. */
|
|
188
|
+
function nativeCommands(probe: TmuxProbe): NativeAnswer {
|
|
189
|
+
const ask = (command: string) => {
|
|
190
|
+
try {
|
|
191
|
+
return { output: probe([command, "-V"]) };
|
|
192
|
+
} catch (error) {
|
|
193
|
+
const failure = error as { stderr?: unknown; message?: string };
|
|
194
|
+
return { failure: String(failure.stderr ?? failure.message ?? "") };
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
const split = ask("tmux-ide-resize-split");
|
|
198
|
+
const events = ask("tmux-ide-events");
|
|
199
|
+
const failures = [split.failure, events.failure].filter((text) => text !== undefined);
|
|
200
|
+
if (failures.some((text) => /no server running|error connecting/u.test(text!)))
|
|
201
|
+
return "no-server";
|
|
202
|
+
const refused = (answer: { failure?: string }, command: string) =>
|
|
203
|
+
answer.failure !== undefined && UNKNOWN(command).test(answer.failure);
|
|
204
|
+
if (refused(split, "tmux-ide-resize-split") && refused(events, "tmux-ide-events")) return "stock";
|
|
205
|
+
if (split.output !== undefined && events.output !== undefined) {
|
|
206
|
+
try {
|
|
207
|
+
return nativeSplitCapability(split.output) ? "full" : "partial";
|
|
208
|
+
} catch {
|
|
209
|
+
return "partial";
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
return failures.length === 2 ? "unknown" : "partial";
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/** Reads the server a session would use. With none running, a throwaway private
|
|
216
|
+
* server shows what the resolved binary would start. */
|
|
217
|
+
export function tmuxFeaturesRow(probeServer: TmuxProbe, probeBinary: TmuxProbe): CheckResult {
|
|
218
|
+
let answer = nativeCommands(probeServer);
|
|
219
|
+
if (answer === "no-server") answer = nativeCommands(probeBinary);
|
|
220
|
+
const details: Record<NativeAnswer, string> = {
|
|
221
|
+
full: "bundled tmux: full features",
|
|
222
|
+
stock: "stock tmux: reduced features",
|
|
223
|
+
partial: "this tmux has only some tmux-ide commands: no pane dividers",
|
|
224
|
+
"no-server": "could not read the tmux server's features",
|
|
225
|
+
unknown: "could not read the tmux server's features",
|
|
226
|
+
};
|
|
227
|
+
return {
|
|
228
|
+
label: "tmux features",
|
|
229
|
+
pass: answer === "full" || answer === "stock",
|
|
230
|
+
detail: details[answer],
|
|
231
|
+
optional: true,
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function runTmuxFeatureProbes(executable: string): CheckResult {
|
|
236
|
+
const run =
|
|
237
|
+
(prefix: readonly string[]): TmuxProbe =>
|
|
238
|
+
(args) =>
|
|
239
|
+
execFileSync(executable, [...prefix, ...args], {
|
|
240
|
+
encoding: "utf8",
|
|
241
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
242
|
+
timeout: 3000,
|
|
243
|
+
});
|
|
244
|
+
const socketPath = process.env[TMUX_SOCKET_PATH_ENV];
|
|
245
|
+
const socketName = process.env.TMUX_IDE_TMUX_SOCKET_NAME;
|
|
246
|
+
const server = socketPath ? ["-S", socketPath] : socketName ? ["-L", socketName] : [];
|
|
247
|
+
const cleanups: (() => void)[] = [];
|
|
248
|
+
const probeBinary: TmuxProbe = (() => {
|
|
249
|
+
let scratch: { dir: string; prefix: readonly string[] } | null = null;
|
|
250
|
+
return (args) => {
|
|
251
|
+
scratch ??= (() => {
|
|
252
|
+
const dir = mkdtempSync(join(tmpdir(), "tmi-doctor-"));
|
|
253
|
+
const prefix = ["-S", join(dir, "s"), "-f", "/dev/null"];
|
|
254
|
+
cleanups.push(() => {
|
|
255
|
+
try {
|
|
256
|
+
run(prefix)(["kill-server"]);
|
|
257
|
+
} catch {
|
|
258
|
+
// The server is already gone.
|
|
259
|
+
}
|
|
260
|
+
rmSync(dir, { recursive: true, force: true });
|
|
261
|
+
});
|
|
262
|
+
run(prefix)(["new-session", "-d", "-s", "probe"]);
|
|
263
|
+
return { dir, prefix };
|
|
264
|
+
})();
|
|
265
|
+
return run(scratch.prefix)(args);
|
|
266
|
+
};
|
|
267
|
+
})();
|
|
268
|
+
try {
|
|
269
|
+
return tmuxFeaturesRow(run(server), probeBinary);
|
|
270
|
+
} finally {
|
|
271
|
+
for (const cleanup of cleanups) cleanup();
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
179
275
|
export function nodeVersionRow(version: string): CheckResult {
|
|
180
276
|
const major = Number(version.split(".")[0]);
|
|
181
277
|
const pass = Number.isInteger(major) && major >= 20;
|
|
@@ -227,6 +323,12 @@ export async function doctor({
|
|
|
227
323
|
}),
|
|
228
324
|
);
|
|
229
325
|
|
|
326
|
+
try {
|
|
327
|
+
checks.push(runTmuxFeatureProbes(resolveTmuxExecutable()));
|
|
328
|
+
} catch {
|
|
329
|
+
// The tmux version row above already reports a missing executable.
|
|
330
|
+
}
|
|
331
|
+
|
|
230
332
|
checks.push(nodeVersionRow(process.versions.node));
|
|
231
333
|
|
|
232
334
|
checks.push(
|
|
@@ -5,6 +5,7 @@ import { TmuxServerVersionSchemaZ } from "@tmux-ide/contracts";
|
|
|
5
5
|
import {
|
|
6
6
|
createNativeSplitCapabilityProbe,
|
|
7
7
|
createNativeSplitReadiness,
|
|
8
|
+
createStockSplitProbe,
|
|
8
9
|
} from "./native-split-capability.ts";
|
|
9
10
|
import { executeCanonicalSplitMutation } from "./canonical-split-mutation.ts";
|
|
10
11
|
import { createGuardedNativeSplitResize } from "./guarded-native-split-resize.ts";
|
|
@@ -1601,6 +1602,9 @@ async function startEmbeddedDaemonGeneration(
|
|
|
1601
1602
|
observation: () => observationSelector ?? null,
|
|
1602
1603
|
runPinnedTmux: nativeGenerationTmuxRunner,
|
|
1603
1604
|
}),
|
|
1605
|
+
splitLayoutStock: createStockSplitProbe({
|
|
1606
|
+
runPinnedTmux: nativeGenerationTmuxRunner,
|
|
1607
|
+
}),
|
|
1604
1608
|
createOwnedViewerAdapter: () => ownedViewerFactory?.(),
|
|
1605
1609
|
nativeServerIdentity: initialNativeServerIdentity,
|
|
1606
1610
|
executable: tmuxAuthority.executablePath,
|
|
@@ -102,3 +102,24 @@ export function createNativeSplitReadiness(options: {
|
|
|
102
102
|
pending = null;
|
|
103
103
|
}));
|
|
104
104
|
}
|
|
105
|
+
|
|
106
|
+
const NATIVE_COMMANDS = ["tmux-ide-resize-split", "tmux-ide-events"] as const;
|
|
107
|
+
/** True only when the selected server refuses every native command by name. A
|
|
108
|
+
* timeout, a lost server or any other failure says nothing, so it stays false. */
|
|
109
|
+
export function createStockSplitProbe(options: {
|
|
110
|
+
runPinnedTmux: NativeSplitRunner;
|
|
111
|
+
}): () => Promise<boolean> {
|
|
112
|
+
return async () => {
|
|
113
|
+
for (const command of NATIVE_COMMANDS) {
|
|
114
|
+
try {
|
|
115
|
+
await options.runPinnedTmux([command, "-V"]);
|
|
116
|
+
return false;
|
|
117
|
+
} catch (error) {
|
|
118
|
+
const failure = error as { stderr?: unknown; cause?: { stderr?: unknown } } | undefined;
|
|
119
|
+
const text = String(failure?.cause?.stderr ?? failure?.stderr ?? "");
|
|
120
|
+
if (!new RegExp(`^unknown command: ${command}$`, "mu").test(text)) return false;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return true;
|
|
124
|
+
};
|
|
125
|
+
}
|
|
@@ -5,6 +5,7 @@ import { shellEscape } from "./shell.ts";
|
|
|
5
5
|
import {
|
|
6
6
|
createNativeSplitCapabilityProbe,
|
|
7
7
|
createNativeSplitReadiness,
|
|
8
|
+
createStockSplitProbe,
|
|
8
9
|
} from "./native-split-capability.ts";
|
|
9
10
|
import { executeCanonicalSplitMutation } from "./canonical-split-mutation.ts";
|
|
10
11
|
import { createGuardedNativeSplitResize } from "./guarded-native-split-resize.ts";
|
|
@@ -394,6 +395,7 @@ export async function createNativeTmuxServerOwner(options: NativeTmuxServerOwner
|
|
|
394
395
|
observation: () => observationSelector ?? null,
|
|
395
396
|
runPinnedTmux: generationRun,
|
|
396
397
|
}),
|
|
398
|
+
splitLayoutStock: createStockSplitProbe({ runPinnedTmux: generationRun }),
|
|
397
399
|
createOwnedViewerAdapter: createOwnedViewerAdapterFactory({
|
|
398
400
|
environmentId: options.environmentId,
|
|
399
401
|
serverScope: { serverId: options.serverId, generation },
|
|
@@ -805,7 +805,8 @@ export class ControlChannelCore {
|
|
|
805
805
|
}
|
|
806
806
|
if (event.kind === "error" && sink.index !== sink.state.resultIndex)
|
|
807
807
|
this.discardedErrors += 1;
|
|
808
|
-
if (event.kind === "error"
|
|
808
|
+
if (event.kind === "error") {
|
|
809
|
+
// tmux drops the failed command's remaining group, so those replies never come.
|
|
809
810
|
while (this.pending[0]?.kind === "command-list" && this.pending[0].state === sink.state)
|
|
810
811
|
this.pending.shift();
|
|
811
812
|
if (!sink.state.settled) {
|
|
@@ -813,7 +814,7 @@ export class ControlChannelCore {
|
|
|
813
814
|
sink.state.onReply({
|
|
814
815
|
ok: false,
|
|
815
816
|
lines:
|
|
816
|
-
sink.state.budget || sink.state.resultIndex === 0
|
|
817
|
+
sink.index > 0 || sink.state.budget || sink.state.resultIndex === 0
|
|
817
818
|
? sink.state.lines
|
|
818
819
|
: sink.state.leadingErrorLines,
|
|
819
820
|
});
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
1
2
|
import { setTimeout as waitForPublication } from "node:timers/promises";
|
|
2
3
|
import {
|
|
3
4
|
WindowSplitResizeTargetSchemaZ,
|
|
@@ -10,6 +11,7 @@ import type {
|
|
|
10
11
|
GuardedNativeSplitResizeResult,
|
|
11
12
|
} from "../../lib/guarded-native-split-resize.ts";
|
|
12
13
|
import { WindowSplitAuthority, WindowSplitLayoutUnavailable } from "./window-split-authority.ts";
|
|
14
|
+
import { resizeStockSplit, type StockSplitResizeResult } from "../protocol/stock-split-resize.ts";
|
|
13
15
|
import { SharedWindowIndex } from "./shared-window-index.ts";
|
|
14
16
|
import { RegisteredWindowGuard, type RegisteredWindowReader } from "./registered-window-guard.ts";
|
|
15
17
|
import type { OwnedViewerAdapter } from "./owned-viewer-adapter.ts";
|
|
@@ -66,6 +68,8 @@ export interface MirrorServiceOptions {
|
|
|
66
68
|
splitLayoutPrepare?: () => Promise<boolean>;
|
|
67
69
|
/** Positively probe this native epoch before issuing handles; absent denies. */
|
|
68
70
|
splitLayoutCapability?: (epoch: string) => boolean | Promise<boolean>;
|
|
71
|
+
/** True only when the server positively lacks the native commands: a stock tmux. */
|
|
72
|
+
splitLayoutStock?: () => Promise<boolean>;
|
|
69
73
|
onSharedWindowConflict?: (session: string, conflicted: boolean) => void;
|
|
70
74
|
createOwnedViewerAdapter?: (session: string) => OwnedViewerAdapter | undefined;
|
|
71
75
|
nativeServerIdentity?: import("../../lib/tmux-server-generation-runner.ts").NativeTmuxServerIdentity;
|
|
@@ -167,6 +171,8 @@ export interface MirrorSessionRetention {
|
|
|
167
171
|
|
|
168
172
|
interface ChannelEntry {
|
|
169
173
|
splitAuthority?: WindowSplitAuthority;
|
|
174
|
+
/** Set once this channel's split authority serves a stock tmux server. */
|
|
175
|
+
stockSplitEpoch?: string;
|
|
170
176
|
channel: SessionChannel;
|
|
171
177
|
started: Promise<void>;
|
|
172
178
|
refs: number;
|
|
@@ -418,9 +424,17 @@ export class MirrorService {
|
|
|
418
424
|
} catch {
|
|
419
425
|
/* Unavailable owner. */
|
|
420
426
|
}
|
|
421
|
-
if (!ready
|
|
427
|
+
if (!ready) {
|
|
428
|
+
// Anything but a positive "no such command" stays a refusal.
|
|
429
|
+
const stock = await this.#stockSplitServer();
|
|
430
|
+
if (!stock || this.disposed || entry.retired || this.channels.get(session) !== entry)
|
|
431
|
+
throw new WindowSplitLayoutUnavailable();
|
|
432
|
+
return this.#readStockSplitLayout(entry, target);
|
|
433
|
+
}
|
|
434
|
+
if (this.disposed || entry.retired || this.channels.get(session) !== entry)
|
|
422
435
|
throw new WindowSplitLayoutUnavailable();
|
|
423
436
|
}
|
|
437
|
+
if (entry.stockSplitEpoch) throw new WindowSplitLayoutUnavailable();
|
|
424
438
|
const epoch = this.opts.splitLayoutEpoch?.();
|
|
425
439
|
let supported = false;
|
|
426
440
|
try {
|
|
@@ -443,6 +457,25 @@ export class MirrorService {
|
|
|
443
457
|
return entry.splitAuthority.read(target);
|
|
444
458
|
}
|
|
445
459
|
|
|
460
|
+
async #stockSplitServer(): Promise<boolean> {
|
|
461
|
+
try {
|
|
462
|
+
return (await this.opts.splitLayoutStock?.()) === true;
|
|
463
|
+
} catch {
|
|
464
|
+
return false;
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
#readStockSplitLayout(entry: ChannelEntry, target: WindowLinkTarget): WindowSplitLayoutResource {
|
|
469
|
+
if (entry.splitAuthority && !entry.stockSplitEpoch) throw new WindowSplitLayoutUnavailable();
|
|
470
|
+
const epoch = (entry.stockSplitEpoch ??= randomUUID());
|
|
471
|
+
entry.splitAuthority ??= new WindowSplitAuthority({
|
|
472
|
+
describe: (window) => entry.channel.describeSplitLayout(window, true),
|
|
473
|
+
serverEpoch: () => epoch,
|
|
474
|
+
stock: true,
|
|
475
|
+
});
|
|
476
|
+
return entry.splitAuthority.read(target);
|
|
477
|
+
}
|
|
478
|
+
|
|
446
479
|
/** Resolve only issued handles, then revalidate immediately at native dispatch. */
|
|
447
480
|
async resizeWindowSplit(
|
|
448
481
|
session: string,
|
|
@@ -451,7 +484,7 @@ export class MirrorService {
|
|
|
451
484
|
authorizeBeforeEffect: () => void,
|
|
452
485
|
runNative: ReturnType<typeof createGuardedNativeSplitResize>,
|
|
453
486
|
): Promise<
|
|
454
|
-
GuardedNativeSplitResizeResult & {
|
|
487
|
+
(GuardedNativeSplitResizeResult | StockSplitResizeResult) & {
|
|
455
488
|
successor?: { resource: WindowSplitLayoutResource; splitId: string } | null;
|
|
456
489
|
}
|
|
457
490
|
> {
|
|
@@ -467,16 +500,22 @@ export class MirrorService {
|
|
|
467
500
|
await entry!.started;
|
|
468
501
|
const resolved = current().resolve(captured);
|
|
469
502
|
const successor = current().prepareSuccessor(captured);
|
|
470
|
-
const
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
503
|
+
const authorize = () => {
|
|
504
|
+
current().resolve(captured);
|
|
505
|
+
authorizeBeforeEffect();
|
|
506
|
+
};
|
|
507
|
+
const result = entry!.stockSplitEpoch
|
|
508
|
+
? await resizeStockSplit(resolved.request, resolved.session.created, authorize, {
|
|
509
|
+
readOptions: (windowId) => entry!.channel.stockSplitOptions(windowId),
|
|
510
|
+
send: (command) => entry!.channel.stockSplitCommand(command),
|
|
511
|
+
})
|
|
512
|
+
: await runNative(resolved.request, {
|
|
513
|
+
operationId,
|
|
514
|
+
serverEpoch: resolved.serverEpoch,
|
|
515
|
+
session: resolved.session,
|
|
516
|
+
anchor: resolved.anchor,
|
|
517
|
+
authorizeBeforeEffect: authorize,
|
|
518
|
+
});
|
|
480
519
|
if (result.status !== "applied") return result;
|
|
481
520
|
// Native success is retained even if canonical publication is late or diverges.
|
|
482
521
|
// This grace period observes only; it never retries a native mutation.
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { STOCK_SPLIT_OPTIONS_FORMAT } from "../protocol/stock-split-resize.ts";
|
|
1
2
|
import { layoutContentRows } from "./layout-content-rows.ts";
|
|
2
3
|
import {
|
|
3
4
|
decodeNativeAtomicSnapshot,
|
|
@@ -440,6 +441,8 @@ export interface NativeSplitLayoutSnapshot {
|
|
|
440
441
|
readonly runtimeWindowId: string;
|
|
441
442
|
readonly semanticWindowId: string;
|
|
442
443
|
readonly rawLayout: string;
|
|
444
|
+
/** Set on a stock server, where it decides how small tmux lets a pane get. */
|
|
445
|
+
readonly paneBorderStatus?: string;
|
|
443
446
|
readonly panes: readonly {
|
|
444
447
|
readonly runtimePaneId: string;
|
|
445
448
|
readonly semanticPaneId: string;
|
|
@@ -964,7 +967,7 @@ export class SessionChannel {
|
|
|
964
967
|
}
|
|
965
968
|
|
|
966
969
|
/** Exact native ancestry, never reconstructed from published pane rectangles. */
|
|
967
|
-
describeSplitLayout(target: WindowLinkTarget): NativeSplitLayoutSnapshot {
|
|
970
|
+
describeSplitLayout(target: WindowLinkTarget, stock = false): NativeSplitLayoutSnapshot {
|
|
968
971
|
const authority = this.windowLinkAuthority;
|
|
969
972
|
const identity = this.attachedIdentity;
|
|
970
973
|
const generation = this.attachedServerGeneration;
|
|
@@ -999,8 +1002,7 @@ export class SessionChannel {
|
|
|
999
1002
|
pane.descriptor?.runtimeSessionId !== identity.runtimeSessionId ||
|
|
1000
1003
|
pane.descriptor?.windowId !== resolved.runtimeWindowId ||
|
|
1001
1004
|
this.panesBySemantic.get(pane.semanticId) !== pane ||
|
|
1002
|
-
!birth ||
|
|
1003
|
-
!/^[1-9]\d*$/u.test(birth) ||
|
|
1005
|
+
(!stock && (!birth || !/^[1-9]\d*$/u.test(birth))) ||
|
|
1004
1006
|
!layout.leaves.some(
|
|
1005
1007
|
(visible) =>
|
|
1006
1008
|
visible.id === leaf.id &&
|
|
@@ -1014,7 +1016,7 @@ export class SessionChannel {
|
|
|
1014
1016
|
return Object.freeze({
|
|
1015
1017
|
runtimePaneId: pane.runtimeId,
|
|
1016
1018
|
semanticPaneId: pane.semanticId,
|
|
1017
|
-
nativePaneBirthId: birth
|
|
1019
|
+
nativePaneBirthId: stock ? "" : birth!,
|
|
1018
1020
|
});
|
|
1019
1021
|
});
|
|
1020
1022
|
return Object.freeze({
|
|
@@ -1024,10 +1026,27 @@ export class SessionChannel {
|
|
|
1024
1026
|
runtimeWindowId: resolved.runtimeWindowId,
|
|
1025
1027
|
semanticWindowId: window.semanticId,
|
|
1026
1028
|
rawLayout: layout.rawLayout,
|
|
1029
|
+
...(stock ? { paneBorderStatus: window.paneBorderStatus } : {}),
|
|
1027
1030
|
panes: Object.freeze(panes),
|
|
1028
1031
|
});
|
|
1029
1032
|
}
|
|
1030
1033
|
|
|
1034
|
+
stockSplitOptions(windowId: string): Promise<string[]> {
|
|
1035
|
+
return this.io.request(`display-message -p -t ${windowId} "${STOCK_SPLIT_OPTIONS_FORMAT}"`);
|
|
1036
|
+
}
|
|
1037
|
+
|
|
1038
|
+
/** One guarded resize on this control connection, for a stock tmux server. */
|
|
1039
|
+
stockSplitCommand(command: string): Promise<string[]> {
|
|
1040
|
+
return new Promise((resolve, reject) => {
|
|
1041
|
+
const onReply = (reply: ControlReply) =>
|
|
1042
|
+
reply.ok ? resolve(reply.lines) : reject(new Error("Stock split command failed"));
|
|
1043
|
+
const limits = { maxBytes: 16 * 1024, maxLines: 4 };
|
|
1044
|
+
if (this.io.commandListBoundedInline)
|
|
1045
|
+
this.io.commandListBoundedInline(command, 3, 2, limits, onReply);
|
|
1046
|
+
else this.io.commandListInline(command, 3, 2, onReply);
|
|
1047
|
+
});
|
|
1048
|
+
}
|
|
1049
|
+
|
|
1031
1050
|
async executeWindowLinkAction(request: {
|
|
1032
1051
|
action: "select" | "unlink";
|
|
1033
1052
|
target?: WindowLinkTarget;
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
import { supportsNativeSessionGuard } from "../../lib/native-operation-command.ts";
|
|
13
13
|
import type { NativeSplitResizeRequest } from "../protocol/native-split-resize.ts";
|
|
14
14
|
import { parseLayoutTree, type LayoutTreeNode } from "../protocol/layout-parse.ts";
|
|
15
|
+
import { stockSplitMovable } from "../protocol/stock-split-resize.ts";
|
|
15
16
|
import {
|
|
16
17
|
SplitLayoutPublicationPending,
|
|
17
18
|
type NativeSplitLayoutSnapshot,
|
|
@@ -44,6 +45,8 @@ export class WindowSplitAuthority {
|
|
|
44
45
|
private readonly options: {
|
|
45
46
|
describe(window: WindowLinkTarget): NativeSplitLayoutSnapshot;
|
|
46
47
|
serverEpoch(): string | null;
|
|
48
|
+
/** A stock server has no pane birth ids, and some splits have no resize target. */
|
|
49
|
+
stock?: boolean;
|
|
47
50
|
},
|
|
48
51
|
) {}
|
|
49
52
|
|
|
@@ -69,9 +72,10 @@ export class WindowSplitAuthority {
|
|
|
69
72
|
if (
|
|
70
73
|
!/^%(0|[1-9][0-9]{0,9})$/u.test(pane.runtimePaneId) ||
|
|
71
74
|
Number(pane.runtimePaneId.slice(1)) > 0xffffffff ||
|
|
72
|
-
!
|
|
73
|
-
|
|
74
|
-
|
|
75
|
+
(!this.options.stock &&
|
|
76
|
+
!NativeJournalUint64SchemaZ.refine((birth) => birth !== "0").safeParse(
|
|
77
|
+
pane.nativePaneBirthId,
|
|
78
|
+
).success)
|
|
75
79
|
)
|
|
76
80
|
throw new WindowSplitLayoutUnavailable();
|
|
77
81
|
});
|
|
@@ -98,7 +102,14 @@ export class WindowSplitAuthority {
|
|
|
98
102
|
}
|
|
99
103
|
node.children.forEach((child, index) => {
|
|
100
104
|
const childPath = [...path, index];
|
|
101
|
-
if (
|
|
105
|
+
if (
|
|
106
|
+
index < node.children.length - 1 &&
|
|
107
|
+
(!this.options.stock ||
|
|
108
|
+
stockSplitMovable(tree, childPath, node.axis, {
|
|
109
|
+
borderStatus: snapshot.paneBorderStatus ?? "off",
|
|
110
|
+
scrollbar: 0,
|
|
111
|
+
}))
|
|
112
|
+
) {
|
|
102
113
|
const splitId = randomUUID();
|
|
103
114
|
paths.set(splitId, childPath);
|
|
104
115
|
splits.push({
|