remote-cli-agent 0.6.0 → 0.7.1
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.d.ts +1 -0
- package/dist/connection.js +22 -0
- package/dist/index.js +35 -3
- package/dist/terminal.d.ts +1 -0
- package/dist/terminal.js +20 -0
- package/package.json +1 -1
package/dist/connection.d.ts
CHANGED
package/dist/connection.js
CHANGED
|
@@ -5,9 +5,11 @@ let reconnectTimer = null;
|
|
|
5
5
|
let reconnectAttempts = 0;
|
|
6
6
|
const MAX_RECONNECT_DELAY = 30000;
|
|
7
7
|
const BASE_RECONNECT_DELAY = 1000;
|
|
8
|
+
let pingInterval = null;
|
|
8
9
|
let serverUrl = '';
|
|
9
10
|
let agentToken = '';
|
|
10
11
|
let isConnected = false;
|
|
12
|
+
let watchInterval = null;
|
|
11
13
|
export function connect(url, token) {
|
|
12
14
|
serverUrl = url;
|
|
13
15
|
agentToken = token;
|
|
@@ -34,6 +36,14 @@ function doConnect() {
|
|
|
34
36
|
reconnectAttempts = 0;
|
|
35
37
|
// Register current sessions
|
|
36
38
|
sendMessage({ type: 'register', sessions: getSessionList() });
|
|
39
|
+
// Keep connection alive with periodic pings (every 30s)
|
|
40
|
+
if (pingInterval)
|
|
41
|
+
clearInterval(pingInterval);
|
|
42
|
+
pingInterval = setInterval(() => {
|
|
43
|
+
if (ws && ws.readyState === WebSocket.OPEN) {
|
|
44
|
+
ws.ping();
|
|
45
|
+
}
|
|
46
|
+
}, 30000);
|
|
37
47
|
});
|
|
38
48
|
ws.on('message', (data) => {
|
|
39
49
|
try {
|
|
@@ -121,6 +131,14 @@ function scheduleReconnect() {
|
|
|
121
131
|
}, delay);
|
|
122
132
|
}
|
|
123
133
|
export function disconnect() {
|
|
134
|
+
if (pingInterval) {
|
|
135
|
+
clearInterval(pingInterval);
|
|
136
|
+
pingInterval = null;
|
|
137
|
+
}
|
|
138
|
+
if (watchInterval) {
|
|
139
|
+
clearInterval(watchInterval);
|
|
140
|
+
watchInterval = null;
|
|
141
|
+
}
|
|
124
142
|
if (reconnectTimer) {
|
|
125
143
|
clearTimeout(reconnectTimer);
|
|
126
144
|
reconnectTimer = null;
|
|
@@ -132,6 +150,10 @@ export function disconnect() {
|
|
|
132
150
|
}
|
|
133
151
|
isConnected = false;
|
|
134
152
|
}
|
|
153
|
+
// Notify server of session changes (exposed for external watchers)
|
|
154
|
+
export function notifySessionsUpdate(sessions) {
|
|
155
|
+
sendMessage({ type: 'sessions_update', sessions });
|
|
156
|
+
}
|
|
135
157
|
export function getConnectionStatus() {
|
|
136
158
|
return isConnected;
|
|
137
159
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { Command } from 'commander';
|
|
3
|
-
import { connect, disconnect } from './connection.js';
|
|
4
|
-
import { listTmuxSessions, attachTmuxSession, createTmuxSession, spawnSession, cleanupAll, getSessionList } from './terminal.js';
|
|
3
|
+
import { connect, disconnect, notifySessionsUpdate } from './connection.js';
|
|
4
|
+
import { listTmuxSessions, attachTmuxSession, createTmuxSession, spawnSession, cleanupAll, getSessionList, removeSessionsByTmux } from './terminal.js';
|
|
5
5
|
import fs from 'fs';
|
|
6
6
|
import path from 'path';
|
|
7
7
|
import os from 'os';
|
|
@@ -96,6 +96,38 @@ program
|
|
|
96
96
|
}
|
|
97
97
|
// Connect to server
|
|
98
98
|
connect(wsUrl, token);
|
|
99
|
+
// Watch for new tmux sessions
|
|
100
|
+
if (useTmux) {
|
|
101
|
+
const knownTmux = new Set();
|
|
102
|
+
for (const s of getSessionList()) {
|
|
103
|
+
if (s.name?.startsWith('tmux: ')) {
|
|
104
|
+
knownTmux.add(s.name.replace('tmux: ', ''));
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
setInterval(() => {
|
|
108
|
+
const current = listTmuxSessions();
|
|
109
|
+
let changed = false;
|
|
110
|
+
for (const name of current) {
|
|
111
|
+
if (!knownTmux.has(name)) {
|
|
112
|
+
console.log(`New tmux session detected: ${name}`);
|
|
113
|
+
attachTmuxSession(name);
|
|
114
|
+
knownTmux.add(name);
|
|
115
|
+
changed = true;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
for (const name of knownTmux) {
|
|
119
|
+
if (!current.includes(name)) {
|
|
120
|
+
console.log(`Tmux session gone: ${name}`);
|
|
121
|
+
removeSessionsByTmux(name);
|
|
122
|
+
knownTmux.delete(name);
|
|
123
|
+
changed = true;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
if (changed) {
|
|
127
|
+
notifySessionsUpdate(getSessionList());
|
|
128
|
+
}
|
|
129
|
+
}, 3000);
|
|
130
|
+
}
|
|
99
131
|
// Handle shutdown
|
|
100
132
|
const shutdown = () => {
|
|
101
133
|
console.log('\nShutting down...');
|
|
@@ -106,7 +138,7 @@ program
|
|
|
106
138
|
process.on('SIGINT', shutdown);
|
|
107
139
|
process.on('SIGTERM', shutdown);
|
|
108
140
|
// Keep process alive
|
|
109
|
-
setInterval(() => { },
|
|
141
|
+
setInterval(() => { }, 60000);
|
|
110
142
|
});
|
|
111
143
|
program
|
|
112
144
|
.command('attach <session>')
|
package/dist/terminal.d.ts
CHANGED
|
@@ -19,4 +19,5 @@ export declare function spawnSession(command?: string): TerminalSession;
|
|
|
19
19
|
export declare function writeToSession(sessionId: string, data: string): boolean;
|
|
20
20
|
export declare function resizeSession(sessionId: string, cols: number, rows: number): boolean;
|
|
21
21
|
export declare function attachSession(sessionId: string): boolean;
|
|
22
|
+
export declare function removeSessionsByTmux(tmuxName: string): boolean;
|
|
22
23
|
export declare function cleanupAll(): void;
|
package/dist/terminal.js
CHANGED
|
@@ -207,6 +207,26 @@ export function resizeSession(sessionId, cols, rows) {
|
|
|
207
207
|
export function attachSession(sessionId) {
|
|
208
208
|
return sessions.has(sessionId);
|
|
209
209
|
}
|
|
210
|
+
// Remove sessions attached to a specific tmux session
|
|
211
|
+
export function removeSessionsByTmux(tmuxName) {
|
|
212
|
+
let removed = false;
|
|
213
|
+
for (const [id, session] of sessions.entries()) {
|
|
214
|
+
if (session.tmuxSession === tmuxName) {
|
|
215
|
+
if (session.pty) {
|
|
216
|
+
try {
|
|
217
|
+
session.pty.kill();
|
|
218
|
+
}
|
|
219
|
+
catch { }
|
|
220
|
+
}
|
|
221
|
+
sessions.delete(id);
|
|
222
|
+
removed = true;
|
|
223
|
+
console.log(`Removed stale session "${session.name}" (${id})`);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
if (removed)
|
|
227
|
+
onSessionsChange?.();
|
|
228
|
+
return removed;
|
|
229
|
+
}
|
|
210
230
|
// Cleanup all sessions
|
|
211
231
|
export function cleanupAll() {
|
|
212
232
|
for (const session of sessions.values()) {
|