aicp-tracker 1.1.7 → 1.1.8

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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/daemon.js +20 -14
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aicp-tracker",
3
- "version": "1.1.7",
3
+ "version": "1.1.8",
4
4
  "description": "AI Code Pulse — Claude Code usage tracker for JIRA cost attribution",
5
5
  "main": "src/daemon.js",
6
6
  "bin": {
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
- // 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
- function detectProjectPath() {
17
- try {
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: ${PROJECT_PATH}`);
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: ${PROJECT_PATH}`);
66
+ console.log(`[daemon] Started (pid ${child.pid}), tracking: ${projectPath}`);
61
67
  }
62
68
 
63
69
  function stop() {