aicp-tracker 1.1.5 → 1.1.7
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/bin/setup.js +8 -0
- package/package.json +1 -1
- package/src/daemon-worker.js +12 -1
- package/src/daemon.js +17 -12
package/bin/setup.js
CHANGED
|
@@ -9,6 +9,14 @@ const path = require('path');
|
|
|
9
9
|
// Skip if already fully configured (upgrade path — no prompts needed)
|
|
10
10
|
const isPostinstall = process.env.npm_lifecycle_event === 'postinstall';
|
|
11
11
|
if (isPostinstall) {
|
|
12
|
+
// Always record which project this package was installed into.
|
|
13
|
+
// process.cwd() during postinstall is the project root — the only reliable moment we know it.
|
|
14
|
+
try {
|
|
15
|
+
const config = require('../src/config');
|
|
16
|
+
const existing = config.load() || {};
|
|
17
|
+
config.save({ ...existing, projectPath: process.cwd() });
|
|
18
|
+
} catch {}
|
|
19
|
+
|
|
12
20
|
let existing = null;
|
|
13
21
|
try { existing = require('../src/config').load(); } catch {}
|
|
14
22
|
if (existing?.apiKey && existing?.vcsUrl) process.exit(0);
|
package/package.json
CHANGED
package/src/daemon-worker.js
CHANGED
|
@@ -5,11 +5,22 @@
|
|
|
5
5
|
const path = require('path');
|
|
6
6
|
const fs = require('fs');
|
|
7
7
|
const { CONFIG_DIR } = require('./config');
|
|
8
|
-
const { tick } = require('./daemon');
|
|
8
|
+
const { tick, PROJECT_PATH } = require('./daemon');
|
|
9
9
|
|
|
10
10
|
const PID_FILE = path.join(CONFIG_DIR, 'daemon.pid');
|
|
11
|
+
const LOG_FILE = path.join(CONFIG_DIR, 'daemon.log');
|
|
12
|
+
|
|
13
|
+
fs.mkdirSync(CONFIG_DIR, { recursive: true });
|
|
11
14
|
fs.writeFileSync(PID_FILE, String(process.pid), 'utf8');
|
|
12
15
|
|
|
16
|
+
// Redirect stdout/stderr to log file so we can inspect daemon activity
|
|
17
|
+
const logStream = fs.createWriteStream(LOG_FILE, { flags: 'a' });
|
|
18
|
+
const origWrite = (chunk) => logStream.write(`[${new Date().toISOString()}] ${chunk}`);
|
|
19
|
+
process.stdout.write = origWrite;
|
|
20
|
+
process.stderr.write = origWrite;
|
|
21
|
+
|
|
22
|
+
console.log(`[daemon-worker] started, tracking project: ${PROJECT_PATH}`);
|
|
23
|
+
|
|
13
24
|
process.on('SIGTERM', () => {
|
|
14
25
|
try { fs.unlinkSync(PID_FILE); } catch {}
|
|
15
26
|
process.exit(0);
|
package/src/daemon.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const path = require('path');
|
|
4
4
|
const fs = require('fs');
|
|
5
|
+
const os = require('os');
|
|
5
6
|
const { findJsonlFiles } = require('./log-scanner');
|
|
6
7
|
const { parseNewLines } = require('./log-parser');
|
|
7
8
|
const wal = require('./wal');
|
|
@@ -10,17 +11,13 @@ const { CONFIG_DIR } = require('./config');
|
|
|
10
11
|
|
|
11
12
|
const PID_FILE = path.join(CONFIG_DIR, 'daemon.pid');
|
|
12
13
|
|
|
13
|
-
//
|
|
14
|
-
//
|
|
15
|
-
// package.json that isn't ours (guards against global/npx installs).
|
|
14
|
+
// projectPath is saved during `npm install` (postinstall) when process.cwd()
|
|
15
|
+
// is reliably the host project root. Falls back to cwd if config is missing.
|
|
16
16
|
function detectProjectPath() {
|
|
17
|
-
const candidate = path.resolve(__dirname, '..', '..', '..');
|
|
18
|
-
const hostPkg = path.join(candidate, 'package.json');
|
|
19
17
|
try {
|
|
20
|
-
const
|
|
21
|
-
if (
|
|
18
|
+
const cfg = require('./config').load();
|
|
19
|
+
if (cfg?.projectPath) return cfg.projectPath;
|
|
22
20
|
} catch {}
|
|
23
|
-
// Global install or npx — fall back to cwd at start time
|
|
24
21
|
return process.cwd();
|
|
25
22
|
}
|
|
26
23
|
|
|
@@ -78,9 +75,17 @@ function stop() {
|
|
|
78
75
|
function status() {
|
|
79
76
|
const pid = readPid();
|
|
80
77
|
const running = pid ? (() => { try { process.kill(pid, 0); return true; } catch { return false; } })() : false;
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
78
|
+
const { pathToProjectFolder } = require('./log-scanner');
|
|
79
|
+
const claudeFolder = pathToProjectFolder(PROJECT_PATH);
|
|
80
|
+
const claudeDir = path.join(os.homedir(), '.claude', 'projects');
|
|
81
|
+
const available = fs.existsSync(claudeDir) ? fs.readdirSync(claudeDir).filter(e => fs.statSync(path.join(claudeDir, e)).isDirectory()) : [];
|
|
82
|
+
const matched = available.includes(claudeFolder);
|
|
83
|
+
console.log(`[daemon] Status: ${running ? `running (pid ${pid})` : 'stopped'}`);
|
|
84
|
+
console.log(`[daemon] Project path: ${PROJECT_PATH}`);
|
|
85
|
+
console.log(`[daemon] Claude folder: ${claudeFolder} ${matched ? '✔ found' : '✘ NOT FOUND in ~/.claude/projects'}`);
|
|
86
|
+
if (!matched) console.log(`[daemon] Available: ${available.join(', ')}`);
|
|
87
|
+
console.log(`[daemon] WAL pending: ${wal.pendingCount()} records`);
|
|
88
|
+
console.log(`[daemon] Log file: ${path.join(CONFIG_DIR, 'daemon.log')}`);
|
|
84
89
|
}
|
|
85
90
|
|
|
86
|
-
module.exports = { start, stop, status, tick };
|
|
91
|
+
module.exports = { start, stop, status, tick, PROJECT_PATH };
|