mirror of
https://github.com/Termix-SSH/Termix.git
synced 2026-11-02 08:35:24 +00:00
feat: convert tmux monitoring into a plugin (B10)
This commit is contained in:
1 parent
79d77678c9
commit
708eedb861
145 files changed
+30308
-4458
No files matched your search
@@ -0,0 +1,54 @@
|
||||
import type { Client, ClientChannel } from "ssh2";
|
||||
import type { PluginContext } from "@termix/plugin-sdk/backend";
|
||||
import {
|
||||
attachOrCreateTmuxSession,
|
||||
detectTmux,
|
||||
waitForTmuxSession,
|
||||
} from "./tmux-commands.js";
|
||||
|
||||
export interface TmuxDetection {
|
||||
available: boolean;
|
||||
sessions: string[];
|
||||
}
|
||||
|
||||
/**
|
||||
* What the terminal (ssh-terminal's optional "tmux.sessions" consumer) asks
|
||||
* of this plugin. Clients and streams cross the service boundary as
|
||||
* `unknown`, since the SDK types services without an ssh2 dependency.
|
||||
*/
|
||||
export interface TmuxSessionsV1 {
|
||||
detect: (client: unknown) => Promise<TmuxDetection>;
|
||||
attachOrCreate: (
|
||||
stream: unknown,
|
||||
name?: string,
|
||||
newName?: string,
|
||||
) => Promise<void>;
|
||||
waitForSession: (client: unknown, name: string) => Promise<string>;
|
||||
}
|
||||
|
||||
export function createTmuxSessionsService(ctx: PluginContext): TmuxSessionsV1 {
|
||||
return {
|
||||
async detect(client) {
|
||||
const result = await detectTmux(client as Client);
|
||||
return {
|
||||
available: result.available,
|
||||
sessions: result.sessions.map((s) => s.name),
|
||||
};
|
||||
},
|
||||
|
||||
async attachOrCreate(stream, name, newName) {
|
||||
attachOrCreateTmuxSession(stream as ClientChannel, name, newName);
|
||||
},
|
||||
|
||||
async waitForSession(client, name) {
|
||||
const confirmed = await waitForTmuxSession(client as Client, name);
|
||||
if (!confirmed) {
|
||||
ctx.log.warn(
|
||||
`Timed out waiting for a new tmux session to appear: ${name}`,
|
||||
);
|
||||
return name;
|
||||
}
|
||||
return confirmed;
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user