@dmsdc-ai/aigentry-telepty 0.1.81 → 0.1.82
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/cli.js +33 -0
- package/daemon.js +10 -8
- package/package.json +1 -1
package/cli.js
CHANGED
|
@@ -1819,6 +1819,39 @@ async function main() {
|
|
|
1819
1819
|
return;
|
|
1820
1820
|
}
|
|
1821
1821
|
|
|
1822
|
+
if (cmd === 'delete') {
|
|
1823
|
+
const sessionRef = args[1];
|
|
1824
|
+
if (!sessionRef) { console.error('❌ Usage: telepty delete <session-id>'); process.exit(1); }
|
|
1825
|
+
try {
|
|
1826
|
+
const target = await resolveSessionTarget(sessionRef);
|
|
1827
|
+
if (!target) { console.error(`❌ Session '${sessionRef}' not found.`); process.exit(1); }
|
|
1828
|
+
const res = await fetchWithAuth(`http://${target.host}:${PORT}/api/sessions/${encodeURIComponent(target.id)}`, { method: 'DELETE' });
|
|
1829
|
+
const data = await res.json();
|
|
1830
|
+
if (!res.ok) { console.error(`❌ Error: ${data.error}`); return; }
|
|
1831
|
+
console.log(`✅ Session '\x1b[36m${target.id}\x1b[0m' deleted.`);
|
|
1832
|
+
} catch (e) { console.error(`❌ ${e.message || 'Failed to delete session.'}`); }
|
|
1833
|
+
return;
|
|
1834
|
+
}
|
|
1835
|
+
|
|
1836
|
+
if (cmd === 'clean') {
|
|
1837
|
+
try {
|
|
1838
|
+
const sessions = await discoverSessions({ silent: true });
|
|
1839
|
+
if (sessions.length === 0) { console.log('No sessions found.'); return; }
|
|
1840
|
+
let cleaned = 0;
|
|
1841
|
+
for (const s of sessions) {
|
|
1842
|
+
if (s.healthStatus === 'STALE' || s.healthStatus === 'DISCONNECTED') {
|
|
1843
|
+
try {
|
|
1844
|
+
const host = s.host || '127.0.0.1';
|
|
1845
|
+
const res = await fetchWithAuth(`http://${host}:${PORT}/api/sessions/${encodeURIComponent(s.id)}`, { method: 'DELETE' });
|
|
1846
|
+
if (res.ok) { console.log(` 🗑 Removed ghost: \x1b[36m${s.id}\x1b[0m (${s.healthStatus})`); cleaned++; }
|
|
1847
|
+
} catch (_) {}
|
|
1848
|
+
}
|
|
1849
|
+
}
|
|
1850
|
+
console.log(cleaned > 0 ? `✅ Cleaned ${cleaned} ghost session(s).` : '✅ No ghost sessions found.');
|
|
1851
|
+
} catch (e) { console.error(`❌ ${e.message || 'Failed to clean sessions.'}`); }
|
|
1852
|
+
return;
|
|
1853
|
+
}
|
|
1854
|
+
|
|
1822
1855
|
if (cmd === 'rename') {
|
|
1823
1856
|
const oldId = args[1]; const newId = args[2];
|
|
1824
1857
|
if (!oldId || !newId) { console.error('❌ Usage: telepty rename <old_id> <new_id>'); process.exit(1); }
|
package/daemon.js
CHANGED
|
@@ -1478,18 +1478,20 @@ app.delete('/api/sessions/:id', (req, res) => {
|
|
|
1478
1478
|
try {
|
|
1479
1479
|
session.isClosing = true;
|
|
1480
1480
|
if (session.type === 'wrapped') {
|
|
1481
|
-
session.clients.forEach(ws => ws.close(1000, 'Session destroyed'));
|
|
1482
|
-
|
|
1483
|
-
console.log(`[KILL] Wrapped session ${id} removed`);
|
|
1484
|
-
persistSessions();
|
|
1485
|
-
} else {
|
|
1481
|
+
if (session.clients) session.clients.forEach(ws => ws.close(1000, 'Session destroyed'));
|
|
1482
|
+
} else if (session.ptyProcess) {
|
|
1486
1483
|
session.ptyProcess.kill();
|
|
1487
|
-
console.log(`[KILL] Session ${id} forcefully closed`);
|
|
1488
|
-
persistSessions();
|
|
1489
1484
|
}
|
|
1485
|
+
delete sessions[id];
|
|
1486
|
+
console.log(`[KILL] Session ${id} removed`);
|
|
1487
|
+
persistSessions();
|
|
1490
1488
|
res.json({ success: true, status: 'closing' });
|
|
1491
1489
|
} catch (err) {
|
|
1492
|
-
|
|
1490
|
+
// Even if kill fails, remove from registry
|
|
1491
|
+
delete sessions[id];
|
|
1492
|
+
persistSessions();
|
|
1493
|
+
console.log(`[KILL] Session ${id} force-removed (process cleanup error: ${err.message})`);
|
|
1494
|
+
res.json({ success: true, status: 'force-removed' });
|
|
1493
1495
|
}
|
|
1494
1496
|
});
|
|
1495
1497
|
|