aicp-tracker 1.1.6 → 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.
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aicp-tracker",
3
- "version": "1.1.6",
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,21 +11,10 @@ const { CONFIG_DIR } = require('./config');
11
11
 
12
12
  const PID_FILE = path.join(CONFIG_DIR, 'daemon.pid');
13
13
 
14
- // When installed locally: __dirname = <project>/node_modules/aicp-tracker/src
15
- // Resolve three levels up to get the host project root, then verify it has a
16
- // package.json that isn't ours (guards against global/npx installs).
17
- function detectProjectPath() {
18
- const candidate = path.resolve(__dirname, '..', '..', '..');
19
- const hostPkg = path.join(candidate, 'package.json');
20
- try {
21
- const pkg = JSON.parse(fs.readFileSync(hostPkg, 'utf8'));
22
- if (pkg.name !== 'aicp-tracker') return candidate;
23
- } catch {}
24
- // Global install or npx — fall back to cwd at start time
25
- return process.cwd();
26
- }
27
-
28
- 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();
29
18
 
30
19
  async function tick() {
31
20
  const files = findJsonlFiles(PROJECT_PATH);
@@ -46,11 +35,24 @@ function readPid() {
46
35
  }
47
36
 
48
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
+
49
51
  const existingPid = readPid();
50
52
  if (existingPid) {
51
53
  try {
52
54
  process.kill(existingPid, 0);
53
- console.log(`[daemon] Already running (pid ${existingPid}), tracking: ${PROJECT_PATH}`);
55
+ console.log(`[daemon] Already running (pid ${existingPid}), tracking: ${projectPath}`);
54
56
  return;
55
57
  } catch {}
56
58
  }
@@ -58,10 +60,10 @@ function start() {
58
60
  const child = require('child_process').spawn(
59
61
  process.execPath,
60
62
  [path.join(__dirname, 'daemon-worker.js')],
61
- { detached: true, stdio: 'ignore' }
63
+ { detached: true, stdio: 'ignore', env: { ...process.env, AICP_PROJECT_PATH: projectPath } }
62
64
  );
63
65
  child.unref();
64
- console.log(`[daemon] Started (pid ${child.pid}), tracking: ${PROJECT_PATH}`);
66
+ console.log(`[daemon] Started (pid ${child.pid}), tracking: ${projectPath}`);
65
67
  }
66
68
 
67
69
  function stop() {