tmux-ide 2.9.24 → 2.9.25
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 +1352 -350
- package/package.json +4 -2
- package/packages/contracts/src/pane-stream.ts +53 -0
- package/packages/daemon/dist/command-center/discovery.js +24 -5
- package/packages/daemon/dist/command-center/server.js +81 -75
- 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/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 +25 -1
- package/packages/daemon/dist/terminal/pane-stream/pane-stream-websocket.js +741 -208
- package/packages/daemon/dist/terminal/session-runtime/registry.js +24 -2
- package/packages/daemon/dist/terminal/session-runtime/terminal-replica-interpreter.js +77 -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/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/server.ts +67 -67
- 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/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/mirror-service.ts +27 -0
- package/packages/daemon/src/terminal/mirror/session-channel.ts +30 -1
- package/packages/daemon/src/terminal/pane-stream/pane-stream-websocket.ts +811 -223
- package/packages/daemon/src/terminal/session-runtime/registry.ts +35 -2
- package/packages/daemon/src/terminal/session-runtime/terminal-replica-interpreter.ts +74 -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/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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tmux-ide",
|
|
3
|
-
"version": "2.9.
|
|
3
|
+
"version": "2.9.25",
|
|
4
4
|
"description": "The open-source workspace for coding agents: run Claude Code, Codex and other agents in tmux with live status",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -62,7 +62,8 @@
|
|
|
62
62
|
"test:pane-frame-package": "pnpm --filter @tmux-ide/presentation run test",
|
|
63
63
|
"typecheck:workspace": "turbo run typecheck",
|
|
64
64
|
"docs:build": "turbo run build --filter=@tmux-ide/docs",
|
|
65
|
-
"pack:check": "pnpm test:installer &&
|
|
65
|
+
"pack:check": "pnpm test:installer && pnpm test:workflow-contracts && node scripts/pack-tui-check.mjs",
|
|
66
|
+
"test:workflow-contracts": "node --test scripts/lib/npm-release-tag.test.mjs scripts/lib/tap-bump-gate.test.mjs scripts/lib/macos-ssh-account.test.mjs scripts/lib/apt-dns-fallback.test.mjs scripts/lib/usvg-pin.test.mjs",
|
|
66
67
|
"test:pack-installed": "node scripts/pack-check-run.mjs",
|
|
67
68
|
"release:opentui:check": "node scripts/opentui-release-check.mjs",
|
|
68
69
|
"check:native-deps": "node packages/daemon/scripts/check-native-deps.mjs",
|
|
@@ -107,6 +108,7 @@
|
|
|
107
108
|
"typecheck:tui-gallery": "tsc --noEmit -p scripts/tsconfig.tui-gallery.json",
|
|
108
109
|
"test:spark-qualification": "node --import tsx --test scripts/lib/spark-*.test.ts scripts/lib/spark-*.test.mjs",
|
|
109
110
|
"test:installer": "node --test scripts/install.test.mjs scripts/lib/installer-service-qualification.test.mjs",
|
|
111
|
+
"test:installer-native": "node --test scripts/install-native-alpha.test.mjs scripts/install-native-dispatch.test.mjs",
|
|
110
112
|
"qualify:styled-ssh": "node scripts/qualify-styled-ssh.mjs"
|
|
111
113
|
},
|
|
112
114
|
"keywords": [
|
|
@@ -257,6 +257,21 @@ export const PANE_STREAM_BROWSER_ICON_CAPABILITY_VERSION = 117;
|
|
|
257
257
|
* Offered in place of 117 because the offer array has nine slots.
|
|
258
258
|
*/
|
|
259
259
|
export const PANE_STREAM_READER_CAPABILITY_VERSION = 118;
|
|
260
|
+
/**
|
|
261
|
+
* The client keeps its stream when the session gains or loses a pane (#723):
|
|
262
|
+
* the daemon sends a `topology` frame where it would otherwise close the
|
|
263
|
+
* stream with 1012 "topology-changed". Offered beside the other versions, not
|
|
264
|
+
* in place of one. The daemon confirms it with `topologyInPlace: true` in the
|
|
265
|
+
* ready frame; without both, nothing changes for either side.
|
|
266
|
+
*/
|
|
267
|
+
export const PANE_STREAM_TOPOLOGY_IN_PLACE_CAPABILITY_VERSION = 119;
|
|
268
|
+
/**
|
|
269
|
+
* 118 and 119 in one number, for a client whose offer array is full (it holds
|
|
270
|
+
* nine, on every daemon, and the Mac app's interactive offer already has
|
|
271
|
+
* nine). Offered in place of 118. A daemon that predates it ignores it and
|
|
272
|
+
* then gives neither, so a client offers it only to a daemon that has it.
|
|
273
|
+
*/
|
|
274
|
+
export const PANE_STREAM_READER_TOPOLOGY_BUNDLE_CAPABILITY_VERSION = 120;
|
|
260
275
|
export const PaneStreamInputLifetimeSchemaZ = z
|
|
261
276
|
.object({
|
|
262
277
|
generation: z.string().min(1).max(256),
|
|
@@ -477,6 +492,8 @@ export const PaneStreamReadyFrameSchemaZ = z
|
|
|
477
492
|
type: z.literal("ready"),
|
|
478
493
|
inputLifetime: z.literal(true).optional(),
|
|
479
494
|
inputBytes: z.literal(true).optional(),
|
|
495
|
+
/** Only to a client that offered capability 119: `topology` frames may follow. */
|
|
496
|
+
topologyInPlace: z.literal(true).optional(),
|
|
480
497
|
protocolVersion: z.literal(PANE_STREAM_PROTOCOL_VERSION),
|
|
481
498
|
daemonInstanceId: BoundedIdentitySchemaZ,
|
|
482
499
|
requestId: z.uuid(),
|
|
@@ -701,6 +718,41 @@ export const PaneStreamFlowFrameSchemaZ = z
|
|
|
701
718
|
})
|
|
702
719
|
.strict();
|
|
703
720
|
|
|
721
|
+
/**
|
|
722
|
+
* Capability 119. The session's pane set changed and the stream stays open.
|
|
723
|
+
* `panes` is the stream's whole pane set from now on, with the meaning it has
|
|
724
|
+
* in the ready frame; `removed` and `added` are its difference from the set
|
|
725
|
+
* before. Sent before the `layout-snapshot` of the same epoch, so a layout
|
|
726
|
+
* never names a pane the client has not been told about. A removed pane's
|
|
727
|
+
* delivery has ended; an added pane's `terminal-delivery-ready` and seed
|
|
728
|
+
* follow the snapshot.
|
|
729
|
+
*/
|
|
730
|
+
export const PaneStreamTopologyFrameSchemaZ = z
|
|
731
|
+
.object({
|
|
732
|
+
type: z.literal("topology"),
|
|
733
|
+
topologyEpoch: z.number().int().nonnegative(),
|
|
734
|
+
panes: PaneSetSchemaZ,
|
|
735
|
+
removed: z.array(PaneStreamSemanticPaneIdSchemaZ).max(PANE_STREAM_MAX_PANES),
|
|
736
|
+
added: z.array(PaneStreamSemanticPaneIdSchemaZ).max(PANE_STREAM_MAX_PANES),
|
|
737
|
+
})
|
|
738
|
+
.strict()
|
|
739
|
+
.superRefine((frame, context) => {
|
|
740
|
+
const panes = new Set(frame.panes);
|
|
741
|
+
const removed = new Set(frame.removed);
|
|
742
|
+
const added = new Set(frame.added);
|
|
743
|
+
if (
|
|
744
|
+
removed.size !== frame.removed.length ||
|
|
745
|
+
added.size !== frame.added.length ||
|
|
746
|
+
frame.added.some((pane) => !panes.has(pane) || removed.has(pane)) ||
|
|
747
|
+
frame.removed.some((pane) => panes.has(pane))
|
|
748
|
+
)
|
|
749
|
+
context.addIssue({
|
|
750
|
+
code: z.ZodIssueCode.custom,
|
|
751
|
+
message: "added panes must be in the set, removed panes must not, and neither may repeat",
|
|
752
|
+
});
|
|
753
|
+
});
|
|
754
|
+
export type PaneStreamTopologyFrame = z.infer<typeof PaneStreamTopologyFrameSchemaZ>;
|
|
755
|
+
|
|
704
756
|
export const PaneStreamClosedFrameSchemaZ = z
|
|
705
757
|
.object({
|
|
706
758
|
type: z.literal("closed"),
|
|
@@ -903,6 +955,7 @@ export const PaneStreamServerFrameSchemaZ = z.discriminatedUnion("type", [
|
|
|
903
955
|
PaneStreamCursorFrameSchemaZ,
|
|
904
956
|
PaneStreamLayoutFrameSchemaZ,
|
|
905
957
|
PaneStreamLayoutSnapshotFrameSchemaZ,
|
|
958
|
+
PaneStreamTopologyFrameSchemaZ,
|
|
906
959
|
PaneStreamFlowFrameSchemaZ,
|
|
907
960
|
PaneStreamClosedFrameSchemaZ,
|
|
908
961
|
PaneStreamInputAckFrameSchemaZ,
|
|
@@ -10,7 +10,9 @@ import { ADOPTED_OPTION } from "../lib/chrome-front-door.js";
|
|
|
10
10
|
let _tmuxRunner = (args) => execFileSync("tmux", ["-u", ...runtimeTmuxArgs(args)], {
|
|
11
11
|
encoding: "utf-8",
|
|
12
12
|
maxBuffer: 1024 * 1024,
|
|
13
|
-
|
|
13
|
+
// Keep stderr on the error: it is how a caller tells "no server running"
|
|
14
|
+
// from a server it could not reach. Nothing is printed either way.
|
|
15
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
14
16
|
}).trim();
|
|
15
17
|
export function _setTmuxRunner(fn) {
|
|
16
18
|
const prev = _tmuxRunner;
|
|
@@ -45,9 +47,20 @@ function semanticPaneIds(session) {
|
|
|
45
47
|
return result;
|
|
46
48
|
}
|
|
47
49
|
export function listTmuxSessions() {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
50
|
+
return readTmuxSessions() ?? [];
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* {@link listTmuxSessions}, but null when tmux could not be asked. Only a
|
|
54
|
+
* server that is not running has no sessions (#753).
|
|
55
|
+
*/
|
|
56
|
+
export function readTmuxSessions() {
|
|
57
|
+
let raw;
|
|
58
|
+
try {
|
|
59
|
+
raw = _tmuxRunner(["list-sessions", "-F", "#{session_name}"]);
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
return serverNotRunning(error) ? [] : null;
|
|
63
|
+
}
|
|
51
64
|
return raw.split("\n").filter(Boolean);
|
|
52
65
|
}
|
|
53
66
|
/**
|
|
@@ -350,7 +363,13 @@ function assembleAdoptedFleet(adopted, panesRaw, registry, nativeEpoch, resolveI
|
|
|
350
363
|
});
|
|
351
364
|
}
|
|
352
365
|
export function discoverSessions() {
|
|
353
|
-
|
|
366
|
+
return readSessions() ?? [];
|
|
367
|
+
}
|
|
368
|
+
/** {@link discoverSessions}, but null when tmux could not be asked (#753). */
|
|
369
|
+
export function readSessions() {
|
|
370
|
+
const sessionNames = readTmuxSessions();
|
|
371
|
+
if (sessionNames === null)
|
|
372
|
+
return null;
|
|
354
373
|
const results = [];
|
|
355
374
|
// Once the workspace registry is loaded (post daemon-embed startup),
|
|
356
375
|
// discovery is gated by registry membership: only registered workspaces
|
|
@@ -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));
|
|
@@ -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,
|