fix(tmux): pass full session info to the terminal's session picker (#1552)

The tmux.sessions service reduced detected sessions to bare names, but the
picker reads session.name, so every entry rendered blank and selecting one
sent an empty name, which created a new session instead of attaching.
This commit is contained in:
ZacharyZcR authored and GitHub committed 2026-10-03 21:04:04 +08:00
1 parent ab7a68aa84
commit 57151c0e84
3 files changed
+31 -14

No files matched your search

+9 -1
View File
@@ -65,9 +65,17 @@ export interface TerminalHistoryV1 {
list: (hostId: number, limit?: number) => Promise<CommandHistoryEntry[]>; list: (hostId: number, limit?: number) => Promise<CommandHistoryEntry[]>;
} }
export interface TmuxSessionInfo {
name: string;
created: number;
lastActivity: number;
windows: number;
attachedClients: number;
}
export interface TmuxDetection { export interface TmuxDetection {
available: boolean; available: boolean;
sessions: string[]; sessions: TmuxSessionInfo[];
} }
/** /**
+4 -10
View File
@@ -4,12 +4,10 @@ import {
attachOrCreateTmuxSession, attachOrCreateTmuxSession,
detectTmux, detectTmux,
waitForTmuxSession, waitForTmuxSession,
type TmuxDetectionResult,
} from "./tmux-commands.js"; } from "./tmux-commands.js";
export interface TmuxDetection { export type TmuxDetection = TmuxDetectionResult;
available: boolean;
sessions: string[];
}
/** /**
* What the terminal (ssh-terminal's optional "tmux.sessions" consumer) asks * What the terminal (ssh-terminal's optional "tmux.sessions" consumer) asks
@@ -29,12 +27,8 @@ export interface TmuxSessionsV1 {
export function createTmuxSessionsService(ctx: PluginContext): TmuxSessionsV1 { export function createTmuxSessionsService(ctx: PluginContext): TmuxSessionsV1 {
return { return {
async detect(client) { detect(client) {
const result = await detectTmux(client as Client); return detectTmux(client as Client);
return {
available: result.available,
sessions: result.sessions.map((s) => s.name),
};
}, },
async attachOrCreate(stream, name, newName, hostId) { async attachOrCreate(stream, name, newName, hostId) {
@@ -38,17 +38,32 @@ describe("createTmuxSessionsService", () => {
}); });
}); });
it("detect() lists session names when tmux is available", async () => { it("detect() lists full session info when tmux is available", async () => {
const { ctx } = createFakeContext({ pluginId: "tmux-monitor" }); const { ctx } = createFakeContext({ pluginId: "tmux-monitor" });
const service = createTmuxSessionsService(ctx); const service = createTmuxSessionsService(ctx);
const client = fakeSshClient({ const client = fakeSshClient({
"-V": "tmux 3.7b\n", "-V": "tmux 3.7b\n",
"list-sessions": "main|1|2|1\nlogs|3|4|0\n", "list-sessions": "main|1|2|3|1\nlogs|4|5|1|0\n",
}); });
await expect(service.detect(client)).resolves.toEqual({ await expect(service.detect(client)).resolves.toEqual({
available: true, available: true,
sessions: ["main", "logs"], sessions: [
{
name: "main",
created: 1,
lastActivity: 2,
windows: 3,
attachedClients: 1,
},
{
name: "logs",
created: 4,
lastActivity: 5,
windows: 1,
attachedClients: 0,
},
],
}); });
}); });