tmux-ide 2.9.21 → 2.9.23
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 +6235 -8473
- package/package.json +3 -3
- package/packages/contracts/src/index.ts +2 -0
- package/packages/contracts/src/pane-reader.ts +121 -0
- package/packages/contracts/src/pane-stream.ts +18 -0
- package/packages/contracts/src/visual-theme-presets.ts +58 -2
- package/packages/contracts/src/websocket-heartbeat.ts +41 -0
- package/packages/daemon/dist/command-center/automation.js +1 -1
- package/packages/daemon/dist/command-center/daemon-fleet-facts-observer.js +37 -5
- package/packages/daemon/dist/command-center/discovery.js +28 -2
- package/packages/daemon/dist/command-center/server.js +8 -2
- package/packages/daemon/dist/command-center/tmux-server-reader.js +41 -0
- package/packages/daemon/dist/command-center/tmux-servers.js +7 -1
- package/packages/daemon/dist/doctor.js +147 -43
- package/packages/daemon/dist/lib/bounded-tmux-read.js +34 -12
- package/packages/daemon/dist/lib/cli-command.js +13 -0
- package/packages/daemon/dist/lib/daemon-embed.js +126 -55
- package/packages/daemon/dist/lib/daemon-stop-progress.js +58 -0
- package/packages/daemon/dist/lib/embedded-daemon-lifecycle.js +11 -0
- package/packages/daemon/dist/lib/embedded-tmux-server-owners.js +88 -12
- package/packages/daemon/dist/lib/headless-daemon.js +177 -10
- package/packages/daemon/dist/lib/log.js +18 -1
- package/packages/daemon/dist/lib/pane-reader-files.js +226 -0
- package/packages/daemon/dist/lib/remote-tmux-command.js +8 -5
- package/packages/daemon/dist/lib/tmux-client-execution.js +73 -7
- package/packages/daemon/dist/lib/tmux-external-interaction-observer.js +140 -19
- package/packages/daemon/dist/lib/tmux-native-browser.js +4 -2
- package/packages/daemon/dist/lib/tmux-pane-reader.js +107 -0
- package/packages/daemon/dist/lib/tmux-server-agent-admission.js +6 -1
- package/packages/daemon/dist/lib/tmux-server-features.js +38 -0
- package/packages/daemon/dist/lib/tmux-server-owner-teardown.js +33 -0
- package/packages/daemon/dist/lib/tmux-server-owner.js +38 -37
- package/packages/daemon/dist/lib/tmux-server-owners.js +310 -20
- package/packages/daemon/dist/lib/tmux-server-registration.js +128 -9
- package/packages/daemon/dist/lib/unix-socket-authority.js +58 -3
- package/packages/daemon/dist/lib/workspace-pane-creation.js +10 -1
- package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/Info.plist +2 -2
- package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/MacOS/tmux-ide-notifier +0 -0
- package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/Resources/Assets.car +0 -0
- package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/_CodeSignature/CodeResources +2 -2
- package/packages/daemon/dist/open-browser.js +26 -12
- package/packages/daemon/dist/open-reader.js +84 -0
- package/packages/daemon/dist/plugins/cli.js +1 -2
- package/packages/daemon/dist/plugins/daemon-plugins.js +2 -10
- package/packages/daemon/dist/restore.js +57 -40
- package/packages/daemon/dist/server/pane-stream-upgrade.js +5 -1
- package/packages/daemon/dist/server/websocket-heartbeat.js +103 -0
- package/packages/daemon/dist/terminal/attachments/native-runtime.js +32 -14
- package/packages/daemon/dist/terminal/mirror/layout-content-rows.js +11 -0
- package/packages/daemon/dist/terminal/mirror/mirror-service.js +61 -3
- package/packages/daemon/dist/terminal/mirror/session-channel.js +13 -12
- package/packages/daemon/dist/terminal/pane-stream/pane-stream-websocket.js +123 -25
- package/packages/daemon/dist/terminal/pane-stream/runtime.js +3 -2
- package/packages/daemon/dist/terminal/protocol/reader-option.js +66 -0
- package/packages/daemon/dist/terminal/protocol/session-descriptor-discovery.js +30 -2
- package/packages/daemon/dist/terminal/protocol/stock-split-resize.js +4 -1
- package/packages/daemon/dist/terminal/session-runtime/registry.js +17 -0
- package/packages/daemon/dist/terminal/session-runtime/terminal-replica-interpreter.js +81 -3
- package/packages/daemon/dist/terminal/session-runtime/terminal-replica-owner.js +60 -3
- package/packages/daemon/dist/tmux-upgrade/cli.js +106 -0
- package/packages/daemon/dist/tmux-upgrade/io.js +540 -0
- package/packages/daemon/dist/tmux-upgrade/plan.js +238 -0
- package/packages/daemon/dist/tmux-upgrade/run.js +199 -0
- package/packages/daemon/dist/tui/chrome/snapshot.js +3 -4
- package/packages/daemon/dist/tui/mirror/runtime/application-home-agent-navigation.js +64 -4
- package/packages/daemon/dist/tui/mirror/runtime/application-home-agents-owner.js +35 -5
- package/packages/daemon/dist/tui/mirror/runtime/application-machine-agent-navigation.js +12 -8
- package/packages/daemon/dist/tui/mirror/runtime/application-terminal-interaction-controller.js +125 -111
- package/packages/daemon/src/command-center/automation.ts +1 -1
- package/packages/daemon/src/command-center/daemon-fleet-facts-observer.ts +49 -8
- package/packages/daemon/src/command-center/discovery.ts +35 -2
- package/packages/daemon/src/command-center/server.ts +22 -8
- package/packages/daemon/src/command-center/tmux-server-reader.ts +62 -0
- package/packages/daemon/src/command-center/tmux-servers.ts +7 -1
- package/packages/daemon/src/doctor.ts +164 -45
- package/packages/daemon/src/lib/bounded-tmux-read.ts +29 -9
- package/packages/daemon/src/lib/cli-command.ts +16 -0
- package/packages/daemon/src/lib/daemon-embed.ts +176 -64
- package/packages/daemon/src/lib/daemon-stop-progress.ts +78 -0
- package/packages/daemon/src/lib/embedded-daemon-lifecycle.ts +12 -0
- package/packages/daemon/src/lib/embedded-tmux-server-owners.ts +115 -11
- package/packages/daemon/src/lib/headless-daemon.ts +205 -12
- package/packages/daemon/src/lib/log.ts +18 -1
- package/packages/daemon/src/lib/pane-reader-files.ts +294 -0
- package/packages/daemon/src/lib/remote-tmux-command.ts +13 -6
- package/packages/daemon/src/lib/tmux-client-execution.ts +79 -7
- package/packages/daemon/src/lib/tmux-external-interaction-observer.ts +163 -25
- package/packages/daemon/src/lib/tmux-native-browser.ts +4 -3
- package/packages/daemon/src/lib/tmux-pane-reader.ts +145 -0
- package/packages/daemon/src/lib/tmux-server-agent-admission.ts +6 -1
- package/packages/daemon/src/lib/tmux-server-features.ts +43 -0
- package/packages/daemon/src/lib/tmux-server-owner-teardown.ts +54 -0
- package/packages/daemon/src/lib/tmux-server-owner.ts +41 -35
- package/packages/daemon/src/lib/tmux-server-owners.ts +427 -22
- package/packages/daemon/src/lib/tmux-server-registration.ts +155 -7
- package/packages/daemon/src/lib/unix-socket-authority.ts +72 -3
- package/packages/daemon/src/lib/workspace-pane-creation.ts +11 -1
- package/packages/daemon/src/open-browser.ts +59 -18
- package/packages/daemon/src/open-reader.ts +148 -0
- package/packages/daemon/src/plugins/cli.ts +1 -2
- package/packages/daemon/src/plugins/daemon-plugins.ts +2 -12
- package/packages/daemon/src/restore.ts +80 -44
- package/packages/daemon/src/server/pane-stream-upgrade.ts +6 -0
- package/packages/daemon/src/server/websocket-heartbeat.ts +135 -0
- package/packages/daemon/src/terminal/attachments/native-runtime.ts +58 -14
- package/packages/daemon/src/terminal/mirror/events.ts +2 -0
- package/packages/daemon/src/terminal/mirror/layout-content-rows.ts +11 -0
- package/packages/daemon/src/terminal/mirror/mirror-service.ts +61 -2
- package/packages/daemon/src/terminal/mirror/session-channel.ts +15 -14
- package/packages/daemon/src/terminal/pane-stream/pane-stream-websocket.ts +140 -23
- package/packages/daemon/src/terminal/pane-stream/runtime.ts +4 -2
- package/packages/daemon/src/terminal/protocol/reader-option.ts +77 -0
- package/packages/daemon/src/terminal/protocol/session-descriptor-discovery.ts +41 -1
- package/packages/daemon/src/terminal/protocol/stock-split-resize.ts +6 -1
- package/packages/daemon/src/terminal/session-runtime/registry.ts +23 -0
- package/packages/daemon/src/terminal/session-runtime/runtime-observability.ts +2 -0
- package/packages/daemon/src/terminal/session-runtime/terminal-replica-interpreter.ts +100 -3
- package/packages/daemon/src/terminal/session-runtime/terminal-replica-owner.ts +60 -3
- package/packages/daemon/src/tmux-upgrade/cli.ts +118 -0
- package/packages/daemon/src/tmux-upgrade/io.ts +596 -0
- package/packages/daemon/src/tmux-upgrade/plan.ts +353 -0
- package/packages/daemon/src/tmux-upgrade/run.ts +325 -0
- package/packages/daemon/src/tui/chrome/snapshot.ts +3 -4
- package/packages/daemon/src/tui/mirror/runtime/application-home-agent-navigation.ts +110 -10
- package/packages/daemon/src/tui/mirror/runtime/application-home-agents-owner.ts +58 -6
- package/packages/daemon/src/tui/mirror/runtime/application-machine-agent-navigation.ts +20 -9
- package/packages/daemon/src/tui/mirror/runtime/application-root-v2.tsx +2 -2
- package/packages/daemon/src/tui/mirror/runtime/application-terminal-interaction-controller.ts +149 -128
- package/packages/daemon-client/src/direct-application-shell-transport.ts +21 -3
- package/packages/daemon-client/src/workspace-event-supervisor.ts +63 -2
- package/packages/tmux-bridge/src/runner.ts +3 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createPaneReaderResolver } from "./tmux-pane-reader.ts";
|
|
1
2
|
import { createNativeBrowserResolver } from "./tmux-native-browser.ts";
|
|
2
3
|
import { createNativeSurfaceContextResolver } from "./native-surface-context.ts";
|
|
3
4
|
import { NativeSurfaceProviderRegistry } from "../terminal/graphics/native-surface-provider.ts";
|
|
@@ -36,6 +37,12 @@ import {
|
|
|
36
37
|
} from "./tmux-server-generation-runner.ts";
|
|
37
38
|
import { createNativeTmuxServerCatalog } from "./tmux-server-owner.ts";
|
|
38
39
|
import { createEmbeddedTmuxServerOwners } from "./embedded-tmux-server-owners.ts";
|
|
40
|
+
import type { TmuxServerOwnerRetirement } from "./tmux-server-owners.ts";
|
|
41
|
+
import {
|
|
42
|
+
PANE_STREAM_DAEMON_RESTARTING_CLOSE,
|
|
43
|
+
paneStreamCloseForRetirement,
|
|
44
|
+
type PaneStreamShutdownClose,
|
|
45
|
+
} from "../terminal/pane-stream/pane-stream-websocket.ts";
|
|
39
46
|
import {
|
|
40
47
|
captureTmuxServerProofAsync,
|
|
41
48
|
captureTmuxServerProof,
|
|
@@ -93,6 +100,7 @@ import { handlePtyWebSocket, shutdownPtyBridges } from "../server/ws-route.ts";
|
|
|
93
100
|
import {
|
|
94
101
|
broadcastInteractionReceipt,
|
|
95
102
|
broadcastResourceChanged,
|
|
103
|
+
broadcastTerminalsChanged,
|
|
96
104
|
handleWsEventsConnection,
|
|
97
105
|
setFleetFactsObserverDiagnostics,
|
|
98
106
|
setFleetFactsTmuxRunner,
|
|
@@ -119,7 +127,7 @@ import {
|
|
|
119
127
|
WorkspacePaneCreationAuthority,
|
|
120
128
|
} from "./workspace-pane-creation.ts";
|
|
121
129
|
import {
|
|
122
|
-
|
|
130
|
+
readLiveSessionSummaries,
|
|
123
131
|
readAdoptedFleet,
|
|
124
132
|
type FleetSessionFacts,
|
|
125
133
|
} from "../command-center/discovery.ts";
|
|
@@ -153,6 +161,7 @@ import {
|
|
|
153
161
|
attachPaneStreamWebSocket,
|
|
154
162
|
type PaneStreamWebSocketBoundary,
|
|
155
163
|
} from "../server/pane-stream-upgrade.ts";
|
|
164
|
+
import { daemonWebSocketHeartbeat } from "../server/websocket-heartbeat.ts";
|
|
156
165
|
import {
|
|
157
166
|
createPaneStreamRuntime,
|
|
158
167
|
type PaneStreamRuntime,
|
|
@@ -167,7 +176,9 @@ import {
|
|
|
167
176
|
import { setActivationBackend, type ProjectActivationOptions } from "./active-projects.ts";
|
|
168
177
|
import { readOrMintEnvironmentId } from "./environment-identity.ts";
|
|
169
178
|
import { captureDaemonProvenance } from "./daemon-provenance.ts";
|
|
170
|
-
import { registerLogSecret, setLogIdentity } from "./log.ts";
|
|
179
|
+
import { logger, registerLogSecret, setLogIdentity } from "./log.ts";
|
|
180
|
+
import { createStopProgress, type DaemonStopProgress } from "./daemon-stop-progress.ts";
|
|
181
|
+
export type { DaemonStopProgress } from "./daemon-stop-progress.ts";
|
|
171
182
|
import { createDaemonPluginSupervisor, pluginsEnabled } from "../plugins/daemon-plugins.ts";
|
|
172
183
|
import type { PluginSupervisor } from "../plugins/supervisor.ts";
|
|
173
184
|
import {
|
|
@@ -275,7 +286,15 @@ export interface EmbeddedDaemonHandle {
|
|
|
275
286
|
projectName: string,
|
|
276
287
|
options?: ProjectActivationOptions,
|
|
277
288
|
): Promise<{ stop: () => Promise<void> }>;
|
|
278
|
-
|
|
289
|
+
/** `restarting`: a new generation follows in this process; streams are told to reconnect. */
|
|
290
|
+
stop(opts?: { gracefulMs?: number; restarting?: boolean }): Promise<void>;
|
|
291
|
+
/** Where a stop is right now; lets a deadline say what was still open (#839). */
|
|
292
|
+
stopDiagnostics?(): DaemonStopProgress;
|
|
293
|
+
/**
|
|
294
|
+
* Last resort for a stop that will not finish: synchronously withdraw
|
|
295
|
+
* daemon.json and the startup claim so the forced exit leaves no stale owner.
|
|
296
|
+
*/
|
|
297
|
+
abandon?(): void;
|
|
279
298
|
}
|
|
280
299
|
|
|
281
300
|
function tmux(...args: string[]): string {
|
|
@@ -458,6 +477,8 @@ function attachWebSockets(
|
|
|
458
477
|
closeServers: () => Promise<void>;
|
|
459
478
|
} {
|
|
460
479
|
const eventsWss = new WebSocketServer({ noServer: true });
|
|
480
|
+
const heartbeat = daemonWebSocketHeartbeat();
|
|
481
|
+
eventsWss.on("headers", (headers) => heartbeat.advertise(headers));
|
|
461
482
|
const ptyWss = new WebSocketServer({ noServer: true });
|
|
462
483
|
const clients = new Set<WebSocket>();
|
|
463
484
|
|
|
@@ -484,6 +505,7 @@ function attachWebSockets(
|
|
|
484
505
|
if (pathname === "/ws/events") {
|
|
485
506
|
eventsWss.handleUpgrade(req, socket, head, (ws) => {
|
|
486
507
|
track(ws);
|
|
508
|
+
heartbeat.watch(ws, "ws-events");
|
|
487
509
|
const requestUrl = new URL(req.url ?? "/ws/events", "http://daemon.local");
|
|
488
510
|
handleWsEventsConnection(ws, opts.daemonIdentity, {
|
|
489
511
|
mode: requestUrl.searchParams.get("mode") === "semantic" ? "semantic" : "legacy",
|
|
@@ -873,11 +895,13 @@ async function startHttpServer({
|
|
|
873
895
|
getTerminalAttachmentRuntime: () => NativeTerminalAttachmentRuntime;
|
|
874
896
|
peekTerminalAttachmentRuntime: () => NativeTerminalAttachmentRuntime | null;
|
|
875
897
|
paneStreamRuntime: PaneStreamRuntime;
|
|
876
|
-
catalogLiveSessions: () =>
|
|
877
|
-
readonly
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
898
|
+
catalogLiveSessions: () =>
|
|
899
|
+
| readonly {
|
|
900
|
+
readonly liveSessionId: `live-session.${string}`;
|
|
901
|
+
readonly sessionName: string;
|
|
902
|
+
readonly paneCount: number;
|
|
903
|
+
}[]
|
|
904
|
+
| null;
|
|
881
905
|
catalogFleet: () =>
|
|
882
906
|
| ReturnType<typeof readAdoptedFleet>
|
|
883
907
|
| Promise<ReturnType<typeof readAdoptedFleet>>;
|
|
@@ -1439,6 +1463,8 @@ async function startEmbeddedDaemonGeneration(
|
|
|
1439
1463
|
};
|
|
1440
1464
|
let terminalAttachmentRuntime: NativeTerminalAttachmentRuntime | null = null;
|
|
1441
1465
|
let paneStreamRuntime: PaneStreamRuntime | null = null;
|
|
1466
|
+
// Declared before the owners so their teardown steps can report into it.
|
|
1467
|
+
const stopProgress = createStopProgress();
|
|
1442
1468
|
let localImages: LocalImageOwner | undefined;
|
|
1443
1469
|
let serverOwners: Awaited<ReturnType<typeof createEmbeddedTmuxServerOwners>> | null = null;
|
|
1444
1470
|
let defaultEditorContextRetired = false;
|
|
@@ -1554,6 +1580,9 @@ async function startEmbeddedDaemonGeneration(
|
|
|
1554
1580
|
{ processId: `daemon:${process.pid}`, daemonInstanceId: instanceId },
|
|
1555
1581
|
)
|
|
1556
1582
|
: null;
|
|
1583
|
+
let windowOwnershipDiagnostic:
|
|
1584
|
+
| ((phase: string, details?: Record<string, unknown>) => void)
|
|
1585
|
+
| undefined;
|
|
1557
1586
|
const runtimeObservability = runtimeTracePath
|
|
1558
1587
|
? createSessionRuntimeObservability({
|
|
1559
1588
|
// The JSONL stream is the qualifying record. Keep only a small
|
|
@@ -1586,11 +1615,20 @@ async function startEmbeddedDaemonGeneration(
|
|
|
1586
1615
|
};
|
|
1587
1616
|
externalInteractionObserver.setDiagnostics(diagnostics);
|
|
1588
1617
|
setFleetFactsObserverDiagnostics(diagnostics);
|
|
1618
|
+
windowOwnershipDiagnostic = (phase, details = {}) =>
|
|
1619
|
+
publishObserverDiagnostic({
|
|
1620
|
+
operation: "window-ownership",
|
|
1621
|
+
phase,
|
|
1622
|
+
atMicros: Math.floor(performance.now() * 1_000),
|
|
1623
|
+
...details,
|
|
1624
|
+
});
|
|
1589
1625
|
}
|
|
1590
1626
|
const nativeSurfaces =
|
|
1591
1627
|
process.platform === "darwin" ? new NativeSurfaceProviderRegistry(instanceId) : undefined;
|
|
1592
1628
|
sessionRuntimeRegistry = new SessionRuntimeRegistry({
|
|
1593
1629
|
generation: instanceId,
|
|
1630
|
+
// An idle client that met the 503 re-reads when the inventory is trusted again.
|
|
1631
|
+
onInventoryRecovered: (session) => broadcastTerminalsChanged(session),
|
|
1594
1632
|
...(runtimeObservability ? { observability: runtimeObservability } : {}),
|
|
1595
1633
|
semanticMutations: {
|
|
1596
1634
|
captureInteractionContext: (intent) => {
|
|
@@ -1624,6 +1662,10 @@ async function startEmbeddedDaemonGeneration(
|
|
|
1624
1662
|
publishResourceChange: (change) => broadcastResourceChanged(change, instanceId),
|
|
1625
1663
|
},
|
|
1626
1664
|
mirror: {
|
|
1665
|
+
// #764 diagnostics (draft only): the window-ownership guard.
|
|
1666
|
+
...(windowOwnershipDiagnostic
|
|
1667
|
+
? { onWindowOwnershipDiagnostic: windowOwnershipDiagnostic }
|
|
1668
|
+
: {}),
|
|
1627
1669
|
onNativeClientPresence: (session, present) =>
|
|
1628
1670
|
nativeSurfaces?.demand.presence(session, present),
|
|
1629
1671
|
splitLayoutEpoch: () => observationSelector?.nativeServerEpoch ?? null,
|
|
@@ -1857,6 +1899,16 @@ async function startEmbeddedDaemonGeneration(
|
|
|
1857
1899
|
});
|
|
1858
1900
|
await externalInteractionObserver.start();
|
|
1859
1901
|
serverOwners = await createEmbeddedTmuxServerOwners({
|
|
1902
|
+
trackTeardown: stopProgress.track,
|
|
1903
|
+
// The background sweep, not a client's request, now notices a server
|
|
1904
|
+
// that came back or was replaced; subscribed clients must hear of it.
|
|
1905
|
+
onServersChanged: () => {
|
|
1906
|
+
broadcastResourceChanged({ workspaceName: null, resource: "fleet-catalog" }, instanceId);
|
|
1907
|
+
broadcastResourceChanged(
|
|
1908
|
+
{ workspaceName: null, resource: "workspace-catalog" },
|
|
1909
|
+
instanceId,
|
|
1910
|
+
);
|
|
1911
|
+
},
|
|
1860
1912
|
localImages,
|
|
1861
1913
|
environmentId,
|
|
1862
1914
|
onDefaultScope: async (scope) => {
|
|
@@ -1996,6 +2048,22 @@ async function startEmbeddedDaemonGeneration(
|
|
|
1996
2048
|
throw new Error("Default native browser owner is unavailable");
|
|
1997
2049
|
},
|
|
1998
2050
|
}),
|
|
2051
|
+
paneReader: createPaneReaderResolver({
|
|
2052
|
+
generation: instanceId,
|
|
2053
|
+
run: fleetFactsTmuxRunner,
|
|
2054
|
+
registry: workspaceRegistry,
|
|
2055
|
+
catalog: createNativeTmuxServerCatalog(workspaceRegistry, fleetFactsTmuxRunner),
|
|
2056
|
+
inventory: terminalInventoryRuntime,
|
|
2057
|
+
assertOpen: () => {
|
|
2058
|
+
if (
|
|
2059
|
+
defaultEditorContextRetired ||
|
|
2060
|
+
serverOwners?.defaultRetired ||
|
|
2061
|
+
!initialNativeServerIdentity ||
|
|
2062
|
+
terminalInventoryRuntime?.lifecycleState() !== "ready"
|
|
2063
|
+
)
|
|
2064
|
+
throw new Error("Default reader owner is unavailable");
|
|
2065
|
+
},
|
|
2066
|
+
}),
|
|
1999
2067
|
catalog: createNativeTmuxServerCatalog(workspaceRegistry, fleetFactsTmuxRunner),
|
|
2000
2068
|
readWindowSplitLayout: async (workspaceName, input) => {
|
|
2001
2069
|
const target = WindowLinkTargetSchemaZ.parse(input);
|
|
@@ -2068,33 +2136,38 @@ async function startEmbeddedDaemonGeneration(
|
|
|
2068
2136
|
sessionRuntimeRegistry,
|
|
2069
2137
|
terminalInventoryRuntime,
|
|
2070
2138
|
paneStreamRuntime,
|
|
2071
|
-
dispose: async () => {
|
|
2139
|
+
dispose: async (retirement?: TmuxServerOwnerRetirement) => {
|
|
2072
2140
|
defaultEditorContextRetired = true;
|
|
2073
2141
|
defaultDiagnosticsLifetime.abort();
|
|
2074
2142
|
sessionMonitor?.stop();
|
|
2075
2143
|
paneSourceCredentials.dispose();
|
|
2144
|
+
// Named steps: a hung stop then reports which of these never settled (#839).
|
|
2145
|
+
const step = <T>(name: string, work: () => T | Promise<T>): Promise<T> =>
|
|
2146
|
+
stopProgress.track(`default-owner:${name}`, work);
|
|
2076
2147
|
const transportResults = await Promise.allSettled([
|
|
2077
|
-
|
|
2078
|
-
|
|
2148
|
+
step("terminal-attachments", () => terminalAttachmentRuntime?.dispose()),
|
|
2149
|
+
step("pane-streams", () =>
|
|
2150
|
+
paneStreamRuntime!.dispose(paneStreamCloseForRetirement(retirement)),
|
|
2151
|
+
),
|
|
2079
2152
|
]);
|
|
2080
2153
|
const authorityResults = await Promise.allSettled([
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2154
|
+
step("terminal-inventory", () => terminalInventoryRuntime!.dispose()),
|
|
2155
|
+
step("pane-creation", () => workspacePaneCreation.dispose()),
|
|
2156
|
+
step("workspace-open", () => workspaceOpen.dispose()),
|
|
2157
|
+
step("workspace-open-handoff", () => workspaceOpenHandoff?.dispose()),
|
|
2158
|
+
step("session-backends", () =>
|
|
2086
2159
|
Promise.all([
|
|
2087
2160
|
workspacePromotion.dispose(),
|
|
2088
2161
|
defaultSessionOpener.dispose(),
|
|
2089
2162
|
defaultSessionCreator.dispose(),
|
|
2090
2163
|
]).then(() => {}),
|
|
2091
2164
|
),
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2165
|
+
step("app-window-mutation", () => appWindowMutation.dispose()),
|
|
2166
|
+
step("multiplexer", () => workspaceMultiplexer.dispose()),
|
|
2167
|
+
step("interaction-observation", () => disposeInteractionObservation()),
|
|
2095
2168
|
]);
|
|
2096
2169
|
try {
|
|
2097
|
-
await sessionRuntimeRegistry!.dispose();
|
|
2170
|
+
await step("session-runtimes", () => sessionRuntimeRegistry!.dispose());
|
|
2098
2171
|
} finally {
|
|
2099
2172
|
interactionReceipts.dispose();
|
|
2100
2173
|
interactionEvidence?.dispose();
|
|
@@ -2144,7 +2217,7 @@ async function startEmbeddedDaemonGeneration(
|
|
|
2144
2217
|
getTerminalAttachmentRuntime,
|
|
2145
2218
|
peekTerminalAttachmentRuntime,
|
|
2146
2219
|
paneStreamRuntime,
|
|
2147
|
-
catalogLiveSessions: () =>
|
|
2220
|
+
catalogLiveSessions: () => readLiveSessionSummaries(catalogTmuxRunner),
|
|
2148
2221
|
catalogFleet: async () => {
|
|
2149
2222
|
const endpoint = (sessionName: string, pane: FleetSessionFacts["panes"][number]) =>
|
|
2150
2223
|
pane.semanticPaneId
|
|
@@ -2232,9 +2305,11 @@ async function startEmbeddedDaemonGeneration(
|
|
|
2232
2305
|
terminalAttachmentBoundary,
|
|
2233
2306
|
paneStreamBoundary,
|
|
2234
2307
|
} = startedServer;
|
|
2235
|
-
const retirePaneStreamTransport = async (
|
|
2308
|
+
const retirePaneStreamTransport = async (
|
|
2309
|
+
close?: PaneStreamShutdownClose,
|
|
2310
|
+
): Promise<readonly unknown[]> => {
|
|
2236
2311
|
const transportResults = await Promise.allSettled([
|
|
2237
|
-
Promise.resolve().then(() => paneStreamRuntime!.dispose()),
|
|
2312
|
+
Promise.resolve().then(() => paneStreamRuntime!.dispose(close)),
|
|
2238
2313
|
Promise.resolve().then(() => paneStreamBoundary.close()),
|
|
2239
2314
|
]);
|
|
2240
2315
|
const runtimeResults = await Promise.allSettled([
|
|
@@ -2358,6 +2433,14 @@ async function startEmbeddedDaemonGeneration(
|
|
|
2358
2433
|
|
|
2359
2434
|
let stopped = false;
|
|
2360
2435
|
let stopping: Promise<void> | null = null;
|
|
2436
|
+
// Idempotent: the normal stop and a deadline-forced exit may both reach it.
|
|
2437
|
+
const releaseCanonicalPublication = (): void => {
|
|
2438
|
+
try {
|
|
2439
|
+
clearCanonicalDaemonInfoIfOwned(instanceId, claim);
|
|
2440
|
+
} finally {
|
|
2441
|
+
releaseCanonicalDaemonClaim(claim);
|
|
2442
|
+
}
|
|
2443
|
+
};
|
|
2361
2444
|
let stopSelf: (() => void) | null = null;
|
|
2362
2445
|
const activeProjectStops = new Map<string, { stop: () => void }>();
|
|
2363
2446
|
|
|
@@ -2501,50 +2584,68 @@ async function startEmbeddedDaemonGeneration(
|
|
|
2501
2584
|
wsUrl,
|
|
2502
2585
|
localBypassToken,
|
|
2503
2586
|
compatibilityTerminalAttachmentRuntimeConstructed: () => terminalAttachmentRuntime !== null,
|
|
2504
|
-
|
|
2587
|
+
stopDiagnostics: () => stopProgress.snapshot(),
|
|
2588
|
+
abandon: () => releaseCanonicalPublication(),
|
|
2589
|
+
stop: async ({ gracefulMs = DEFAULT_GRACEFUL_MS, restarting = false } = {}) => {
|
|
2505
2590
|
if (stopping) return stopping;
|
|
2506
2591
|
if (stopped) return;
|
|
2507
2592
|
stopping = (async () => {
|
|
2508
2593
|
const failures: unknown[] = [];
|
|
2509
|
-
const capture = async (
|
|
2594
|
+
const capture = async (
|
|
2595
|
+
stage: string,
|
|
2596
|
+
operation: () => void | Promise<void>,
|
|
2597
|
+
): Promise<void> => {
|
|
2510
2598
|
try {
|
|
2511
|
-
await operation
|
|
2599
|
+
await stopProgress.run(stage, operation);
|
|
2512
2600
|
} catch (error) {
|
|
2513
2601
|
failures.push(error);
|
|
2514
2602
|
}
|
|
2515
2603
|
};
|
|
2516
2604
|
try {
|
|
2517
2605
|
stopped = true;
|
|
2518
|
-
|
|
2519
|
-
await capture(() =>
|
|
2520
|
-
await capture(() =>
|
|
2606
|
+
stopProgress.begin();
|
|
2607
|
+
await capture("plugins", () => pluginSupervisor?.stop());
|
|
2608
|
+
await capture("activation-backend", () => setActivationBackend(null));
|
|
2609
|
+
await capture("session-monitor", () => sessionMonitor?.stop());
|
|
2521
2610
|
paneSourceCredentials.dispose();
|
|
2522
|
-
|
|
2611
|
+
// A generation restarting in place tells its streams to reconnect
|
|
2612
|
+
// now; only a real shutdown says "daemon-shutdown" (#840).
|
|
2613
|
+
await capture("tmux-server-owners", () =>
|
|
2614
|
+
serverOwners?.dispose(restarting ? "generation-restart" : "shutdown"),
|
|
2615
|
+
);
|
|
2523
2616
|
|
|
2524
2617
|
// Retire direct-ticket admission, live PTYs, and the direct upgrade
|
|
2525
2618
|
// listener before touching the legacy WS or HTTP surfaces.
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
await capture(() =>
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2619
|
+
await capture("terminal-attachments", async () => {
|
|
2620
|
+
failures.push(
|
|
2621
|
+
...(await retireTerminalAttachmentTransport(
|
|
2622
|
+
terminalAttachmentRuntime,
|
|
2623
|
+
terminalAttachmentBoundary,
|
|
2624
|
+
)),
|
|
2625
|
+
);
|
|
2626
|
+
});
|
|
2627
|
+
await capture("pane-streams", async () => {
|
|
2628
|
+
failures.push(
|
|
2629
|
+
...(await retirePaneStreamTransport(
|
|
2630
|
+
restarting ? PANE_STREAM_DAEMON_RESTARTING_CLOSE : undefined,
|
|
2631
|
+
)),
|
|
2632
|
+
);
|
|
2633
|
+
});
|
|
2634
|
+
await capture("local-images", () => localImages?.dispose());
|
|
2635
|
+
await capture("terminal-inventory", () => terminalInventoryRuntime.dispose());
|
|
2636
|
+
await capture("pane-creation", () => workspacePaneCreation.dispose());
|
|
2637
|
+
await capture("workspace-open", () => workspaceOpen.dispose());
|
|
2638
|
+
await capture("workspace-open-handoff", () => workspaceOpenHandoff?.dispose());
|
|
2639
|
+
await capture("session-backends", () =>
|
|
2539
2640
|
Promise.all([
|
|
2540
2641
|
workspacePromotion.dispose(),
|
|
2541
2642
|
defaultSessionOpener.dispose(),
|
|
2542
2643
|
defaultSessionCreator.dispose(),
|
|
2543
2644
|
]).then(() => {}),
|
|
2544
2645
|
);
|
|
2545
|
-
await capture(() => appWindowMutation.dispose());
|
|
2546
|
-
await capture(() => workspaceMultiplexer.dispose());
|
|
2547
|
-
await capture(() => disposeInteractionObservation());
|
|
2646
|
+
await capture("app-window-mutation", () => appWindowMutation.dispose());
|
|
2647
|
+
await capture("workspace-multiplexer", () => workspaceMultiplexer.dispose());
|
|
2648
|
+
await capture("interaction-observation", () => disposeInteractionObservation());
|
|
2548
2649
|
|
|
2549
2650
|
let closePromise: Promise<void>;
|
|
2550
2651
|
try {
|
|
@@ -2553,26 +2654,28 @@ async function startEmbeddedDaemonGeneration(
|
|
|
2553
2654
|
failures.push(error);
|
|
2554
2655
|
closePromise = Promise.resolve();
|
|
2555
2656
|
}
|
|
2556
|
-
await capture(() => closeClients());
|
|
2657
|
+
await capture("http-clients", () => closeClients());
|
|
2557
2658
|
for (const stop of activeProjectStops.values()) {
|
|
2558
|
-
await capture(() => stop.stop());
|
|
2659
|
+
await capture("active-projects", () => stop.stop());
|
|
2559
2660
|
}
|
|
2560
2661
|
activeProjectStops.clear();
|
|
2561
|
-
await capture(() => shutdownPtyBridges());
|
|
2562
|
-
await capture(() =>
|
|
2662
|
+
await capture("pty-bridges", () => shutdownPtyBridges());
|
|
2663
|
+
await capture("http-close-grace", () =>
|
|
2664
|
+
Promise.race([closePromise, delay(gracefulMs)]),
|
|
2665
|
+
);
|
|
2563
2666
|
for (const socket of sockets) {
|
|
2564
|
-
await capture(() => {
|
|
2667
|
+
await capture("http-sockets", () => {
|
|
2565
2668
|
socket.destroy();
|
|
2566
2669
|
});
|
|
2567
2670
|
}
|
|
2568
|
-
await capture(() => Promise.race([closePromise, delay(100)]));
|
|
2569
|
-
await capture(() => closeWsServers());
|
|
2570
|
-
await capture(() => shutdownWsEventObservation());
|
|
2571
|
-
await capture(() => setFleetFactsTmuxRunner(null));
|
|
2572
|
-
await capture(() => closeRuntimeTraceStream());
|
|
2573
|
-
await capture(() => setRemoteAccessRestartBackend(null));
|
|
2574
|
-
await capture(() => setDaemonShutdownBackend(null));
|
|
2575
|
-
await capture(() => setDaemonRestartBackend(null));
|
|
2671
|
+
await capture("http-close-final", () => Promise.race([closePromise, delay(100)]));
|
|
2672
|
+
await capture("ws-servers", () => closeWsServers());
|
|
2673
|
+
await capture("ws-event-observation", () => shutdownWsEventObservation());
|
|
2674
|
+
await capture("fleet-facts-runner", () => setFleetFactsTmuxRunner(null));
|
|
2675
|
+
await capture("runtime-trace", () => closeRuntimeTraceStream());
|
|
2676
|
+
await capture("remote-access-backend", () => setRemoteAccessRestartBackend(null));
|
|
2677
|
+
await capture("shutdown-backend", () => setDaemonShutdownBackend(null));
|
|
2678
|
+
await capture("restart-backend", () => setDaemonRestartBackend(null));
|
|
2576
2679
|
|
|
2577
2680
|
if (failures.length > 0) {
|
|
2578
2681
|
const cause =
|
|
@@ -2582,11 +2685,20 @@ async function startEmbeddedDaemonGeneration(
|
|
|
2582
2685
|
throw new DaemonShutdownError("Daemon shutdown failed", { cause: cause as Error });
|
|
2583
2686
|
}
|
|
2584
2687
|
} finally {
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2688
|
+
const progress = stopProgress.finish();
|
|
2689
|
+
// A quick clean stop is routine (debug); a restart, a slow stop or a
|
|
2690
|
+
// failing one is what the next investigation needs (info).
|
|
2691
|
+
const notable = restarting || failures.length > 0 || progress.elapsedMs >= 1_000;
|
|
2692
|
+
logger[notable ? "info" : "debug"]("daemon-lifecycle", "generation stopped", {
|
|
2693
|
+
generationInstanceId: instanceId,
|
|
2694
|
+
port,
|
|
2695
|
+
stopMs: progress.elapsedMs,
|
|
2696
|
+
failures: failures.length,
|
|
2697
|
+
slowestStages: [...progress.completed]
|
|
2698
|
+
.sort((left, right) => right.ms - left.ms)
|
|
2699
|
+
.slice(0, 5),
|
|
2700
|
+
});
|
|
2701
|
+
releaseCanonicalPublication();
|
|
2590
2702
|
}
|
|
2591
2703
|
})();
|
|
2592
2704
|
return stopping;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
export interface DaemonStopProgress {
|
|
2
|
+
readonly started: boolean;
|
|
3
|
+
readonly finished: boolean;
|
|
4
|
+
readonly elapsedMs: number;
|
|
5
|
+
/** The teardown stage in flight, or null when none is. */
|
|
6
|
+
readonly stage: string | null;
|
|
7
|
+
readonly stageMs: number;
|
|
8
|
+
readonly completed: readonly { readonly stage: string; readonly ms: number }[];
|
|
9
|
+
/** Steps inside the stage that have started and not settled, with their age. */
|
|
10
|
+
readonly openSteps: readonly { readonly step: string; readonly ms: number }[];
|
|
11
|
+
/** Steps settled so far; with `completed` it shows whether a slow stop still moves. */
|
|
12
|
+
readonly stepsSettled: number;
|
|
13
|
+
}
|
|
14
|
+
/** Wraps one named step of a teardown; steps may run in parallel. */
|
|
15
|
+
export type TrackTeardownStep = <T>(step: string, work: () => T | Promise<T>) => Promise<T>;
|
|
16
|
+
|
|
17
|
+
/** Records which teardown stage a stop is in and how long each one took. */
|
|
18
|
+
export function createStopProgress(now: () => number = () => performance.now()): {
|
|
19
|
+
begin(): void;
|
|
20
|
+
run(stage: string, operation: () => void | Promise<void>): Promise<void>;
|
|
21
|
+
track: TrackTeardownStep;
|
|
22
|
+
finish(): DaemonStopProgress;
|
|
23
|
+
snapshot(): DaemonStopProgress;
|
|
24
|
+
} {
|
|
25
|
+
const open = new Map<symbol, { step: string; startedAt: number }>();
|
|
26
|
+
let stepsSettled = 0;
|
|
27
|
+
let startedAt: number | null = null;
|
|
28
|
+
let finishedAt: number | null = null;
|
|
29
|
+
let stage: string | null = null;
|
|
30
|
+
let stageStartedAt = 0;
|
|
31
|
+
const completed: { stage: string; ms: number }[] = [];
|
|
32
|
+
const snapshot = (): DaemonStopProgress => {
|
|
33
|
+
const at = finishedAt ?? now();
|
|
34
|
+
return {
|
|
35
|
+
started: startedAt !== null,
|
|
36
|
+
finished: finishedAt !== null,
|
|
37
|
+
elapsedMs: startedAt === null ? 0 : Math.round(at - startedAt),
|
|
38
|
+
stage,
|
|
39
|
+
stageMs: stage === null ? 0 : Math.round(at - stageStartedAt),
|
|
40
|
+
completed: completed.map((entry) => ({ ...entry })),
|
|
41
|
+
openSteps: [...open.values()].map((entry) => ({
|
|
42
|
+
step: entry.step,
|
|
43
|
+
ms: Math.round(at - entry.startedAt),
|
|
44
|
+
})),
|
|
45
|
+
stepsSettled,
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
return {
|
|
49
|
+
begin() {
|
|
50
|
+
startedAt ??= now();
|
|
51
|
+
},
|
|
52
|
+
async run(name, operation) {
|
|
53
|
+
stage = name;
|
|
54
|
+
stageStartedAt = now();
|
|
55
|
+
try {
|
|
56
|
+
await operation();
|
|
57
|
+
} finally {
|
|
58
|
+
completed.push({ stage: name, ms: Math.round(now() - stageStartedAt) });
|
|
59
|
+
stage = null;
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
async track(step, work) {
|
|
63
|
+
const key = Symbol(step);
|
|
64
|
+
open.set(key, { step, startedAt: now() });
|
|
65
|
+
try {
|
|
66
|
+
return await work();
|
|
67
|
+
} finally {
|
|
68
|
+
open.delete(key);
|
|
69
|
+
stepsSettled += 1;
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
finish() {
|
|
73
|
+
finishedAt ??= now();
|
|
74
|
+
return snapshot();
|
|
75
|
+
},
|
|
76
|
+
snapshot,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
@@ -86,6 +86,18 @@ export async function startOwnedEmbeddedDaemon(
|
|
|
86
86
|
tmuxAuthorityReplaced: () => current.tmuxAuthorityReplaced?.() ?? Promise.resolve(false),
|
|
87
87
|
compatibilityTerminalAttachmentRuntimeConstructed: () =>
|
|
88
88
|
current.compatibilityTerminalAttachmentRuntimeConstructed(),
|
|
89
|
+
stopDiagnostics: () =>
|
|
90
|
+
current.stopDiagnostics?.() ?? {
|
|
91
|
+
started: false,
|
|
92
|
+
finished: false,
|
|
93
|
+
elapsedMs: 0,
|
|
94
|
+
stage: null,
|
|
95
|
+
stageMs: 0,
|
|
96
|
+
completed: [],
|
|
97
|
+
openSteps: [],
|
|
98
|
+
stepsSettled: 0,
|
|
99
|
+
},
|
|
100
|
+
abandon: () => current.abandon?.(),
|
|
89
101
|
activateProject: (name, activationOptions) => {
|
|
90
102
|
if (closed || !available) return Promise.reject(new Error("Embedded daemon is retiring"));
|
|
91
103
|
return current.activateProject(name, activationOptions);
|