@ebowwa/terminal 0.3.4 → 0.3.6

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.
@@ -0,0 +1,327 @@
1
+ /**
2
+ * Multi-Node Tmux Session Manager
3
+ * Provides unified management of tmux sessions across multiple VPS nodes
4
+ * Supports batch operations, session tracking, and parallel execution
5
+ */
6
+ /**
7
+ * Represents a single node (server) in the cluster
8
+ */
9
+ export interface Node {
10
+ /** Unique identifier (server ID from Hetzner) */
11
+ id: string;
12
+ /** Server name */
13
+ name: string;
14
+ /** IPv4 address */
15
+ ip: string;
16
+ /** IPv6 address (optional) */
17
+ ipv6?: string | null;
18
+ /** SSH user */
19
+ user: string;
20
+ /** SSH port */
21
+ port: number;
22
+ /** SSH key path (optional) */
23
+ keyPath?: string;
24
+ /** Node status */
25
+ status: "running" | "stopped" | "unreachable";
26
+ /** Metadata tags */
27
+ tags?: string[];
28
+ /** Datacenter location */
29
+ location?: string;
30
+ }
31
+ /**
32
+ * Represents a tmux session on a node
33
+ */
34
+ export interface TmuxSession {
35
+ /** Session name */
36
+ name: string;
37
+ /** Node ID */
38
+ nodeId: string;
39
+ /** Number of windows */
40
+ windows?: number;
41
+ /** Number of panes */
42
+ panes?: number;
43
+ /** Session exists */
44
+ exists: boolean;
45
+ }
46
+ /**
47
+ * Detailed session information with windows and panes
48
+ */
49
+ export interface DetailedTmuxSession extends TmuxSession {
50
+ windows: Array<{
51
+ index: string;
52
+ name: string;
53
+ active: boolean;
54
+ panes: Array<{
55
+ index: string;
56
+ currentPath: string;
57
+ pid: string;
58
+ active: boolean;
59
+ }>;
60
+ }>;
61
+ }
62
+ /**
63
+ * Batch operation result across multiple nodes
64
+ */
65
+ export interface BatchOperationResult<T = any> {
66
+ /** Total nodes in batch */
67
+ total: number;
68
+ /** Successful operations */
69
+ successful: number;
70
+ /** Failed operations */
71
+ failed: number;
72
+ /** Results per node */
73
+ results: Array<{
74
+ nodeId: string;
75
+ nodeName: string;
76
+ success: boolean;
77
+ data?: T;
78
+ error?: string;
79
+ }>;
80
+ }
81
+ /**
82
+ * Options for creating a new tmux session
83
+ */
84
+ export interface CreateSessionOptions {
85
+ /** Session name (auto-generated if not provided) */
86
+ sessionName?: string;
87
+ /** Initial working directory */
88
+ cwd?: string;
89
+ /** Initial command to run */
90
+ initialCommand?: string;
91
+ /** Window layout */
92
+ layout?: "even-horizontal" | "even-vertical" | "main-horizontal" | "main-vertical" | "tiled";
93
+ }
94
+ /**
95
+ * Options for batch command execution
96
+ */
97
+ export interface BatchCommandOptions {
98
+ /** Command to execute */
99
+ command: string;
100
+ /** Target pane index (default: "0") */
101
+ paneIndex?: string;
102
+ /** Execute in parallel (default: true) */
103
+ parallel?: boolean;
104
+ /** Continue on error (default: true) */
105
+ continueOnError?: boolean;
106
+ /** Timeout per node (seconds) */
107
+ timeout?: number;
108
+ }
109
+ /**
110
+ * Options for multi-node session queries
111
+ */
112
+ export interface SessionQueryOptions {
113
+ /** Filter by node IDs */
114
+ nodeIds?: string[];
115
+ /** Filter by tags */
116
+ tags?: string[];
117
+ /** Include detailed session info */
118
+ detailed?: boolean;
119
+ /** Include inactive sessions */
120
+ includeInactive?: boolean;
121
+ }
122
+ /**
123
+ * Multi-Node Tmux Session Manager
124
+ * Manages tmux sessions across multiple VPS nodes
125
+ */
126
+ export declare class TmuxSessionManager {
127
+ private nodes;
128
+ private sessionCache;
129
+ private cacheTimeout;
130
+ private lastCacheUpdate;
131
+ /**
132
+ * Add or update a node in the manager
133
+ */
134
+ addNode(node: Node): void;
135
+ /**
136
+ * Remove a node from the manager
137
+ */
138
+ removeNode(nodeId: string): void;
139
+ /**
140
+ * Get a node by ID
141
+ */
142
+ getNode(nodeId: string): Node | undefined;
143
+ /**
144
+ * Get all nodes
145
+ */
146
+ getAllNodes(): Node[];
147
+ /**
148
+ * Get nodes by tag
149
+ */
150
+ getNodesByTag(tag: string): Node[];
151
+ /**
152
+ * Get active nodes (running and reachable)
153
+ */
154
+ getActiveNodes(): Node[];
155
+ /**
156
+ * Get SSH options for a node
157
+ */
158
+ private getSSHOptions;
159
+ /**
160
+ * Invalidate session cache for a node or all nodes
161
+ */
162
+ invalidateCache(nodeId?: string): void;
163
+ /**
164
+ * Check if cache is valid for a node
165
+ */
166
+ private isCacheValid;
167
+ /**
168
+ * Create a new tmux session on a node
169
+ */
170
+ createSession(nodeId: string, options?: CreateSessionOptions): Promise<{
171
+ success: boolean;
172
+ sessionName?: string;
173
+ error?: string;
174
+ }>;
175
+ /**
176
+ * Attach to a tmux session on a node (returns SSH command args)
177
+ */
178
+ attachSession(nodeId: string, sessionName?: string): Promise<{
179
+ success: true;
180
+ sshArgs: string[];
181
+ sessionName: string;
182
+ } | {
183
+ success: false;
184
+ error: string;
185
+ }>;
186
+ /**
187
+ * List all sessions across nodes
188
+ */
189
+ listSessions(options?: SessionQueryOptions): Promise<TmuxSession[]>;
190
+ /**
191
+ * Get detailed session information
192
+ */
193
+ getDetailedSession(nodeId: string, sessionName: string): Promise<DetailedTmuxSession | null>;
194
+ /**
195
+ * Kill a session on a node
196
+ */
197
+ killSession(nodeId: string, sessionName: string): Promise<{
198
+ success: boolean;
199
+ error?: string;
200
+ }>;
201
+ /**
202
+ * Send a command to a specific session on a node
203
+ */
204
+ sendCommand(nodeId: string, sessionName: string, command: string, paneIndex?: string): Promise<{
205
+ success: boolean;
206
+ error?: string;
207
+ }>;
208
+ /**
209
+ * Send command to multiple nodes (batch operation)
210
+ */
211
+ sendCommandToNodes(nodeIds: string[], sessionName: string, command: string, options?: BatchCommandOptions): Promise<BatchOperationResult>;
212
+ /**
213
+ * Split a pane in a session
214
+ */
215
+ splitPaneOnNode(nodeId: string, sessionName: string, direction?: "h" | "v", command?: string | null, windowIndex?: string): Promise<{
216
+ success: boolean;
217
+ newPaneIndex?: string;
218
+ error?: string;
219
+ }>;
220
+ /**
221
+ * Capture pane output from a session
222
+ */
223
+ capturePaneOutput(nodeId: string, sessionName: string, paneIndex?: string): Promise<{
224
+ success: boolean;
225
+ output?: string;
226
+ error?: string;
227
+ }>;
228
+ /**
229
+ * Get pane history (scrollback buffer)
230
+ */
231
+ getPaneHistory(nodeId: string, sessionName: string, paneIndex?: string, lines?: number): Promise<{
232
+ success: boolean;
233
+ history?: string;
234
+ error?: string;
235
+ }>;
236
+ /**
237
+ * List windows in a session
238
+ */
239
+ listWindows(nodeId: string, sessionName: string): Promise<{
240
+ success: boolean;
241
+ windows?: Array<{
242
+ index: string;
243
+ name: string;
244
+ active: boolean;
245
+ }>;
246
+ error?: string;
247
+ }>;
248
+ /**
249
+ * List panes in a window
250
+ */
251
+ listPanes(nodeId: string, sessionName: string, windowIndex?: string): Promise<{
252
+ success: boolean;
253
+ panes?: Array<{
254
+ index: string;
255
+ currentPath: string;
256
+ pid: string;
257
+ active: boolean;
258
+ }>;
259
+ error?: string;
260
+ }>;
261
+ /**
262
+ * Switch to a different window in a session
263
+ */
264
+ switchToWindow(nodeId: string, sessionName: string, windowIndex: string): Promise<{
265
+ success: boolean;
266
+ error?: string;
267
+ }>;
268
+ /**
269
+ * Switch to a different pane in a session
270
+ */
271
+ switchToPane(nodeId: string, sessionName: string, paneIndex: string): Promise<{
272
+ success: boolean;
273
+ error?: string;
274
+ }>;
275
+ /**
276
+ * Rename a window in a session
277
+ */
278
+ renameWindowInSession(nodeId: string, sessionName: string, windowIndex: string, newName: string): Promise<{
279
+ success: boolean;
280
+ error?: string;
281
+ }>;
282
+ /**
283
+ * Kill a pane in a session
284
+ */
285
+ killPaneInSession(nodeId: string, sessionName: string, paneIndex: string): Promise<{
286
+ success: boolean;
287
+ error?: string;
288
+ }>;
289
+ /**
290
+ * Cleanup old sessions on a node
291
+ */
292
+ cleanupOldSessions(nodeId: string, ageLimitMs?: number): Promise<{
293
+ success: boolean;
294
+ cleaned?: number;
295
+ errors?: string[];
296
+ }>;
297
+ /**
298
+ * Get resource usage for sessions on a node
299
+ */
300
+ getResourceUsage(nodeId: string): Promise<{
301
+ success: boolean;
302
+ usage?: {
303
+ totalSessions: number;
304
+ codespacesSessions: number;
305
+ estimatedMemoryMB: number;
306
+ };
307
+ error?: string;
308
+ }>;
309
+ /**
310
+ * Get summary statistics across all nodes
311
+ */
312
+ getSummary(): Promise<{
313
+ totalNodes: number;
314
+ activeNodes: number;
315
+ totalSessions: number;
316
+ totalMemoryUsageMB: number;
317
+ nodesWithSessions: number;
318
+ }>;
319
+ }
320
+ /**
321
+ * Get the global tmux session manager instance
322
+ */
323
+ export declare function getTmuxManager(): TmuxSessionManager;
324
+ /**
325
+ * Reset the global manager (for testing)
326
+ */
327
+ export declare function resetTmuxManager(): void;
package/dist/tmux.d.ts ADDED
@@ -0,0 +1,212 @@
1
+ /**
2
+ * tmux-based Terminal Sessions
3
+ * Provides persistent terminal sessions using tmux on remote servers
4
+ * Includes automatic tmux installation and session management
5
+ */
6
+ import type { SSHOptions } from "./types.js";
7
+ /**
8
+ * tmux session configuration
9
+ */
10
+ interface TmuxConfig {
11
+ /** Session name prefix for codespaces sessions */
12
+ sessionPrefix: string;
13
+ /** Default shell to use in tmux */
14
+ defaultShell: string;
15
+ /** Terminal type */
16
+ term: string;
17
+ /** Timeout for SSH commands (seconds) */
18
+ timeout: number;
19
+ /** Scrollback limit (lines) */
20
+ historyLimit: number;
21
+ /** Session age limit for cleanup (milliseconds) */
22
+ sessionAgeLimit: number;
23
+ }
24
+ /**
25
+ * Generate a tmux session name for a host
26
+ */
27
+ export declare function generateSessionName(host: string, user?: string): string;
28
+ /**
29
+ * Check if tmux is installed on the remote server
30
+ */
31
+ export declare function isTmuxInstalled(options: SSHOptions): Promise<boolean>;
32
+ /**
33
+ * Install tmux on the remote server
34
+ *
35
+ * FALLBACK MECHANISM: This should NOT be the primary installation method.
36
+ * tmux should be installed via cloud-init during initial node provisioning.
37
+ *
38
+ * This function exists for:
39
+ * - Legacy nodes provisioned before cloud-init included tmux
40
+ * - Manual node provisioning outside cheapspaces
41
+ * - Recovery scenarios where cloud-init failed
42
+ *
43
+ * @see workspace/docs/design/node-agent/TMUX-INSTALLATION.md
44
+ * @see workspace/src/lib/bootstrap/cloud-init.ts - where tmux should be added to packages
45
+ *
46
+ * Supports Debian/Ubuntu (apt) and CentOS/RHEL (yum/dnf)
47
+ */
48
+ export declare function installTmux(options: SSHOptions): Promise<{
49
+ success: boolean;
50
+ message: string;
51
+ }>;
52
+ /**
53
+ * Ensure tmux is available, installing if necessary
54
+ */
55
+ export declare function ensureTmux(options: SSHOptions): Promise<{
56
+ success: boolean;
57
+ message: string;
58
+ }>;
59
+ /**
60
+ * List existing tmux sessions on the remote server
61
+ */
62
+ export declare function listTmuxSessions(options: SSHOptions): Promise<string[]>;
63
+ /**
64
+ * Check if a specific tmux session exists
65
+ */
66
+ export declare function hasTmuxSession(sessionName: string, options: SSHOptions): Promise<boolean>;
67
+ /**
68
+ * Create or attach to a tmux session
69
+ * Returns the SSH command arguments to connect to the tmux session
70
+ */
71
+ export declare function createOrAttachTmuxSession(host: string, user?: string, keyPath?: string, config?: Partial<TmuxConfig>): Promise<{
72
+ sshArgs: string[];
73
+ sessionName: string;
74
+ newlyCreated: boolean;
75
+ }>;
76
+ /**
77
+ * Kill a tmux session on the remote server
78
+ */
79
+ export declare function killTmuxSession(sessionName: string, options: SSHOptions): Promise<boolean>;
80
+ /**
81
+ * Get tmux session information
82
+ */
83
+ export declare function getTmuxSessionInfo(sessionName: string, options: SSHOptions): Promise<{
84
+ exists: boolean;
85
+ windows?: number;
86
+ panes?: number;
87
+ } | null>;
88
+ /**
89
+ * Cleanup old tmux sessions on a remote server
90
+ * Kills sessions with matching prefix that are older than specified age limit
91
+ * @param options SSH connection options
92
+ * @param config Optional configuration (uses default age limit if not provided)
93
+ * @returns Object with cleaned count and errors
94
+ */
95
+ export declare function cleanupOldTmuxSessions(options: SSHOptions, config?: Partial<TmuxConfig>): Promise<{
96
+ cleaned: number;
97
+ errors: string[];
98
+ }>;
99
+ /**
100
+ * Get resource usage information for tmux sessions on a remote server
101
+ * @param options SSH connection options
102
+ * @returns Resource usage summary
103
+ */
104
+ export declare function getTmuxResourceUsage(options: SSHOptions): Promise<{
105
+ totalSessions: number;
106
+ codespacesSessions: number;
107
+ estimatedMemoryMB: number;
108
+ } | null>;
109
+ /**
110
+ * Send a command to a specific pane in a tmux session
111
+ * @param sessionName Target tmux session name
112
+ * @param paneIndex Pane index (default: 0 for first pane)
113
+ * @param command Command to execute (sent as keystrokes)
114
+ * @param options SSH connection options
115
+ */
116
+ export declare function sendCommandToPane(sessionName: string, command: string, paneIndex: string, options: SSHOptions): Promise<boolean>;
117
+ /**
118
+ * Split a pane horizontally or vertically in a tmux session
119
+ * @param sessionName Target tmux session name
120
+ * @param windowIndex Window index (default: 0)
121
+ * @param direction Split direction: "h" (horizontal) or "v" (vertical)
122
+ * @param command Optional command to run in the new pane
123
+ * @param options SSH connection options
124
+ * @returns The new pane index
125
+ */
126
+ export declare function splitPane(sessionName: string, direction: "h" | "v", command: string | null, options: SSHOptions): Promise<string | null>;
127
+ /**
128
+ * List all windows in a tmux session
129
+ * @param sessionName Target tmux session name
130
+ * @param options SSH connection options
131
+ */
132
+ export declare function listSessionWindows(sessionName: string, options: SSHOptions): Promise<Array<{
133
+ index: string;
134
+ name: string;
135
+ active: boolean;
136
+ }>>;
137
+ /**
138
+ * List all panes in a tmux session window
139
+ * @param sessionName Target tmux session name
140
+ * @param windowIndex Window index (default: 0)
141
+ * @param options SSH connection options
142
+ */
143
+ export declare function listWindowPanes(sessionName: string, windowIndex: string, options: SSHOptions): Promise<Array<{
144
+ index: string;
145
+ currentPath: string;
146
+ pid: string;
147
+ active: boolean;
148
+ }>>;
149
+ /**
150
+ * Capture the current output of a pane
151
+ * @param sessionName Target tmux session name
152
+ * @param paneIndex Pane index (default: 0)
153
+ * @param options SSH connection options
154
+ */
155
+ export declare function capturePane(sessionName: string, paneIndex: string, options: SSHOptions): Promise<string | null>;
156
+ /**
157
+ * Get scrollback/history from a pane
158
+ * @param sessionName Target tmux session name
159
+ * @param paneIndex Pane index (default: 0)
160
+ * @param lines Number of lines to retrieve (default: all)
161
+ * @param options SSH connection options
162
+ */
163
+ export declare function getPaneHistory(sessionName: string, paneIndex: string, lines: number, options: SSHOptions): Promise<string | null>;
164
+ /**
165
+ * Switch to a specific window in a tmux session
166
+ * @param sessionName Target tmux session name
167
+ * @param windowIndex Target window index
168
+ * @param options SSH connection options
169
+ */
170
+ export declare function switchWindow(sessionName: string, windowIndex: string, options: SSHOptions): Promise<boolean>;
171
+ /**
172
+ * Switch to a specific pane in a tmux session window
173
+ * @param sessionName Target tmux session name
174
+ * @param paneIndex Target pane index (e.g., "0", "1", "0.1" for window.pane)
175
+ * @param options SSH connection options
176
+ */
177
+ export declare function switchPane(sessionName: string, paneIndex: string, options: SSHOptions): Promise<boolean>;
178
+ /**
179
+ * Rename a window in a tmux session
180
+ * @param sessionName Target tmux session name
181
+ * @param windowIndex Window index (default: 0)
182
+ * @param newName New window name
183
+ * @param options SSH connection options
184
+ */
185
+ export declare function renameWindow(sessionName: string, windowIndex: string, newName: string, options: SSHOptions): Promise<boolean>;
186
+ /**
187
+ * Kill a specific pane in a tmux session
188
+ * @param sessionName Target tmux session name
189
+ * @param paneIndex Pane index to kill
190
+ * @param options SSH connection options
191
+ */
192
+ export declare function killPane(sessionName: string, paneIndex: string, options: SSHOptions): Promise<boolean>;
193
+ /**
194
+ * Get detailed information about all panes in a session
195
+ * @param sessionName Target tmux session name
196
+ * @param options SSH connection options
197
+ */
198
+ export declare function getDetailedSessionInfo(sessionName: string, options: SSHOptions): Promise<{
199
+ exists: boolean;
200
+ windows: Array<{
201
+ index: string;
202
+ name: string;
203
+ active: boolean;
204
+ panes: Array<{
205
+ index: string;
206
+ currentPath: string;
207
+ pid: string;
208
+ active: boolean;
209
+ }>;
210
+ }>;
211
+ } | null>;
212
+ export {};
@@ -0,0 +1,17 @@
1
+ /**
2
+ * SSH type definitions
3
+ */
4
+ export interface SSHOptions {
5
+ host: string;
6
+ user?: string;
7
+ timeout?: number;
8
+ port?: number;
9
+ keyPath?: string;
10
+ password?: string;
11
+ }
12
+ export interface SCPOptions extends SSHOptions {
13
+ source: string;
14
+ destination: string;
15
+ recursive?: boolean;
16
+ preserve?: boolean;
17
+ }
package/package.json CHANGED
@@ -1,57 +1,29 @@
1
1
  {
2
2
  "name": "@ebowwa/terminal",
3
- "version": "0.3.4",
3
+ "version": "0.3.6",
4
4
  "description": "Terminal session management with tmux integration, SSH client, WebSocket support, and MCP interface",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",
8
8
  "exports": {
9
- ".": "./dist/index.js",
10
- "./mcp": "./dist/mcp/index.js",
11
- "./client": "./dist/index.js"
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "default": "./dist/index.js"
12
12
  },
13
- "scripts": {
14
- "build": "bun build src/index.ts --outdir dist --target bun --external 'node-ssh' --external 'hono' --external 'zod' --external 'node:*' && bun build src/mcp/index.ts --outdir dist/mcp --target bun --external 'node-ssh' --external 'hono' --external 'zod' --external 'node:*' --external '@modelcontextprotocol/*'",
15
- "prepublishOnly": "bun run build"
16
- },
17
- "files": [
18
- "dist"
19
- ],
20
- "keywords": [
21
- "terminal",
22
- "tmux",
23
- "ssh",
24
- "session",
25
- "websocket",
26
- "mcp",
27
- "pty",
28
- "cli",
29
- "remote"
30
- ],
31
- "author": "Ebowwa Labs <labs@ebowwa.com>",
32
- "license": "MIT",
33
- "homepage": "https://github.com/ebowwa/terminal#readme",
34
- "repository": {
35
- "type": "git",
36
- "url": "git+https://github.com/ebowwa/terminal.git",
37
- "directory": "/"
38
- },
39
- "bugs": {
40
- "url": "https://github.com/ebowwa/terminal/issues"
41
- },
42
- "engines": {
43
- "node": ">=18.0.0"
44
- },
45
- "dependencies": {
46
- "@ebowwa/codespaces-types": "^1.4.0",
47
- "@ebowwa/ssh": "^0.2.1",
48
- "node-ssh": "^13.2.1",
49
- "hono": "^4.11.3",
50
- "zod": "^3.24.1"
51
- },
52
- "devDependencies": {
53
- "@types/bun": "latest",
54
- "@types/node-ssh": "^11.0.0",
55
- "typescript": "^5.9.3"
56
- }
13
+ "./mcp": {
14
+ "types": "./dist/mcp/index.d.ts",
15
+ "default": "./dist/mcp/index.js"
16
+ },
17
+ "./types": {
18
+ "types": "./dist/types.d.ts",
19
+ "default": "./dist/types.d.ts"
20
+ }
21
+ },
22
+ "files": ["dist"],
23
+ "keywords": ["terminal", "tmux", "ssh", "mcp"],
24
+ "author": "Ebowwa Labs <labs@ebowwa.com>",
25
+ "license": "MIT",
26
+ "dependencies": {
27
+ "zod": "^3.24.1"
28
+ }
57
29
  }