agentlytics 0.2.2 → 0.2.3

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 (3) hide show
  1. package/index.js +47 -18
  2. package/package.json +1 -1
  3. package/server.js +4 -0
package/index.js CHANGED
@@ -139,10 +139,9 @@ if (!collectOnly && !fs.existsSync(publicIndex) && fs.existsSync(uiDir)) {
139
139
  console.log(chalk.cyan(' ⟳ Building dashboard UI (first run)...'));
140
140
  try {
141
141
  const uiModules = path.join(uiDir, 'node_modules');
142
- if (!fs.existsSync(uiModules)) {
143
- console.log(chalk.dim(' Installing UI dependencies...'));
144
- execSync('npm install --no-audit --no-fund', { cwd: uiDir, stdio: 'pipe' });
145
- }
142
+ if (fs.existsSync(uiModules)) fs.rmSync(uiModules, { recursive: true, force: true });
143
+ console.log(chalk.dim(' Installing UI dependencies...'));
144
+ execSync('npm install --no-audit --no-fund', { cwd: uiDir, stdio: 'pipe' });
146
145
  console.log(chalk.dim(' Compiling frontend...'));
147
146
  execSync('npm run build', { cwd: uiDir, stdio: 'pipe' });
148
147
  console.log(chalk.green(' ✓ UI built successfully'));
@@ -278,20 +277,50 @@ const BOT_STYLES = [
278
277
  process.exit(0);
279
278
  }
280
279
 
281
- // Start server
280
+ // Start server (kill stale agentlytics if port is busy)
282
281
  const app = require('./server');
283
- app.listen(PORT, () => {
284
- const url = `http://localhost:${PORT}`;
285
- console.log(chalk.green(` Dashboard ready at ${chalk.bold.white(url)}`));
286
- console.log('');
287
- console.log(chalk.dim(' 💡 Share sessions with your team:'));
288
- console.log(chalk.dim(` npx agentlytics --relay Start a relay server`));
289
- console.log(chalk.dim(` npx agentlytics --join <host:port> --username Join a relay server`));
290
- console.log('');
291
- console.log(chalk.dim(' Press Ctrl+C to stop\n'));
282
+ const http = require('http');
283
+
284
+ function tryListen() {
285
+ app.listen(PORT, () => {
286
+ const url = `http://localhost:${PORT}`;
287
+ console.log(chalk.green(` Dashboard ready at ${chalk.bold.white(url)}`));
288
+ console.log('');
289
+ console.log(chalk.dim(' Press Ctrl+C to stop\n'));
290
+
291
+ // Auto-open browser
292
+ const open = require('open');
293
+ open(url).catch(() => {});
294
+ }).on('error', (err) => {
295
+ if (err.code !== 'EADDRINUSE') throw err;
296
+
297
+ // Port in use — check if it's a previous agentlytics instance
298
+ const req = http.get(`http://localhost:${PORT}/api/ping`, { timeout: 2000 }, (res) => {
299
+ let body = '';
300
+ res.on('data', (d) => body += d);
301
+ res.on('end', () => {
302
+ try {
303
+ const data = JSON.parse(body);
304
+ if (data.app === 'agentlytics' && data.pid) {
305
+ console.log(chalk.yellow(` ⟳ Killing previous Agentlytics instance (PID ${data.pid})...`));
306
+ try { process.kill(data.pid, 'SIGTERM'); } catch {}
307
+ setTimeout(tryListen, 1000);
308
+ } else {
309
+ console.error(chalk.red(` ✖ Port ${PORT} is in use by another application.`));
310
+ process.exit(1);
311
+ }
312
+ } catch {
313
+ console.error(chalk.red(` ✖ Port ${PORT} is in use by another application.`));
314
+ process.exit(1);
315
+ }
316
+ });
317
+ });
318
+ req.on('error', () => {
319
+ console.error(chalk.red(` ✖ Port ${PORT} is in use but not responding. Kill the process manually or use PORT=<n> env.`));
320
+ process.exit(1);
321
+ });
322
+ });
323
+ }
292
324
 
293
- // Auto-open browser
294
- const open = require('open');
295
- open(url).catch(() => {});
296
- });
325
+ tryListen();
297
326
  })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agentlytics",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "description": "Comprehensive analytics dashboard for AI coding agents — Cursor, Windsurf, Claude Code, VS Code Copilot, Zed, Antigravity, OpenCode, Command Code",
5
5
  "main": "index.js",
6
6
  "bin": {
package/server.js CHANGED
@@ -41,6 +41,10 @@ function parseDateOpts(query) {
41
41
  return opts;
42
42
  }
43
43
 
44
+ app.get('/api/ping', (req, res) => {
45
+ res.json({ app: 'agentlytics', pid: process.pid });
46
+ });
47
+
44
48
  app.get('/api/mode', (req, res) => {
45
49
  res.json({ mode: 'local' });
46
50
  });