@ebowwa/terminal 0.3.1 → 0.3.2

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.
Files changed (77) hide show
  1. package/package.json +8 -70
  2. package/dist/api.d.ts +0 -7
  3. package/dist/client.d.ts +0 -14
  4. package/dist/config.d.ts +0 -85
  5. package/dist/cpufeatures-vxqw2k6s.node +0 -0
  6. package/dist/error.d.ts +0 -7
  7. package/dist/exec.d.ts +0 -46
  8. package/dist/files.d.ts +0 -123
  9. package/dist/fingerprint.d.ts +0 -66
  10. package/dist/index.d.ts +0 -20
  11. package/dist/manager.d.ts +0 -102
  12. package/dist/mcp/cpufeatures-vxqw2k6s.node +0 -0
  13. package/dist/mcp/index.d.ts +0 -8
  14. package/dist/mcp/sshcrypto-gez6h7ch.node +0 -0
  15. package/dist/mcp/stdio.d.ts +0 -8
  16. package/dist/network-error-detector.d.ts +0 -18
  17. package/dist/pool.d.ts +0 -142
  18. package/dist/pty.d.ts +0 -58
  19. package/dist/resources.d.ts +0 -62
  20. package/dist/scp.d.ts +0 -29
  21. package/dist/sessions.d.ts +0 -100
  22. package/dist/sshcrypto-gez6h7ch.node +0 -0
  23. package/dist/tmux-exec.d.ts +0 -49
  24. package/dist/tmux-local.d.ts +0 -272
  25. package/dist/tmux-manager.d.ts +0 -327
  26. package/dist/tmux.d.ts +0 -212
  27. package/dist/types.d.ts +0 -17
  28. package/mcp/README.md +0 -181
  29. package/mcp/package.json +0 -40
  30. package/mcp/stdio.js +0 -555
  31. package/mcp/test-fix.sh +0 -273
  32. package/mcp/wrapper.mjs +0 -10
  33. package/src/api.js +0 -861
  34. package/src/api.ts +0 -752
  35. package/src/client.js +0 -92
  36. package/src/client.ts +0 -55
  37. package/src/config.js +0 -490
  38. package/src/config.ts +0 -489
  39. package/src/error.js +0 -32
  40. package/src/error.ts +0 -13
  41. package/src/exec.js +0 -183
  42. package/src/exec.ts +0 -128
  43. package/src/files.js +0 -521
  44. package/src/files.ts +0 -636
  45. package/src/fingerprint.js +0 -336
  46. package/src/fingerprint.ts +0 -263
  47. package/src/index.js +0 -127
  48. package/src/index.ts +0 -148
  49. package/src/manager.js +0 -358
  50. package/src/manager.ts +0 -319
  51. package/src/mcp/index.js +0 -555
  52. package/src/mcp/index.ts +0 -467
  53. package/src/mcp/stdio.js +0 -840
  54. package/src/mcp/stdio.ts +0 -708
  55. package/src/network-error-detector.js +0 -101
  56. package/src/network-error-detector.ts +0 -121
  57. package/src/pool.js +0 -840
  58. package/src/pool.ts +0 -662
  59. package/src/pty.js +0 -344
  60. package/src/pty.ts +0 -285
  61. package/src/resources.js +0 -64
  62. package/src/resources.ts +0 -72
  63. package/src/scp.js +0 -166
  64. package/src/scp.ts +0 -109
  65. package/src/sessions.js +0 -895
  66. package/src/sessions.ts +0 -861
  67. package/src/tmux-exec.js +0 -169
  68. package/src/tmux-exec.ts +0 -96
  69. package/src/tmux-local.js +0 -937
  70. package/src/tmux-local.ts +0 -839
  71. package/src/tmux-manager.js +0 -1026
  72. package/src/tmux-manager.ts +0 -962
  73. package/src/tmux.js +0 -826
  74. package/src/tmux.ts +0 -711
  75. package/src/types.js +0 -5
  76. package/src/types.ts +0 -19
  77. package/tsconfig.json +0 -28
