tmux-ide 2.9.17 → 2.9.20
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 +631 -320
- package/package.json +1 -1
- package/packages/daemon/dist/doctor.js +108 -2
- package/packages/daemon/dist/lib/daemon-embed.js +4 -1
- package/packages/daemon/dist/lib/native-split-capability.js +18 -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 +20 -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 +111 -2
- package/packages/daemon/src/lib/daemon-embed.ts +4 -0
- package/packages/daemon/src/lib/native-split-capability.ts +20 -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 +24 -4
- package/packages/daemon/src/terminal/mirror/window-split-authority.ts +16 -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,106 @@ 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" | "older" | "partial" | "no-server" | "unknown";
|
|
186
|
+
/** The same reading of the server as the mirror's: the stock resize when it refuses
|
|
187
|
+
* the split command 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")) {
|
|
205
|
+
if (refused(events, "tmux-ide-events")) return "stock";
|
|
206
|
+
// The journal answers: a tmux-ide tmux built before the split command.
|
|
207
|
+
if (events.output !== undefined) return "older";
|
|
208
|
+
return "unknown";
|
|
209
|
+
}
|
|
210
|
+
if (split.output !== undefined && events.output !== undefined) {
|
|
211
|
+
try {
|
|
212
|
+
return nativeSplitCapability(split.output) ? "full" : "partial";
|
|
213
|
+
} catch {
|
|
214
|
+
return "partial";
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return failures.length === 2 ? "unknown" : "partial";
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/** Reads the server a session would use. With none running, a throwaway private
|
|
221
|
+
* server shows what the resolved binary would start. */
|
|
222
|
+
export function tmuxFeaturesRow(probeServer: TmuxProbe, probeBinary: TmuxProbe): CheckResult {
|
|
223
|
+
let answer = nativeCommands(probeServer);
|
|
224
|
+
if (answer === "no-server") answer = nativeCommands(probeBinary);
|
|
225
|
+
const details: Record<NativeAnswer, string> = {
|
|
226
|
+
full: "bundled tmux: full features",
|
|
227
|
+
stock: "stock tmux: reduced features",
|
|
228
|
+
older:
|
|
229
|
+
"older tmux-ide tmux: reduced features (restart it with tmux-ide's own tmux for every feature; that ends its sessions)",
|
|
230
|
+
partial: "this tmux has only some tmux-ide commands: no pane dividers",
|
|
231
|
+
"no-server": "could not read the tmux server's features",
|
|
232
|
+
unknown: "could not read the tmux server's features",
|
|
233
|
+
};
|
|
234
|
+
return {
|
|
235
|
+
label: "tmux features",
|
|
236
|
+
pass: answer === "full" || answer === "stock" || answer === "older",
|
|
237
|
+
detail: details[answer],
|
|
238
|
+
optional: true,
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
function runTmuxFeatureProbes(executable: string): CheckResult {
|
|
243
|
+
const run =
|
|
244
|
+
(prefix: readonly string[]): TmuxProbe =>
|
|
245
|
+
(args) =>
|
|
246
|
+
execFileSync(executable, [...prefix, ...args], {
|
|
247
|
+
encoding: "utf8",
|
|
248
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
249
|
+
timeout: 3000,
|
|
250
|
+
});
|
|
251
|
+
const socketPath = process.env[TMUX_SOCKET_PATH_ENV];
|
|
252
|
+
const socketName = process.env.TMUX_IDE_TMUX_SOCKET_NAME;
|
|
253
|
+
const server = socketPath ? ["-S", socketPath] : socketName ? ["-L", socketName] : [];
|
|
254
|
+
const cleanups: (() => void)[] = [];
|
|
255
|
+
const probeBinary: TmuxProbe = (() => {
|
|
256
|
+
let scratch: { dir: string; prefix: readonly string[] } | null = null;
|
|
257
|
+
return (args) => {
|
|
258
|
+
scratch ??= (() => {
|
|
259
|
+
const dir = mkdtempSync(join(tmpdir(), "tmi-doctor-"));
|
|
260
|
+
const prefix = ["-S", join(dir, "s"), "-f", "/dev/null"];
|
|
261
|
+
cleanups.push(() => {
|
|
262
|
+
try {
|
|
263
|
+
run(prefix)(["kill-server"]);
|
|
264
|
+
} catch {
|
|
265
|
+
// The server is already gone.
|
|
266
|
+
}
|
|
267
|
+
rmSync(dir, { recursive: true, force: true });
|
|
268
|
+
});
|
|
269
|
+
run(prefix)(["new-session", "-d", "-s", "probe"]);
|
|
270
|
+
return { dir, prefix };
|
|
271
|
+
})();
|
|
272
|
+
return run(scratch.prefix)(args);
|
|
273
|
+
};
|
|
274
|
+
})();
|
|
275
|
+
try {
|
|
276
|
+
return tmuxFeaturesRow(run(server), probeBinary);
|
|
277
|
+
} finally {
|
|
278
|
+
for (const cleanup of cleanups) cleanup();
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
179
282
|
export function nodeVersionRow(version: string): CheckResult {
|
|
180
283
|
const major = Number(version.split(".")[0]);
|
|
181
284
|
const pass = Number.isInteger(major) && major >= 20;
|
|
@@ -227,6 +330,12 @@ export async function doctor({
|
|
|
227
330
|
}),
|
|
228
331
|
);
|
|
229
332
|
|
|
333
|
+
try {
|
|
334
|
+
checks.push(runTmuxFeatureProbes(resolveTmuxExecutable()));
|
|
335
|
+
} catch {
|
|
336
|
+
// The tmux version row above already reports a missing executable.
|
|
337
|
+
}
|
|
338
|
+
|
|
230
339
|
checks.push(nodeVersionRow(process.versions.node));
|
|
231
340
|
|
|
232
341
|
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,23 @@ export function createNativeSplitReadiness(options: {
|
|
|
102
102
|
pending = null;
|
|
103
103
|
}));
|
|
104
104
|
}
|
|
105
|
+
|
|
106
|
+
/** True only when the selected server refuses `tmux-ide-resize-split` by name: a
|
|
107
|
+
* stock tmux, or a tmux-ide tmux built before that command, which may still have
|
|
108
|
+
* the journal. A timeout, a lost server or any other failure says nothing, so it
|
|
109
|
+
* stays false. */
|
|
110
|
+
export function createStockSplitProbe(options: {
|
|
111
|
+
runPinnedTmux: NativeSplitRunner;
|
|
112
|
+
}): () => Promise<boolean> {
|
|
113
|
+
const command = "tmux-ide-resize-split";
|
|
114
|
+
return async () => {
|
|
115
|
+
try {
|
|
116
|
+
await options.runPinnedTmux([command, "-V"]);
|
|
117
|
+
return false;
|
|
118
|
+
} catch (error) {
|
|
119
|
+
const failure = error as { stderr?: unknown; cause?: { stderr?: unknown } } | undefined;
|
|
120
|
+
const text = String(failure?.cause?.stderr ?? failure?.stderr ?? "");
|
|
121
|
+
return new RegExp(`^unknown command: ${command}$`, "mu").test(text);
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
}
|
|
@@ -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,8 @@ 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
|
-
|
|
1003
|
-
!/^[1-9]\d*$/u.test(birth) ||
|
|
1005
|
+
// A stock server has no birth ids; a server that has them must give valid ones.
|
|
1006
|
+
((!stock || birth) && (!birth || !/^[1-9]\d*$/u.test(birth))) ||
|
|
1004
1007
|
!layout.leaves.some(
|
|
1005
1008
|
(visible) =>
|
|
1006
1009
|
visible.id === leaf.id &&
|
|
@@ -1014,7 +1017,7 @@ export class SessionChannel {
|
|
|
1014
1017
|
return Object.freeze({
|
|
1015
1018
|
runtimePaneId: pane.runtimeId,
|
|
1016
1019
|
semanticPaneId: pane.semanticId,
|
|
1017
|
-
nativePaneBirthId: birth,
|
|
1020
|
+
nativePaneBirthId: birth || "",
|
|
1018
1021
|
});
|
|
1019
1022
|
});
|
|
1020
1023
|
return Object.freeze({
|
|
@@ -1024,10 +1027,27 @@ export class SessionChannel {
|
|
|
1024
1027
|
runtimeWindowId: resolved.runtimeWindowId,
|
|
1025
1028
|
semanticWindowId: window.semanticId,
|
|
1026
1029
|
rawLayout: layout.rawLayout,
|
|
1030
|
+
...(stock ? { paneBorderStatus: window.paneBorderStatus } : {}),
|
|
1027
1031
|
panes: Object.freeze(panes),
|
|
1028
1032
|
});
|
|
1029
1033
|
}
|
|
1030
1034
|
|
|
1035
|
+
stockSplitOptions(windowId: string): Promise<string[]> {
|
|
1036
|
+
return this.io.request(`display-message -p -t ${windowId} "${STOCK_SPLIT_OPTIONS_FORMAT}"`);
|
|
1037
|
+
}
|
|
1038
|
+
|
|
1039
|
+
/** One guarded resize on this control connection, for a stock tmux server. */
|
|
1040
|
+
stockSplitCommand(command: string): Promise<string[]> {
|
|
1041
|
+
return new Promise((resolve, reject) => {
|
|
1042
|
+
const onReply = (reply: ControlReply) =>
|
|
1043
|
+
reply.ok ? resolve(reply.lines) : reject(new Error("Stock split command failed"));
|
|
1044
|
+
const limits = { maxBytes: 16 * 1024, maxLines: 4 };
|
|
1045
|
+
if (this.io.commandListBoundedInline)
|
|
1046
|
+
this.io.commandListBoundedInline(command, 3, 2, limits, onReply);
|
|
1047
|
+
else this.io.commandListInline(command, 3, 2, onReply);
|
|
1048
|
+
});
|
|
1049
|
+
}
|
|
1050
|
+
|
|
1031
1051
|
async executeWindowLinkAction(request: {
|
|
1032
1052
|
action: "select" | "unlink";
|
|
1033
1053
|
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,9 @@ export class WindowSplitAuthority {
|
|
|
44
45
|
private readonly options: {
|
|
45
46
|
describe(window: WindowLinkTarget): NativeSplitLayoutSnapshot;
|
|
46
47
|
serverEpoch(): string | null;
|
|
48
|
+
/** A server without the native split command: pane birth ids may be missing,
|
|
49
|
+
* and some splits have no resize target. */
|
|
50
|
+
stock?: boolean;
|
|
47
51
|
},
|
|
48
52
|
) {}
|
|
49
53
|
|
|
@@ -69,9 +73,10 @@ export class WindowSplitAuthority {
|
|
|
69
73
|
if (
|
|
70
74
|
!/^%(0|[1-9][0-9]{0,9})$/u.test(pane.runtimePaneId) ||
|
|
71
75
|
Number(pane.runtimePaneId.slice(1)) > 0xffffffff ||
|
|
72
|
-
!
|
|
73
|
-
|
|
74
|
-
|
|
76
|
+
(!(this.options.stock && pane.nativePaneBirthId === "") &&
|
|
77
|
+
!NativeJournalUint64SchemaZ.refine((birth) => birth !== "0").safeParse(
|
|
78
|
+
pane.nativePaneBirthId,
|
|
79
|
+
).success)
|
|
75
80
|
)
|
|
76
81
|
throw new WindowSplitLayoutUnavailable();
|
|
77
82
|
});
|
|
@@ -98,7 +103,14 @@ export class WindowSplitAuthority {
|
|
|
98
103
|
}
|
|
99
104
|
node.children.forEach((child, index) => {
|
|
100
105
|
const childPath = [...path, index];
|
|
101
|
-
if (
|
|
106
|
+
if (
|
|
107
|
+
index < node.children.length - 1 &&
|
|
108
|
+
(!this.options.stock ||
|
|
109
|
+
stockSplitMovable(tree, childPath, node.axis, {
|
|
110
|
+
borderStatus: snapshot.paneBorderStatus ?? "off",
|
|
111
|
+
scrollbar: 0,
|
|
112
|
+
}))
|
|
113
|
+
) {
|
|
102
114
|
const splitId = randomUUID();
|
|
103
115
|
paths.set(splitId, childPath);
|
|
104
116
|
splits.push({
|