remote-cli-agent 0.6.0 → 0.7.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.d.ts +1 -0
- package/dist/connection.js +22 -0
- package/dist/index.js +31 -2
- 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,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { Command } from 'commander';
|
|
3
|
-
import { connect, disconnect } from './connection.js';
|
|
3
|
+
import { connect, disconnect, notifySessionsUpdate } from './connection.js';
|
|
4
4
|
import { listTmuxSessions, attachTmuxSession, createTmuxSession, spawnSession, cleanupAll, getSessionList } from './terminal.js';
|
|
5
5
|
import fs from 'fs';
|
|
6
6
|
import path from 'path';
|
|
@@ -96,6 +96,35 @@ 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
|
+
knownTmux.delete(name);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
if (changed) {
|
|
124
|
+
notifySessionsUpdate(getSessionList());
|
|
125
|
+
}
|
|
126
|
+
}, 3000);
|
|
127
|
+
}
|
|
99
128
|
// Handle shutdown
|
|
100
129
|
const shutdown = () => {
|
|
101
130
|
console.log('\nShutting down...');
|
|
@@ -106,7 +135,7 @@ program
|
|
|
106
135
|
process.on('SIGINT', shutdown);
|
|
107
136
|
process.on('SIGTERM', shutdown);
|
|
108
137
|
// Keep process alive
|
|
109
|
-
setInterval(() => { },
|
|
138
|
+
setInterval(() => { }, 60000);
|
|
110
139
|
});
|
|
111
140
|
program
|
|
112
141
|
.command('attach <session>')
|