ai-terminal-remote-bot 1.0.13 → 1.0.15

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 -42
  2. package/package.json +1 -1
package/cli.js CHANGED
@@ -8,7 +8,7 @@
8
8
  import { readFileSync, writeFileSync, unlinkSync, existsSync, openSync } from 'fs';
9
9
  import { dirname, join } from 'path';
10
10
  import { fileURLToPath } from 'url';
11
- import { spawn, execSync } from 'child_process';
11
+ import { spawn } from 'child_process';
12
12
  import { loadConfig, configExists, CONFIG_DIR } from './src/config.mjs';
13
13
  import { runSetup } from './src/setup.mjs';
14
14
  import { startServer } from './src/server.mjs';
@@ -42,46 +42,32 @@ function isRunning(pid) {
42
42
  }
43
43
 
44
44
  function stopBot() {
45
- let stopped = false;
46
-
47
- // Kill by PID file first
48
45
  const pid = readPid();
49
- if (pid && isRunning(pid)) {
50
- try { process.kill(pid, 'SIGKILL'); stopped = true; } catch {}
46
+ if (!pid || !isRunning(pid)) {
47
+ console.log(t('cli.botNotRunning'));
48
+ return false;
51
49
  }
52
- try { unlinkSync(PID_FILE); } catch {}
53
-
54
- // Also kill any remaining processes matching our CLI
55
50
  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) {
51
+ process.kill(pid, 'SIGTERM');
52
+ try { unlinkSync(PID_FILE); } catch {}
66
53
  console.log(t('cli.botStopped'));
67
- } else {
68
- console.log(t('cli.botNotRunning'));
54
+ return true;
55
+ } catch (err) {
56
+ console.error(t('cli.botStopFailed', { pid, error: err.message }));
57
+ return false;
69
58
  }
70
- return stopped;
71
59
  }
72
60
 
73
61
  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 {}
84
- try { unlinkSync(PID_FILE); } catch {}
62
+ const pid = readPid();
63
+ if (pid && isRunning(pid)) {
64
+ console.log(t('cli.botAlreadyRunning', { pid }));
65
+ return;
66
+ }
67
+ // Clean stale PID file
68
+ if (pid) {
69
+ try { unlinkSync(PID_FILE); } catch {}
70
+ }
85
71
 
86
72
  const logFd = openSync(LOG_FILE, 'a');
87
73
  const child = spawn(process.execPath, ['--disable-warning=DEP0040', fileURLToPath(import.meta.url), '--daemon'], {
@@ -135,24 +121,21 @@ if (!configExists()) {
135
121
  const config = loadConfig();
136
122
  initI18n(config.language);
137
123
 
138
- // --stop / stop
139
- if (args.includes('--stop') || args.includes('stop')) {
124
+ // --stop
125
+ if (args.includes('--stop')) {
140
126
  stopBot();
141
127
  process.exit(0);
142
128
  }
143
129
 
144
- // --restart / restart
145
- if (args.includes('--restart') || args.includes('restart')) {
130
+ // --restart
131
+ if (args.includes('--restart')) {
146
132
  stopBot();
147
- // Wait for processes to die
148
- const { setTimeout: sleep } = await import('timers/promises');
149
- await sleep(1500);
150
133
  startDaemon();
151
134
  process.exit(0);
152
135
  }
153
136
 
154
- // --status / status
155
- if (args.includes('--status') || args.includes('status')) {
137
+ // --status
138
+ if (args.includes('--status')) {
156
139
  const pid = readPid();
157
140
  if (pid && isRunning(pid)) {
158
141
  console.log(t('cli.botRunning', { pid }));
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.15",
4
4
  "description": "Secure remote terminal bot with Claude Code integration",
5
5
  "type": "module",
6
6
  "bin": {