tmux-ide 2.9.24 → 2.9.26
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 +1689 -393
- package/package.json +5 -2
- package/packages/contracts/src/pane-stream.ts +72 -0
- package/packages/contracts/src/terminal-delivery.ts +8 -2
- package/packages/contracts/src/terminal-runtime-inventory.ts +61 -1
- package/packages/contracts/src/tmux-server-scope.ts +18 -0
- package/packages/daemon/dist/command-center/discovery.js +24 -5
- package/packages/daemon/dist/command-center/resources/terminal-runtime-inventory.js +42 -2
- package/packages/daemon/dist/command-center/server.js +81 -75
- package/packages/daemon/dist/command-center/tmux-servers.js +17 -7
- package/packages/daemon/dist/doctor.js +46 -10
- package/packages/daemon/dist/lib/canonical-daemon-bootstrap.js +20 -2
- package/packages/daemon/dist/lib/daemon-crash-snapshot.js +118 -0
- package/packages/daemon/dist/lib/daemon-embed.js +6 -0
- package/packages/daemon/dist/lib/headless-daemon.js +63 -6
- package/packages/daemon/dist/lib/invocation-directory.js +20 -0
- package/packages/daemon/dist/lib/runtime-namespace.js +22 -6
- package/packages/daemon/dist/lib/tmux-client-execution.js +12 -3
- package/packages/daemon/dist/lib/tmux-server-owner.js +4 -2
- package/packages/daemon/dist/lib/update-check.js +18 -0
- package/packages/daemon/dist/lib/update-daemon-outcome.js +31 -0
- package/packages/daemon/dist/lib/update.js +39 -14
- 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/graphics/kitty-graphics.js +16 -4
- package/packages/daemon/dist/terminal/mirror/mirror-service.js +26 -0
- package/packages/daemon/dist/terminal/mirror/session-channel.js +31 -2
- package/packages/daemon/dist/terminal/pane-stream/lease-manager.js +1 -0
- package/packages/daemon/dist/terminal/pane-stream/pane-stream-websocket.js +831 -222
- package/packages/daemon/dist/terminal/protocol/browser-icon.js +1 -1
- package/packages/daemon/dist/terminal/protocol/session-descriptor-discovery.js +26 -3
- package/packages/daemon/dist/terminal/session-runtime/registry.js +25 -2
- package/packages/daemon/dist/terminal/session-runtime/terminal-delivery-hub.js +121 -6
- package/packages/daemon/dist/terminal/session-runtime/terminal-replica-interpreter.js +79 -2
- package/packages/daemon/dist/terminal/session-runtime/terminal-replica-owner.js +24 -2
- package/packages/daemon/dist/terminal/session-runtime/transport-binding.js +38 -0
- package/packages/daemon/dist/terminal/session-runtime/xterm-terminal-interpreter-backend.js +51 -4
- package/packages/daemon/dist/tui/chrome/snapshot.js +36 -1
- package/packages/daemon/dist/tui/chrome/statusline.js +8 -5
- package/packages/daemon/dist/tui/chrome/updater.js +2 -0
- package/packages/daemon/src/command-center/discovery.ts +24 -4
- package/packages/daemon/src/command-center/resources/terminal-runtime-inventory.ts +48 -1
- package/packages/daemon/src/command-center/server.ts +67 -67
- package/packages/daemon/src/command-center/tmux-servers.ts +19 -6
- package/packages/daemon/src/doctor.ts +50 -9
- package/packages/daemon/src/lib/canonical-daemon-bootstrap.ts +31 -5
- package/packages/daemon/src/lib/daemon-crash-snapshot.ts +175 -0
- package/packages/daemon/src/lib/daemon-embed.ts +22 -0
- package/packages/daemon/src/lib/headless-daemon.ts +88 -7
- package/packages/daemon/src/lib/invocation-directory.ts +21 -0
- package/packages/daemon/src/lib/runtime-namespace.ts +25 -7
- package/packages/daemon/src/lib/tmux-client-execution.ts +14 -5
- package/packages/daemon/src/lib/tmux-server-owner.ts +6 -3
- package/packages/daemon/src/lib/update-check.ts +34 -0
- package/packages/daemon/src/lib/update-daemon-outcome.ts +42 -0
- package/packages/daemon/src/lib/update.ts +58 -16
- package/packages/daemon/src/terminal/graphics/kitty-graphics.ts +22 -6
- package/packages/daemon/src/terminal/mirror/events.ts +2 -0
- package/packages/daemon/src/terminal/mirror/mirror-service.ts +27 -0
- package/packages/daemon/src/terminal/mirror/session-channel.ts +38 -2
- package/packages/daemon/src/terminal/pane-stream/lease-manager.ts +3 -0
- package/packages/daemon/src/terminal/pane-stream/pane-stream-websocket.ts +915 -236
- package/packages/daemon/src/terminal/protocol/browser-icon.ts +1 -1
- package/packages/daemon/src/terminal/protocol/session-descriptor-discovery.ts +32 -2
- package/packages/daemon/src/terminal/session-runtime/registry.ts +36 -2
- package/packages/daemon/src/terminal/session-runtime/terminal-delivery-hub.ts +136 -6
- package/packages/daemon/src/terminal/session-runtime/terminal-interpreter-backend.ts +6 -0
- package/packages/daemon/src/terminal/session-runtime/terminal-replica-interpreter.ts +76 -2
- package/packages/daemon/src/terminal/session-runtime/terminal-replica-owner.ts +21 -1
- package/packages/daemon/src/terminal/session-runtime/transport-binding.ts +42 -2
- package/packages/daemon/src/terminal/session-runtime/xterm-terminal-interpreter-backend.ts +67 -3
- package/packages/daemon/src/tui/chrome/snapshot.ts +47 -1
- package/packages/daemon/src/tui/chrome/statusline.ts +7 -4
- package/packages/daemon/src/tui/chrome/updater.ts +3 -0
- package/packages/daemon-client/src/pane-stream-client.ts +47 -5
|
@@ -14,7 +14,7 @@ import { fileURLToPath } from "node:url";
|
|
|
14
14
|
import { Hono } from "hono";
|
|
15
15
|
import { streamSSE } from "hono/streaming";
|
|
16
16
|
import { cors } from "hono/cors";
|
|
17
|
-
import {
|
|
17
|
+
import { readSessions, readLiveSessionSummaries, buildOverviews, buildProjectDetail, } from "./discovery.js";
|
|
18
18
|
import { listSessionPanes, sendCommand, sendEnterToPane, sendLiteralToPane, sendText, getPaneBusyStatus, } from "../widgets/lib/pane-comms.js";
|
|
19
19
|
import { resolvePane } from "../send.js";
|
|
20
20
|
import { getSessionState, killSession, stopSessionMonitor } from "@tmux-ide/tmux-bridge";
|
|
@@ -309,6 +309,20 @@ function sandboxResolveDir(rawDir) {
|
|
|
309
309
|
return { canonical };
|
|
310
310
|
}
|
|
311
311
|
export function createApp(options = {}) {
|
|
312
|
+
/**
|
|
313
|
+
* The running session a /api/project/:name route acts on. "unavailable" when
|
|
314
|
+
* tmux could not be asked: the session may well still run, so the routes
|
|
315
|
+
* answer 503 tmux-unavailable, not 404 (#753).
|
|
316
|
+
*/
|
|
317
|
+
const lookupSession = (name) => {
|
|
318
|
+
const sessions = readSessions();
|
|
319
|
+
if (sessions === null)
|
|
320
|
+
return "unavailable";
|
|
321
|
+
return sessions.find((session) => session.name === name) ?? "not-found";
|
|
322
|
+
};
|
|
323
|
+
const sessionMissing = (c, missing) => missing === "unavailable"
|
|
324
|
+
? c.json({ error: "Tmux session discovery is unavailable", code: "tmux-unavailable" }, 503)
|
|
325
|
+
: c.json({ error: "Session not found" }, 404);
|
|
312
326
|
const authConfig = options.authConfig ?? { method: "none", token_expiry: 86400 };
|
|
313
327
|
const authService = options.authService ?? new AuthService();
|
|
314
328
|
const daemonIdentity = options.daemonIdentity ?? {
|
|
@@ -572,7 +586,10 @@ export function createApp(options = {}) {
|
|
|
572
586
|
});
|
|
573
587
|
});
|
|
574
588
|
app.get("/api/sessions", (c) => {
|
|
575
|
-
const sessions =
|
|
589
|
+
const sessions = readSessions();
|
|
590
|
+
// An empty list would tell the TUI the sessions are gone while they run (#753).
|
|
591
|
+
if (sessions === null)
|
|
592
|
+
return c.json({ error: "Tmux session discovery is unavailable", code: "tmux-unavailable" }, 503);
|
|
576
593
|
const overviews = buildOverviews(sessions);
|
|
577
594
|
return c.json({ sessions: overviews });
|
|
578
595
|
});
|
|
@@ -703,11 +720,9 @@ export function createApp(options = {}) {
|
|
|
703
720
|
});
|
|
704
721
|
app.get("/api/project/:name", (c) => {
|
|
705
722
|
const name = c.req.param("name");
|
|
706
|
-
const
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
return c.json({ error: "Session not found" }, 404);
|
|
710
|
-
}
|
|
723
|
+
const session = lookupSession(name);
|
|
724
|
+
if (typeof session === "string")
|
|
725
|
+
return sessionMissing(c, session);
|
|
711
726
|
const detail = buildProjectDetail(session);
|
|
712
727
|
return c.json({ ...detail });
|
|
713
728
|
});
|
|
@@ -815,9 +830,9 @@ export function createApp(options = {}) {
|
|
|
815
830
|
const backend = options.applicationShellInventoryBackend;
|
|
816
831
|
if (!backend) {
|
|
817
832
|
if (requestedVersion === String(APPLICATION_SHELL_RESOURCE_V1_VERSION)) {
|
|
818
|
-
const standaloneSession =
|
|
819
|
-
if (
|
|
820
|
-
return c
|
|
833
|
+
const standaloneSession = lookupSession(name);
|
|
834
|
+
if (typeof standaloneSession === "string")
|
|
835
|
+
return sessionMissing(c, standaloneSession);
|
|
821
836
|
markV1Compatibility();
|
|
822
837
|
return c.json({
|
|
823
838
|
version: APPLICATION_SHELL_RESOURCE_V1_VERSION,
|
|
@@ -908,14 +923,15 @@ export function createApp(options = {}) {
|
|
|
908
923
|
panes = listSessionPanes(name);
|
|
909
924
|
}
|
|
910
925
|
catch {
|
|
911
|
-
|
|
926
|
+
// A missing session, or a tmux that could not be asked (#753).
|
|
927
|
+
const session = lookupSession(name);
|
|
928
|
+
return sessionMissing(c, typeof session === "string" ? session : "not-found");
|
|
912
929
|
}
|
|
913
930
|
if (panes.length === 0) {
|
|
914
931
|
// Verify the session actually exists before returning empty
|
|
915
|
-
const
|
|
916
|
-
if (
|
|
917
|
-
return c
|
|
918
|
-
}
|
|
932
|
+
const session = lookupSession(name);
|
|
933
|
+
if (typeof session === "string")
|
|
934
|
+
return sessionMissing(c, session);
|
|
919
935
|
}
|
|
920
936
|
return c.json({
|
|
921
937
|
panes: panes.map((p) => ({
|
|
@@ -934,10 +950,9 @@ export function createApp(options = {}) {
|
|
|
934
950
|
});
|
|
935
951
|
app.get("/api/project/:name/terminals", async (c) => {
|
|
936
952
|
const name = c.req.param("name");
|
|
937
|
-
const
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
return c.json({ error: "Session not found" }, 404);
|
|
953
|
+
const session = lookupSession(name);
|
|
954
|
+
if (typeof session === "string")
|
|
955
|
+
return sessionMissing(c, session);
|
|
941
956
|
const records = loadTerminals(session.dir);
|
|
942
957
|
const terminals = records.map((t) => {
|
|
943
958
|
const bridge = defaultPtyBridgeRegistry.peek(t.id);
|
|
@@ -961,10 +976,9 @@ export function createApp(options = {}) {
|
|
|
961
976
|
});
|
|
962
977
|
app.post("/api/project/:name/terminals", zValidator("json", terminalCreateRequestSchema), async (c) => {
|
|
963
978
|
const name = c.req.param("name");
|
|
964
|
-
const
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
return c.json({ error: "Session not found" }, 404);
|
|
979
|
+
const session = lookupSession(name);
|
|
980
|
+
if (typeof session === "string")
|
|
981
|
+
return sessionMissing(c, session);
|
|
968
982
|
const body = c.req.valid("json");
|
|
969
983
|
// Pick the id: explicit > deterministic (when script provided) >
|
|
970
984
|
// UUID. The script-derived id collapse is the load-bearing bit
|
|
@@ -1005,10 +1019,9 @@ export function createApp(options = {}) {
|
|
|
1005
1019
|
app.post("/api/project/:name/terminals/:id/rename", zValidator("json", terminalRenameRequestSchema), async (c) => {
|
|
1006
1020
|
const name = c.req.param("name");
|
|
1007
1021
|
const id = c.req.param("id");
|
|
1008
|
-
const
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
return c.json({ error: "Session not found" }, 404);
|
|
1022
|
+
const session = lookupSession(name);
|
|
1023
|
+
if (typeof session === "string")
|
|
1024
|
+
return sessionMissing(c, session);
|
|
1012
1025
|
try {
|
|
1013
1026
|
const record = renameTerminalRecord(session.dir, id, c.req.valid("json").name);
|
|
1014
1027
|
if (!record)
|
|
@@ -1023,10 +1036,9 @@ export function createApp(options = {}) {
|
|
|
1023
1036
|
app.delete("/api/project/:name/terminals/:id", async (c) => {
|
|
1024
1037
|
const name = c.req.param("name");
|
|
1025
1038
|
const id = c.req.param("id");
|
|
1026
|
-
const
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
return c.json({ error: "Session not found" }, 404);
|
|
1039
|
+
const session = lookupSession(name);
|
|
1040
|
+
if (typeof session === "string")
|
|
1041
|
+
return sessionMissing(c, session);
|
|
1030
1042
|
const removedRecord = deleteTerminalRecord(session.dir, id);
|
|
1031
1043
|
// Kill the live bridge too — keep store + registry consistent.
|
|
1032
1044
|
const killed = defaultPtyBridgeRegistry.delete(id);
|
|
@@ -1041,18 +1053,16 @@ export function createApp(options = {}) {
|
|
|
1041
1053
|
// so these surfaces only carry the live pane/project snapshot.
|
|
1042
1054
|
app.get("/api/project/:name/events", (c) => {
|
|
1043
1055
|
const name = c.req.param("name");
|
|
1044
|
-
const session =
|
|
1045
|
-
if (
|
|
1046
|
-
return c
|
|
1047
|
-
}
|
|
1056
|
+
const session = lookupSession(name);
|
|
1057
|
+
if (typeof session === "string")
|
|
1058
|
+
return sessionMissing(c, session);
|
|
1048
1059
|
return c.json({ events: [] });
|
|
1049
1060
|
});
|
|
1050
1061
|
app.get("/api/project/:name/stream", (c) => {
|
|
1051
1062
|
const name = c.req.param("name");
|
|
1052
|
-
const session =
|
|
1053
|
-
if (
|
|
1054
|
-
return c
|
|
1055
|
-
}
|
|
1063
|
+
const session = lookupSession(name);
|
|
1064
|
+
if (typeof session === "string")
|
|
1065
|
+
return sessionMissing(c, session);
|
|
1056
1066
|
return streamSSE(c, async (stream) => {
|
|
1057
1067
|
projectStreamConnections += 1;
|
|
1058
1068
|
sseMetrics.connections = projectStreamConnections;
|
|
@@ -1078,10 +1088,12 @@ export function createApp(options = {}) {
|
|
|
1078
1088
|
writeChanges(session);
|
|
1079
1089
|
while (!closed) {
|
|
1080
1090
|
await stream.sleep(250);
|
|
1081
|
-
const current =
|
|
1082
|
-
if (
|
|
1091
|
+
const current = lookupSession(name);
|
|
1092
|
+
if (current === "not-found")
|
|
1083
1093
|
break;
|
|
1084
|
-
|
|
1094
|
+
// tmux could not be asked: the session may still run; ask again (#753).
|
|
1095
|
+
if (current !== "unavailable")
|
|
1096
|
+
writeChanges(current);
|
|
1085
1097
|
const now = Date.now();
|
|
1086
1098
|
if (now - lastPing >= 25_000) {
|
|
1087
1099
|
writeSse("ping", { at: new Date().toISOString() });
|
|
@@ -1097,11 +1109,9 @@ export function createApp(options = {}) {
|
|
|
1097
1109
|
});
|
|
1098
1110
|
app.post("/api/project/:name/inject", async (c) => {
|
|
1099
1111
|
const name = c.req.param("name");
|
|
1100
|
-
const
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
return c.json({ error: "Session not found" }, 404);
|
|
1104
|
-
}
|
|
1112
|
+
const session = lookupSession(name);
|
|
1113
|
+
if (typeof session === "string")
|
|
1114
|
+
return sessionMissing(c, session);
|
|
1105
1115
|
let body;
|
|
1106
1116
|
try {
|
|
1107
1117
|
body = await c.req.json();
|
|
@@ -1139,11 +1149,9 @@ export function createApp(options = {}) {
|
|
|
1139
1149
|
// Send message to a pane by name/title/role/ID
|
|
1140
1150
|
app.post("/api/project/:name/send", zValidator("json", sendCommandSchema), async (c) => {
|
|
1141
1151
|
const name = c.req.param("name");
|
|
1142
|
-
const
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
return c.json({ error: "Session not found" }, 404);
|
|
1146
|
-
}
|
|
1152
|
+
const session = lookupSession(name);
|
|
1153
|
+
if (typeof session === "string")
|
|
1154
|
+
return sessionMissing(c, session);
|
|
1147
1155
|
const { target, message, noEnter } = c.req.valid("json");
|
|
1148
1156
|
const panes = listSessionPanes(name);
|
|
1149
1157
|
const pane = resolvePane(panes, target);
|
|
@@ -1181,10 +1189,9 @@ export function createApp(options = {}) {
|
|
|
1181
1189
|
// the v2 Config editor to hydrate the form.
|
|
1182
1190
|
app.get("/api/project/:name/config", async (c) => {
|
|
1183
1191
|
const name = c.req.param("name");
|
|
1184
|
-
const
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
return c.json({ error: "Session not found" }, 404);
|
|
1192
|
+
const session = lookupSession(name);
|
|
1193
|
+
if (typeof session === "string")
|
|
1194
|
+
return sessionMissing(c, session);
|
|
1188
1195
|
try {
|
|
1189
1196
|
const resolved = await resolveConfig(session.dir);
|
|
1190
1197
|
if (!resolved.launchConfig || !resolved.path) {
|
|
@@ -1210,10 +1217,9 @@ export function createApp(options = {}) {
|
|
|
1210
1217
|
// config so the client can re-hydrate without a follow-up GET.
|
|
1211
1218
|
app.post("/api/project/:name/config", async (c) => {
|
|
1212
1219
|
const name = c.req.param("name");
|
|
1213
|
-
const
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
return c.json({ error: "Session not found" }, 404);
|
|
1220
|
+
const session = lookupSession(name);
|
|
1221
|
+
if (typeof session === "string")
|
|
1222
|
+
return sessionMissing(c, session);
|
|
1217
1223
|
let body;
|
|
1218
1224
|
try {
|
|
1219
1225
|
body = await c.req.json();
|
|
@@ -1251,10 +1257,9 @@ export function createApp(options = {}) {
|
|
|
1251
1257
|
// 30s timeout so the client can retry on its own.
|
|
1252
1258
|
app.post("/api/project/:name/restart", async (c) => {
|
|
1253
1259
|
const name = c.req.param("name");
|
|
1254
|
-
const
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
return c.json({ error: "Session not found" }, 404);
|
|
1260
|
+
const session = lookupSession(name);
|
|
1261
|
+
if (typeof session === "string")
|
|
1262
|
+
return sessionMissing(c, session);
|
|
1258
1263
|
try {
|
|
1259
1264
|
await execFileAsync("tmux-ide", ["restart", "--json"], {
|
|
1260
1265
|
cwd: session.dir,
|
|
@@ -1270,11 +1275,9 @@ export function createApp(options = {}) {
|
|
|
1270
1275
|
});
|
|
1271
1276
|
app.post("/api/project/:name/launch", async (c) => {
|
|
1272
1277
|
const name = c.req.param("name");
|
|
1273
|
-
const
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
return c.json({ error: "Session not found" }, 404);
|
|
1277
|
-
}
|
|
1278
|
+
const session = lookupSession(name);
|
|
1279
|
+
if (typeof session === "string")
|
|
1280
|
+
return sessionMissing(c, session);
|
|
1278
1281
|
// Check if already running
|
|
1279
1282
|
const state = getSessionState(name);
|
|
1280
1283
|
if (state.running) {
|
|
@@ -1296,11 +1299,9 @@ export function createApp(options = {}) {
|
|
|
1296
1299
|
// Stop a tmux-ide session
|
|
1297
1300
|
app.post("/api/project/:name/stop", async (c) => {
|
|
1298
1301
|
const name = c.req.param("name");
|
|
1299
|
-
const
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
return c.json({ error: "Session not found" }, 404);
|
|
1303
|
-
}
|
|
1302
|
+
const session = lookupSession(name);
|
|
1303
|
+
if (typeof session === "string")
|
|
1304
|
+
return sessionMissing(c, session);
|
|
1304
1305
|
const state = getSessionState(name);
|
|
1305
1306
|
if (!state.running) {
|
|
1306
1307
|
return c.json({ ok: true, session: name, status: "not_running" });
|
|
@@ -1317,7 +1318,12 @@ export function createApp(options = {}) {
|
|
|
1317
1318
|
return streamSSE(c, async (stream) => {
|
|
1318
1319
|
let prevOverviews = [];
|
|
1319
1320
|
const poll = () => {
|
|
1320
|
-
const sessions =
|
|
1321
|
+
const sessions = readSessions();
|
|
1322
|
+
// tmux could not be asked: the sessions may well still run. Diffing an
|
|
1323
|
+
// empty list would announce every one as removed, then added (#753).
|
|
1324
|
+
// Keep the last answer and wait for the next poll.
|
|
1325
|
+
if (sessions === null)
|
|
1326
|
+
return;
|
|
1321
1327
|
const overviews = buildOverviews(sessions);
|
|
1322
1328
|
const prevNames = new Set(prevOverviews.map((s) => s.name));
|
|
1323
1329
|
const currNames = new Set(overviews.map((s) => s.name));
|
|
@@ -11,7 +11,7 @@ import { streamSSE } from "hono/streaming";
|
|
|
11
11
|
import { projectApplicationShellResource } from "./resources/application-shell.js";
|
|
12
12
|
import { fleetSessionIdForName } from "./resources/fleet-catalog.js";
|
|
13
13
|
import { z } from "zod";
|
|
14
|
-
import { TmuxAgentOpenRequestSchemaZ, TmuxAgentOpenResponseSchemaZ, WorkspaceCatalogLiveSessionIdSchemaZ, WindowLinkTargetSchemaZ, WindowSplitLayoutResourceSchemaZ, TMUX_SERVERS_API_PATH, PANE_STREAM_ISSUE_PATH, TmuxServerIdSchemaZ, TmuxServerScopeSchemaZ, TmuxServersResourceSchemaZ, TmuxServerSessionsResourceSchemaZ, TmuxServerSessionsResourceV2SchemaZ, WorkspaceMultiplexerMutationRequestSchemaZ, WorkspacePaneCreateMutationRequestSchemaZ, WorkspaceSessionCreateArgumentsSchemaZ, } from "@tmux-ide/contracts";
|
|
14
|
+
import { TmuxAgentOpenRequestSchemaZ, TmuxAgentOpenResponseSchemaZ, WorkspaceCatalogLiveSessionIdSchemaZ, WindowLinkTargetSchemaZ, WindowSplitLayoutResourceSchemaZ, TMUX_SERVERS_API_PATH, PANE_STREAM_ISSUE_PATH, TmuxServerIdSchemaZ, TmuxServerScopeSchemaZ, TmuxServersResourceSchemaZ, TmuxServerSessionsResourceSchemaZ, TmuxServerSessionsResourceV2SchemaZ, TmuxServerSessionsResourceV3SchemaZ, WorkspaceMultiplexerMutationRequestSchemaZ, WorkspacePaneCreateMutationRequestSchemaZ, WorkspaceSessionCreateArgumentsSchemaZ, } from "@tmux-ide/contracts";
|
|
15
15
|
import { TmuxServerRegistrationSchemaZ, TmuxServerScopeError, } from "../lib/tmux-server-owners.js";
|
|
16
16
|
import { createSessionFaviconResolver } from "../lib/session-favicon.js";
|
|
17
17
|
import { WorkspaceMultiplexerError } from "../lib/workspace-multiplexer-verbs.js";
|
|
@@ -19,7 +19,7 @@ import { WorkspacePaneCreationError } from "../lib/workspace-pane-creation.js";
|
|
|
19
19
|
import { ownerBearerMatches } from "./owner-authority.js";
|
|
20
20
|
import { logger } from "../lib/log.js";
|
|
21
21
|
import { mountPaneStreamIssueRoute } from "./pane-stream-issue.js";
|
|
22
|
-
import { projectTerminalRuntimeInventory } from "./resources/terminal-runtime-inventory.js";
|
|
22
|
+
import { projectTerminalRuntimeInventory, projectTerminalRuntimeInventoryV2, } from "./resources/terminal-runtime-inventory.js";
|
|
23
23
|
/** Total raw favicon bytes one version 2 sessions response may carry. */
|
|
24
24
|
export const SESSIONS_RESOURCE_FAVICON_BUDGET_BYTES = 512 * 1024;
|
|
25
25
|
const registrationSchema = TmuxServerRegistrationSchemaZ.omit({ serverId: true }).strict();
|
|
@@ -206,7 +206,9 @@ export function mountTmuxServerRoutes(app, options) {
|
|
|
206
206
|
}));
|
|
207
207
|
app.get(`${scoped}/sessions`, route(async (c) => {
|
|
208
208
|
const server = scope(c);
|
|
209
|
-
|
|
209
|
+
// #806: version 3 is version 2 plus the largest window's pane count.
|
|
210
|
+
const v3 = c.req.query("version") === "3";
|
|
211
|
+
const v2 = v3 || c.req.query("version") === "2";
|
|
210
212
|
const { rows, favicons } = await options.owners.withOwner(server, async (owner) => {
|
|
211
213
|
const sessions = await owner.catalog();
|
|
212
214
|
const workspaces = owner.workspaceRegistry.list();
|
|
@@ -231,8 +233,9 @@ export function mountTmuxServerRoutes(app, options) {
|
|
|
231
233
|
})),
|
|
232
234
|
}));
|
|
233
235
|
let budget = SESSIONS_RESOURCE_FAVICON_BUDGET_BYTES;
|
|
234
|
-
|
|
235
|
-
|
|
236
|
+
const schema = v3 ? TmuxServerSessionsResourceV3SchemaZ : TmuxServerSessionsResourceV2SchemaZ;
|
|
237
|
+
return c.json(schema.parse({
|
|
238
|
+
version: v3 ? 3 : 2,
|
|
236
239
|
server,
|
|
237
240
|
sessions: rows.map(({ session, workspaceName }, index) => {
|
|
238
241
|
const found = favicons[index] ?? null;
|
|
@@ -245,6 +248,7 @@ export function mountTmuxServerRoutes(app, options) {
|
|
|
245
248
|
workspaceName,
|
|
246
249
|
paneCount: session.paneCount,
|
|
247
250
|
windowCount: session.windowCount,
|
|
251
|
+
...(v3 ? { largestWindowPaneCount: session.largestWindowPaneCount } : {}),
|
|
248
252
|
lastActivity: session.lastActivity,
|
|
249
253
|
favicon: favicon ? { mime: favicon.mime, data: favicon.data } : null,
|
|
250
254
|
};
|
|
@@ -262,6 +266,8 @@ export function mountTmuxServerRoutes(app, options) {
|
|
|
262
266
|
app.get(`${scoped}/inventory/:workspaceName`, route(async (c) => {
|
|
263
267
|
const server = scope(c);
|
|
264
268
|
const workspaceName = workspaceSchema.parse(c.req.param("workspaceName"));
|
|
269
|
+
// #806: version 2 also names each window and its panes.
|
|
270
|
+
const v2 = c.req.query("version") === "2";
|
|
265
271
|
const resource = await options.owners.withOwner(server, async (owner) => {
|
|
266
272
|
const sessions = await owner.catalog();
|
|
267
273
|
const workspace = owner.workspaceRegistry.get(workspaceName);
|
|
@@ -272,10 +278,14 @@ export function mountTmuxServerRoutes(app, options) {
|
|
|
272
278
|
!sessions.some((row) => row.sessionName === workspace.sessionName && row.liveSessionId === expected))
|
|
273
279
|
throw new TmuxServerScopeError("stale-generation");
|
|
274
280
|
const snapshot = await owner.terminalInventoryRuntime.discoverTerminalRuntimeSession(workspace.sessionName, c.req.raw.signal);
|
|
275
|
-
|
|
281
|
+
if (!snapshot)
|
|
282
|
+
return null;
|
|
283
|
+
return v2
|
|
284
|
+
? projectTerminalRuntimeInventoryV2(snapshot, 0)
|
|
285
|
+
: projectTerminalRuntimeInventory(snapshot, 0);
|
|
276
286
|
});
|
|
277
287
|
return resource
|
|
278
|
-
? c.json({ version: 1, server, resource })
|
|
288
|
+
? c.json({ version: v2 ? 2 : 1, server, resource })
|
|
279
289
|
: c.json({ error: { code: "workspace-not-found" } }, 404);
|
|
280
290
|
}));
|
|
281
291
|
app.get(`${scoped}/catalog`, route(async (c) => {
|
|
@@ -6,7 +6,7 @@ import { accessSync, constants, existsSync, mkdtempSync, realpathSync, rmSync }
|
|
|
6
6
|
import { tmpdir } from "node:os";
|
|
7
7
|
import { delimiter, resolve, dirname, join } from "node:path";
|
|
8
8
|
import { resolveBundledTmux } from "./lib/bundled-tmux.js";
|
|
9
|
-
import { readSnapshot } from "./tui/chrome/snapshot.js";
|
|
9
|
+
import { readSnapshot, snapshotIsRestorePoint } from "./tui/chrome/snapshot.js";
|
|
10
10
|
import { isListableSession } from "./tui/team/sessions.js";
|
|
11
11
|
import { nativeCommands } from "./lib/tmux-server-features.js";
|
|
12
12
|
import { fileURLToPath } from "node:url";
|
|
@@ -168,7 +168,7 @@ export function tmuxFeaturesRow(probeServer, probeBinary) {
|
|
|
168
168
|
: "";
|
|
169
169
|
const details = {
|
|
170
170
|
full: "bundled tmux: full features",
|
|
171
|
-
stock: `stock tmux: reduced features${upgrade}`,
|
|
171
|
+
stock: `stock tmux: reduced features (tab positions in saved output are reconstructed)${upgrade}`,
|
|
172
172
|
older: `older tmux-ide tmux: reduced features${upgrade}`,
|
|
173
173
|
partial: "this tmux has only some tmux-ide commands: no pane dividers",
|
|
174
174
|
"no-server": "could not read the tmux server's features",
|
|
@@ -206,12 +206,15 @@ export function plainTmuxRow(pathTmux, bundled) {
|
|
|
206
206
|
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
207
207
|
/**
|
|
208
208
|
* PURE — is the crash snapshot fresh enough to restore from? It fails when it
|
|
209
|
-
* is missing a live session, or is over a day old while sessions run.
|
|
210
|
-
* chrome updater writes it
|
|
209
|
+
* is missing a live session, or is over a day old while sessions run. The
|
|
210
|
+
* chrome updater writes it while a session is adopted; otherwise the background
|
|
211
|
+
* service does, for its default server (lib/daemon-crash-snapshot.ts).
|
|
211
212
|
*/
|
|
212
|
-
export function snapshotRow(snapshot, liveSessions, nowMs
|
|
213
|
+
export function snapshotRow(snapshot, liveSessions, nowMs,
|
|
214
|
+
/** When the running tmux server started, if known. */
|
|
215
|
+
serverStartMs = null) {
|
|
213
216
|
const label = "crash snapshot (restore)";
|
|
214
|
-
const hint = "
|
|
217
|
+
const hint = "The background service writes it within a minute while it runs; without the service, `tmux-ide adopt --all` starts a writer";
|
|
215
218
|
if (!snapshot) {
|
|
216
219
|
return liveSessions?.length
|
|
217
220
|
? { label, pass: false, detail: `none yet. ${hint}`, optional: true }
|
|
@@ -221,6 +224,20 @@ export function snapshotRow(snapshot, liveSessions, nowMs) {
|
|
|
221
224
|
const age = ageMs >= DAY_MS
|
|
222
225
|
? `${Math.floor(ageMs / DAY_MS)} days old`
|
|
223
226
|
: `${Math.max(0, Math.round(ageMs / 60_000))} min old`;
|
|
227
|
+
if (liveSessions &&
|
|
228
|
+
serverStartMs !== null &&
|
|
229
|
+
snapshotIsRestorePoint(snapshot, { serverStartMs, sessions: liveSessions })) {
|
|
230
|
+
// No writer replaces this file: it is the only record of the server that died.
|
|
231
|
+
const gone = snapshot.sessions
|
|
232
|
+
.map((session) => session.name)
|
|
233
|
+
.filter((name) => !liveSessions.includes(name));
|
|
234
|
+
return {
|
|
235
|
+
label,
|
|
236
|
+
pass: false,
|
|
237
|
+
detail: `restore point kept: saved ${age}, before this tmux server started; ${gone.length} of its sessions ${gone.length === 1 ? "is" : "are"} not running (${gone.slice(0, 5).join(", ")}${gone.length > 5 ? ", …" : ""}). \`tmux-ide restore\` brings them back; delete snapshot.json to let a new snapshot replace it`,
|
|
238
|
+
optional: true,
|
|
239
|
+
};
|
|
240
|
+
}
|
|
224
241
|
const saved = new Set(snapshot.sessions.map((session) => session.name));
|
|
225
242
|
const missing = (liveSessions ?? []).filter((name) => !saved.has(name));
|
|
226
243
|
if (missing.length)
|
|
@@ -256,12 +273,31 @@ function safeBundledTmux() {
|
|
|
256
273
|
return null;
|
|
257
274
|
}
|
|
258
275
|
}
|
|
276
|
+
/** The `-S`/`-L` arguments that name the server doctor reads. */
|
|
277
|
+
function doctorTmuxServer() {
|
|
278
|
+
const socketPath = process.env[TMUX_SOCKET_PATH_ENV];
|
|
279
|
+
const socketName = process.env.TMUX_IDE_TMUX_SOCKET_NAME;
|
|
280
|
+
return socketPath ? ["-S", socketPath] : socketName ? ["-L", socketName] : [];
|
|
281
|
+
}
|
|
282
|
+
/** `#{start_time}` of the server doctor reads, or null when it cannot be asked. */
|
|
283
|
+
function liveServerStartMs() {
|
|
284
|
+
try {
|
|
285
|
+
const server = doctorTmuxServer();
|
|
286
|
+
const seconds = Number(execFileSync(resolveTmuxExecutable(), [...server, "display-message", "-p", "#{start_time}"], {
|
|
287
|
+
encoding: "utf8",
|
|
288
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
289
|
+
timeout: 3000,
|
|
290
|
+
}).trim());
|
|
291
|
+
return Number.isFinite(seconds) && seconds > 0 ? seconds * 1000 : null;
|
|
292
|
+
}
|
|
293
|
+
catch {
|
|
294
|
+
return null;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
259
297
|
/** The sessions the snapshot should hold, on the server doctor reads; null when unreadable. */
|
|
260
298
|
function liveListableSessions() {
|
|
261
299
|
try {
|
|
262
|
-
const
|
|
263
|
-
const socketName = process.env.TMUX_IDE_TMUX_SOCKET_NAME;
|
|
264
|
-
const server = socketPath ? ["-S", socketPath] : socketName ? ["-L", socketName] : [];
|
|
300
|
+
const server = doctorTmuxServer();
|
|
265
301
|
return execFileSync(resolveTmuxExecutable(), [...server, "list-sessions", "-F", "#{session_name}"], { encoding: "utf8", stdio: ["ignore", "pipe", "pipe"], timeout: 3000 })
|
|
266
302
|
.split("\n")
|
|
267
303
|
.filter((name) => name && isListableSession(name));
|
|
@@ -398,7 +434,7 @@ export async function doctor({ json, } = {}) {
|
|
|
398
434
|
// The tmux version row above already reports a missing executable.
|
|
399
435
|
}
|
|
400
436
|
checks.push(plainTmuxRow(firstOnPath("tmux"), safeBundledTmux()));
|
|
401
|
-
checks.push(snapshotRow(readSnapshot(), liveListableSessions(), Date.now()));
|
|
437
|
+
checks.push(snapshotRow(readSnapshot(), liveListableSessions(), Date.now(), liveServerStartMs()));
|
|
402
438
|
checks.push(nodeVersionRow(process.versions.node));
|
|
403
439
|
checks.push(check("256-color terminal", () => {
|
|
404
440
|
const term = process.env.TERM ?? "";
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { captureTmuxServerProof, captureUnboundTmuxSelectorProof, } from "./tmux-server-proof.js";
|
|
2
|
+
import { invocationDirectory } from "./invocation-directory.js";
|
|
2
3
|
import { createPinnedWorkspaceTmuxRunner, resolveWorkspacePaneTmuxAuthority, } from "./workspace-pane-creation.js";
|
|
3
4
|
import { resolveRuntimeNamespace, resolveTmuxServerIntent } from "./runtime-namespace.js";
|
|
4
5
|
import { compareProductVersions } from "./semver.js";
|
|
@@ -177,6 +178,18 @@ async function replaceOlderCanonicalDaemon(deps, info, timeoutMs, expectedProduc
|
|
|
177
178
|
throw transportFailure.original;
|
|
178
179
|
throw new DaemonBootstrapError("control-timeout", "The older canonical daemon did not retire after accepting the version upgrade.", { reason: "protocol-mismatch" });
|
|
179
180
|
}
|
|
181
|
+
const DAEMON_PROOF_PENDING = Symbol("daemon-server-proof-pending");
|
|
182
|
+
/**
|
|
183
|
+
* The daemon supports server proofs, but its identity or this side's own probe
|
|
184
|
+
* has no proof yet: a generation that just started on a replaced tmux server,
|
|
185
|
+
* or a slow tmux answer. Waiting can resolve it; an unsupported proof or a
|
|
186
|
+
* positive mismatch cannot.
|
|
187
|
+
*/
|
|
188
|
+
export function daemonServerProofPending(error) {
|
|
189
|
+
return (error instanceof DaemonBootstrapError &&
|
|
190
|
+
error[DAEMON_PROOF_PENDING] ===
|
|
191
|
+
true);
|
|
192
|
+
}
|
|
180
193
|
async function assertServerIntent(deps, info, identity, intent) {
|
|
181
194
|
if (!intent)
|
|
182
195
|
return;
|
|
@@ -202,7 +215,11 @@ async function assertServerIntent(deps, info, identity, intent) {
|
|
|
202
215
|
}
|
|
203
216
|
}
|
|
204
217
|
if (info.tmuxServerProofVersion !== 1 || !identity.tmuxServerProof || !proof)
|
|
205
|
-
throw new DaemonBootstrapError("incompatible", `Cannot prove the requested tmux server for this daemon. Its server identity is unavailable or unsupported; the existing daemon was left running. Proof availability: capability=${info.tmuxServerProofVersion === 1}, daemon=${Boolean(identity.tmuxServerProof)}, client=${Boolean(proof)}.`, { reason: "tmux-server-unproven" })
|
|
218
|
+
throw Object.assign(new DaemonBootstrapError("incompatible", `Cannot prove the requested tmux server for this daemon. Its server identity is unavailable or unsupported; the existing daemon was left running. Proof availability: capability=${info.tmuxServerProofVersion === 1}, daemon=${Boolean(identity.tmuxServerProof)}, client=${Boolean(proof)}.`, { reason: "tmux-server-unproven" }), {
|
|
219
|
+
// Either side's proof can be late (a slow tmux answer); only a daemon
|
|
220
|
+
// without the capability can never prove it.
|
|
221
|
+
[DAEMON_PROOF_PENDING]: info.tmuxServerProofVersion === 1,
|
|
222
|
+
});
|
|
206
223
|
if (identity.tmuxServerProof.kind !== proof.kind ||
|
|
207
224
|
identity.tmuxServerProof.digest !== proof.digest)
|
|
208
225
|
throw new DaemonBootstrapError("incompatible", "The existing daemon manages a different tmux server. It was left running; select its server or use a separate daemon namespace.", { reason: "tmux-server-mismatch" });
|
|
@@ -297,7 +314,8 @@ export function createCanonicalDaemonBootstrapCoordinator(options, dependencies
|
|
|
297
314
|
probe: () => probeCanonical(deps, options.expectedProductVersion, options.tmuxServerIntent === undefined
|
|
298
315
|
? resolveTmuxServerIntent()
|
|
299
316
|
: options.tmuxServerIntent),
|
|
300
|
-
|
|
317
|
+
// A deleted current directory starts the daemon from home (#585).
|
|
318
|
+
spawn: () => deps.spawnOwner(resolve(options.entryPath), resolve(options.cwd ?? invocationDirectory())),
|
|
301
319
|
timeoutMs: options.timeoutMs,
|
|
302
320
|
onPhaseChanged: options.onPhaseChanged,
|
|
303
321
|
now: deps.now,
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The crash snapshot (`snapshot.json`, read by `tmux-ide restore`) written by
|
|
3
|
+
* the daemon for its default tmux server.
|
|
4
|
+
*
|
|
5
|
+
* The chrome updater writes that file, but it runs only while a session is
|
|
6
|
+
* adopted. A server started by plain `tmux` then has no snapshot, silently
|
|
7
|
+
* (#783). The daemon fills the gap: it writes the same file, with the same
|
|
8
|
+
* builder, whenever the updater's own session is not running. One writer at a
|
|
9
|
+
* time, so the two never rotate each other's generation away. Neither replaces
|
|
10
|
+
* a restore point: the snapshot of a server that is gone and whose sessions
|
|
11
|
+
* have not come back (`snapshotIsRestorePoint`).
|
|
12
|
+
*/
|
|
13
|
+
import { UPDATER_SESSION } from "./chrome-front-door.js";
|
|
14
|
+
/** How often the daemon looks. A new server has its snapshot within a minute. */
|
|
15
|
+
export const DAEMON_CRASH_SNAPSHOT_INTERVAL_MS = 30_000;
|
|
16
|
+
/**
|
|
17
|
+
* Is `existing` a restore point: the snapshot of a tmux server that is gone,
|
|
18
|
+
* naming at least one session the running server lacks? That file is what
|
|
19
|
+
* `tmux-ide restore` rebuilds from, so no writer may replace it. It stops
|
|
20
|
+
* being one when its sessions run again (after a restore) or the user deletes
|
|
21
|
+
* the file. A server's own snapshot is never one: it was saved after the
|
|
22
|
+
* server started.
|
|
23
|
+
*/
|
|
24
|
+
export function snapshotIsRestorePoint(existing, live) {
|
|
25
|
+
if (!existing || !(live.serverStartMs > Date.parse(existing.savedAt)))
|
|
26
|
+
return false;
|
|
27
|
+
const running = new Set(live.sessions);
|
|
28
|
+
return existing.sessions.some((session) => !running.has(session.name));
|
|
29
|
+
}
|
|
30
|
+
export function createDaemonCrashSnapshot(deps) {
|
|
31
|
+
const { source } = deps;
|
|
32
|
+
/** The tmux answers of the last pulse that built a snapshot. */
|
|
33
|
+
let seen = null;
|
|
34
|
+
return {
|
|
35
|
+
async pulse() {
|
|
36
|
+
let sessions;
|
|
37
|
+
let panes;
|
|
38
|
+
let existing;
|
|
39
|
+
let serverStartMs = Number.NaN;
|
|
40
|
+
try {
|
|
41
|
+
sessions = await deps.run(["list-sessions", "-F", source.sessionFormat]);
|
|
42
|
+
if (sessions.split("\n").some((line) => line.split("\t")[0] === UPDATER_SESSION)) {
|
|
43
|
+
// The updater owns the file now; start over from the file when it stops.
|
|
44
|
+
seen = null;
|
|
45
|
+
return "updater-writes";
|
|
46
|
+
}
|
|
47
|
+
panes = await deps.run(["list-panes", "-a", "-F", source.paneFormat]);
|
|
48
|
+
if (`${sessions}\n\n${panes}` === seen)
|
|
49
|
+
return "unchanged";
|
|
50
|
+
existing = source.read();
|
|
51
|
+
if (existing)
|
|
52
|
+
serverStartMs =
|
|
53
|
+
Number((await deps.run(["display-message", "-p", "#{start_time}"])).trim()) * 1000;
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
// A server that is gone or unreachable must not replace the snapshot
|
|
57
|
+
// that restores it.
|
|
58
|
+
return "tmux-unavailable";
|
|
59
|
+
}
|
|
60
|
+
const running = sessions.split("\n").map((line) => line.split("\t")[0]);
|
|
61
|
+
if (snapshotIsRestorePoint(existing, { serverStartMs, sessions: running })) {
|
|
62
|
+
// Look again next time: a restore or a deleted file changes no tmux
|
|
63
|
+
// answer this pulse could remember.
|
|
64
|
+
seen = null;
|
|
65
|
+
return "restore-point-kept";
|
|
66
|
+
}
|
|
67
|
+
const snapshot = await source.build(panes.split("\n").filter(Boolean), sessions.split("\n").filter(Boolean));
|
|
68
|
+
seen = `${sessions}\n\n${panes}`;
|
|
69
|
+
if (existing && source.fingerprint(existing) === source.fingerprint(snapshot))
|
|
70
|
+
return "unchanged";
|
|
71
|
+
source.write(snapshot);
|
|
72
|
+
return "written";
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* What a daemon generation passes to {@link startDaemonCrashSnapshot}: its
|
|
78
|
+
* launcher and the source its owner injected. A pure function so a test can pin
|
|
79
|
+
* that the source reaches the writer without starting a daemon.
|
|
80
|
+
*/
|
|
81
|
+
export function daemonCrashSnapshotStart(opts, run, retired) {
|
|
82
|
+
return {
|
|
83
|
+
launcher: opts.launcher ?? "embedded",
|
|
84
|
+
source: opts.crashSnapshotSource,
|
|
85
|
+
run,
|
|
86
|
+
retired,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Pulse on a timer until `retired` says the daemon generation is gone; the
|
|
91
|
+
* timer then clears itself, so no stop step has to know about it. Returns a
|
|
92
|
+
* stop function for callers that have one. Only the background service
|
|
93
|
+
* ("headless") writes: a daemon embedded in an app lives only as long as its
|
|
94
|
+
* window, and gets null. So does a daemon started without a snapshot source.
|
|
95
|
+
*/
|
|
96
|
+
export function startDaemonCrashSnapshot(deps) {
|
|
97
|
+
if (deps.launcher !== "headless" || !deps.source)
|
|
98
|
+
return null;
|
|
99
|
+
const snapshot = createDaemonCrashSnapshot({ run: deps.run, source: deps.source });
|
|
100
|
+
let busy = false;
|
|
101
|
+
const timer = setInterval(() => {
|
|
102
|
+
if (deps.retired()) {
|
|
103
|
+
clearInterval(timer);
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
if (busy)
|
|
107
|
+
return;
|
|
108
|
+
busy = true;
|
|
109
|
+
void snapshot
|
|
110
|
+
.pulse()
|
|
111
|
+
.catch(() => undefined)
|
|
112
|
+
.finally(() => {
|
|
113
|
+
busy = false;
|
|
114
|
+
});
|
|
115
|
+
}, DAEMON_CRASH_SNAPSHOT_INTERVAL_MS);
|
|
116
|
+
timer.unref?.();
|
|
117
|
+
return () => clearInterval(timer);
|
|
118
|
+
}
|