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
|
@@ -14,6 +14,21 @@ export function createApplicationHomeAgentNavigator(options) {
|
|
|
14
14
|
};
|
|
15
15
|
const listed = (current, target) => !!target.paneId &&
|
|
16
16
|
!!current?.agents.some((agent) => agent.id === target.agentId && agent.paneId === target.paneId);
|
|
17
|
+
/** Before a check that would refuse a stale target: let a re-reading roster finish. */
|
|
18
|
+
const settleTarget = async (token, target, signal) => {
|
|
19
|
+
if (!options.waitForCurrentTarget || !active(token) || options.isCurrentTarget(target))
|
|
20
|
+
return;
|
|
21
|
+
if (waitingNote !== token) {
|
|
22
|
+
options.setNote(`Waiting for agent in ${target.sessionName}…`);
|
|
23
|
+
waitingNote = token;
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
await options.waitForCurrentTarget(target, signal);
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
// A failed wait decides nothing; the check that follows does.
|
|
30
|
+
}
|
|
31
|
+
};
|
|
17
32
|
/** Every admission check; null admits. Notes are set only for a refusal. */
|
|
18
33
|
const refusal = (token, target, expectedGeneration) => {
|
|
19
34
|
if (!active(token))
|
|
@@ -56,7 +71,7 @@ export function createApplicationHomeAgentNavigator(options) {
|
|
|
56
71
|
const admission = new Promise((resolve) => {
|
|
57
72
|
settle = resolve;
|
|
58
73
|
});
|
|
59
|
-
options.selectPane(target.paneId, source, admission);
|
|
74
|
+
const selection = options.selectPane(target.paneId, source, admission);
|
|
60
75
|
// The cold path's "Opening agent in …" note, for the warm wait.
|
|
61
76
|
options.setNote(`Waiting for agent in ${target.sessionName}…`);
|
|
62
77
|
waitingNote = token;
|
|
@@ -66,13 +81,36 @@ export function createApplicationHomeAgentNavigator(options) {
|
|
|
66
81
|
catch {
|
|
67
82
|
// A failed wait is a refusal below, never an admission.
|
|
68
83
|
}
|
|
69
|
-
if (
|
|
70
|
-
|
|
84
|
+
if (options.waitForCurrentTarget && !options.isCurrentTarget(target))
|
|
85
|
+
await settleTarget(token, target, signal);
|
|
71
86
|
// A refusal replaces the note; an admission clears it below.
|
|
72
87
|
const refused = refusal(token, target, generationKey);
|
|
73
88
|
settle(refused === null);
|
|
74
|
-
if (refused)
|
|
89
|
+
if (refused) {
|
|
90
|
+
if (waitingNote === token)
|
|
91
|
+
waitingNote = null;
|
|
75
92
|
return refused;
|
|
93
|
+
}
|
|
94
|
+
// Admitted is not selected: the runtime may still refuse the pane, or take
|
|
95
|
+
// a moment for a pane that was just created. The wait note stays until it
|
|
96
|
+
// answers, and the terminals are shown only for a pane that was selected.
|
|
97
|
+
let selected;
|
|
98
|
+
try {
|
|
99
|
+
selected = (await selection) ?? "selected";
|
|
100
|
+
}
|
|
101
|
+
catch {
|
|
102
|
+
selected = "failed";
|
|
103
|
+
}
|
|
104
|
+
if (waitingNote === token)
|
|
105
|
+
waitingNote = null;
|
|
106
|
+
if (!active(token))
|
|
107
|
+
return { opened: false, failure: "superseded" };
|
|
108
|
+
if (selected === "superseded" || selected === "not-admitted") {
|
|
109
|
+
options.setNote(null);
|
|
110
|
+
return { opened: false, failure: "superseded" };
|
|
111
|
+
}
|
|
112
|
+
if (selected === "failed")
|
|
113
|
+
return failure(token, "selection-failed", "That agent's terminal could not be selected yet. Select the agent again.");
|
|
76
114
|
options.showTerminals(source);
|
|
77
115
|
options.setNote(null);
|
|
78
116
|
return { opened: true };
|
|
@@ -90,6 +128,14 @@ export function createApplicationHomeAgentNavigator(options) {
|
|
|
90
128
|
try {
|
|
91
129
|
if (!target.paneId)
|
|
92
130
|
return failure(token, "unavailable", "This agent has no available terminal to open.");
|
|
131
|
+
// Only when it is needed: a warm open of a current target stays synchronous.
|
|
132
|
+
if (options.waitForCurrentTarget && !options.isCurrentTarget(target)) {
|
|
133
|
+
await settleTarget(token, target, controller.signal);
|
|
134
|
+
if (!active(token))
|
|
135
|
+
return { opened: false, failure: "superseded" };
|
|
136
|
+
if (waitingNote === token)
|
|
137
|
+
waitingNote = null;
|
|
138
|
+
}
|
|
93
139
|
if (!options.isCurrentTarget(target))
|
|
94
140
|
return failure(token, "stale-target", "That agent changed or disappeared. Select it again on Home.");
|
|
95
141
|
const attached = options.currentGeneration();
|
|
@@ -122,6 +168,13 @@ export function createApplicationHomeAgentNavigator(options) {
|
|
|
122
168
|
if (!ready)
|
|
123
169
|
return failure(token, "attach-failed", "The session opened, but agent details are not ready. Return Home and retry.");
|
|
124
170
|
}
|
|
171
|
+
if (options.waitForCurrentTarget && !options.isCurrentTarget(target)) {
|
|
172
|
+
await settleTarget(token, target, controller.signal);
|
|
173
|
+
if (!active(token))
|
|
174
|
+
return { opened: false, failure: "superseded" };
|
|
175
|
+
if (waitingNote === token)
|
|
176
|
+
waitingNote = null;
|
|
177
|
+
}
|
|
125
178
|
return admit(token, target, source, opened.generationKey);
|
|
126
179
|
}
|
|
127
180
|
catch {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { waitForRosterTarget } from "../../../lib/home-agent-observer.js";
|
|
1
2
|
import { createApplicationNewAgentOwner } from "./application-new-agent-owner.js";
|
|
2
3
|
import { createEffect, createSignal, onCleanup, untrack } from "solid-js";
|
|
3
4
|
import { createApplicationHomeAgentObserver, } from "./application-home-agent-observer.js";
|
|
@@ -86,14 +87,15 @@ export function createApplicationHomeAgentsOwner(options) {
|
|
|
86
87
|
const [selected, setSelected] = createSignal(selection.snapshot());
|
|
87
88
|
const [opening, setOpening] = createSignal(false);
|
|
88
89
|
let request = 0;
|
|
90
|
+
const currentTarget = (target) => {
|
|
91
|
+
const catalog = options.catalog();
|
|
92
|
+
return (catalog.phase === "live" &&
|
|
93
|
+
catalog.daemonInstanceId === target.daemonInstanceId &&
|
|
94
|
+
catalog.sessions.some((session) => session.name === target.sessionName && session.liveSessionId === target.liveSessionId) &&
|
|
95
|
+
observer.isCurrentTarget(target));
|
|
96
|
+
};
|
|
89
97
|
const navigator = createApplicationHomeAgentNavigator({
|
|
90
|
-
isCurrentTarget
|
|
91
|
-
const catalog = options.catalog();
|
|
92
|
-
return (catalog.phase === "live" &&
|
|
93
|
-
catalog.daemonInstanceId === target.daemonInstanceId &&
|
|
94
|
-
catalog.sessions.some((session) => session.name === target.sessionName && session.liveSessionId === target.liveSessionId) &&
|
|
95
|
-
observer.isCurrentTarget(target));
|
|
96
|
-
},
|
|
98
|
+
isCurrentTarget: currentTarget,
|
|
97
99
|
currentGeneration() {
|
|
98
100
|
const generation = options.generation();
|
|
99
101
|
const generationKey = applicationGenerationNavigationKey(generation);
|
|
@@ -109,6 +111,15 @@ export function createApplicationHomeAgentsOwner(options) {
|
|
|
109
111
|
agents: semantic.sidebar.agents,
|
|
110
112
|
};
|
|
111
113
|
},
|
|
114
|
+
waitForCurrentTarget: (target, signal) => waitForRosterTarget({
|
|
115
|
+
isCurrent: () => currentTarget(target),
|
|
116
|
+
refreshing: () => {
|
|
117
|
+
const observed = observer.getSnapshot();
|
|
118
|
+
return observed.refreshingSessionKeys.length > 0 || observed.loadingSessions > 0;
|
|
119
|
+
},
|
|
120
|
+
subscribe: (listener) => observer.subscribe(() => listener()),
|
|
121
|
+
signal,
|
|
122
|
+
}),
|
|
112
123
|
waitForGeneration: (key, signal) => waitForHomeAgentSemantic(options.generation, key, signal),
|
|
113
124
|
waitForAgent: (key, listed, signal) => waitForHomeAgentListed(options.generation, key, listed, signal),
|
|
114
125
|
startGeneration: options.startGeneration,
|
|
@@ -2,6 +2,16 @@ import { retainsAgentControl } from "./application-retained-agent.js";
|
|
|
2
2
|
import { createApplicationHomeAgentNavigator, } from "./application-home-agent-navigation.js";
|
|
3
3
|
import { applicationGenerationNavigationKey } from "./application-generation-starter.js";
|
|
4
4
|
import { agentOpeningOwnsKey, waitForHomeAgentListed, waitForHomeAgentSemantic, } from "./application-home-agents-owner.js";
|
|
5
|
+
/**
|
|
6
|
+
* The two checks the navigator asks of the machines' agent roster: is a row
|
|
7
|
+
* current, and is it current once a re-read in progress has finished.
|
|
8
|
+
*/
|
|
9
|
+
export function machineAgentRosterChecks(roster) {
|
|
10
|
+
return {
|
|
11
|
+
isCurrentTarget: (machineId, row) => roster.isCurrentTarget(machineId, row),
|
|
12
|
+
waitForCurrentTarget: (machineId, row, signal) => roster.whenCurrentTarget(machineId, row, signal),
|
|
13
|
+
};
|
|
14
|
+
}
|
|
5
15
|
/** Machine identity fences the existing exact-agent admission owner. No independent input path. */
|
|
6
16
|
export function createApplicationMachineAgentNavigator(options) {
|
|
7
17
|
let current = null;
|
|
@@ -51,6 +61,13 @@ export function createApplicationMachineAgentNavigator(options) {
|
|
|
51
61
|
agents: semantic.sidebar.agents,
|
|
52
62
|
};
|
|
53
63
|
},
|
|
64
|
+
...(options.waitForCurrentTarget
|
|
65
|
+
? {
|
|
66
|
+
waitForCurrentTarget: (row, signal) => selected()
|
|
67
|
+
? options.waitForCurrentTarget(machineId, row, signal)
|
|
68
|
+
: Promise.resolve(false),
|
|
69
|
+
}
|
|
70
|
+
: {}),
|
|
54
71
|
waitForGeneration: (key, signal) => waitForHomeAgentSemantic(generation, key, signal),
|
|
55
72
|
waitForAgent: (key, listed, signal) => waitForHomeAgentListed(generation, key, listed, signal),
|
|
56
73
|
startGeneration: (session, prepared, origin, focus, admission) => options.startGeneration(session, prepared, origin, focus, () => selected() && options.isCurrentTarget(machineId, target) && (admission?.() ?? true)),
|
|
@@ -305,7 +305,8 @@ export function createApplicationMachineNavigation(options) {
|
|
|
305
305
|
const row = agentGroups()
|
|
306
306
|
.find((group) => group.machineId === id)
|
|
307
307
|
?.agents.find((agent) => agent.sessionName === sessionName && agent.paneId === paneId);
|
|
308
|
-
|
|
308
|
+
// A row is not current while its roster re-reads; the opener waits for that.
|
|
309
|
+
if (!row || (!agents.isCurrentTarget(id, row) && !agents.isRefreshing(id))) {
|
|
309
310
|
options.setNote("That agent is unavailable or has changed. Wait for its machine to reconnect.");
|
|
310
311
|
return;
|
|
311
312
|
}
|
|
@@ -358,7 +359,8 @@ export function createApplicationMachineNavigation(options) {
|
|
|
358
359
|
agents,
|
|
359
360
|
selectedMachineId: () => manager.snapshot().selectedMachineId,
|
|
360
361
|
openHomeAgent: (row, source) => {
|
|
361
|
-
if (!agents.isCurrentTarget(row.machineId, row) || row.disabled)
|
|
362
|
+
if ((!agents.isCurrentTarget(row.machineId, row) || row.disabled) &&
|
|
363
|
+
!agents.isRefreshing(row.machineId))
|
|
362
364
|
return;
|
|
363
365
|
const session = snapshot()
|
|
364
366
|
.groups.find((group) => group.id === row.machineId)
|
package/packages/daemon/dist/tui/mirror/runtime/application-terminal-interaction-controller.js
CHANGED
|
@@ -10,6 +10,13 @@ import { TerminalPaneInputRouter } from "./terminal-pane-input-router.js";
|
|
|
10
10
|
import { resizeTerminalPane, } from "./resize-terminal-pane.js";
|
|
11
11
|
import { ResizeTransactionController } from "@tmux-ide/core";
|
|
12
12
|
import { nativePaneResizeCells } from "./pane-resize-geometry.js";
|
|
13
|
+
/**
|
|
14
|
+
* Waits between tries of a selection the daemon refused as
|
|
15
|
+
* `pane_inventory_not_ready`: it refuses, before any effect, a pane its
|
|
16
|
+
* inventory has not adopted yet, which is the case for a moment after a pane
|
|
17
|
+
* is created (#764). About 3 s in all.
|
|
18
|
+
*/
|
|
19
|
+
export const PANE_INVENTORY_RETRY_DELAYS_MS = [100, 200, 400, 800, 1500];
|
|
13
20
|
function paneForWindow(layout) {
|
|
14
21
|
return (layout.panes.find((pane) => pane.active && pane.pane)?.pane ??
|
|
15
22
|
layout.panes.find((pane) => pane.pane)?.pane ??
|
|
@@ -527,7 +534,29 @@ export function createApplicationTerminalInteractionController(options) {
|
|
|
527
534
|
};
|
|
528
535
|
// The one way a pane selection reaches the runtime (#764: also used once an
|
|
529
536
|
// admitted agent selection settles).
|
|
537
|
+
const selectionRetryDelaysMs = options.selectionRetryDelaysMs ?? PANE_INVENTORY_RETRY_DELAYS_MS;
|
|
538
|
+
/**
|
|
539
|
+
* A refusal for an inventory that is not ready happened before any effect,
|
|
540
|
+
* so the same selection may be sent again while it is still the current one.
|
|
541
|
+
* Any other failure is final.
|
|
542
|
+
*/
|
|
530
543
|
const selectInRuntime = async (paneId) => {
|
|
544
|
+
const version = paneInput.selectionVersion;
|
|
545
|
+
for (let attempt = 0;; attempt++) {
|
|
546
|
+
const failure = { current: null };
|
|
547
|
+
if (await selectInRuntimeOnce(paneId, failure))
|
|
548
|
+
return true;
|
|
549
|
+
const delayMs = selectionRetryDelaysMs[attempt];
|
|
550
|
+
if (delayMs === undefined ||
|
|
551
|
+
failure.current?.backendReason !== "pane_inventory_not_ready" ||
|
|
552
|
+
paneInput.selectionVersion !== version)
|
|
553
|
+
return false;
|
|
554
|
+
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
555
|
+
if (paneInput.selectionVersion !== version)
|
|
556
|
+
return false;
|
|
557
|
+
}
|
|
558
|
+
};
|
|
559
|
+
const selectInRuntimeOnce = async (paneId, selectionFailure) => {
|
|
531
560
|
finishLinkSelection(false);
|
|
532
561
|
const initial = options.generation();
|
|
533
562
|
const selectionControl = controlIdentity(initial);
|
|
@@ -553,7 +582,6 @@ export function createApplicationTerminalInteractionController(options) {
|
|
|
553
582
|
let dispatchedRendererEpoch;
|
|
554
583
|
const selecting = pendingWindowSwitch;
|
|
555
584
|
const operationId = selecting?.traceId;
|
|
556
|
-
const selectionFailure = { current: null };
|
|
557
585
|
const receipt = expected
|
|
558
586
|
? await selectTerminalPane(expected, () => {
|
|
559
587
|
if (!selectionControl)
|
|
@@ -916,22 +944,35 @@ export function createApplicationTerminalInteractionController(options) {
|
|
|
916
944
|
maybeRequestWindowSwitchFrame();
|
|
917
945
|
maybeRequestPaneResizeFrame();
|
|
918
946
|
},
|
|
919
|
-
selectPane: (paneId, admission) => {
|
|
947
|
+
selectPane: ((paneId, admission) => {
|
|
920
948
|
finishLinkSelection(false);
|
|
921
|
-
if (admission)
|
|
922
|
-
// Ordered now; selected only once admitted, otherwise held input drops.
|
|
923
|
-
paneInput.selectPane(paneId, {
|
|
924
|
-
presentOptimistically: false,
|
|
925
|
-
selection: () => {
|
|
926
|
-
// A later selection supersedes this one: never select it after all.
|
|
927
|
-
const version = paneInput.selectionVersion;
|
|
928
|
-
return admission.then((admitted) => admitted && paneInput.selectionVersion === version ? selectInRuntime(paneId) : false);
|
|
929
|
-
},
|
|
930
|
-
});
|
|
931
|
-
else
|
|
949
|
+
if (!admission) {
|
|
932
950
|
paneInput.selectPane(paneId);
|
|
951
|
+
selectionWaiter.reconcile();
|
|
952
|
+
return;
|
|
953
|
+
}
|
|
954
|
+
let outcome;
|
|
955
|
+
// Ordered now; selected only once admitted, otherwise held input drops.
|
|
956
|
+
paneInput.selectPane(paneId, {
|
|
957
|
+
presentOptimistically: false,
|
|
958
|
+
selection: () => {
|
|
959
|
+
// A later selection supersedes this one: never select it after all.
|
|
960
|
+
const version = paneInput.selectionVersion;
|
|
961
|
+
outcome = admission.then(async (admitted) => {
|
|
962
|
+
if (!admitted)
|
|
963
|
+
return "not-admitted";
|
|
964
|
+
if (paneInput.selectionVersion !== version)
|
|
965
|
+
return "superseded";
|
|
966
|
+
if (await selectInRuntime(paneId))
|
|
967
|
+
return "selected";
|
|
968
|
+
return paneInput.selectionVersion === version ? "failed" : "superseded";
|
|
969
|
+
});
|
|
970
|
+
return outcome.then((result) => result === "selected");
|
|
971
|
+
},
|
|
972
|
+
});
|
|
933
973
|
selectionWaiter.reconcile();
|
|
934
|
-
|
|
974
|
+
return outcome;
|
|
975
|
+
}),
|
|
935
976
|
async unlinkWindowLink(target) {
|
|
936
977
|
const expected = liveSelectionTarget();
|
|
937
978
|
const observed = windowLinkTarget(options.layout(), target.linkId);
|
|
@@ -38,6 +38,7 @@ import { createSessionFaviconResolver, type SessionFavicon } from "../lib/sessio
|
|
|
38
38
|
import { WorkspaceMultiplexerError } from "../lib/workspace-multiplexer-verbs.ts";
|
|
39
39
|
import { WorkspacePaneCreationError } from "../lib/workspace-pane-creation.ts";
|
|
40
40
|
import { ownerBearerMatches } from "./owner-authority.ts";
|
|
41
|
+
import { logger } from "../lib/log.ts";
|
|
41
42
|
import { mountPaneStreamIssueRoute } from "./pane-stream-issue.ts";
|
|
42
43
|
import { projectTerminalRuntimeInventory } from "./resources/terminal-runtime-inventory.ts";
|
|
43
44
|
|
|
@@ -96,6 +97,16 @@ function failure(c: Context, error: unknown): Response {
|
|
|
96
97
|
return c.json({ error: { code: error.code } }, 409);
|
|
97
98
|
if (error instanceof z.ZodError || error instanceof SyntaxError || error instanceof TypeError)
|
|
98
99
|
return c.json({ error: { code: "invalid-request" } }, 400);
|
|
100
|
+
// Everything above tells the client its cause. This answer does not, and a
|
|
101
|
+
// client can only retry it: the cause goes to the daemon's own log.
|
|
102
|
+
const code = (error as { code?: unknown } | null)?.code;
|
|
103
|
+
logger.warn("tmux-server-routes", "request failed as server-unavailable", {
|
|
104
|
+
method: c.req.method,
|
|
105
|
+
route: c.req.routePath,
|
|
106
|
+
errorName: error instanceof Error ? error.name : typeof error,
|
|
107
|
+
...(typeof code === "string" ? { errorCode: code.slice(0, 80) } : {}),
|
|
108
|
+
error: (error instanceof Error ? error.message : String(error)).slice(0, 300),
|
|
109
|
+
});
|
|
99
110
|
return c.json({ error: { code: "server-unavailable" } }, 503);
|
|
100
111
|
}
|
|
101
112
|
/** Owner capability is mandatory even when the ordinary local HTTP surface is open. */
|
|
@@ -139,6 +139,7 @@ import { FleetLifecycleAuthority } from "./fleet-lifecycle-authority.ts";
|
|
|
139
139
|
import { AppWindowMutationAuthority } from "./app-window-mutation.ts";
|
|
140
140
|
import { WorkspaceMultiplexerAuthority } from "./workspace-multiplexer-verbs.ts";
|
|
141
141
|
import { TmuxExternalInteractionObserver } from "./tmux-external-interaction-observer.ts";
|
|
142
|
+
import { createOrphanedControlClientWatch } from "./orphaned-control-clients.ts";
|
|
142
143
|
import {
|
|
143
144
|
createTmuxInteractionObservationHandler,
|
|
144
145
|
externalTmuxInteractionDraft,
|
|
@@ -1233,6 +1234,13 @@ async function startEmbeddedDaemonGeneration(
|
|
|
1233
1234
|
const fleetFactsTmuxRunner = initialNativeServerIdentity
|
|
1234
1235
|
? createServerGenerationFencedTmuxAsyncRunner(tmuxAuthority, initialNativeServerIdentity)
|
|
1235
1236
|
: createPinnedWorkspaceTmuxAsyncRunner(tmuxAuthority);
|
|
1237
|
+
// The daemon's own server: a predecessor killed without a stop may have
|
|
1238
|
+
// left control clients attached to it.
|
|
1239
|
+
const defaultServerOrphanWatch = createOrphanedControlClientWatch({
|
|
1240
|
+
selector: tmuxAuthority.socketSelector,
|
|
1241
|
+
serverId: null,
|
|
1242
|
+
});
|
|
1243
|
+
void defaultServerOrphanWatch.onOwnership();
|
|
1236
1244
|
const tmuxAuthorityReplaced = createTmuxAuthorityReplacementProbe(
|
|
1237
1245
|
tmuxAuthority,
|
|
1238
1246
|
catalogTmuxRunner,
|
|
@@ -2004,7 +2012,12 @@ async function startEmbeddedDaemonGeneration(
|
|
|
2004
2012
|
resolveNativeSurfaceContext: createNativeSurfaceContextResolver({
|
|
2005
2013
|
generation: instanceId,
|
|
2006
2014
|
registry: workspaceRegistry,
|
|
2007
|
-
catalog: createNativeTmuxServerCatalog(
|
|
2015
|
+
catalog: createNativeTmuxServerCatalog(
|
|
2016
|
+
workspaceRegistry,
|
|
2017
|
+
fleetFactsTmuxRunner,
|
|
2018
|
+
undefined,
|
|
2019
|
+
defaultServerOrphanWatch.onTrouble,
|
|
2020
|
+
),
|
|
2008
2021
|
inventory: terminalInventoryRuntime,
|
|
2009
2022
|
run: (args, signal) => fleetFactsTmuxRunner(args, signal),
|
|
2010
2023
|
assertOpen: () => {
|
|
@@ -2020,7 +2033,12 @@ async function startEmbeddedDaemonGeneration(
|
|
|
2020
2033
|
resolvePaneEditorContext: createPaneEditorContextResolver({
|
|
2021
2034
|
generation: instanceId,
|
|
2022
2035
|
registry: workspaceRegistry,
|
|
2023
|
-
catalog: createNativeTmuxServerCatalog(
|
|
2036
|
+
catalog: createNativeTmuxServerCatalog(
|
|
2037
|
+
workspaceRegistry,
|
|
2038
|
+
fleetFactsTmuxRunner,
|
|
2039
|
+
undefined,
|
|
2040
|
+
defaultServerOrphanWatch.onTrouble,
|
|
2041
|
+
),
|
|
2024
2042
|
inventory: terminalInventoryRuntime,
|
|
2025
2043
|
assertOpen: () => {
|
|
2026
2044
|
if (
|
|
@@ -2036,7 +2054,12 @@ async function startEmbeddedDaemonGeneration(
|
|
|
2036
2054
|
generation: instanceId,
|
|
2037
2055
|
run: fleetFactsTmuxRunner,
|
|
2038
2056
|
registry: workspaceRegistry,
|
|
2039
|
-
catalog: createNativeTmuxServerCatalog(
|
|
2057
|
+
catalog: createNativeTmuxServerCatalog(
|
|
2058
|
+
workspaceRegistry,
|
|
2059
|
+
fleetFactsTmuxRunner,
|
|
2060
|
+
undefined,
|
|
2061
|
+
defaultServerOrphanWatch.onTrouble,
|
|
2062
|
+
),
|
|
2040
2063
|
inventory: terminalInventoryRuntime,
|
|
2041
2064
|
assertOpen: () => {
|
|
2042
2065
|
if (
|
|
@@ -2052,7 +2075,12 @@ async function startEmbeddedDaemonGeneration(
|
|
|
2052
2075
|
generation: instanceId,
|
|
2053
2076
|
run: fleetFactsTmuxRunner,
|
|
2054
2077
|
registry: workspaceRegistry,
|
|
2055
|
-
catalog: createNativeTmuxServerCatalog(
|
|
2078
|
+
catalog: createNativeTmuxServerCatalog(
|
|
2079
|
+
workspaceRegistry,
|
|
2080
|
+
fleetFactsTmuxRunner,
|
|
2081
|
+
undefined,
|
|
2082
|
+
defaultServerOrphanWatch.onTrouble,
|
|
2083
|
+
),
|
|
2056
2084
|
inventory: terminalInventoryRuntime,
|
|
2057
2085
|
assertOpen: () => {
|
|
2058
2086
|
if (
|
|
@@ -2064,12 +2092,19 @@ async function startEmbeddedDaemonGeneration(
|
|
|
2064
2092
|
throw new Error("Default reader owner is unavailable");
|
|
2065
2093
|
},
|
|
2066
2094
|
}),
|
|
2067
|
-
catalog: createNativeTmuxServerCatalog(
|
|
2095
|
+
catalog: createNativeTmuxServerCatalog(
|
|
2096
|
+
workspaceRegistry,
|
|
2097
|
+
fleetFactsTmuxRunner,
|
|
2098
|
+
undefined,
|
|
2099
|
+
defaultServerOrphanWatch.onTrouble,
|
|
2100
|
+
),
|
|
2068
2101
|
readWindowSplitLayout: async (workspaceName, input) => {
|
|
2069
2102
|
const target = WindowLinkTargetSchemaZ.parse(input);
|
|
2070
2103
|
const sessions = await createNativeTmuxServerCatalog(
|
|
2071
2104
|
workspaceRegistry,
|
|
2072
2105
|
fleetFactsTmuxRunner,
|
|
2106
|
+
undefined,
|
|
2107
|
+
defaultServerOrphanWatch.onTrouble,
|
|
2073
2108
|
)();
|
|
2074
2109
|
const sessionName = workspaceRegistry.get(workspaceName)?.sessionName;
|
|
2075
2110
|
if (
|
|
@@ -2085,7 +2120,12 @@ async function startEmbeddedDaemonGeneration(
|
|
|
2085
2120
|
},
|
|
2086
2121
|
openAgent: async (liveSessionId, observed) => {
|
|
2087
2122
|
const target = observedAgentSchema.parse(observed);
|
|
2088
|
-
await createNativeTmuxServerCatalog(
|
|
2123
|
+
await createNativeTmuxServerCatalog(
|
|
2124
|
+
workspaceRegistry,
|
|
2125
|
+
fleetFactsTmuxRunner,
|
|
2126
|
+
undefined,
|
|
2127
|
+
defaultServerOrphanWatch.onTrouble,
|
|
2128
|
+
)();
|
|
2089
2129
|
try {
|
|
2090
2130
|
return await defaultSessionOpener.openAgent(liveSessionId, target);
|
|
2091
2131
|
} finally {
|
|
@@ -2093,7 +2133,12 @@ async function startEmbeddedDaemonGeneration(
|
|
|
2093
2133
|
}
|
|
2094
2134
|
},
|
|
2095
2135
|
openSession: async (liveSessionId) => {
|
|
2096
|
-
await createNativeTmuxServerCatalog(
|
|
2136
|
+
await createNativeTmuxServerCatalog(
|
|
2137
|
+
workspaceRegistry,
|
|
2138
|
+
fleetFactsTmuxRunner,
|
|
2139
|
+
undefined,
|
|
2140
|
+
defaultServerOrphanWatch.onTrouble,
|
|
2141
|
+
)();
|
|
2097
2142
|
const result = await defaultSessionOpener.openSession(liveSessionId);
|
|
2098
2143
|
terminalInventoryRuntime!.invalidate();
|
|
2099
2144
|
return result;
|
|
@@ -375,3 +375,56 @@ export function createHomeAgentObserver(deps: HomeAgentDependencies): HomeAgentO
|
|
|
375
375
|
},
|
|
376
376
|
};
|
|
377
377
|
}
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
* A roster answers "is this row current" with no while it re-reads the row's
|
|
381
|
+
* session, and it re-reads whenever an agent appears or changes: the moment a
|
|
382
|
+
* row gets clicked. This waits for that re-read to finish instead of taking
|
|
383
|
+
* the no for an answer.
|
|
384
|
+
*/
|
|
385
|
+
export const ROSTER_SETTLE_MS = 3_000;
|
|
386
|
+
|
|
387
|
+
/**
|
|
388
|
+
* Resolves true as soon as the target is current, false as soon as the roster
|
|
389
|
+
* is not re-reading and the target still is not current, and whatever holds at
|
|
390
|
+
* the bound or when `signal` aborts (aborted: false).
|
|
391
|
+
*/
|
|
392
|
+
export function waitForRosterTarget(options: {
|
|
393
|
+
readonly isCurrent: () => boolean;
|
|
394
|
+
readonly refreshing: () => boolean;
|
|
395
|
+
/** Called on every roster publication; may deliver one synchronously. */
|
|
396
|
+
readonly subscribe: (listener: () => void) => () => void;
|
|
397
|
+
readonly signal: AbortSignal;
|
|
398
|
+
readonly boundMs?: number;
|
|
399
|
+
}): Promise<boolean> {
|
|
400
|
+
if (options.signal.aborted) return Promise.resolve(false);
|
|
401
|
+
if (options.isCurrent()) return Promise.resolve(true);
|
|
402
|
+
if (!options.refreshing()) return Promise.resolve(false);
|
|
403
|
+
return new Promise((resolve) => {
|
|
404
|
+
let settled = false;
|
|
405
|
+
let stop: (() => void) | null = null;
|
|
406
|
+
const finish = (value: boolean): void => {
|
|
407
|
+
if (settled) return;
|
|
408
|
+
settled = true;
|
|
409
|
+
clearTimeout(timer);
|
|
410
|
+
options.signal.removeEventListener("abort", abort);
|
|
411
|
+
stop?.();
|
|
412
|
+
resolve(value);
|
|
413
|
+
};
|
|
414
|
+
const abort = (): void => finish(false);
|
|
415
|
+
const check = (): void => {
|
|
416
|
+
if (settled) return;
|
|
417
|
+
if (options.isCurrent()) finish(true);
|
|
418
|
+
else if (!options.refreshing()) finish(false);
|
|
419
|
+
};
|
|
420
|
+
const timer = setTimeout(
|
|
421
|
+
() => finish(options.isCurrent()),
|
|
422
|
+
options.boundMs ?? ROSTER_SETTLE_MS,
|
|
423
|
+
);
|
|
424
|
+
(timer as { unref?: () => void }).unref?.();
|
|
425
|
+
options.signal.addEventListener("abort", abort, { once: true });
|
|
426
|
+
const unsubscribe = options.subscribe(check);
|
|
427
|
+
if (settled) unsubscribe();
|
|
428
|
+
else stop = unsubscribe;
|
|
429
|
+
});
|
|
430
|
+
}
|
|
@@ -5,7 +5,11 @@ import {
|
|
|
5
5
|
type MachineConnectionManager,
|
|
6
6
|
} from "./machine-connection-manager.ts";
|
|
7
7
|
import type { MachineCatalogSnapshot } from "./machine-catalog.ts";
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
createHomeAgentObserver,
|
|
10
|
+
waitForRosterTarget,
|
|
11
|
+
type HomeAgentObserver,
|
|
12
|
+
} from "./home-agent-observer.ts";
|
|
9
13
|
import { createHomeAgentTransport } from "./home-agent-transport.ts";
|
|
10
14
|
import type { HomeAgentRow, HomeAgentSnapshot } from "@tmux-ide/presentation/home-agent-roster";
|
|
11
15
|
|
|
@@ -185,6 +189,26 @@ export function createMachineAgents(options: {
|
|
|
185
189
|
!!entry.observer?.isCurrentTarget(row)
|
|
186
190
|
);
|
|
187
191
|
},
|
|
192
|
+
/** The machine's roster is re-reading a session right now. */
|
|
193
|
+
isRefreshing(machineId: string): boolean {
|
|
194
|
+
const observed = entries.get(machineId)?.observer?.getSnapshot();
|
|
195
|
+
return (
|
|
196
|
+
!!observed && (observed.refreshingSessionKeys.length > 0 || observed.loadingSessions > 0)
|
|
197
|
+
);
|
|
198
|
+
},
|
|
199
|
+
/**
|
|
200
|
+
* `isCurrentTarget` once the machine's roster has finished re-reading:
|
|
201
|
+
* a row is not current during the read, and a click should wait for it.
|
|
202
|
+
*/
|
|
203
|
+
whenCurrentTarget(machineId: string, row: HomeAgentRow, signal: AbortSignal): Promise<boolean> {
|
|
204
|
+
return waitForRosterTarget({
|
|
205
|
+
isCurrent: () => this.isCurrentTarget(machineId, row),
|
|
206
|
+
refreshing: () => this.isRefreshing(machineId),
|
|
207
|
+
subscribe: (listener) =>
|
|
208
|
+
entries.get(machineId)?.observer?.subscribe(() => listener()) ?? (() => undefined),
|
|
209
|
+
signal,
|
|
210
|
+
});
|
|
211
|
+
},
|
|
188
212
|
retry() {
|
|
189
213
|
for (const entry of entries.values()) entry.observer?.retry();
|
|
190
214
|
},
|