ai-terminal-remote-bot 1.0.13 → 1.0.14

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 (2) hide show
  1. package/cli.js +25 -27
  2. package/package.json +1 -1
package/cli.js CHANGED
@@ -41,46 +41,44 @@ function isRunning(pid) {
41
41
  }
42
42
  }
43
43
 
44
+ function findDaemonPids() {
45
+ try {
46
+ const out = execSync('ps aux 2>/dev/null', { encoding: 'utf8' });
47
+ return out.split('\n')
48
+ .filter(line => line.includes('ai-terminal-remote-bot') && line.includes('--daemon'))
49
+ .map(line => parseInt(line.trim().split(/\s+/)[1]))
50
+ .filter(pid => pid && pid !== process.pid);
51
+ } catch { return []; }
52
+ }
53
+
54
+ function killAllDaemons() {
55
+ let killed = false;
56
+ for (const pid of findDaemonPids()) {
57
+ try { process.kill(pid, 'SIGKILL'); killed = true; } catch {}
58
+ }
59
+ return killed;
60
+ }
61
+
44
62
  function stopBot() {
45
63
  let stopped = false;
46
64
 
47
- // Kill by PID file first
65
+ // Kill by PID file
48
66
  const pid = readPid();
49
67
  if (pid && isRunning(pid)) {
50
68
  try { process.kill(pid, 'SIGKILL'); stopped = true; } catch {}
51
69
  }
52
70
  try { unlinkSync(PID_FILE); } catch {}
53
71
 
54
- // Also kill any remaining processes matching our CLI
55
- try {
56
- const pids = execSync('pgrep -f "ai-terminal-remote-bot" 2>/dev/null', { encoding: 'utf8' }).trim().split('\n');
57
- for (const p of pids) {
58
- const n = parseInt(p);
59
- if (n && n !== process.pid) {
60
- try { process.kill(n, 'SIGKILL'); stopped = true; } catch {}
61
- }
62
- }
63
- } catch {}
64
-
65
- if (stopped) {
66
- console.log(t('cli.botStopped'));
67
- } else {
68
- console.log(t('cli.botNotRunning'));
69
- }
72
+ // Kill any orphaned daemons
73
+ if (killAllDaemons()) stopped = true;
74
+
75
+ console.log(stopped ? t('cli.botStopped') : t('cli.botNotRunning'));
70
76
  return stopped;
71
77
  }
72
78
 
73
79
  function startDaemon() {
74
- // Kill any orphaned processes first
75
- try {
76
- const pids = execSync('pgrep -f "ai-terminal-remote-bot.*--daemon" 2>/dev/null', { encoding: 'utf8' }).trim().split('\n');
77
- for (const p of pids) {
78
- const n = parseInt(p);
79
- if (n && n !== process.pid) {
80
- try { process.kill(n, 'SIGKILL'); } catch {}
81
- }
82
- }
83
- } catch {}
80
+ // Kill orphans first
81
+ killAllDaemons();
84
82
  try { unlinkSync(PID_FILE); } catch {}
85
83
 
86
84
  const logFd = openSync(LOG_FILE, 'a');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-terminal-remote-bot",
3
- "version": "1.0.13",
3
+ "version": "1.0.14",
4
4
  "description": "Secure remote terminal bot with Claude Code integration",
5
5
  "type": "module",
6
6
  "bin": {