package/dist/pool.d.ts DELETED
@@ -1,142 +0,0 @@
1
- /**
2
- * SSH Connection Pool Manager
3
- * Maintains persistent SSH connections for reuse across commands
4
- */
5
- import { NodeSSH } from 'node-ssh';
6
- import type { SSHOptions } from './types.js';
7
- /**
8
- * Connection pool configuration
9
- */
10
- interface PoolConfig {
11
- /** Maximum number of connections to keep alive across all hosts */
12
- maxConnections: number;
13
- /** Maximum number of connections per host (for parallel execution) */
14
- maxConnectionsPerHost: number;
15
- /** Idle timeout in milliseconds (default: 5 minutes) */
16
- idleTimeout: number;
17
- /** Connection timeout in milliseconds (default: 10 seconds) */
18
- connectionTimeout: number;
19
- /** Keep alive interval in milliseconds (default: 30 seconds) */
20
- keepAliveInterval: number;
21
- }
22
- /**
23
- * SSH Connection Pool Class
24
- */
25
- export declare class SSHConnectionPool {
26
- private connections;
27
- private config;
28
- private cleanupInterval;
29
- private nextId;
30
- constructor(config?: Partial<PoolConfig>);
31
- /**
32
- * Generate a unique key for the connection (host-based)
33
- */
34
- private getKey;
35
- /**
36
- * Get all connections for a given host
37
- */
38
- private getConnectionsList;
39
- /**
40
- * Get or create a connection (returns least recently used connection)
41
- */
42
- getConnection(options: SSHOptions): Promise<NodeSSH>;
43
- /**
44
- * Get or create a connection using password authentication
45
- */
46
- getConnectionWithPassword(host: string, user: string, password: string, port?: number): Promise<NodeSSH>;
47
- /**
48
- * Get or create multiple connections for parallel execution
49
- * @param options - SSH connection options
50
- * @param count - Number of connections to retrieve
51
- * @returns Array of SSH connections
52
- */
53
- getConnections(options: SSHOptions, count: number): Promise<NodeSSH[]>;
54
- /**
55
- * Create a new SSH connection
56
- * Tries key-based auth first, then password auth, then SSH agent
57
- */
58
- private createConnection;
59
- /**
60
- * Get total number of connections across all hosts
61
- */
62
- private getTotalConnectionCount;
63
- /**
64
- * Execute a command using a pooled connection
65
- *
66
- * ERROR HANDLING BEHAVIOR:
67
- * =========================
68
- * If result.stderr exists AND result.stdout is empty, we throw an error.
69
- * This is intentional - commands that fail should return fallback values
70
- * via shell redirection (e.g., `|| echo "0"` or `2>/dev/null`).
71
- *
72
- * Example of proper fallback handling:
73
- * `type nvidia-smi 2>/dev/null && nvidia-smi ... || echo NOGPU`
74
- *
75
- * This ensures commands don't silently fail - they must handle their own
76
- * error cases and return sensible defaults.
77
- */
78
- exec(command: string, options: SSHOptions): Promise<string>;
79
- /**
80
- * Check if a connection exists and is alive for a given host
81
- */
82
- hasConnection(options: SSHOptions): Promise<boolean>;
83
- /**
84
- * Close a specific connection by SSH instance
85
- */
86
- private closeConnectionInstance;
87
- /**
88
- * Close all connections for a specific host
89
- */
90
- closeConnection(options: SSHOptions): Promise<void>;
91
- /**
92
- * Evict the oldest connection from the pool
93
- */
94
- private evictOldest;
95
- /**
96
- * Clean up idle connections
97
- */
98
- private cleanupIdle;
99
- /**
100
- * Start periodic cleanup
101
- */
102
- private startCleanup;
103
- /**
104
- * Stop cleanup interval
105
- */
106
- private stopCleanup;
107
- /**
108
- * Close all connections and stop cleanup
109
- */
110
- closeAll(): Promise<void>;
111
- /**
112
- * Get pool statistics
113
- */
114
- getStats(): {
115
- totalConnections: number;
116
- connections: Array<{
117
- host: string;
118
- port: number;
119
- user: string;
120
- lastUsed: Date;
121
- idleMs: number;
122
- id: string;
123
- }>;
124
- };
125
- /**
126
- * Check if a host has an active connection
127
- */
128
- isConnected(host: string, user?: string, port?: number): boolean;
129
- }
130
- /**
131
- * Get the global connection pool instance
132
- */
133
- export declare function getSSHPool(config?: Partial<PoolConfig>): SSHConnectionPool;
134
- /**
135
- * Close the global pool (for cleanup/shutdown)
136
- */
137
- export declare function closeGlobalSSHPool(): Promise<void>;
138
- /**
139
- * Get active SSH connections (for monitoring)
140
- */
141
- export declare function getActiveSSHConnections(): ReturnType<SSHConnectionPool['getStats']>;
142
- export {};
package/dist/pty.d.ts DELETED
@@ -1,58 +0,0 @@
1
- /**
2
- * SSH PTY session manager for interactive terminal sessions
3
- * Handles bidirectional communication with remote shells
4
- */
5
- interface PTYSession {
6
- id: string;
7
- host: string;
8
- user: string;
9
- proc: any;
10
- stdin: WritableStream<Uint8Array>;
11
- stdout: ReadableStream<Uint8Array>;
12
- stderr: ReadableStream<Uint8Array>;
13
- rows: number;
14
- cols: number;
15
- createdAt: number;
16
- }
17
- /**
18
- * Create a new SSH PTY session
19
- * Uses script or expect to wrap SSH with PTY allocation
20
- */
21
- export declare function createPTYSession(host: string, user?: string, options?: {
22
- rows?: number;
23
- cols?: number;
24
- port?: number;
25
- keyPath?: string;
26
- }): Promise<{
27
- sessionId: string;
28
- initialOutput: string;
29
- }>;
30
- /**
31
- * Write data to PTY session stdin
32
- */
33
- export declare function writeToPTY(sessionId: string, data: string): Promise<boolean>;
34
- /**
35
- * Set PTY size (rows and columns)
36
- */
37
- export declare function setPTYSize(sessionId: string, rows: number, cols: number): Promise<boolean>;
38
- /**
39
- * Read from PTY session stdout (non-blocking)
40
- */
41
- export declare function readFromPTY(sessionId: string, timeout?: number): Promise<string | null>;
42
- /**
43
- * Close PTY session
44
- */
45
- export declare function closePTYSession(sessionId: string): Promise<boolean>;
46
- /**
47
- * Get session info
48
- */
49
- export declare function getPTYSession(sessionId: string): PTYSession | undefined;
50
- /**
51
- * Get all active sessions
52
- */
53
- export declare function getActivePTYSessions(): PTYSession[];
54
- /**
55
- * Clean up stale sessions (older than specified milliseconds)
56
- */
57
- export declare function cleanupStaleSessions(maxAge?: number): void;
58
- export {};
@@ -1,62 +0,0 @@
1
- /**
2
- * Resource monitoring commands for remote servers
3
- *
4
- * SSH commands for fetching system resources via execSSHParallel
5
- * Returns: raw command string to execute via SSH
6
- *
7
- * Commands avoid complex quoting for reliable SSH execution
8
- */
9
- /**
10
- * SSH commands for fetching system resources
11
- * Each command returns space-separated values for easy parsing
12
- */
13
- export declare const RESOURCE_COMMANDS: {
14
- /**
15
- * CPU usage percentage
16
- * Format: "12.5" (user+system as percentage of total)
17
- */
18
- readonly cpu: "cat /proc/stat | head -1 | awk '{print ($2+$4)*100/($2+$4+$5)}'";
19
- /**
20
- * Memory usage - reads from /proc/meminfo
21
- * Format: "percent used_gb total_gb"
22
- * Example: "17.5 0.7 3.7"
23
- */
24
- readonly memory: "cat /proc/meminfo | grep -E '^MemTotal|^MemAvailable' | awk '{if(NR==1)t=$2; else a=$2} END {print (t-a)*100/t, (t-a)/1024/1024, t/1024/1024}'";
25
- /**
26
- * Disk usage for root partition
27
- * Format: "percent used_size total_size"
28
- * Example: "4% 2.8G 75G"
29
- */
30
- readonly disk: "df -h / | grep -v '^Filesystem' | awk '{print $5, $3, $2}' | head -1";
31
- /**
32
- * GPU usage (if NVIDIA GPU present)
33
- * Format: "utilization_percent memory_used_mb memory_total_mb" or "NOGPU"
34
- */
35
- readonly gpu: "type nvidia-smi 2>/dev/null && nvidia-smi --query-gpu=utilization.gpu,memory.used,memory.total --format=csv,noheader,nounits | head -1 || echo NOGPU";
36
- /**
37
- * Network I/O bytes (total rx/tx since boot)
38
- * Format: "rx_bytes tx_bytes"
39
- */
40
- readonly network: "cat /proc/net/dev | grep -E ': ' | head -1 | awk '{print $2, $10}'";
41
- /**
42
- * Load average (1min, 5min, 15min)
43
- * Format: "1min 5min 15min"
44
- */
45
- readonly loadavg: "cut -d' ' -f1-3 /proc/loadavg";
46
- /**
47
- * Active process count
48
- * Format: "count"
49
- */
50
- readonly processes: "ls /proc 2>/dev/null | grep -cE '^[0-9]+$'";
51
- /**
52
- * Active network connections (established + listening)
53
- * Format: "count"
54
- */
55
- readonly connections: "cat /proc/net/tcp /proc/net/tcp6 2>/dev/null | wc -l";
56
- /**
57
- * Active listening ports (hex format)
58
- * Format: "port1;port2;..." or empty
59
- */
60
- readonly ports: "cat /proc/net/tcp /proc/net/tcp6 2>/dev/null | grep -v 'local_address' | awk '{print $2}' | cut -d: -f2 | sort -u | tr '\\n' ';' | sed 's/;$//'";
61
- };
62
- export type ResourceCommand = keyof typeof RESOURCE_COMMANDS;
package/dist/scp.d.ts DELETED
@@ -1,29 +0,0 @@
1
- /**
2
- * SCP/SFTP file transfer operations
3
- * Uses SSH connection pool and SFTP for efficient transfers
4
- */
5
- import type { SCPOptions } from "./types.js";
6
- /**
7
- * Upload a file to remote server via SFTP
8
- * @param options - SCP options including source and destination
9
- * @returns True if successful
10
- */
11
- export declare function scpUpload(options: SCPOptions): Promise<boolean>;
12
- /**
13
- * Download a file from remote server via SFTP
14
- * @param options - SCP options including source (remote) and destination (local)
15
- * @returns True if successful
16
- */
17
- export declare function scpDownload(options: SCPOptions): Promise<boolean>;
18
- /**
19
- * Upload a directory to remote server via SFTP
20
- * @param options - SCP options with source directory
21
- * @returns True if successful
22
- */
23
- export declare function scpUploadDirectory(options: SCPOptions): Promise<boolean>;
24
- /**
25
- * Download a directory from remote server via SFTP
26
- * @param options - SCP options with source directory
27
- * @returns True if successful
28
- */
29
- export declare function scpDownloadDirectory(options: SCPOptions): Promise<boolean>;
@@ -1,100 +0,0 @@
1
- /**
2
- * Terminal Session Management
3
- * Handles SSH PTY session lifecycle, persistence, and querying
4
- * Uses tmux for persistent sessions that survive disconnections
5
- */
6
- import type { ServerWebSocket, Subprocess } from "bun";
7
- /**
8
- * Terminal session interface
9
- * Represents an active SSH PTY session
10
- */
11
- export interface TerminalSession {
12
- sessionId: string;
13
- proc: Subprocess<"pipe", "pipe", "pipe">;
14
- stdin: Subprocess<"pipe", "pipe", "pipe">["stdin"];
15
- stdout: ReadableStream<Uint8Array>;
16
- stderr: ReadableStream<Uint8Array>;
17
- host: string;
18
- user: string;
19
- ws: ServerWebSocket<unknown> | null;
20
- createdAt: number;
21
- lastUsed: number;
22
- reader: ReadableStreamDefaultReader<Uint8Array> | null;
23
- stderrReader: ReadableStreamDefaultReader<Uint8Array> | null;
24
- writer: WritableStreamDefaultWriter<Uint8Array> | null;
25
- closed: boolean;
26
- tmuxSessionName?: string;
27
- bootstrapLogStreamer?: Subprocess;
28
- }
29
- /**
30
- * Session info for API responses (safe to expose)
31
- */
32
- export interface SessionInfo {
33
- sessionId: string;
34
- host: string;
35
- user: string;
36
- createdAt: number;
37
- lastUsed: number;
38
- hasActiveWebSocket: boolean;
39
- closed: boolean;
40
- uptime: number;
41
- idleTime: number;
42
- }
43
- /**
44
- * Clean up old sessions (older than specified milliseconds)
45
- * Called automatically by interval timer
46
- */
47
- export declare function cleanupStaleSessions(maxAge?: number): string[];
48
- /**
49
- * Close a specific session
50
- */
51
- export declare function closeSession(sessionId: string): Promise<boolean>;
52
- /**
53
- * Find or create a session for a host
54
- * If sessionId is provided, try to reuse that specific session
55
- * If sessionId is null/undefined, always create a new session (for multiple terminals)
56
- * @param onProgress - Optional callback to send progress updates to WebSocket
57
- * @param onBootstrapOutput - Optional callback to stream bootstrap log output to WebSocket
58
- */
59
- export declare function getOrCreateSession(host: string, user?: string, sessionId?: string | null, keyPath?: string, onProgress?: (message: string, status: "info" | "success" | "error") => void, environmentId?: string, onBootstrapOutput?: (data: string) => void): Promise<TerminalSession>;
60
- /**
61
- * Get a session by ID
62
- */
63
- export declare function getSession(sessionId: string): TerminalSession | undefined;
64
- /**
65
- * Get all active sessions
66
- */
67
- export declare function getAllSessions(): TerminalSession[];
68
- /**
69
- * Get session info for all sessions (safe for API responses)
70
- */
71
- export declare function getAllSessionInfo(): SessionInfo[];
72
- /**
73
- * Get session info for a specific session
74
- */
75
- export declare function getSessionInfo(sessionId: string): SessionInfo | undefined;
76
- /**
77
- * Get the total number of active sessions
78
- */
79
- export declare function getSessionCount(): number;
80
- /**
81
- * Find sessions by host
82
- */
83
- export declare function getSessionsByHost(host: string): TerminalSession[];
84
- /**
85
- * Attach a WebSocket to a session
86
- * Sets up stdin/stdout/stderr streaming
87
- */
88
- export declare function attachWebSocket(session: TerminalSession, ws: ServerWebSocket<unknown>, wasReused?: boolean): void;
89
- /**
90
- * Write data to a session's stdin
91
- */
92
- export declare function writeToSession(sessionId: string, data: string): Promise<boolean>;
93
- /**
94
- * Resize a session's PTY
95
- */
96
- export declare function resizeSession(sessionId: string, rows: number, cols: number): Promise<boolean>;
97
- /**
98
- * Detach WebSocket from session (without closing session)
99
- */
100
- export declare function detachWebSocket(sessionId: string, ws: ServerWebSocket): boolean;
Binary file
@@ -1,49 +0,0 @@
1
- /**
2
- * SSH command execution via tmux
3
- * Executes commands through persistent tmux sessions instead of creating new SSH connections
4
- */
5
- import type { SSHOptions } from "./types.js";
6
- /**
7
- * Execute a command via tmux session (simplified approach)
8
- *
9
- * DESIGN RATIONALE:
10
- * ================
11
- *
12
- * Current approach: Each API call creates multiple SSH connections
13
- * - /api/environments/:id/resources: 4 connections (9 commands distributed)
14
- * - /api/environments/:id/node-agent: 1 connection
15
- * - Total: 5 SSH connections per page load
16
- *
17
- * New approach: Use existing tmux session for all commands
18
- * - One persistent tmux session per server (already used for terminal WebSocket)
19
- * - Execute commands via tmux send-keys, capture output
20
- * - Total: 1 SSH connection per server (for tmux session management)
21
- *
22
- * Implementation:
23
- * - Use existing tmux session's main window
24
- * - Send command via send-keys
25
- * - Wait for completion
26
- * - Capture output with capture-pane
27
- *
28
- * Note: This is a simplified implementation that reuses the main tmux window.
29
- * For production, we should create dedicated windows per command.
30
- *
31
- * @param command - Shell command to execute
32
- * @param options - SSH connection options
33
- * @param timeout - Command timeout in seconds (default: 10)
34
- * @returns Command stdout output
35
- */
36
- export declare function execViaTmux(command: string, options: SSHOptions, timeout?: number): Promise<string>;
37
- /**
38
- * Execute multiple commands in parallel via tmux
39
- *
40
- * Note: This creates multiple temporary windows in parallel,
41
- * each executing one command. This is more efficient than
42
- * sequential execution but uses more tmux windows temporarily.
43
- *
44
- * @param commands - Object mapping names to shell commands
45
- * @param options - SSH connection options
46
- * @param timeout - Per-command timeout in seconds (default: 10)
47
- * @returns Object mapping names to command outputs
48
- */
49
- export declare function execViaTmuxParallel(commands: Record<string, string>, options: SSHOptions, timeout?: number): Promise<Record<string, string>>;