tmux-ide 2.9.23 → 2.9.24
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 +285 -36
- package/package.json +1 -1
- package/packages/daemon/dist/command-center/tmux-servers.js +11 -0
- package/packages/daemon/dist/lib/daemon-embed.js +16 -8
- package/packages/daemon/dist/lib/home-agent-observer.js +50 -0
- package/packages/daemon/dist/lib/machine-agents.js +18 -1
- package/packages/daemon/dist/lib/orphaned-control-clients.js +162 -0
- package/packages/daemon/dist/lib/tmux-external-interaction-observer.js +32 -9
- package/packages/daemon/dist/lib/tmux-server-owner.js +26 -4
- package/packages/daemon/dist/lib/workspace-promotion.js +24 -3
- 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/attachments/native-runtime.js +17 -2
- package/packages/daemon/dist/terminal/mirror/session-channel.js +2 -1
- package/packages/daemon/dist/terminal/pane-stream/pane-stream-websocket.js +8 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-home-agent-navigation.js +57 -4
- package/packages/daemon/dist/tui/mirror/runtime/application-home-agents-owner.js +18 -7
- package/packages/daemon/dist/tui/mirror/runtime/application-machine-agent-navigation.js +17 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-machine-navigation.js +4 -2
- package/packages/daemon/dist/tui/mirror/runtime/application-terminal-interaction-controller.js +55 -14
- package/packages/daemon/src/command-center/tmux-servers.ts +11 -0
- package/packages/daemon/src/lib/daemon-embed.ts +52 -7
- package/packages/daemon/src/lib/home-agent-observer.ts +53 -0
- package/packages/daemon/src/lib/machine-agents.ts +25 -1
- package/packages/daemon/src/lib/orphaned-control-clients.ts +215 -0
- package/packages/daemon/src/lib/tmux-external-interaction-observer.ts +32 -8
- package/packages/daemon/src/lib/tmux-server-owner.ts +28 -3
- package/packages/daemon/src/lib/workspace-promotion.ts +26 -3
- package/packages/daemon/src/terminal/attachments/native-runtime.ts +21 -2
- package/packages/daemon/src/terminal/mirror/session-channel.ts +2 -1
- package/packages/daemon/src/terminal/pane-stream/pane-stream-websocket.ts +8 -0
- package/packages/daemon/src/tui/mirror/runtime/application-home-agent-navigation.ts +69 -4
- package/packages/daemon/src/tui/mirror/runtime/application-home-agents-owner.ts +30 -13
- package/packages/daemon/src/tui/mirror/runtime/application-machine-agent-navigation.ts +38 -1
- package/packages/daemon/src/tui/mirror/runtime/application-machine-navigation.ts +7 -2
- package/packages/daemon/src/tui/mirror/runtime/application-root-v2.tsx +4 -4
- package/packages/daemon/src/tui/mirror/runtime/application-terminal-interaction-controller.ts +71 -17
|
@@ -79,6 +79,7 @@ import { FleetLifecycleAuthority } from "./fleet-lifecycle-authority.js";
|
|
|
79
79
|
import { AppWindowMutationAuthority } from "./app-window-mutation.js";
|
|
80
80
|
import { WorkspaceMultiplexerAuthority } from "./workspace-multiplexer-verbs.js";
|
|
81
81
|
import { TmuxExternalInteractionObserver } from "./tmux-external-interaction-observer.js";
|
|
82
|
+
import { createOrphanedControlClientWatch } from "./orphaned-control-clients.js";
|
|
82
83
|
import { createTmuxInteractionObservationHandler, externalTmuxInteractionDraft, } from "./tmux-interaction-observation-handler.js";
|
|
83
84
|
import { InteractionReceiptJournal } from "./interaction-receipt-journal.js";
|
|
84
85
|
import { InteractionObservationStatusStore } from "./interaction-observation-status.js";
|
|
@@ -764,6 +765,13 @@ async function startEmbeddedDaemonGeneration(opts) {
|
|
|
764
765
|
const fleetFactsTmuxRunner = initialNativeServerIdentity
|
|
765
766
|
? createServerGenerationFencedTmuxAsyncRunner(tmuxAuthority, initialNativeServerIdentity)
|
|
766
767
|
: createPinnedWorkspaceTmuxAsyncRunner(tmuxAuthority);
|
|
768
|
+
// The daemon's own server: a predecessor killed without a stop may have
|
|
769
|
+
// left control clients attached to it.
|
|
770
|
+
const defaultServerOrphanWatch = createOrphanedControlClientWatch({
|
|
771
|
+
selector: tmuxAuthority.socketSelector,
|
|
772
|
+
serverId: null,
|
|
773
|
+
});
|
|
774
|
+
void defaultServerOrphanWatch.onOwnership();
|
|
767
775
|
const tmuxAuthorityReplaced = createTmuxAuthorityReplacementProbe(tmuxAuthority, catalogTmuxRunner);
|
|
768
776
|
const registryTmuxRunner = createPinnedWorkspaceTmuxRunner(tmuxAuthority, {
|
|
769
777
|
timeoutMs: WORKSPACE_REGISTRY_TMUX_TIMEOUT_MS,
|
|
@@ -1422,7 +1430,7 @@ async function startEmbeddedDaemonGeneration(opts) {
|
|
|
1422
1430
|
resolveNativeSurfaceContext: createNativeSurfaceContextResolver({
|
|
1423
1431
|
generation: instanceId,
|
|
1424
1432
|
registry: workspaceRegistry,
|
|
1425
|
-
catalog: createNativeTmuxServerCatalog(workspaceRegistry, fleetFactsTmuxRunner),
|
|
1433
|
+
catalog: createNativeTmuxServerCatalog(workspaceRegistry, fleetFactsTmuxRunner, undefined, defaultServerOrphanWatch.onTrouble),
|
|
1426
1434
|
inventory: terminalInventoryRuntime,
|
|
1427
1435
|
run: (args, signal) => fleetFactsTmuxRunner(args, signal),
|
|
1428
1436
|
assertOpen: () => {
|
|
@@ -1436,7 +1444,7 @@ async function startEmbeddedDaemonGeneration(opts) {
|
|
|
1436
1444
|
resolvePaneEditorContext: createPaneEditorContextResolver({
|
|
1437
1445
|
generation: instanceId,
|
|
1438
1446
|
registry: workspaceRegistry,
|
|
1439
|
-
catalog: createNativeTmuxServerCatalog(workspaceRegistry, fleetFactsTmuxRunner),
|
|
1447
|
+
catalog: createNativeTmuxServerCatalog(workspaceRegistry, fleetFactsTmuxRunner, undefined, defaultServerOrphanWatch.onTrouble),
|
|
1440
1448
|
inventory: terminalInventoryRuntime,
|
|
1441
1449
|
assertOpen: () => {
|
|
1442
1450
|
if (defaultEditorContextRetired ||
|
|
@@ -1450,7 +1458,7 @@ async function startEmbeddedDaemonGeneration(opts) {
|
|
|
1450
1458
|
generation: instanceId,
|
|
1451
1459
|
run: fleetFactsTmuxRunner,
|
|
1452
1460
|
registry: workspaceRegistry,
|
|
1453
|
-
catalog: createNativeTmuxServerCatalog(workspaceRegistry, fleetFactsTmuxRunner),
|
|
1461
|
+
catalog: createNativeTmuxServerCatalog(workspaceRegistry, fleetFactsTmuxRunner, undefined, defaultServerOrphanWatch.onTrouble),
|
|
1454
1462
|
inventory: terminalInventoryRuntime,
|
|
1455
1463
|
assertOpen: () => {
|
|
1456
1464
|
if (defaultEditorContextRetired ||
|
|
@@ -1464,7 +1472,7 @@ async function startEmbeddedDaemonGeneration(opts) {
|
|
|
1464
1472
|
generation: instanceId,
|
|
1465
1473
|
run: fleetFactsTmuxRunner,
|
|
1466
1474
|
registry: workspaceRegistry,
|
|
1467
|
-
catalog: createNativeTmuxServerCatalog(workspaceRegistry, fleetFactsTmuxRunner),
|
|
1475
|
+
catalog: createNativeTmuxServerCatalog(workspaceRegistry, fleetFactsTmuxRunner, undefined, defaultServerOrphanWatch.onTrouble),
|
|
1468
1476
|
inventory: terminalInventoryRuntime,
|
|
1469
1477
|
assertOpen: () => {
|
|
1470
1478
|
if (defaultEditorContextRetired ||
|
|
@@ -1474,10 +1482,10 @@ async function startEmbeddedDaemonGeneration(opts) {
|
|
|
1474
1482
|
throw new Error("Default reader owner is unavailable");
|
|
1475
1483
|
},
|
|
1476
1484
|
}),
|
|
1477
|
-
catalog: createNativeTmuxServerCatalog(workspaceRegistry, fleetFactsTmuxRunner),
|
|
1485
|
+
catalog: createNativeTmuxServerCatalog(workspaceRegistry, fleetFactsTmuxRunner, undefined, defaultServerOrphanWatch.onTrouble),
|
|
1478
1486
|
readWindowSplitLayout: async (workspaceName, input) => {
|
|
1479
1487
|
const target = WindowLinkTargetSchemaZ.parse(input);
|
|
1480
|
-
const sessions = await createNativeTmuxServerCatalog(workspaceRegistry, fleetFactsTmuxRunner)();
|
|
1488
|
+
const sessions = await createNativeTmuxServerCatalog(workspaceRegistry, fleetFactsTmuxRunner, undefined, defaultServerOrphanWatch.onTrouble)();
|
|
1481
1489
|
const sessionName = workspaceRegistry.get(workspaceName)?.sessionName;
|
|
1482
1490
|
if (!sessionName ||
|
|
1483
1491
|
!sessions.some((row) => row.sessionName === sessionName && row.liveSessionId === target.liveSessionId))
|
|
@@ -1488,7 +1496,7 @@ async function startEmbeddedDaemonGeneration(opts) {
|
|
|
1488
1496
|
},
|
|
1489
1497
|
openAgent: async (liveSessionId, observed) => {
|
|
1490
1498
|
const target = observedAgentSchema.parse(observed);
|
|
1491
|
-
await createNativeTmuxServerCatalog(workspaceRegistry, fleetFactsTmuxRunner)();
|
|
1499
|
+
await createNativeTmuxServerCatalog(workspaceRegistry, fleetFactsTmuxRunner, undefined, defaultServerOrphanWatch.onTrouble)();
|
|
1492
1500
|
try {
|
|
1493
1501
|
return await defaultSessionOpener.openAgent(liveSessionId, target);
|
|
1494
1502
|
}
|
|
@@ -1497,7 +1505,7 @@ async function startEmbeddedDaemonGeneration(opts) {
|
|
|
1497
1505
|
}
|
|
1498
1506
|
},
|
|
1499
1507
|
openSession: async (liveSessionId) => {
|
|
1500
|
-
await createNativeTmuxServerCatalog(workspaceRegistry, fleetFactsTmuxRunner)();
|
|
1508
|
+
await createNativeTmuxServerCatalog(workspaceRegistry, fleetFactsTmuxRunner, undefined, defaultServerOrphanWatch.onTrouble)();
|
|
1501
1509
|
const result = await defaultSessionOpener.openSession(liveSessionId);
|
|
1502
1510
|
terminalInventoryRuntime.invalidate();
|
|
1503
1511
|
return result;
|
|
@@ -319,3 +319,53 @@ export function createHomeAgentObserver(deps) {
|
|
|
319
319
|
},
|
|
320
320
|
};
|
|
321
321
|
}
|
|
322
|
+
/**
|
|
323
|
+
* A roster answers "is this row current" with no while it re-reads the row's
|
|
324
|
+
* session, and it re-reads whenever an agent appears or changes: the moment a
|
|
325
|
+
* row gets clicked. This waits for that re-read to finish instead of taking
|
|
326
|
+
* the no for an answer.
|
|
327
|
+
*/
|
|
328
|
+
export const ROSTER_SETTLE_MS = 3_000;
|
|
329
|
+
/**
|
|
330
|
+
* Resolves true as soon as the target is current, false as soon as the roster
|
|
331
|
+
* is not re-reading and the target still is not current, and whatever holds at
|
|
332
|
+
* the bound or when `signal` aborts (aborted: false).
|
|
333
|
+
*/
|
|
334
|
+
export function waitForRosterTarget(options) {
|
|
335
|
+
if (options.signal.aborted)
|
|
336
|
+
return Promise.resolve(false);
|
|
337
|
+
if (options.isCurrent())
|
|
338
|
+
return Promise.resolve(true);
|
|
339
|
+
if (!options.refreshing())
|
|
340
|
+
return Promise.resolve(false);
|
|
341
|
+
return new Promise((resolve) => {
|
|
342
|
+
let settled = false;
|
|
343
|
+
let stop = null;
|
|
344
|
+
const finish = (value) => {
|
|
345
|
+
if (settled)
|
|
346
|
+
return;
|
|
347
|
+
settled = true;
|
|
348
|
+
clearTimeout(timer);
|
|
349
|
+
options.signal.removeEventListener("abort", abort);
|
|
350
|
+
stop?.();
|
|
351
|
+
resolve(value);
|
|
352
|
+
};
|
|
353
|
+
const abort = () => finish(false);
|
|
354
|
+
const check = () => {
|
|
355
|
+
if (settled)
|
|
356
|
+
return;
|
|
357
|
+
if (options.isCurrent())
|
|
358
|
+
finish(true);
|
|
359
|
+
else if (!options.refreshing())
|
|
360
|
+
finish(false);
|
|
361
|
+
};
|
|
362
|
+
const timer = setTimeout(() => finish(options.isCurrent()), options.boundMs ?? ROSTER_SETTLE_MS);
|
|
363
|
+
timer.unref?.();
|
|
364
|
+
options.signal.addEventListener("abort", abort, { once: true });
|
|
365
|
+
const unsubscribe = options.subscribe(check);
|
|
366
|
+
if (settled)
|
|
367
|
+
unsubscribe();
|
|
368
|
+
else
|
|
369
|
+
stop = unsubscribe;
|
|
370
|
+
});
|
|
371
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isDeepStrictEqual } from "node:util";
|
|
2
2
|
import { machineResourceKey } from "@tmux-ide/core";
|
|
3
|
-
import { createHomeAgentObserver } from "./home-agent-observer.js";
|
|
3
|
+
import { createHomeAgentObserver, waitForRosterTarget, } from "./home-agent-observer.js";
|
|
4
4
|
import { createHomeAgentTransport } from "./home-agent-transport.js";
|
|
5
5
|
function bindingFor(handle) {
|
|
6
6
|
const daemon = handle.read();
|
|
@@ -145,6 +145,23 @@ export function createMachineAgents(options) {
|
|
|
145
145
|
entry.binding === bindingFor(entry.handle) &&
|
|
146
146
|
!!entry.observer?.isCurrentTarget(row));
|
|
147
147
|
},
|
|
148
|
+
/** The machine's roster is re-reading a session right now. */
|
|
149
|
+
isRefreshing(machineId) {
|
|
150
|
+
const observed = entries.get(machineId)?.observer?.getSnapshot();
|
|
151
|
+
return (!!observed && (observed.refreshingSessionKeys.length > 0 || observed.loadingSessions > 0));
|
|
152
|
+
},
|
|
153
|
+
/**
|
|
154
|
+
* `isCurrentTarget` once the machine's roster has finished re-reading:
|
|
155
|
+
* a row is not current during the read, and a click should wait for it.
|
|
156
|
+
*/
|
|
157
|
+
whenCurrentTarget(machineId, row, signal) {
|
|
158
|
+
return waitForRosterTarget({
|
|
159
|
+
isCurrent: () => this.isCurrentTarget(machineId, row),
|
|
160
|
+
refreshing: () => this.isRefreshing(machineId),
|
|
161
|
+
subscribe: (listener) => entries.get(machineId)?.observer?.subscribe(() => listener()) ?? (() => undefined),
|
|
162
|
+
signal,
|
|
163
|
+
});
|
|
164
|
+
},
|
|
148
165
|
retry() {
|
|
149
166
|
for (const entry of entries.values())
|
|
150
167
|
entry.observer?.retry();
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { logger } from "./log.js";
|
|
3
|
+
export const ORPHAN_KILL_GRACE_MS = 500;
|
|
4
|
+
/** PURE. `ps -o pid=,ppid=,command=` output, one process per line. */
|
|
5
|
+
export function parseProcessTable(text) {
|
|
6
|
+
const rows = [];
|
|
7
|
+
for (const line of text.split("\n")) {
|
|
8
|
+
const match = /^\s*([0-9]+)\s+([0-9]+)\s+(.+)$/u.exec(line);
|
|
9
|
+
if (match)
|
|
10
|
+
rows.push({ pid: Number(match[1]), ppid: Number(match[2]), command: match[3] });
|
|
11
|
+
}
|
|
12
|
+
return rows;
|
|
13
|
+
}
|
|
14
|
+
/** The attach flags only this daemon's control client uses (mirrorControlAttachArgs). */
|
|
15
|
+
export function isTmuxIdeControlClientCommand(command) {
|
|
16
|
+
return (/(?:^|\s)-C(?:\s|$)/u.test(command) &&
|
|
17
|
+
/ignore-size,pause-after=[0-9]+,active-pane/u.test(command));
|
|
18
|
+
}
|
|
19
|
+
const withoutPrivate = (path) => path.replace(/^\/private(?=\/)/u, "");
|
|
20
|
+
/** PURE. Does this tmux command line address the given server? */
|
|
21
|
+
export function commandTargetsServer(command, selector) {
|
|
22
|
+
const words = command.split(/\s+/u);
|
|
23
|
+
for (let index = 0; index < words.length; index += 1) {
|
|
24
|
+
const word = words[index];
|
|
25
|
+
if (word === "-C")
|
|
26
|
+
return false;
|
|
27
|
+
const flag = selector.kind === "path" ? "-S" : "-L";
|
|
28
|
+
const value = word === flag ? words[index + 1] : word.startsWith(flag) ? word.slice(2) : null;
|
|
29
|
+
if (value === null || value === undefined || value === "")
|
|
30
|
+
continue;
|
|
31
|
+
return selector.kind === "path"
|
|
32
|
+
? withoutPrivate(value) === withoutPrivate(selector.path)
|
|
33
|
+
: value === selector.name;
|
|
34
|
+
}
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
/** init, or a service manager that adopts orphans in its place. */
|
|
38
|
+
function adoptsOrphans(pid, command) {
|
|
39
|
+
if (pid === 1)
|
|
40
|
+
return true;
|
|
41
|
+
// The command's own name (its first word, with or without a path), never a
|
|
42
|
+
// word further on: a daemon run as `… --supervised launchd-user` is no manager.
|
|
43
|
+
return command !== null && /^(?:\S*\/)?(?:systemd|launchd|init)(?:\s|$)/u.test(command);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Ends tmux-ide control clients of this server whose daemon is gone. Never
|
|
47
|
+
* this daemon's own clients, another live daemon's, another server's, or any
|
|
48
|
+
* other program's. Returns the pids it ended. Failures end the pass; they
|
|
49
|
+
* never throw.
|
|
50
|
+
*/
|
|
51
|
+
export async function evictOrphanedControlClients(io, ownPid, selector) {
|
|
52
|
+
let processes;
|
|
53
|
+
try {
|
|
54
|
+
processes = await io.listProcesses();
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
return [];
|
|
58
|
+
}
|
|
59
|
+
const byPid = new Map(processes.map((row) => [row.pid, row]));
|
|
60
|
+
const evicted = [];
|
|
61
|
+
for (const client of processes) {
|
|
62
|
+
if (client.pid <= 1 ||
|
|
63
|
+
client.pid === ownPid ||
|
|
64
|
+
client.ppid === ownPid ||
|
|
65
|
+
!isTmuxIdeControlClientCommand(client.command) ||
|
|
66
|
+
!commandTargetsServer(client.command, selector) ||
|
|
67
|
+
!adoptsOrphans(client.ppid, byPid.get(client.ppid)?.command ?? null))
|
|
68
|
+
continue;
|
|
69
|
+
try {
|
|
70
|
+
io.kill(client.pid, "SIGTERM");
|
|
71
|
+
await io.delay(ORPHAN_KILL_GRACE_MS);
|
|
72
|
+
if (io.isAlive(client.pid))
|
|
73
|
+
io.kill(client.pid, "SIGKILL");
|
|
74
|
+
evicted.push(client.pid);
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
// One client that cannot be signalled does not stop the pass.
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return evicted;
|
|
81
|
+
}
|
|
82
|
+
/** The real process table and signals. */
|
|
83
|
+
export function orphanedControlClientIo() {
|
|
84
|
+
return {
|
|
85
|
+
listProcesses: () => new Promise((resolve, reject) => {
|
|
86
|
+
execFile("/bin/ps", ["-xww", "-o", "pid=,ppid=,command="], {
|
|
87
|
+
encoding: "utf8",
|
|
88
|
+
timeout: 3_000,
|
|
89
|
+
maxBuffer: 16 * 1024 * 1024,
|
|
90
|
+
env: { LC_ALL: "C", PATH: "/usr/bin:/bin" },
|
|
91
|
+
}, (error, stdout) => (error ? reject(error) : resolve(parseProcessTable(stdout))));
|
|
92
|
+
}),
|
|
93
|
+
kill: (pid, signal) => {
|
|
94
|
+
process.kill(pid, signal);
|
|
95
|
+
},
|
|
96
|
+
isAlive: (pid) => {
|
|
97
|
+
try {
|
|
98
|
+
process.kill(pid, 0);
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
return error.code === "EPERM";
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
delay: (ms) => new Promise((resolve) => setTimeout(resolve, ms)),
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
export const EMPTY_SERVER_PASS_INTERVAL_MS = 10_000;
|
|
109
|
+
export const EMPTY_SERVER_LOG_INTERVAL_MS = 60_000;
|
|
110
|
+
/**
|
|
111
|
+
* One per owned server. Neither call is awaited by the owner, delays it or
|
|
112
|
+
* fails it.
|
|
113
|
+
* - `onOwnership`: one pass when the daemon takes the server.
|
|
114
|
+
* - `onTrouble`: a catalog read found the server with no sessions, or got no
|
|
115
|
+
* answer from a server whose socket is still there. A tmux server normally
|
|
116
|
+
* exits with its last session, so either it is configured to stay or it
|
|
117
|
+
* cannot exit. At most one pass per 10 s, and one warning per minute that
|
|
118
|
+
* names the state: scoped reads fail in it, and nothing else says why.
|
|
119
|
+
*/
|
|
120
|
+
export function createOrphanedControlClientWatch(options) {
|
|
121
|
+
const io = options.io ?? orphanedControlClientIo();
|
|
122
|
+
const now = options.now ?? Date.now;
|
|
123
|
+
const fields = options.serverId ? { serverId: options.serverId } : {};
|
|
124
|
+
let lastPassAt = Number.NEGATIVE_INFINITY;
|
|
125
|
+
let lastLogAt = Number.NEGATIVE_INFINITY;
|
|
126
|
+
let running = null;
|
|
127
|
+
const pass = () => {
|
|
128
|
+
if (running)
|
|
129
|
+
return running;
|
|
130
|
+
lastPassAt = now();
|
|
131
|
+
const current = evictOrphanedControlClients(io, process.pid, options.selector)
|
|
132
|
+
.catch(() => [])
|
|
133
|
+
.then((pids) => {
|
|
134
|
+
if (pids.length > 0)
|
|
135
|
+
logger.warn("tmux-server-owners", "ended control clients a dead daemon left attached", {
|
|
136
|
+
...fields,
|
|
137
|
+
pids,
|
|
138
|
+
});
|
|
139
|
+
return pids;
|
|
140
|
+
})
|
|
141
|
+
.finally(() => {
|
|
142
|
+
if (running === current)
|
|
143
|
+
running = null;
|
|
144
|
+
});
|
|
145
|
+
running = current;
|
|
146
|
+
return current;
|
|
147
|
+
};
|
|
148
|
+
return {
|
|
149
|
+
onOwnership: () => pass().then(() => undefined),
|
|
150
|
+
async onTrouble(kind) {
|
|
151
|
+
if (now() - lastPassAt < EMPTY_SERVER_PASS_INTERVAL_MS)
|
|
152
|
+
return;
|
|
153
|
+
const pids = await pass();
|
|
154
|
+
if (now() - lastLogAt < EMPTY_SERVER_LOG_INTERVAL_MS)
|
|
155
|
+
return;
|
|
156
|
+
lastLogAt = now();
|
|
157
|
+
logger.warn("tmux-server-owners", kind === "no-sessions"
|
|
158
|
+
? "tmux server answers with no sessions"
|
|
159
|
+
: "tmux server does not answer its catalog", { ...fields, endedControlClients: pids.length });
|
|
160
|
+
},
|
|
161
|
+
};
|
|
162
|
+
}
|
|
@@ -34,12 +34,21 @@ export const DEFAULT_HOOK_HEALTHCHECK_SCHEDULE = Object.freeze({
|
|
|
34
34
|
// `set-hook -gu`) can take them away; that is then noticed within 5 minutes.
|
|
35
35
|
maxMs: 300_000,
|
|
36
36
|
});
|
|
37
|
-
/**
|
|
38
|
-
|
|
37
|
+
/**
|
|
38
|
+
* Pure cadence rule: healthy checks double the wait up to the cap; a repair or
|
|
39
|
+
* failure resets it to the base. A check that is unhealthy again right after
|
|
40
|
+
* one that was (`consecutiveUnhealthy` of 2 or more) backs off as well: on a
|
|
41
|
+
* tmux server that is shutting down but cannot exit, every repair "succeeds"
|
|
42
|
+
* and is gone at the next check, and the base cadence then cost about 400 tmux
|
|
43
|
+
* calls a minute for as long as the server lingered.
|
|
44
|
+
*/
|
|
45
|
+
export function nextHookHealthcheckDelay(previousMs, outcome, schedule = DEFAULT_HOOK_HEALTHCHECK_SCHEDULE, consecutiveUnhealthy = 1) {
|
|
39
46
|
const base = Math.max(1, Math.floor(schedule.baseMs));
|
|
40
47
|
const max = Math.max(base, Math.floor(schedule.maxMs));
|
|
41
|
-
if (outcome !== "healthy")
|
|
42
|
-
|
|
48
|
+
if (outcome !== "healthy") {
|
|
49
|
+
const streak = Math.max(1, Math.min(32, Math.floor(consecutiveUnhealthy) || 1));
|
|
50
|
+
return Math.min(base * 2 ** (streak - 1), max);
|
|
51
|
+
}
|
|
43
52
|
const previous = Number.isFinite(previousMs) ? Math.max(base, Math.floor(previousMs)) : base;
|
|
44
53
|
return Math.min(previous * 2, max);
|
|
45
54
|
}
|
|
@@ -249,6 +258,8 @@ export class TmuxExternalInteractionObserver {
|
|
|
249
258
|
#healthcheckSchedule;
|
|
250
259
|
#healthcheckDelayMs;
|
|
251
260
|
#lastHealthcheckOutcome = "failed";
|
|
261
|
+
/** Scheduled checks in a row that did not find the hooks intact. */
|
|
262
|
+
#unhealthyChecks = 0;
|
|
252
263
|
#onAvailability;
|
|
253
264
|
#onGap;
|
|
254
265
|
#tmuxWork = Promise.resolve();
|
|
@@ -374,9 +385,10 @@ export class TmuxExternalInteractionObserver {
|
|
|
374
385
|
this.#reportGap("hook-repair-failed");
|
|
375
386
|
outcome = "failed";
|
|
376
387
|
}
|
|
388
|
+
this.#unhealthyChecks = outcome === "healthy" ? 0 : this.#unhealthyChecks + 1;
|
|
377
389
|
// A signal-path reset that landed during this check wins over the outcome.
|
|
378
390
|
if (this.#healthcheckDelayMs === delayBefore) {
|
|
379
|
-
this.#healthcheckDelayMs = nextHookHealthcheckDelay(delayBefore, outcome, this.#healthcheckSchedule);
|
|
391
|
+
this.#healthcheckDelayMs = nextHookHealthcheckDelay(delayBefore, outcome, this.#healthcheckSchedule, this.#unhealthyChecks);
|
|
380
392
|
}
|
|
381
393
|
if (this.#hookHealthcheck === null)
|
|
382
394
|
this.#scheduleHealthcheck();
|
|
@@ -485,11 +497,20 @@ export class TmuxExternalInteractionObserver {
|
|
|
485
497
|
const work = this.#serializeTmux(async () => {
|
|
486
498
|
const finish = this.#beginDiagnostic("healthcheck");
|
|
487
499
|
try {
|
|
488
|
-
|
|
500
|
+
const hooks = await this.#ownedHooksPresent(this.#abort.signal);
|
|
501
|
+
if (hooks === "present") {
|
|
489
502
|
this.#lastHealthcheckOutcome = "healthy";
|
|
490
503
|
finish(true);
|
|
491
504
|
return;
|
|
492
505
|
}
|
|
506
|
+
if (hooks === "unknown") {
|
|
507
|
+
// The check could not be made (tmux timed out or could not be
|
|
508
|
+
// started). That says nothing about the hooks: leave them, report
|
|
509
|
+
// no gap, and ask again at the base cadence.
|
|
510
|
+
this.#lastHealthcheckOutcome = "failed";
|
|
511
|
+
finish(false);
|
|
512
|
+
return;
|
|
513
|
+
}
|
|
493
514
|
// Hooks that were installed and are now gone dropped every interaction
|
|
494
515
|
// since their removal; the repair restores future observation only.
|
|
495
516
|
if (this.#installed)
|
|
@@ -756,10 +777,12 @@ export class TmuxExternalInteractionObserver {
|
|
|
756
777
|
output = await this.#io.runTmux(["show-hooks", "-g", "after-send-keys", ";", "show-hooks", "-g", "after-capture-pane"], signal);
|
|
757
778
|
}
|
|
758
779
|
catch {
|
|
759
|
-
return
|
|
780
|
+
return "unknown";
|
|
760
781
|
}
|
|
761
|
-
return
|
|
762
|
-
ownedHookInstalled(output, "after-capture-pane", this.#bufferName)
|
|
782
|
+
return ownedHookInstalled(output, "after-send-keys", this.#bufferName) &&
|
|
783
|
+
ownedHookInstalled(output, "after-capture-pane", this.#bufferName)
|
|
784
|
+
? "present"
|
|
785
|
+
: "missing";
|
|
763
786
|
}
|
|
764
787
|
get available() {
|
|
765
788
|
return this.#installed;
|
|
@@ -33,6 +33,7 @@ import { liveSessionIdForNativeIdentity } from "../terminal/protocol/live-sessio
|
|
|
33
33
|
import { SessionRuntimeRegistry } from "../terminal/session-runtime/registry.js";
|
|
34
34
|
import { createSessionRuntimeMultiplexerBackend } from "../terminal/session-runtime/multiplexer-backend.js";
|
|
35
35
|
import { TmuxExternalInteractionObserver } from "./tmux-external-interaction-observer.js";
|
|
36
|
+
import { createOrphanedControlClientWatch } from "./orphaned-control-clients.js";
|
|
36
37
|
import { InteractionReceiptJournal } from "./interaction-receipt-journal.js";
|
|
37
38
|
import { InteractionObservationStatusStore } from "./interaction-observation-status.js";
|
|
38
39
|
import { InteractionEvidenceAuthority } from "./interaction-evidence-authority.js";
|
|
@@ -58,9 +59,19 @@ function discoveredWorkspaceName(registry, sessionName) {
|
|
|
58
59
|
throw new Error("Unable to allocate discovered workspace identity");
|
|
59
60
|
}
|
|
60
61
|
/** Refresh discovered live membership without changing durable workspace intent or aliases. */
|
|
61
|
-
export function createNativeTmuxServerCatalog(workspaceRegistry, run, assertOpen = () => undefined
|
|
62
|
+
export function createNativeTmuxServerCatalog(workspaceRegistry, run, assertOpen = () => undefined,
|
|
63
|
+
/** Told when the server has no sessions or does not answer; never awaited. */
|
|
64
|
+
onTrouble) {
|
|
62
65
|
return async () => {
|
|
63
66
|
assertOpen();
|
|
67
|
+
const tell = (kind) => {
|
|
68
|
+
try {
|
|
69
|
+
void Promise.resolve(onTrouble?.(kind)).catch(() => undefined);
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
/* A watcher never decides the catalog. */
|
|
73
|
+
}
|
|
74
|
+
};
|
|
64
75
|
const raw = await run([
|
|
65
76
|
"-N",
|
|
66
77
|
"if-shell",
|
|
@@ -76,12 +87,18 @@ export function createNativeTmuxServerCatalog(workspaceRegistry, run, assertOpen
|
|
|
76
87
|
]
|
|
77
88
|
.map(shellEscape)
|
|
78
89
|
.join(" "),
|
|
79
|
-
], AbortSignal.timeout(2_000))
|
|
90
|
+
], AbortSignal.timeout(2_000)).catch((error) => {
|
|
91
|
+
tell("unanswered");
|
|
92
|
+
throw error;
|
|
93
|
+
});
|
|
80
94
|
assertOpen();
|
|
81
95
|
const rows = new Map();
|
|
82
96
|
// Only the successful server-side zero-session branch proves emptiness.
|
|
83
97
|
// Command errors, unsupported formats and unwitnessed blank output stay failures.
|
|
84
|
-
const
|
|
98
|
+
const empty = raw.trim() === "tmux-ide-empty-catalog-v1";
|
|
99
|
+
if (empty)
|
|
100
|
+
tell("no-sessions");
|
|
101
|
+
const lines = empty ? [] : raw.trim().split("\n");
|
|
85
102
|
for (const line of lines) {
|
|
86
103
|
const [pid, id, created, name, pane, window, activity, ...pathParts] = line.split("\t");
|
|
87
104
|
const dir = pathParts.join("\t");
|
|
@@ -156,6 +173,11 @@ export async function createNativeTmuxServerOwner(options) {
|
|
|
156
173
|
startTime: identityParts[1],
|
|
157
174
|
};
|
|
158
175
|
const generationRunAsync = createServerGenerationFencedTmuxAsyncRunner(authority, nativeServerIdentity);
|
|
176
|
+
const orphanWatch = createOrphanedControlClientWatch({
|
|
177
|
+
selector: authority.socketSelector,
|
|
178
|
+
serverId: options.serverId,
|
|
179
|
+
});
|
|
180
|
+
void orphanWatch.onOwnership();
|
|
159
181
|
const multiplexer = new WorkspaceMultiplexerAuthority({
|
|
160
182
|
daemonInstanceId: generation,
|
|
161
183
|
registry: workspaceRegistry,
|
|
@@ -401,7 +423,7 @@ export async function createNativeTmuxServerOwner(options) {
|
|
|
401
423
|
registry: sessionRuntimeRegistry,
|
|
402
424
|
resolveSession: (name) => workspaceRegistry.get(name)?.sessionName ?? null,
|
|
403
425
|
});
|
|
404
|
-
const catalog = createNativeTmuxServerCatalog(workspaceRegistry, generationRunAsync, assertOpen);
|
|
426
|
+
const catalog = createNativeTmuxServerCatalog(workspaceRegistry, generationRunAsync, assertOpen, orphanWatch.onTrouble);
|
|
405
427
|
const sessionCreator = createNativeTmuxSessionCreator({
|
|
406
428
|
generation,
|
|
407
429
|
registry: workspaceRegistry,
|
|
@@ -81,6 +81,11 @@ const ERROR_MESSAGES = {
|
|
|
81
81
|
operation_conflict: "The operation id was already used for another promotion intent.",
|
|
82
82
|
operation_capacity: "The daemon has reached its bounded workspace-promote operation capacity.",
|
|
83
83
|
};
|
|
84
|
+
/**
|
|
85
|
+
* How often a promotion stamps and proves a session whose pane inventory
|
|
86
|
+
* changed between the proof's two reads, before it refuses.
|
|
87
|
+
*/
|
|
88
|
+
export const PROMOTION_PROOF_ATTEMPTS = 3;
|
|
84
89
|
export class WorkspacePromotionError extends Error {
|
|
85
90
|
code;
|
|
86
91
|
context;
|
|
@@ -392,9 +397,25 @@ export class WorkspacePromotionAuthority {
|
|
|
392
397
|
? { workspaceName: alreadyRegistered.name, sessionName: session.sessionName }
|
|
393
398
|
: derivePromotionIdentity(session.sessionName);
|
|
394
399
|
this.#assertConflictFreeIdentity(identity);
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
400
|
+
// Another tmux client may split or close a pane while the session is
|
|
401
|
+
// being proved (an agent does it all day). The proof then cannot hold:
|
|
402
|
+
// stamp what is there now and prove again, a bounded number of times.
|
|
403
|
+
let canonicalRoot;
|
|
404
|
+
for (let attempt = 1;; attempt += 1) {
|
|
405
|
+
canonicalRoot = await this.#stampSession(request, session, identity);
|
|
406
|
+
this.#assertActive(request.operationId);
|
|
407
|
+
try {
|
|
408
|
+
await this.#verifyPromotedInventory(session.sessionId, identity);
|
|
409
|
+
break;
|
|
410
|
+
}
|
|
411
|
+
catch (error) {
|
|
412
|
+
if (attempt >= PROMOTION_PROOF_ATTEMPTS ||
|
|
413
|
+
!(error instanceof WorkspacePromotionError) ||
|
|
414
|
+
error.context.reason !== "inventory_changed_during_proof")
|
|
415
|
+
throw error;
|
|
416
|
+
this.#assertActive(request.operationId);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
398
419
|
await this.#publishFleetEnrollment(request, session, identity);
|
|
399
420
|
// Catalog discovery can admit this session while the native stamping
|
|
400
421
|
// and verification awaits run. Reuse that exact registry identity instead
|
|
@@ -21,9 +21,9 @@
|
|
|
21
21
|
<key>CFBundlePackageType</key>
|
|
22
22
|
<string>APPL</string>
|
|
23
23
|
<key>CFBundleShortVersionString</key>
|
|
24
|
-
<string>2.9.
|
|
24
|
+
<string>2.9.24</string>
|
|
25
25
|
<key>CFBundleVersion</key>
|
|
26
|
-
<string>2.9.
|
|
26
|
+
<string>2.9.24</string>
|
|
27
27
|
<key>LSMinimumSystemVersion</key>
|
|
28
28
|
<string>11.0</string>
|
|
29
29
|
<key>LSUIElement</key>
|
|
Binary file
|
|
Binary file
|
package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/_CodeSignature/CodeResources
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
</data>
|
|
11
11
|
<key>Resources/Assets.car</key>
|
|
12
12
|
<data>
|
|
13
|
-
|
|
13
|
+
GCWmy3k4L/Ut1Iml1My4dWKAUXA=
|
|
14
14
|
</data>
|
|
15
15
|
</dict>
|
|
16
16
|
<key>files2</key>
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
<dict>
|
|
27
27
|
<key>hash2</key>
|
|
28
28
|
<data>
|
|
29
|
-
|
|
29
|
+
mxm/LqezJ+GdXPR4Ujh+KGO7Z0Fod7ULKDxJsNy91/A=
|
|
30
30
|
</data>
|
|
31
31
|
</dict>
|
|
32
32
|
</dict>
|
|
@@ -1075,6 +1075,21 @@ export class WorkspaceTerminalInventoryRuntime {
|
|
|
1075
1075
|
throw new NativeTerminalAttachmentRuntimeError("runtime-disposed");
|
|
1076
1076
|
const epoch = this.#inventoryEpoch;
|
|
1077
1077
|
const nativeEpoch = this.#nativeServerEpoch?.() ?? null;
|
|
1078
|
+
// An invalidation can also land while the snapshot is being adopted. That
|
|
1079
|
+
// publication is refused, as before, and the inventory is read again: it
|
|
1080
|
+
// used to fail the caller, and at startup the caller is the daemon.
|
|
1081
|
+
const publish = async (value, publicationSignal) => {
|
|
1082
|
+
try {
|
|
1083
|
+
return await this.#publishInventory(value, nativeEpoch, publicationSignal, epoch);
|
|
1084
|
+
}
|
|
1085
|
+
catch (error) {
|
|
1086
|
+
if (this.#disposed || signal?.aborted || this.#inventoryEpoch === epoch)
|
|
1087
|
+
throw error;
|
|
1088
|
+
if (staleRetry < INVENTORY_STALE_RETRIES)
|
|
1089
|
+
return this.#readInventory(signal, staleRetry + 1);
|
|
1090
|
+
throw new NativeTerminalAttachmentRuntimeError("discovery-failed", "overtaken-by-invalidations");
|
|
1091
|
+
}
|
|
1092
|
+
};
|
|
1078
1093
|
if (signal) {
|
|
1079
1094
|
if (signal.aborted)
|
|
1080
1095
|
throw new NativeTerminalAttachmentRuntimeError("runtime-disposed");
|
|
@@ -1097,7 +1112,7 @@ export class WorkspaceTerminalInventoryRuntime {
|
|
|
1097
1112
|
return this.#readInventory(signal, staleRetry + 1);
|
|
1098
1113
|
throw new NativeTerminalAttachmentRuntimeError("discovery-failed", "overtaken-by-invalidations");
|
|
1099
1114
|
}
|
|
1100
|
-
return
|
|
1115
|
+
return publish(snapshot, signal);
|
|
1101
1116
|
}
|
|
1102
1117
|
if (this.#inventoryRead?.epoch === epoch)
|
|
1103
1118
|
return this.#inventoryRead.promise;
|
|
@@ -1120,7 +1135,7 @@ export class WorkspaceTerminalInventoryRuntime {
|
|
|
1120
1135
|
return this.#readInventory(undefined, staleRetry + 1);
|
|
1121
1136
|
throw new NativeTerminalAttachmentRuntimeError("discovery-failed", "overtaken-by-invalidations");
|
|
1122
1137
|
}
|
|
1123
|
-
return
|
|
1138
|
+
return publish(value, abort.signal);
|
|
1124
1139
|
})().finally(() => {
|
|
1125
1140
|
if (this.#inventoryRead?.promise === promise)
|
|
1126
1141
|
this.#inventoryRead = null;
|
|
@@ -3080,7 +3080,8 @@ export class SessionChannel {
|
|
|
3080
3080
|
!leftLayout ||
|
|
3081
3081
|
!rightLayout ||
|
|
3082
3082
|
leftWindow.semanticId !== rightWindow.semanticId ||
|
|
3083
|
-
|
|
3083
|
+
// Not the name: tmux derives it from the running command, and the
|
|
3084
|
+
// pane rows' own check ignores it too (sameSessionPaneInventory, #730).
|
|
3084
3085
|
leftWindow.paneBorderStatus !== rightWindow.paneBorderStatus ||
|
|
3085
3086
|
leftWindow.modeKeys !== rightWindow.modeKeys ||
|
|
3086
3087
|
!layoutIdentitiesEqual(leftLayout, rightLayout)) {
|
|
@@ -2558,6 +2558,14 @@ export class PaneStreamLiveConnection {
|
|
|
2558
2558
|
].includes(rawCode)
|
|
2559
2559
|
? rawCode
|
|
2560
2560
|
: "stream-unavailable";
|
|
2561
|
+
// A refused intent is answered to the client only; without this line a
|
|
2562
|
+
// click that did nothing leaves no trace in either log (#764).
|
|
2563
|
+
logger.info("pane-stream", "intent rejected", {
|
|
2564
|
+
session: this.#descriptor.sessionName,
|
|
2565
|
+
clientId: this.#clientId,
|
|
2566
|
+
verb: intent.verb,
|
|
2567
|
+
code,
|
|
2568
|
+
});
|
|
2561
2569
|
this.#sendFrame(null, {
|
|
2562
2570
|
type: "semantic-intent-ack",
|
|
2563
2571
|
operationId,
|