aicp-tracker 1.1.7 → 1.1.9
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 +20 -14
- package/src/log-scanner.js +3 -2
package/package.json
CHANGED
package/src/daemon.js
CHANGED
|
@@ -11,17 +11,10 @@ const { CONFIG_DIR } = require('./config');
|
|
|
11
11
|
|
|
12
12
|
const PID_FILE = path.join(CONFIG_DIR, 'daemon.pid');
|
|
13
13
|
|
|
14
|
-
//
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const cfg = require('./config').load();
|
|
19
|
-
if (cfg?.projectPath) return cfg.projectPath;
|
|
20
|
-
} catch {}
|
|
21
|
-
return process.cwd();
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const PROJECT_PATH = detectProjectPath();
|
|
14
|
+
// Priority: env var set by parent spawn → config saved at postinstall → cwd fallback
|
|
15
|
+
const PROJECT_PATH = process.env.AICP_PROJECT_PATH
|
|
16
|
+
|| (() => { try { return require('./config').load()?.projectPath || ''; } catch { return ''; } })()
|
|
17
|
+
|| process.cwd();
|
|
25
18
|
|
|
26
19
|
async function tick() {
|
|
27
20
|
const files = findJsonlFiles(PROJECT_PATH);
|
|
@@ -42,11 +35,24 @@ function readPid() {
|
|
|
42
35
|
}
|
|
43
36
|
|
|
44
37
|
function start() {
|
|
38
|
+
const cwd = process.cwd();
|
|
39
|
+
// Only update saved projectPath when run from a real project dir (not a system dir)
|
|
40
|
+
const isProject = fs.existsSync(path.join(cwd, 'package.json')) || fs.existsSync(path.join(cwd, '.git'));
|
|
41
|
+
if (isProject) {
|
|
42
|
+
try {
|
|
43
|
+
const cfg = require('./config').load() || {};
|
|
44
|
+
require('./config').save({ ...cfg, projectPath: cwd });
|
|
45
|
+
} catch {}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Resolved path to pass to the worker (env var survives detach)
|
|
49
|
+
const projectPath = (isProject ? cwd : null) || PROJECT_PATH;
|
|
50
|
+
|
|
45
51
|
const existingPid = readPid();
|
|
46
52
|
if (existingPid) {
|
|
47
53
|
try {
|
|
48
54
|
process.kill(existingPid, 0);
|
|
49
|
-
console.log(`[daemon] Already running (pid ${existingPid}), tracking: ${
|
|
55
|
+
console.log(`[daemon] Already running (pid ${existingPid}), tracking: ${projectPath}`);
|
|
50
56
|
return;
|
|
51
57
|
} catch {}
|
|
52
58
|
}
|
|
@@ -54,10 +60,10 @@ function start() {
|
|
|
54
60
|
const child = require('child_process').spawn(
|
|
55
61
|
process.execPath,
|
|
56
62
|
[path.join(__dirname, 'daemon-worker.js')],
|
|
57
|
-
{ detached: true, stdio: 'ignore' }
|
|
63
|
+
{ detached: true, stdio: 'ignore', env: { ...process.env, AICP_PROJECT_PATH: projectPath } }
|
|
58
64
|
);
|
|
59
65
|
child.unref();
|
|
60
|
-
console.log(`[daemon] Started (pid ${child.pid}), tracking: ${
|
|
66
|
+
console.log(`[daemon] Started (pid ${child.pid}), tracking: ${projectPath}`);
|
|
61
67
|
}
|
|
62
68
|
|
|
63
69
|
function stop() {
|
package/src/log-scanner.js
CHANGED
|
@@ -17,9 +17,10 @@ function pathToProjectFolder(p) {
|
|
|
17
17
|
return p
|
|
18
18
|
.replace(/\\/g, '/')
|
|
19
19
|
.replace(/^([A-Za-z]):\//, (_, d) => d.toLowerCase() + '--')
|
|
20
|
-
.replace(/\//g, '-')
|
|
20
|
+
.replace(/\//g, '-')
|
|
21
|
+
.replace(/_/g, '-');
|
|
21
22
|
}
|
|
22
|
-
return p.replace(/\//g, '-');
|
|
23
|
+
return p.replace(/\//g, '-').replace(/_/g, '-');
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
function findJsonlFiles(projectPath) {
|