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
package/package.json
CHANGED
|
@@ -10,7 +10,7 @@ export interface BufferedFnv64 {
|
|
|
10
10
|
digest(): string;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
interface NativeHasher {
|
|
13
|
+
export interface NativeHasher {
|
|
14
14
|
readonly scratch: Uint8Array;
|
|
15
15
|
readonly update: (state: bigint, length: number) => bigint;
|
|
16
16
|
}
|
|
@@ -49,6 +49,13 @@ function initialize(): NativeHasher | null {
|
|
|
49
49
|
return native;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
+
/** Direct access to the WASM scratch buffer and its update, for one synchronous
|
|
53
|
+
* hash at a time. Callers must not yield between filling the scratch and update. */
|
|
54
|
+
export function nativeFnv64(): NativeHasher | null {
|
|
55
|
+
return initialize();
|
|
56
|
+
}
|
|
57
|
+
export const FNV64_OFFSET_BASIS = OFFSET_BASIS;
|
|
58
|
+
|
|
52
59
|
/** Internal optional accelerator. Canonical serialization remains the caller's responsibility. */
|
|
53
60
|
export function createBufferedFnv64(initialState = OFFSET_BASIS): BufferedFnv64 | null {
|
|
54
61
|
const hasher = initialize();
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
|
+
isOwnedTerminalReplicaRow,
|
|
2
3
|
isSchemaValidProjectedTerminalReplicaRow,
|
|
3
4
|
TERMINAL_REPLICA_DEFAULT_COLOR,
|
|
4
5
|
} from "./terminal-replica-owned-row.ts";
|
|
5
6
|
import type { TerminalReplicaColor, TerminalReplicaRow } from "@tmux-ide/contracts";
|
|
6
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
createBufferedFnv64,
|
|
9
|
+
FNV64_OFFSET_BASIS,
|
|
10
|
+
nativeFnv64,
|
|
11
|
+
type BufferedFnv64,
|
|
12
|
+
} from "./terminal-fnv64-wasm.ts";
|
|
7
13
|
|
|
8
14
|
const ROW_HASH_CACHE = new WeakMap<object, string>();
|
|
9
15
|
const DEEPLY_FROZEN_ROWS = new WeakSet<object>();
|
|
@@ -425,6 +431,12 @@ export function hashTerminalReplicaRowCached(
|
|
|
425
431
|
const cached = ROW_HASH_CACHE.get(row);
|
|
426
432
|
if (cached) return cached;
|
|
427
433
|
onMiss?.();
|
|
434
|
+
const native = nativeFnv64();
|
|
435
|
+
if (native) {
|
|
436
|
+
const digest = hashRowBytes(row, native);
|
|
437
|
+
if (isTerminalReplicaRowDeeplyFrozen(row)) ROW_HASH_CACHE.set(row, digest);
|
|
438
|
+
return digest;
|
|
439
|
+
}
|
|
428
440
|
const hash = encodingCache?.createHash() ?? new CanonicalFnv64();
|
|
429
441
|
let canonicalBytes = 10 + String(row.cells.length).length;
|
|
430
442
|
hash.ascii("a2:");
|
|
@@ -631,6 +643,11 @@ export function primeTerminalReplicaRowHash(row: TerminalReplicaRow, digest: str
|
|
|
631
643
|
|
|
632
644
|
export function isTerminalReplicaRowDeeplyFrozen(row: TerminalReplicaRow): boolean {
|
|
633
645
|
if (DEEPLY_FROZEN_ROWS.has(row)) return true;
|
|
646
|
+
// Every owned-row constructor freezes the row, its cells and their colors.
|
|
647
|
+
if (isOwnedTerminalReplicaRow(row as unknown)) {
|
|
648
|
+
DEEPLY_FROZEN_ROWS.add(row);
|
|
649
|
+
return true;
|
|
650
|
+
}
|
|
634
651
|
if (!Object.isFrozen(row) || !Object.isFrozen(row.cells)) return false;
|
|
635
652
|
for (const cell of row.cells) {
|
|
636
653
|
if (
|
|
@@ -643,3 +660,93 @@ export function isTerminalReplicaRowDeeplyFrozen(row: TerminalReplicaRow): boole
|
|
|
643
660
|
DEEPLY_FROZEN_ROWS.add(row);
|
|
644
661
|
return true;
|
|
645
662
|
}
|
|
663
|
+
|
|
664
|
+
// #708: the same canonical row bytes as hashTerminalReplicaRowCached's
|
|
665
|
+
// CanonicalFnv64 path, assembled from per-cell byte strings and hashed in
|
|
666
|
+
// WASM in 4 KiB chunks instead of several small JS writes per cell.
|
|
667
|
+
const ASCII_ENCODER = new TextEncoder();
|
|
668
|
+
const CELL_BYTES_LIMIT = 4_096;
|
|
669
|
+
const PLAIN_CELL_BYTES = new Map<string, Uint8Array>();
|
|
670
|
+
const STYLED_CELL_BYTES = new Map<string, Uint8Array>();
|
|
671
|
+
const ROW_TRAILER = ASCII_ENCODER.encode(";;");
|
|
672
|
+
|
|
673
|
+
function canonicalNumber(value: number): string {
|
|
674
|
+
const text = String(value);
|
|
675
|
+
return `d${text.length}:${text};`;
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
function canonicalColor(color: TerminalReplicaColor): string {
|
|
679
|
+
if (color.kind === "default") return "o1:s4:kind;s7:default;;";
|
|
680
|
+
if (color.kind === "indexed")
|
|
681
|
+
return `o2:s5:index;${canonicalNumber(color.index)}s4:kind;s7:indexed;;`;
|
|
682
|
+
return `o2:s4:kind;s3:rgb;s5:value;${canonicalNumber(color.value)};`;
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
function encodeCell(cell: TerminalReplicaRow["cells"][number]): Uint8Array {
|
|
686
|
+
const grapheme = cell.grapheme;
|
|
687
|
+
let length = grapheme.length;
|
|
688
|
+
for (let index = 0; index < grapheme.length; index += 1)
|
|
689
|
+
if (grapheme.charCodeAt(index) > 0x7f) {
|
|
690
|
+
length = UTF8_ENCODER.encode(grapheme).byteLength;
|
|
691
|
+
break;
|
|
692
|
+
}
|
|
693
|
+
return UTF8_ENCODER.encode(
|
|
694
|
+
`a5:s${length}:${grapheme};${canonicalNumber(cell.width)}${canonicalColor(
|
|
695
|
+
cell.foreground,
|
|
696
|
+
)}${canonicalColor(cell.background)}${canonicalNumber(cell.attributes)};`,
|
|
697
|
+
);
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
function remember(cache: Map<string, Uint8Array>, key: string, bytes: Uint8Array): Uint8Array {
|
|
701
|
+
if (cache.size >= CELL_BYTES_LIMIT) cache.clear();
|
|
702
|
+
cache.set(key, bytes);
|
|
703
|
+
return bytes;
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
function cellBytes(cell: TerminalReplicaRow["cells"][number]): Uint8Array {
|
|
707
|
+
const { grapheme, width, attributes, foreground, background } = cell;
|
|
708
|
+
if (
|
|
709
|
+
width === 1 &&
|
|
710
|
+
attributes === 0 &&
|
|
711
|
+
foreground.kind === "default" &&
|
|
712
|
+
background.kind === "default"
|
|
713
|
+
)
|
|
714
|
+
return PLAIN_CELL_BYTES.get(grapheme) ?? remember(PLAIN_CELL_BYTES, grapheme, encodeCell(cell));
|
|
715
|
+
const key = `${width}\u0000${attributes}\u0000${canonicalColor(foreground)}\u0000${canonicalColor(
|
|
716
|
+
background,
|
|
717
|
+
)}\u0000${grapheme}`;
|
|
718
|
+
return STYLED_CELL_BYTES.get(key) ?? remember(STYLED_CELL_BYTES, key, encodeCell(cell));
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
function hashRowBytes(
|
|
722
|
+
row: TerminalReplicaRow,
|
|
723
|
+
native: NonNullable<ReturnType<typeof nativeFnv64>>,
|
|
724
|
+
): string {
|
|
725
|
+
const scratch = native.scratch;
|
|
726
|
+
const capacity = scratch.byteLength;
|
|
727
|
+
let state = FNV64_OFFSET_BASIS;
|
|
728
|
+
let length = 0;
|
|
729
|
+
const write = (bytes: Uint8Array) => {
|
|
730
|
+
if (bytes.byteLength <= capacity - length) {
|
|
731
|
+
scratch.set(bytes, length);
|
|
732
|
+
length += bytes.byteLength;
|
|
733
|
+
return;
|
|
734
|
+
}
|
|
735
|
+
let offset = 0;
|
|
736
|
+
while (offset < bytes.byteLength) {
|
|
737
|
+
const count = Math.min(capacity - length, bytes.byteLength - offset);
|
|
738
|
+
scratch.set(bytes.subarray(offset, offset + count), length);
|
|
739
|
+
length += count;
|
|
740
|
+
offset += count;
|
|
741
|
+
if (length === capacity) {
|
|
742
|
+
state = BigInt.asUintN(64, native.update(state, length));
|
|
743
|
+
length = 0;
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
};
|
|
747
|
+
write(ASCII_ENCODER.encode(`a2:${row.wrapped ? "b1;" : "b0;"}a${row.cells.length}:`));
|
|
748
|
+
for (const cell of row.cells) write(cellBytes(cell));
|
|
749
|
+
write(ROW_TRAILER);
|
|
750
|
+
state = BigInt.asUintN(64, native.update(state, length));
|
|
751
|
+
return state.toString(16).padStart(16, "0");
|
|
752
|
+
}
|
|
@@ -1001,6 +1001,20 @@ function resolveFrameHash(
|
|
|
1001
1001
|
* seed whose frame hash differs is a protocol conflict, not idempotent.
|
|
1002
1002
|
*/
|
|
1003
1003
|
function terminalReplicaFrameIdentity(update: CanonicalTerminalReplicaUpdate): unknown {
|
|
1004
|
+
if (update.type === "terminal.patch") {
|
|
1005
|
+
// #708: a flood patch appends many history rows the interpreter has just
|
|
1006
|
+
// hashed; enter them, and the changed screen rows, by their row hashes.
|
|
1007
|
+
const { rows, history, historyDelta, ...rest } = update.patch;
|
|
1008
|
+
return [
|
|
1009
|
+
"terminal-replica-patch-frame-v2",
|
|
1010
|
+
{ ...update, patch: rest },
|
|
1011
|
+
rows.map(({ index, row }) => [index, hashTerminalReplicaRow(row)]),
|
|
1012
|
+
history === undefined ? null : hashTerminalReplicaRows(history),
|
|
1013
|
+
historyDelta === undefined
|
|
1014
|
+
? null
|
|
1015
|
+
: [historyDelta.trim, hashTerminalReplicaRows(historyDelta.append)],
|
|
1016
|
+
];
|
|
1017
|
+
}
|
|
1004
1018
|
if (update.type !== "terminal.seed") return update;
|
|
1005
1019
|
const { grid, history, ...rest } = update.snapshot;
|
|
1006
1020
|
return [
|
|
@@ -160,11 +160,15 @@ export function isVisibleFleetSession(name) {
|
|
|
160
160
|
export function readAdoptedSessionNames(runTmux = _tmuxRunner) {
|
|
161
161
|
let raw;
|
|
162
162
|
try {
|
|
163
|
-
raw = runTmux(
|
|
163
|
+
raw = runTmux(ADOPTED_SESSIONS_ARGS);
|
|
164
164
|
}
|
|
165
165
|
catch {
|
|
166
166
|
return null;
|
|
167
167
|
}
|
|
168
|
+
return parseAdoptedSessionNames(raw);
|
|
169
|
+
}
|
|
170
|
+
const ADOPTED_SESSIONS_ARGS = ["list-sessions", "-F", `#{session_name}\t#{${ADOPTED_OPTION}}`];
|
|
171
|
+
function parseAdoptedSessionNames(raw) {
|
|
168
172
|
const names = [];
|
|
169
173
|
for (const line of raw.split("\n")) {
|
|
170
174
|
if (!line)
|
|
@@ -223,18 +227,47 @@ export function readAdoptedFleet(registry = getDefaultWorkspaceRegistry(), runTm
|
|
|
223
227
|
const adopted = readAdoptedSessionNames(runTmux);
|
|
224
228
|
if (adopted === null)
|
|
225
229
|
return null;
|
|
226
|
-
|
|
227
|
-
|
|
230
|
+
if (adopted.length === 0)
|
|
231
|
+
return [];
|
|
232
|
+
let panesRaw;
|
|
233
|
+
try {
|
|
234
|
+
panesRaw = runTmux(FLEET_PANES_ARGS);
|
|
235
|
+
}
|
|
236
|
+
catch {
|
|
237
|
+
panesRaw = "";
|
|
238
|
+
}
|
|
239
|
+
return assembleAdoptedFleet(adopted, panesRaw, registry, nativeEpoch, resolveInteractionEndpoint, nativeServerEpoch);
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* {@link readAdoptedFleet} over an asynchronous tmux runner: the same two reads
|
|
243
|
+
* in the same order, without blocking the event loop while tmux answers (#709).
|
|
244
|
+
*/
|
|
245
|
+
export async function readAdoptedFleetAsync(registry, runTmux, resolveInteractionEndpoint, nativeServerEpoch) {
|
|
246
|
+
const nativeEpoch = nativeServerEpoch?.() ?? null;
|
|
247
|
+
let sessionsRaw;
|
|
248
|
+
try {
|
|
249
|
+
sessionsRaw = await runTmux(ADOPTED_SESSIONS_ARGS);
|
|
250
|
+
}
|
|
251
|
+
catch {
|
|
252
|
+
return null;
|
|
253
|
+
}
|
|
254
|
+
const adopted = parseAdoptedSessionNames(sessionsRaw);
|
|
255
|
+
if (adopted.length === 0)
|
|
228
256
|
return [];
|
|
229
|
-
const appCreatedSessions = new Set(registry.list().map((workspace) => workspace.sessionName));
|
|
230
|
-
const panesBySession = new Map();
|
|
231
257
|
let panesRaw;
|
|
232
258
|
try {
|
|
233
|
-
panesRaw = runTmux(
|
|
259
|
+
panesRaw = await runTmux(FLEET_PANES_ARGS);
|
|
234
260
|
}
|
|
235
261
|
catch {
|
|
236
262
|
panesRaw = "";
|
|
237
263
|
}
|
|
264
|
+
return assembleAdoptedFleet(adopted, panesRaw, registry, nativeEpoch, resolveInteractionEndpoint, nativeServerEpoch);
|
|
265
|
+
}
|
|
266
|
+
const FLEET_PANES_ARGS = ["list-panes", "-a", "-F", FLEET_PANE_FORMAT];
|
|
267
|
+
function assembleAdoptedFleet(adopted, panesRaw, registry, nativeEpoch, resolveInteractionEndpoint, nativeServerEpoch) {
|
|
268
|
+
const adoptedSet = new Set(adopted);
|
|
269
|
+
const appCreatedSessions = new Set(registry.list().map((workspace) => workspace.sessionName));
|
|
270
|
+
const panesBySession = new Map();
|
|
238
271
|
for (const line of panesRaw.split("\n")) {
|
|
239
272
|
if (!line)
|
|
240
273
|
continue;
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { requireSupportedTmuxVersion } from "./lib/tmux-version.js";
|
|
2
2
|
import { resolveTmuxExecutable } from "./lib/tmux-client-execution.js";
|
|
3
|
+
import { TMUX_SOCKET_PATH_ENV } from "./lib/runtime-namespace.js";
|
|
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.js";
|
|
6
9
|
import { fileURLToPath } from "node:url";
|
|
7
10
|
import { getCurrentVersion, getUpdateStatus } from "./lib/update-check.js";
|
|
8
11
|
import { installedSkillVersion } from "./lib/skill-sync.js";
|
|
@@ -149,6 +152,96 @@ function check(label, fn, { optional = false } = {}) {
|
|
|
149
152
|
return { label, pass: false, detail: e.message, optional };
|
|
150
153
|
}
|
|
151
154
|
}
|
|
155
|
+
const UNKNOWN = (command) => new RegExp(`^unknown command: ${command}$`, "mu");
|
|
156
|
+
/** The same reading of the server as the mirror's: stock only when it refuses both
|
|
157
|
+
* native commands by name, and full only with the split capability it requires. */
|
|
158
|
+
function nativeCommands(probe) {
|
|
159
|
+
const ask = (command) => {
|
|
160
|
+
try {
|
|
161
|
+
return { output: probe([command, "-V"]) };
|
|
162
|
+
}
|
|
163
|
+
catch (error) {
|
|
164
|
+
const failure = error;
|
|
165
|
+
return { failure: String(failure.stderr ?? failure.message ?? "") };
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
const split = ask("tmux-ide-resize-split");
|
|
169
|
+
const events = ask("tmux-ide-events");
|
|
170
|
+
const failures = [split.failure, events.failure].filter((text) => text !== undefined);
|
|
171
|
+
if (failures.some((text) => /no server running|error connecting/u.test(text)))
|
|
172
|
+
return "no-server";
|
|
173
|
+
const refused = (answer, command) => answer.failure !== undefined && UNKNOWN(command).test(answer.failure);
|
|
174
|
+
if (refused(split, "tmux-ide-resize-split") && refused(events, "tmux-ide-events"))
|
|
175
|
+
return "stock";
|
|
176
|
+
if (split.output !== undefined && events.output !== undefined) {
|
|
177
|
+
try {
|
|
178
|
+
return nativeSplitCapability(split.output) ? "full" : "partial";
|
|
179
|
+
}
|
|
180
|
+
catch {
|
|
181
|
+
return "partial";
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return failures.length === 2 ? "unknown" : "partial";
|
|
185
|
+
}
|
|
186
|
+
/** Reads the server a session would use. With none running, a throwaway private
|
|
187
|
+
* server shows what the resolved binary would start. */
|
|
188
|
+
export function tmuxFeaturesRow(probeServer, probeBinary) {
|
|
189
|
+
let answer = nativeCommands(probeServer);
|
|
190
|
+
if (answer === "no-server")
|
|
191
|
+
answer = nativeCommands(probeBinary);
|
|
192
|
+
const details = {
|
|
193
|
+
full: "bundled tmux: full features",
|
|
194
|
+
stock: "stock tmux: reduced features",
|
|
195
|
+
partial: "this tmux has only some tmux-ide commands: no pane dividers",
|
|
196
|
+
"no-server": "could not read the tmux server's features",
|
|
197
|
+
unknown: "could not read the tmux server's features",
|
|
198
|
+
};
|
|
199
|
+
return {
|
|
200
|
+
label: "tmux features",
|
|
201
|
+
pass: answer === "full" || answer === "stock",
|
|
202
|
+
detail: details[answer],
|
|
203
|
+
optional: true,
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
function runTmuxFeatureProbes(executable) {
|
|
207
|
+
const run = (prefix) => (args) => execFileSync(executable, [...prefix, ...args], {
|
|
208
|
+
encoding: "utf8",
|
|
209
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
210
|
+
timeout: 3000,
|
|
211
|
+
});
|
|
212
|
+
const socketPath = process.env[TMUX_SOCKET_PATH_ENV];
|
|
213
|
+
const socketName = process.env.TMUX_IDE_TMUX_SOCKET_NAME;
|
|
214
|
+
const server = socketPath ? ["-S", socketPath] : socketName ? ["-L", socketName] : [];
|
|
215
|
+
const cleanups = [];
|
|
216
|
+
const probeBinary = (() => {
|
|
217
|
+
let scratch = null;
|
|
218
|
+
return (args) => {
|
|
219
|
+
scratch ??= (() => {
|
|
220
|
+
const dir = mkdtempSync(join(tmpdir(), "tmi-doctor-"));
|
|
221
|
+
const prefix = ["-S", join(dir, "s"), "-f", "/dev/null"];
|
|
222
|
+
cleanups.push(() => {
|
|
223
|
+
try {
|
|
224
|
+
run(prefix)(["kill-server"]);
|
|
225
|
+
}
|
|
226
|
+
catch {
|
|
227
|
+
// The server is already gone.
|
|
228
|
+
}
|
|
229
|
+
rmSync(dir, { recursive: true, force: true });
|
|
230
|
+
});
|
|
231
|
+
run(prefix)(["new-session", "-d", "-s", "probe"]);
|
|
232
|
+
return { dir, prefix };
|
|
233
|
+
})();
|
|
234
|
+
return run(scratch.prefix)(args);
|
|
235
|
+
};
|
|
236
|
+
})();
|
|
237
|
+
try {
|
|
238
|
+
return tmuxFeaturesRow(run(server), probeBinary);
|
|
239
|
+
}
|
|
240
|
+
finally {
|
|
241
|
+
for (const cleanup of cleanups)
|
|
242
|
+
cleanup();
|
|
243
|
+
}
|
|
244
|
+
}
|
|
152
245
|
export function nodeVersionRow(version) {
|
|
153
246
|
const major = Number(version.split(".")[0]);
|
|
154
247
|
const pass = Number.isInteger(major) && major >= 20;
|
|
@@ -190,6 +283,12 @@ export async function doctor({ json, } = {}) {
|
|
|
190
283
|
requireSupportedTmuxVersion(version);
|
|
191
284
|
return `${version} (${executable})`;
|
|
192
285
|
}));
|
|
286
|
+
try {
|
|
287
|
+
checks.push(runTmuxFeatureProbes(resolveTmuxExecutable()));
|
|
288
|
+
}
|
|
289
|
+
catch {
|
|
290
|
+
// The tmux version row above already reports a missing executable.
|
|
291
|
+
}
|
|
193
292
|
checks.push(nodeVersionRow(process.versions.node));
|
|
194
293
|
checks.push(check("256-color terminal", () => {
|
|
195
294
|
const term = process.env.TERM ?? "";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { readAdoptedFleet, readAdoptedFleetAsync, } from "../command-center/discovery.js";
|
|
2
|
+
/**
|
|
3
|
+
* Read the catalog fleet without blocking the event loop (#709), except inside
|
|
4
|
+
* a session mutation, where the read keeps the fence's synchronous runner.
|
|
5
|
+
*/
|
|
6
|
+
export async function readCatalogFleet(registry, runners, resolveInteractionEndpoint, nativeServerEpoch) {
|
|
7
|
+
return runners.fence.active
|
|
8
|
+
? readAdoptedFleet(registry, runners.fencedSync, resolveInteractionEndpoint, nativeServerEpoch)
|
|
9
|
+
: readAdoptedFleetAsync(registry, runners.generationFencedAsync, resolveInteractionEndpoint, nativeServerEpoch);
|
|
10
|
+
}
|
|
@@ -10,7 +10,7 @@ import { createNativeBrowserResolver } from "./tmux-native-browser.js";
|
|
|
10
10
|
import { createNativeSurfaceContextResolver } from "./native-surface-context.js";
|
|
11
11
|
import { NativeSurfaceProviderRegistry } from "../terminal/graphics/native-surface-provider.js";
|
|
12
12
|
import { TmuxServerVersionSchemaZ } from "@tmux-ide/contracts";
|
|
13
|
-
import { createNativeSplitCapabilityProbe, createNativeSplitReadiness, } from "./native-split-capability.js";
|
|
13
|
+
import { createNativeSplitCapabilityProbe, createNativeSplitReadiness, createStockSplitProbe, } from "./native-split-capability.js";
|
|
14
14
|
import { executeCanonicalSplitMutation } from "./canonical-split-mutation.js";
|
|
15
15
|
import { createGuardedNativeSplitResize } from "./guarded-native-split-resize.js";
|
|
16
16
|
import { WindowLinkTargetSchemaZ } from "@tmux-ide/contracts";
|
|
@@ -68,7 +68,8 @@ import { setDaemonShutdownBackend, setDaemonRestartBackend, } from "../command-c
|
|
|
68
68
|
import { readAppSettings } from "./app-settings.js";
|
|
69
69
|
import { getDefaultWorkspaceRegistry, readWorkspaceRegistrySessionInventory, WORKSPACE_REGISTRY_TMUX_TIMEOUT_MS, } from "./workspace-registry.js";
|
|
70
70
|
import { createPinnedWorkspaceTmuxRunner, createPinnedWorkspaceTmuxAsyncRunner, resolveWorkspacePaneTmuxAuthority, WorkspacePaneCreationAuthority, } from "./workspace-pane-creation.js";
|
|
71
|
-
import { discoverLiveSessionSummaries, readAdoptedFleet } from "../command-center/discovery.js";
|
|
71
|
+
import { discoverLiveSessionSummaries, readAdoptedFleet, } from "../command-center/discovery.js";
|
|
72
|
+
import { readCatalogFleet } from "./catalog-fleet-read.js";
|
|
72
73
|
import { WorkspaceOpenAuthority } from "./workspace-open.js";
|
|
73
74
|
import { WorkspacePromotionAuthority } from "./workspace-promotion.js";
|
|
74
75
|
import { WorkspaceOpenHandoffCoordinator } from "./workspace-open-handoff.js";
|
|
@@ -1111,6 +1112,9 @@ async function startEmbeddedDaemonGeneration(opts) {
|
|
|
1111
1112
|
observation: () => observationSelector ?? null,
|
|
1112
1113
|
runPinnedTmux: nativeGenerationTmuxRunner,
|
|
1113
1114
|
}),
|
|
1115
|
+
splitLayoutStock: createStockSplitProbe({
|
|
1116
|
+
runPinnedTmux: nativeGenerationTmuxRunner,
|
|
1117
|
+
}),
|
|
1114
1118
|
createOwnedViewerAdapter: () => ownedViewerFactory?.(),
|
|
1115
1119
|
nativeServerIdentity: initialNativeServerIdentity,
|
|
1116
1120
|
executable: tmuxAuthority.executablePath,
|
|
@@ -1542,9 +1546,19 @@ async function startEmbeddedDaemonGeneration(opts) {
|
|
|
1542
1546
|
paneStreamRuntime,
|
|
1543
1547
|
catalogLiveSessions: () => discoverLiveSessionSummaries(catalogTmuxRunner),
|
|
1544
1548
|
catalogFleet: async () => {
|
|
1545
|
-
const
|
|
1549
|
+
const endpoint = (sessionName, pane) => pane.semanticPaneId
|
|
1546
1550
|
? (interactionEvidence?.captureInventoryEndpoint(sessionName, pane.runtimePaneId, pane.semanticPaneId) ?? null)
|
|
1547
|
-
: null
|
|
1551
|
+
: null;
|
|
1552
|
+
const epoch = () => observationSelector?.nativeServerEpoch ?? null;
|
|
1553
|
+
// Same pinned server generation either way. Outside a session
|
|
1554
|
+
// mutation the read must not block the event loop: every concurrent
|
|
1555
|
+
// catalog request queued behind its spawnSync (#709). Inside one,
|
|
1556
|
+
// keep the fenced synchronous runner the mutation relies on.
|
|
1557
|
+
const fleet = await readCatalogFleet(workspaceRegistry, {
|
|
1558
|
+
fence: sessionMutationFence,
|
|
1559
|
+
fencedSync: nativeGenerationTmuxRunner,
|
|
1560
|
+
generationFencedAsync: (args) => fleetFactsTmuxRunner(args),
|
|
1561
|
+
}, endpoint, epoch);
|
|
1548
1562
|
if (!fleet)
|
|
1549
1563
|
return null;
|
|
1550
1564
|
const names = await readTeamMemberships(fleet.flatMap((session) => session.panes.map((pane) => ({
|
|
@@ -106,13 +106,18 @@ export async function manageDaemonService(action, executable, deps = defaults())
|
|
|
106
106
|
refused("The service manager loaded a different definition; refusing to control it");
|
|
107
107
|
return state;
|
|
108
108
|
};
|
|
109
|
-
|
|
109
|
+
// `retiredPid` is the process this restart terminated. It can publish a record
|
|
110
|
+
// while it shuts down (a KeepAlive relaunch just before the restart), so it is
|
|
111
|
+
// never the replacement, whatever its instance id.
|
|
112
|
+
const ready = async (previousInstance, retiredPid) => {
|
|
110
113
|
const deadline = Date.now() + deps.waitMs;
|
|
111
114
|
do {
|
|
112
115
|
const state = deps.inspect();
|
|
113
116
|
if (!boundTo(state, plan.supervisionId))
|
|
114
117
|
refused("Service reservation changed during startup");
|
|
115
|
-
if (state.status === "valid" &&
|
|
118
|
+
if (state.status === "valid" &&
|
|
119
|
+
state.info.instanceId !== previousInstance &&
|
|
120
|
+
state.info.pid !== retiredPid) {
|
|
116
121
|
const identity = await deps.probe(state.info);
|
|
117
122
|
const service = await inspectManager();
|
|
118
123
|
if (identity &&
|
|
@@ -236,11 +241,14 @@ export async function manageDaemonService(action, executable, deps = defaults())
|
|
|
236
241
|
const before = deps.inspect();
|
|
237
242
|
if (action === "install" && service.active)
|
|
238
243
|
return await ready();
|
|
239
|
-
|
|
240
|
-
|
|
244
|
+
// Read the manager again: a relaunch may have replaced the process while this
|
|
245
|
+
// waited for the lock, and the restart terminates whichever one runs now.
|
|
246
|
+
const current = service.loaded ? await inspectManager() : service;
|
|
247
|
+
if (current.loaded)
|
|
248
|
+
await manager.restart(current.pid !== null);
|
|
241
249
|
else
|
|
242
250
|
await manager.install();
|
|
243
|
-
return await ready(before.status === "valid" ? before.info.instanceId : undefined);
|
|
251
|
+
return await ready(before.status === "valid" ? before.info.instanceId : undefined, current.loaded ? current.pid : null);
|
|
244
252
|
}
|
|
245
253
|
catch (error) {
|
|
246
254
|
// Never discard ownership after an uncertain OS activation. The retained
|
|
@@ -80,3 +80,23 @@ export function createNativeSplitReadiness(options) {
|
|
|
80
80
|
pending = null;
|
|
81
81
|
}));
|
|
82
82
|
}
|
|
83
|
+
const NATIVE_COMMANDS = ["tmux-ide-resize-split", "tmux-ide-events"];
|
|
84
|
+
/** True only when the selected server refuses every native command by name. A
|
|
85
|
+
* timeout, a lost server or any other failure says nothing, so it stays false. */
|
|
86
|
+
export function createStockSplitProbe(options) {
|
|
87
|
+
return async () => {
|
|
88
|
+
for (const command of NATIVE_COMMANDS) {
|
|
89
|
+
try {
|
|
90
|
+
await options.runPinnedTmux([command, "-V"]);
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
const failure = error;
|
|
95
|
+
const text = String(failure?.cause?.stderr ?? failure?.stderr ?? "");
|
|
96
|
+
if (!new RegExp(`^unknown command: ${command}$`, "mu").test(text))
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return true;
|
|
101
|
+
};
|
|
102
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createNativeBrowserResolver } from "./tmux-native-browser.js";
|
|
2
2
|
import { createNativeSurfaceContextResolver } from "./native-surface-context.js";
|
|
3
3
|
import { shellEscape } from "./shell.js";
|
|
4
|
-
import { createNativeSplitCapabilityProbe, createNativeSplitReadiness, } from "./native-split-capability.js";
|
|
4
|
+
import { createNativeSplitCapabilityProbe, createNativeSplitReadiness, createStockSplitProbe, } from "./native-split-capability.js";
|
|
5
5
|
import { executeCanonicalSplitMutation } from "./canonical-split-mutation.js";
|
|
6
6
|
import { createGuardedNativeSplitResize } from "./guarded-native-split-resize.js";
|
|
7
7
|
import { execFileSync } from "node:child_process";
|
|
@@ -287,6 +287,7 @@ export async function createNativeTmuxServerOwner(options) {
|
|
|
287
287
|
observation: () => observationSelector ?? null,
|
|
288
288
|
runPinnedTmux: generationRun,
|
|
289
289
|
}),
|
|
290
|
+
splitLayoutStock: createStockSplitProbe({ runPinnedTmux: generationRun }),
|
|
290
291
|
createOwnedViewerAdapter: createOwnedViewerAdapterFactory({
|
|
291
292
|
environmentId: options.environmentId,
|
|
292
293
|
serverScope: { serverId: options.serverId, generation },
|
|
@@ -24,6 +24,8 @@ export class TmuxServerOwners {
|
|
|
24
24
|
constructor(options) {
|
|
25
25
|
this.options = options;
|
|
26
26
|
}
|
|
27
|
+
#queuedRefresh = null;
|
|
28
|
+
#queuedRefreshTail = null;
|
|
27
29
|
#serial(work) {
|
|
28
30
|
const run = this.#tail.then(() => {
|
|
29
31
|
if (this.#disposed)
|
|
@@ -134,12 +136,29 @@ export class TmuxServerOwners {
|
|
|
134
136
|
this.#entries.set(scope.serverId, { registration, scope, observation, owner });
|
|
135
137
|
}
|
|
136
138
|
refresh() {
|
|
137
|
-
|
|
139
|
+
// A refresh still waiting its turn has not probed anything yet, so it is
|
|
140
|
+
// as fresh for a later caller as a new one: share it instead of queuing
|
|
141
|
+
// another full refresh behind it (#709). Once it starts, callers queue anew.
|
|
142
|
+
// Share it only while nothing has been queued behind it, so a refresh
|
|
143
|
+
// stays ordered after any mutation queued before the caller asked.
|
|
144
|
+
if (this.#queuedRefresh && this.#tail === this.#queuedRefreshTail)
|
|
145
|
+
return this.#queuedRefresh;
|
|
146
|
+
const queued = this.#serial(async () => {
|
|
147
|
+
if (this.#queuedRefresh === queued)
|
|
148
|
+
this.#queuedRefresh = null;
|
|
138
149
|
// Sequential admission bounds subprocess work and avoids alias races.
|
|
139
150
|
for (const entry of this.#entries.values())
|
|
140
151
|
await this.#refresh(entry);
|
|
141
152
|
return this.list();
|
|
142
153
|
});
|
|
154
|
+
this.#queuedRefresh = queued;
|
|
155
|
+
this.#queuedRefreshTail = this.#tail;
|
|
156
|
+
const settle = () => {
|
|
157
|
+
if (this.#queuedRefresh === queued)
|
|
158
|
+
this.#queuedRefresh = null;
|
|
159
|
+
};
|
|
160
|
+
queued.then(settle, settle);
|
|
161
|
+
return queued;
|
|
143
162
|
}
|
|
144
163
|
current(scopeInput) {
|
|
145
164
|
const scope = TmuxServerScopeSchemaZ.parse(scopeInput);
|