tmux-ide 2.9.16 → 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 +913 -367
- package/package.json +1 -1
- package/packages/core/src/terminal-fnv64-wasm.ts +8 -1
- package/packages/core/src/terminal-replica-hash-cache.ts +108 -1
- package/packages/core/src/terminal-replica.ts +14 -0
- package/packages/daemon/dist/command-center/discovery.js +39 -6
- package/packages/daemon/dist/doctor.js +101 -2
- package/packages/daemon/dist/lib/catalog-fleet-read.js +10 -0
- package/packages/daemon/dist/lib/daemon-embed.js +18 -4
- package/packages/daemon/dist/lib/daemon-service.js +13 -5
- 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/lib/tmux-server-owners.js +20 -1
- package/packages/daemon/dist/lib/tui-binary.js +83 -17
- 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/AppIcon.icns +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 +4 -4
- 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/command-center/discovery.ts +72 -7
- package/packages/daemon/src/doctor.ts +104 -2
- package/packages/daemon/src/lib/catalog-fleet-read.ts +40 -0
- package/packages/daemon/src/lib/daemon-embed.ts +31 -12
- package/packages/daemon/src/lib/daemon-service.ts +17 -4
- 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/lib/tmux-server-owners.ts +17 -1
- package/packages/daemon/src/lib/tui-binary.ts +114 -22
- 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
|
+
}
|
|
@@ -208,10 +208,16 @@ export function isVisibleFleetSession(name: string): boolean {
|
|
|
208
208
|
export function readAdoptedSessionNames(runTmux: TmuxRunner = _tmuxRunner): string[] | null {
|
|
209
209
|
let raw: string;
|
|
210
210
|
try {
|
|
211
|
-
raw = runTmux(
|
|
211
|
+
raw = runTmux(ADOPTED_SESSIONS_ARGS);
|
|
212
212
|
} catch {
|
|
213
213
|
return null;
|
|
214
214
|
}
|
|
215
|
+
return parseAdoptedSessionNames(raw);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
const ADOPTED_SESSIONS_ARGS = ["list-sessions", "-F", `#{session_name}\t#{${ADOPTED_OPTION}}`];
|
|
219
|
+
|
|
220
|
+
function parseAdoptedSessionNames(raw: string): string[] {
|
|
215
221
|
const names: string[] = [];
|
|
216
222
|
for (const line of raw.split("\n")) {
|
|
217
223
|
if (!line) continue;
|
|
@@ -312,18 +318,77 @@ export function readAdoptedFleet(
|
|
|
312
318
|
const nativeEpoch = nativeServerEpoch?.() ?? null;
|
|
313
319
|
const adopted = readAdoptedSessionNames(runTmux);
|
|
314
320
|
if (adopted === null) return null;
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
321
|
+
if (adopted.length === 0) return [];
|
|
322
|
+
let panesRaw: string;
|
|
323
|
+
try {
|
|
324
|
+
panesRaw = runTmux(FLEET_PANES_ARGS);
|
|
325
|
+
} catch {
|
|
326
|
+
panesRaw = "";
|
|
327
|
+
}
|
|
328
|
+
return assembleAdoptedFleet(
|
|
329
|
+
adopted,
|
|
330
|
+
panesRaw,
|
|
331
|
+
registry,
|
|
332
|
+
nativeEpoch,
|
|
333
|
+
resolveInteractionEndpoint,
|
|
334
|
+
nativeServerEpoch,
|
|
335
|
+
);
|
|
336
|
+
}
|
|
319
337
|
|
|
320
|
-
|
|
338
|
+
/**
|
|
339
|
+
* {@link readAdoptedFleet} over an asynchronous tmux runner: the same two reads
|
|
340
|
+
* in the same order, without blocking the event loop while tmux answers (#709).
|
|
341
|
+
*/
|
|
342
|
+
export async function readAdoptedFleetAsync(
|
|
343
|
+
registry: { list(): { sessionName: string }[] },
|
|
344
|
+
runTmux: (args: string[]) => Promise<string>,
|
|
345
|
+
resolveInteractionEndpoint?: (
|
|
346
|
+
sessionName: string,
|
|
347
|
+
pane: FleetPaneFacts,
|
|
348
|
+
) => Extract<InteractionPaneEndpoint, { kind: "pane" }> | null,
|
|
349
|
+
nativeServerEpoch?: () => string | null,
|
|
350
|
+
): Promise<FleetSessionFacts[] | null> {
|
|
351
|
+
const nativeEpoch = nativeServerEpoch?.() ?? null;
|
|
352
|
+
let sessionsRaw: string;
|
|
353
|
+
try {
|
|
354
|
+
sessionsRaw = await runTmux(ADOPTED_SESSIONS_ARGS);
|
|
355
|
+
} catch {
|
|
356
|
+
return null;
|
|
357
|
+
}
|
|
358
|
+
const adopted = parseAdoptedSessionNames(sessionsRaw);
|
|
359
|
+
if (adopted.length === 0) return [];
|
|
321
360
|
let panesRaw: string;
|
|
322
361
|
try {
|
|
323
|
-
panesRaw = runTmux(
|
|
362
|
+
panesRaw = await runTmux(FLEET_PANES_ARGS);
|
|
324
363
|
} catch {
|
|
325
364
|
panesRaw = "";
|
|
326
365
|
}
|
|
366
|
+
return assembleAdoptedFleet(
|
|
367
|
+
adopted,
|
|
368
|
+
panesRaw,
|
|
369
|
+
registry,
|
|
370
|
+
nativeEpoch,
|
|
371
|
+
resolveInteractionEndpoint,
|
|
372
|
+
nativeServerEpoch,
|
|
373
|
+
);
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
const FLEET_PANES_ARGS = ["list-panes", "-a", "-F", FLEET_PANE_FORMAT];
|
|
377
|
+
|
|
378
|
+
function assembleAdoptedFleet(
|
|
379
|
+
adopted: string[],
|
|
380
|
+
panesRaw: string,
|
|
381
|
+
registry: { list(): { sessionName: string }[] },
|
|
382
|
+
nativeEpoch: string | null,
|
|
383
|
+
resolveInteractionEndpoint?: (
|
|
384
|
+
sessionName: string,
|
|
385
|
+
pane: FleetPaneFacts,
|
|
386
|
+
) => Extract<InteractionPaneEndpoint, { kind: "pane" }> | null,
|
|
387
|
+
nativeServerEpoch?: () => string | null,
|
|
388
|
+
): FleetSessionFacts[] {
|
|
389
|
+
const adoptedSet = new Set(adopted);
|
|
390
|
+
const appCreatedSessions = new Set(registry.list().map((workspace) => workspace.sessionName));
|
|
391
|
+
const panesBySession = new Map<string, FleetPaneFacts[]>();
|
|
327
392
|
for (const line of panesRaw.split("\n")) {
|
|
328
393
|
if (!line) continue;
|
|
329
394
|
const fields = line.split(FLEET_FIELD_SEPARATOR);
|
|
@@ -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(
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { InteractionPaneEndpoint } from "@tmux-ide/contracts";
|
|
2
|
+
import {
|
|
3
|
+
readAdoptedFleet,
|
|
4
|
+
readAdoptedFleetAsync,
|
|
5
|
+
type FleetPaneFacts,
|
|
6
|
+
type FleetSessionFacts,
|
|
7
|
+
} from "../command-center/discovery.ts";
|
|
8
|
+
|
|
9
|
+
/** The two runners a catalog fleet read may use; both are fenced to one tmux server generation. */
|
|
10
|
+
export interface CatalogFleetRunners {
|
|
11
|
+
/** The session-mutation fence; only its `active` state is read here. */
|
|
12
|
+
readonly fence: { readonly active: boolean };
|
|
13
|
+
/** Synchronous runner wrapped by that fence: inside a mutation it adds the session check. */
|
|
14
|
+
readonly fencedSync: (args: string[]) => string;
|
|
15
|
+
/** Asynchronous runner fenced to the same server generation. */
|
|
16
|
+
readonly generationFencedAsync: (args: string[]) => Promise<string>;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Read the catalog fleet without blocking the event loop (#709), except inside
|
|
21
|
+
* a session mutation, where the read keeps the fence's synchronous runner.
|
|
22
|
+
*/
|
|
23
|
+
export async function readCatalogFleet(
|
|
24
|
+
registry: { list(): { sessionName: string }[] },
|
|
25
|
+
runners: CatalogFleetRunners,
|
|
26
|
+
resolveInteractionEndpoint?: (
|
|
27
|
+
sessionName: string,
|
|
28
|
+
pane: FleetPaneFacts,
|
|
29
|
+
) => Extract<InteractionPaneEndpoint, { kind: "pane" }> | null,
|
|
30
|
+
nativeServerEpoch?: () => string | null,
|
|
31
|
+
): Promise<FleetSessionFacts[] | null> {
|
|
32
|
+
return runners.fence.active
|
|
33
|
+
? readAdoptedFleet(registry, runners.fencedSync, resolveInteractionEndpoint, nativeServerEpoch)
|
|
34
|
+
: readAdoptedFleetAsync(
|
|
35
|
+
registry,
|
|
36
|
+
runners.generationFencedAsync,
|
|
37
|
+
resolveInteractionEndpoint,
|
|
38
|
+
nativeServerEpoch,
|
|
39
|
+
);
|
|
40
|
+
}
|
|
@@ -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";
|
|
@@ -117,7 +118,12 @@ import {
|
|
|
117
118
|
resolveWorkspacePaneTmuxAuthority,
|
|
118
119
|
WorkspacePaneCreationAuthority,
|
|
119
120
|
} from "./workspace-pane-creation.ts";
|
|
120
|
-
import {
|
|
121
|
+
import {
|
|
122
|
+
discoverLiveSessionSummaries,
|
|
123
|
+
readAdoptedFleet,
|
|
124
|
+
type FleetSessionFacts,
|
|
125
|
+
} from "../command-center/discovery.ts";
|
|
126
|
+
import { readCatalogFleet } from "./catalog-fleet-read.ts";
|
|
121
127
|
import { WorkspaceOpenAuthority } from "./workspace-open.ts";
|
|
122
128
|
import { WorkspacePromotionAuthority } from "./workspace-promotion.ts";
|
|
123
129
|
import { WorkspaceOpenHandoffCoordinator } from "./workspace-open-handoff.ts";
|
|
@@ -1596,6 +1602,9 @@ async function startEmbeddedDaemonGeneration(
|
|
|
1596
1602
|
observation: () => observationSelector ?? null,
|
|
1597
1603
|
runPinnedTmux: nativeGenerationTmuxRunner,
|
|
1598
1604
|
}),
|
|
1605
|
+
splitLayoutStock: createStockSplitProbe({
|
|
1606
|
+
runPinnedTmux: nativeGenerationTmuxRunner,
|
|
1607
|
+
}),
|
|
1599
1608
|
createOwnedViewerAdapter: () => ownedViewerFactory?.(),
|
|
1600
1609
|
nativeServerIdentity: initialNativeServerIdentity,
|
|
1601
1610
|
executable: tmuxAuthority.executablePath,
|
|
@@ -2103,18 +2112,28 @@ async function startEmbeddedDaemonGeneration(
|
|
|
2103
2112
|
paneStreamRuntime,
|
|
2104
2113
|
catalogLiveSessions: () => discoverLiveSessionSummaries(catalogTmuxRunner),
|
|
2105
2114
|
catalogFleet: async () => {
|
|
2106
|
-
const
|
|
2115
|
+
const endpoint = (sessionName: string, pane: FleetSessionFacts["panes"][number]) =>
|
|
2116
|
+
pane.semanticPaneId
|
|
2117
|
+
? (interactionEvidence?.captureInventoryEndpoint(
|
|
2118
|
+
sessionName,
|
|
2119
|
+
pane.runtimePaneId,
|
|
2120
|
+
pane.semanticPaneId,
|
|
2121
|
+
) ?? null)
|
|
2122
|
+
: null;
|
|
2123
|
+
const epoch = () => observationSelector?.nativeServerEpoch ?? null;
|
|
2124
|
+
// Same pinned server generation either way. Outside a session
|
|
2125
|
+
// mutation the read must not block the event loop: every concurrent
|
|
2126
|
+
// catalog request queued behind its spawnSync (#709). Inside one,
|
|
2127
|
+
// keep the fenced synchronous runner the mutation relies on.
|
|
2128
|
+
const fleet = await readCatalogFleet(
|
|
2107
2129
|
workspaceRegistry,
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
) ?? null)
|
|
2116
|
-
: null,
|
|
2117
|
-
() => observationSelector?.nativeServerEpoch ?? null,
|
|
2130
|
+
{
|
|
2131
|
+
fence: sessionMutationFence,
|
|
2132
|
+
fencedSync: nativeGenerationTmuxRunner,
|
|
2133
|
+
generationFencedAsync: (args) => fleetFactsTmuxRunner(args),
|
|
2134
|
+
},
|
|
2135
|
+
endpoint,
|
|
2136
|
+
epoch,
|
|
2118
2137
|
);
|
|
2119
2138
|
if (!fleet) return null;
|
|
2120
2139
|
const names = await readTeamMemberships(
|
|
@@ -149,13 +149,20 @@ export async function manageDaemonService(
|
|
|
149
149
|
refused("The service manager loaded a different definition; refusing to control it");
|
|
150
150
|
return state;
|
|
151
151
|
};
|
|
152
|
-
|
|
152
|
+
// `retiredPid` is the process this restart terminated. It can publish a record
|
|
153
|
+
// while it shuts down (a KeepAlive relaunch just before the restart), so it is
|
|
154
|
+
// never the replacement, whatever its instance id.
|
|
155
|
+
const ready = async (previousInstance?: string, retiredPid?: number | null) => {
|
|
153
156
|
const deadline = Date.now() + deps.waitMs;
|
|
154
157
|
do {
|
|
155
158
|
const state = deps.inspect();
|
|
156
159
|
if (!boundTo(state, plan.supervisionId))
|
|
157
160
|
refused("Service reservation changed during startup");
|
|
158
|
-
if (
|
|
161
|
+
if (
|
|
162
|
+
state.status === "valid" &&
|
|
163
|
+
state.info.instanceId !== previousInstance &&
|
|
164
|
+
state.info.pid !== retiredPid
|
|
165
|
+
) {
|
|
159
166
|
const identity = await deps.probe(state.info);
|
|
160
167
|
const service = await inspectManager();
|
|
161
168
|
if (
|
|
@@ -283,9 +290,15 @@ export async function manageDaemonService(
|
|
|
283
290
|
}
|
|
284
291
|
const before = deps.inspect();
|
|
285
292
|
if (action === "install" && service.active) return await ready();
|
|
286
|
-
|
|
293
|
+
// Read the manager again: a relaunch may have replaced the process while this
|
|
294
|
+
// waited for the lock, and the restart terminates whichever one runs now.
|
|
295
|
+
const current = service.loaded ? await inspectManager() : service;
|
|
296
|
+
if (current.loaded) await manager.restart(current.pid !== null);
|
|
287
297
|
else await manager.install();
|
|
288
|
-
return await ready(
|
|
298
|
+
return await ready(
|
|
299
|
+
before.status === "valid" ? before.info.instanceId : undefined,
|
|
300
|
+
current.loaded ? current.pid : null,
|
|
301
|
+
);
|
|
289
302
|
} catch (error) {
|
|
290
303
|
// Never discard ownership after an uncertain OS activation. The retained
|
|
291
304
|
// record/reservation gives the explicit remove/restart commands a recovery path.
|
|
@@ -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 },
|
|
@@ -59,6 +59,8 @@ export class TmuxServerOwners<T extends DisposableTmuxServerOwner> {
|
|
|
59
59
|
#disposed = false;
|
|
60
60
|
#disposePromise: Promise<void> | null = null;
|
|
61
61
|
constructor(readonly options: TmuxServerOwnersOptions<T>) {}
|
|
62
|
+
#queuedRefresh: Promise<readonly TmuxServerDescriptor[]> | null = null;
|
|
63
|
+
#queuedRefreshTail: Promise<unknown> | null = null;
|
|
62
64
|
#serial<R>(work: () => Promise<R>): Promise<R> {
|
|
63
65
|
const run = this.#tail.then(() => {
|
|
64
66
|
if (this.#disposed) throw new TmuxServerScopeError("disposed");
|
|
@@ -178,11 +180,25 @@ export class TmuxServerOwners<T extends DisposableTmuxServerOwner> {
|
|
|
178
180
|
this.#entries.set(scope.serverId, { registration, scope, observation, owner });
|
|
179
181
|
}
|
|
180
182
|
refresh(): Promise<readonly TmuxServerDescriptor[]> {
|
|
181
|
-
|
|
183
|
+
// A refresh still waiting its turn has not probed anything yet, so it is
|
|
184
|
+
// as fresh for a later caller as a new one: share it instead of queuing
|
|
185
|
+
// another full refresh behind it (#709). Once it starts, callers queue anew.
|
|
186
|
+
// Share it only while nothing has been queued behind it, so a refresh
|
|
187
|
+
// stays ordered after any mutation queued before the caller asked.
|
|
188
|
+
if (this.#queuedRefresh && this.#tail === this.#queuedRefreshTail) return this.#queuedRefresh;
|
|
189
|
+
const queued = this.#serial(async () => {
|
|
190
|
+
if (this.#queuedRefresh === queued) this.#queuedRefresh = null;
|
|
182
191
|
// Sequential admission bounds subprocess work and avoids alias races.
|
|
183
192
|
for (const entry of this.#entries.values()) await this.#refresh(entry);
|
|
184
193
|
return this.list();
|
|
185
194
|
});
|
|
195
|
+
this.#queuedRefresh = queued;
|
|
196
|
+
this.#queuedRefreshTail = this.#tail;
|
|
197
|
+
const settle = () => {
|
|
198
|
+
if (this.#queuedRefresh === queued) this.#queuedRefresh = null;
|
|
199
|
+
};
|
|
200
|
+
queued.then(settle, settle);
|
|
201
|
+
return queued;
|
|
186
202
|
}
|
|
187
203
|
current(scopeInput: TmuxServerScope): T {
|
|
188
204
|
const scope = TmuxServerScopeSchemaZ.parse(scopeInput);
|