aicp-tracker 1.1.3 → 1.1.4
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/package.json +1 -1
- package/src/daemon.js +17 -12
- package/src/log-scanner.js +22 -5
package/package.json
CHANGED
package/src/daemon.js
CHANGED
|
@@ -2,18 +2,19 @@
|
|
|
2
2
|
|
|
3
3
|
const path = require('path');
|
|
4
4
|
const fs = require('fs');
|
|
5
|
-
const os = require('os');
|
|
6
5
|
const { findJsonlFiles } = require('./log-scanner');
|
|
7
6
|
const { parseNewLines } = require('./log-parser');
|
|
8
7
|
const wal = require('./wal');
|
|
9
8
|
const { sendPending } = require('./sender');
|
|
10
|
-
const
|
|
9
|
+
const config = require('./config');
|
|
10
|
+
const { CONFIG_DIR } = config;
|
|
11
11
|
|
|
12
|
-
const PID_FILE
|
|
13
|
-
const INTERVAL_MS = 5 * 60 * 1000; // 5 minutes
|
|
12
|
+
const PID_FILE = path.join(CONFIG_DIR, 'daemon.pid');
|
|
14
13
|
|
|
15
14
|
async function tick() {
|
|
16
|
-
const
|
|
15
|
+
const cfg = (() => { try { return config.load(); } catch { return null; } })();
|
|
16
|
+
const projectPath = cfg?.projectPath || null;
|
|
17
|
+
const files = findJsonlFiles(projectPath);
|
|
17
18
|
let total = 0;
|
|
18
19
|
for (const f of files) {
|
|
19
20
|
const records = parseNewLines(f);
|
|
@@ -26,21 +27,23 @@ async function tick() {
|
|
|
26
27
|
await sendPending();
|
|
27
28
|
}
|
|
28
29
|
|
|
29
|
-
function writePid() {
|
|
30
|
-
fs.mkdirSync(CONFIG_DIR, { recursive: true });
|
|
31
|
-
fs.writeFileSync(PID_FILE, String(process.pid), 'utf8');
|
|
32
|
-
}
|
|
33
|
-
|
|
34
30
|
function readPid() {
|
|
35
31
|
try { return parseInt(fs.readFileSync(PID_FILE, 'utf8'), 10); } catch { return null; }
|
|
36
32
|
}
|
|
37
33
|
|
|
34
|
+
function saveProjectPath() {
|
|
35
|
+
const cfg = config.load() || {};
|
|
36
|
+
config.save({ ...cfg, projectPath: process.cwd() });
|
|
37
|
+
}
|
|
38
|
+
|
|
38
39
|
function start() {
|
|
40
|
+
saveProjectPath();
|
|
41
|
+
|
|
39
42
|
const existingPid = readPid();
|
|
40
43
|
if (existingPid) {
|
|
41
44
|
try {
|
|
42
45
|
process.kill(existingPid, 0); // check if running
|
|
43
|
-
console.log(`[daemon] Already running (pid ${existingPid})`);
|
|
46
|
+
console.log(`[daemon] Already running (pid ${existingPid}), tracking: ${process.cwd()}`);
|
|
44
47
|
return;
|
|
45
48
|
} catch {}
|
|
46
49
|
}
|
|
@@ -52,7 +55,7 @@ function start() {
|
|
|
52
55
|
{ detached: true, stdio: 'ignore' }
|
|
53
56
|
);
|
|
54
57
|
child.unref();
|
|
55
|
-
console.log(`[daemon] Started (pid ${child.pid})`);
|
|
58
|
+
console.log(`[daemon] Started (pid ${child.pid}), tracking: ${process.cwd()}`);
|
|
56
59
|
}
|
|
57
60
|
|
|
58
61
|
function stop() {
|
|
@@ -70,7 +73,9 @@ function stop() {
|
|
|
70
73
|
function status() {
|
|
71
74
|
const pid = readPid();
|
|
72
75
|
const running = pid ? (() => { try { process.kill(pid, 0); return true; } catch { return false; } })() : false;
|
|
76
|
+
const cfg = (() => { try { return config.load(); } catch { return null; } })();
|
|
73
77
|
console.log(`[daemon] Status: ${running ? `running (pid ${pid})` : 'stopped'}`);
|
|
78
|
+
console.log(`[daemon] Project: ${cfg?.projectPath || '(all projects)'}`);
|
|
74
79
|
console.log(`[daemon] WAL pending: ${wal.pendingCount()} records`);
|
|
75
80
|
}
|
|
76
81
|
|
package/src/log-scanner.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
// Finds
|
|
3
|
+
// Finds Claude Code session jsonl files under ~/.claude/projects/
|
|
4
|
+
// Scoped to the project folder that matches the configured projectPath.
|
|
4
5
|
|
|
5
6
|
const fs = require('fs');
|
|
6
7
|
const path = require('path');
|
|
@@ -8,12 +9,28 @@ const os = require('os');
|
|
|
8
9
|
|
|
9
10
|
const CLAUDE_DIR = path.join(os.homedir(), '.claude', 'projects');
|
|
10
11
|
|
|
11
|
-
|
|
12
|
+
// Converts an absolute project path to the folder name Claude Code uses.
|
|
13
|
+
// C:\Users\Alexey\Project → c--Users-Alexey-Project
|
|
14
|
+
// /home/user/project → -home-user-project
|
|
15
|
+
function pathToProjectFolder(p) {
|
|
16
|
+
if (process.platform === 'win32') {
|
|
17
|
+
return p
|
|
18
|
+
.replace(/\\/g, '/')
|
|
19
|
+
.replace(/^([A-Za-z]):\//, (_, d) => d.toLowerCase() + '--')
|
|
20
|
+
.replace(/\//g, '-');
|
|
21
|
+
}
|
|
22
|
+
return p.replace(/\//g, '-');
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function findJsonlFiles(projectPath) {
|
|
12
26
|
const results = [];
|
|
13
27
|
if (!fs.existsSync(CLAUDE_DIR)) return results;
|
|
14
28
|
|
|
15
|
-
|
|
16
|
-
|
|
29
|
+
const targetFolder = projectPath ? pathToProjectFolder(projectPath) : null;
|
|
30
|
+
|
|
31
|
+
for (const entry of fs.readdirSync(CLAUDE_DIR)) {
|
|
32
|
+
if (targetFolder && entry !== targetFolder) continue;
|
|
33
|
+
const projectDir = path.join(CLAUDE_DIR, entry);
|
|
17
34
|
if (!fs.statSync(projectDir).isDirectory()) continue;
|
|
18
35
|
for (const file of fs.readdirSync(projectDir)) {
|
|
19
36
|
if (file.endsWith('.jsonl')) {
|
|
@@ -25,4 +42,4 @@ function findJsonlFiles() {
|
|
|
25
42
|
return results;
|
|
26
43
|
}
|
|
27
44
|
|
|
28
|
-
module.exports = { findJsonlFiles };
|
|
45
|
+
module.exports = { findJsonlFiles, pathToProjectFolder };
|