remote-cli-agent 0.4.0 → 0.6.0
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/dist/connection.js +15 -5
- package/dist/index.js +28 -12
- package/dist/terminal.d.ts +1 -0
- package/dist/terminal.js +13 -0
- package/package.json +1 -1
package/dist/connection.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import WebSocket from 'ws';
|
|
2
|
-
import { getSessionList, writeToSession, resizeSession, attachSession, spawnSession, setOutputHandler, setSessionsChangeHandler } from './terminal.js';
|
|
2
|
+
import { getSessionList, writeToSession, resizeSession, attachSession, spawnSession, createTmuxSession, attachTmuxSession, setOutputHandler, setSessionsChangeHandler } from './terminal.js';
|
|
3
3
|
let ws = null;
|
|
4
4
|
let reconnectTimer = null;
|
|
5
5
|
let reconnectAttempts = 0;
|
|
@@ -78,10 +78,20 @@ function handleMessage(msg) {
|
|
|
78
78
|
break;
|
|
79
79
|
}
|
|
80
80
|
case 'spawn': {
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
81
|
+
const name = msg.name || `session-${Date.now()}`;
|
|
82
|
+
// Create a tmux session so it can be shared locally
|
|
83
|
+
const tmuxName = createTmuxSession(name);
|
|
84
|
+
if (tmuxName) {
|
|
85
|
+
const session = attachTmuxSession(tmuxName);
|
|
86
|
+
if (session) {
|
|
87
|
+
console.log(`Created tmux session: ${tmuxName} (${session.id})`);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
// Fallback to PTY
|
|
92
|
+
const session = spawnSession(msg.command);
|
|
93
|
+
console.log(`Spawned session: ${session.name} (${session.id})`);
|
|
94
|
+
}
|
|
85
95
|
sendMessage({ type: 'sessions_update', sessions: getSessionList() });
|
|
86
96
|
break;
|
|
87
97
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { Command } from 'commander';
|
|
3
3
|
import { connect, disconnect } from './connection.js';
|
|
4
|
-
import { listTmuxSessions, attachTmuxSession, spawnSession, cleanupAll, getSessionList } from './terminal.js';
|
|
4
|
+
import { listTmuxSessions, attachTmuxSession, createTmuxSession, spawnSession, cleanupAll, getSessionList } from './terminal.js';
|
|
5
5
|
import fs from 'fs';
|
|
6
6
|
import path from 'path';
|
|
7
7
|
import os from 'os';
|
|
@@ -45,7 +45,8 @@ program
|
|
|
45
45
|
.description('Connect to the server and register available sessions')
|
|
46
46
|
.option('-s, --server <url>', 'Server URL (overrides config)')
|
|
47
47
|
.option('-t, --token <token>', 'Agent token (overrides config)')
|
|
48
|
-
.option('--spawn [command]', 'Spawn a new session
|
|
48
|
+
.option('--spawn [command]', 'Spawn a new PTY session (not shared locally)')
|
|
49
|
+
.option('--no-tmux', 'Disable tmux (use isolated PTY instead)')
|
|
49
50
|
.action((opts) => {
|
|
50
51
|
const config = loadConfig();
|
|
51
52
|
const server = opts.server || config?.server;
|
|
@@ -58,14 +59,30 @@ program
|
|
|
58
59
|
// Convert http(s) to ws(s) for WebSocket connection
|
|
59
60
|
const wsUrl = server.replace(/^http/, 'ws');
|
|
60
61
|
console.log(`Connecting to ${server}...`);
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
tmuxSessions.
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
62
|
+
const useTmux = opts.tmux !== false;
|
|
63
|
+
if (useTmux) {
|
|
64
|
+
// List tmux sessions
|
|
65
|
+
const tmuxSessions = listTmuxSessions();
|
|
66
|
+
if (tmuxSessions.length > 0) {
|
|
67
|
+
console.log(`Found ${tmuxSessions.length} tmux session(s):`);
|
|
68
|
+
tmuxSessions.forEach(s => console.log(` - ${s}`));
|
|
69
|
+
// Auto-attach all tmux sessions
|
|
70
|
+
for (const sessionName of tmuxSessions) {
|
|
71
|
+
attachTmuxSession(sessionName);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
// No tmux sessions - create one
|
|
76
|
+
console.log('No tmux sessions found. Creating one...');
|
|
77
|
+
const name = createTmuxSession('remote-cli');
|
|
78
|
+
if (name) {
|
|
79
|
+
attachTmuxSession(name);
|
|
80
|
+
console.log(`\nTo use this session locally: tmux attach -t ${name}`);
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
console.log('Failed to create tmux session. Falling back to PTY...');
|
|
84
|
+
spawnSession();
|
|
85
|
+
}
|
|
69
86
|
}
|
|
70
87
|
}
|
|
71
88
|
// Spawn a session if requested
|
|
@@ -73,9 +90,8 @@ program
|
|
|
73
90
|
const command = typeof opts.spawn === 'string' ? opts.spawn : undefined;
|
|
74
91
|
spawnSession(command);
|
|
75
92
|
}
|
|
76
|
-
// If no sessions available, spawn a default one
|
|
93
|
+
// If no sessions available (--no-tmux or tmux failed), spawn a default one
|
|
77
94
|
if (getSessionList().length === 0) {
|
|
78
|
-
console.log('No tmux sessions found. Spawning a default shell session...');
|
|
79
95
|
spawnSession();
|
|
80
96
|
}
|
|
81
97
|
// Connect to server
|
package/dist/terminal.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ export declare function getSessionList(): {
|
|
|
12
12
|
name: string;
|
|
13
13
|
command?: string;
|
|
14
14
|
}[];
|
|
15
|
+
export declare function createTmuxSession(name?: string): string | null;
|
|
15
16
|
export declare function listTmuxSessions(): string[];
|
|
16
17
|
export declare function attachTmuxSession(sessionName: string): TerminalSession | null;
|
|
17
18
|
export declare function spawnSession(command?: string): TerminalSession;
|
package/dist/terminal.js
CHANGED
|
@@ -27,6 +27,19 @@ export function getSessionList() {
|
|
|
27
27
|
command: s.command
|
|
28
28
|
}));
|
|
29
29
|
}
|
|
30
|
+
// Create a new tmux session
|
|
31
|
+
export function createTmuxSession(name) {
|
|
32
|
+
const sessionName = name || `remote-cli-${Date.now()}`;
|
|
33
|
+
try {
|
|
34
|
+
execSync(`tmux new-session -d -s ${sessionName}`, { encoding: 'utf-8' });
|
|
35
|
+
console.log(`Created tmux session: ${sessionName}`);
|
|
36
|
+
return sessionName;
|
|
37
|
+
}
|
|
38
|
+
catch (err) {
|
|
39
|
+
console.error('Failed to create tmux session:', err.message);
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
30
43
|
// List available tmux sessions
|
|
31
44
|
export function listTmuxSessions() {
|
|
32
45
|
try {
|