agentlytics 0.2.0 → 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.
package/editors/codex.js CHANGED
@@ -5,17 +5,25 @@ const os = require('os');
5
5
  const name = 'codex';
6
6
  const DEFAULT_CODEX_HOME = path.join(os.homedir(), '.codex');
7
7
  const SESSION_SUBDIR = 'sessions';
8
+ const ARCHIVED_SESSION_SUBDIR = 'archived_sessions';
8
9
  const MAX_TOOL_RESULT_PREVIEW = 500;
9
10
 
10
11
  function getChats() {
11
- const sessionsDir = getSessionsDir();
12
- if (!fs.existsSync(sessionsDir)) return [];
13
-
12
+ const dirs = [getSessionsDir(), getArchivedSessionsDir()];
13
+ const seen = new Set();
14
14
  const chats = [];
15
- for (const filePath of walkJsonlFiles(sessionsDir)) {
16
- const chat = readChatMetadata(filePath);
17
- if (chat) chats.push(chat);
15
+
16
+ for (const dir of dirs) {
17
+ if (!fs.existsSync(dir)) continue;
18
+ for (const filePath of walkJsonlFiles(dir)) {
19
+ const chat = readChatMetadata(filePath);
20
+ if (!chat) continue;
21
+ if (seen.has(chat.composerId)) continue;
22
+ seen.add(chat.composerId);
23
+ chats.push(chat);
24
+ }
18
25
  }
26
+
19
27
  return chats;
20
28
  }
21
29
 
@@ -25,11 +33,18 @@ function getMessages(chat) {
25
33
  return parseSessionMessages(filePath);
26
34
  }
27
35
 
28
- function getSessionsDir() {
29
- const codexHome = process.env.CODEX_HOME && process.env.CODEX_HOME.trim()
36
+ function getCodexHome() {
37
+ return process.env.CODEX_HOME && process.env.CODEX_HOME.trim()
30
38
  ? path.resolve(process.env.CODEX_HOME.trim())
31
39
  : DEFAULT_CODEX_HOME;
32
- return path.join(codexHome, SESSION_SUBDIR);
40
+ }
41
+
42
+ function getSessionsDir() {
43
+ return path.join(getCodexHome(), SESSION_SUBDIR);
44
+ }
45
+
46
+ function getArchivedSessionsDir() {
47
+ return path.join(getCodexHome(), ARCHIVED_SESSION_SUBDIR);
33
48
  }
34
49
 
35
50
  function walkJsonlFiles(dir) {
@@ -442,12 +457,7 @@ function safeParseJson(value) {
442
457
  // ============================================================
443
458
 
444
459
  function getCodexAuth() {
445
- const authPath = path.join(
446
- process.env.CODEX_HOME && process.env.CODEX_HOME.trim()
447
- ? path.resolve(process.env.CODEX_HOME.trim())
448
- : DEFAULT_CODEX_HOME,
449
- 'auth.json'
450
- );
460
+ const authPath = path.join(getCodexHome(), 'auth.json');
451
461
  try {
452
462
  return JSON.parse(fs.readFileSync(authPath, 'utf-8'));
453
463
  } catch { return null; }
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.0",
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
  });