aicp-tracker 1.0.1 → 1.0.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.
@@ -1,20 +1,33 @@
1
1
  #!/usr/bin/env node
2
2
  'use strict';
3
3
 
4
- const [,, cmd, ...args] = process.argv;
4
+ const [,, cmd] = process.argv;
5
+
6
+ async function ensureConfigured() {
7
+ const config = require('../src/config');
8
+ const existing = (() => { try { return config.load(); } catch { return null; } })();
9
+ if (existing?.apiKey && existing?.vcsUrl) return;
10
+ // No config — run the wizard first, then continue
11
+ await require('./setup').main();
12
+ }
5
13
 
6
14
  switch (cmd) {
7
- case 'start': require('../src/daemon').start(); break;
15
+ case 'start':
16
+ ensureConfigured().then(() => require('../src/daemon').start()).catch(e => {
17
+ console.error('[aicp-tracker] Setup failed:', e.message);
18
+ process.exit(1);
19
+ });
20
+ break;
8
21
  case 'stop': require('../src/daemon').stop(); break;
9
22
  case 'status': require('../src/daemon').status(); break;
10
- case 'setup': require('./setup'); break;
23
+ case 'setup': require('./setup').main().catch(e => console.error('[aicp-tracker] Setup failed:', e.message)); break;
11
24
  case 'flush': require('../src/wal').flush(); break;
12
25
  default:
13
26
  console.log(`
14
27
  aicp-tracker <command>
15
28
 
16
29
  Commands:
17
- start Start the background tracker (sends usage every 5 min)
30
+ start Start the background tracker (runs setup wizard on first use)
18
31
  stop Stop the background tracker
19
32
  status Show tracker status and WAL queue depth
20
33
  setup Re-run the configuration wizard
package/bin/setup.js CHANGED
@@ -4,6 +4,22 @@
4
4
  // Runs on `npm install` (postinstall). Skipped in CI environments.
5
5
  if (process.env.CI || process.env.npm_config_yes) process.exit(0);
6
6
 
7
+ // Skip if already fully configured (upgrade path — no prompts needed)
8
+ const isPostinstall = process.env.npm_lifecycle_event === 'postinstall';
9
+ if (isPostinstall) {
10
+ let existing = null;
11
+ try { existing = require('../src/config').load(); } catch {}
12
+ if (existing?.apiKey && existing?.vcsUrl) process.exit(0);
13
+
14
+ // Interactive prompts are unreliable in the postinstall context across npm
15
+ // versions and platforms. The wizard runs on first `aicp-tracker start` instead.
16
+ console.log('\n\x1b[1m AI Code Pulse Tracker installed.\x1b[0m');
17
+ console.log(' Run \x1b[1maicp-tracker start\x1b[0m to activate tracking.\n');
18
+ process.exit(0);
19
+ }
20
+
21
+ // ── When called directly (aicp-tracker setup) ─────────────────────────────────
22
+
7
23
  const { prompt } = require('enquirer');
8
24
  const { execSync } = require('child_process');
9
25
  const fs = require('fs');
@@ -12,7 +28,7 @@ const path = require('path');
12
28
  const config = require('../src/config');
13
29
  const daemon = require('../src/daemon');
14
30
 
15
- const API_URL = 'http://147.5.102.208:3000';
31
+ const API_URL = 'https://aicp-tracker.duckdns.org';
16
32
  const TASK_NAME = 'AI Code Pulse Tracker';
17
33
 
18
34
  const PLANS = [
@@ -32,14 +48,11 @@ function installAutoStart() {
32
48
 
33
49
  try {
34
50
  if (process.platform === 'win32') {
35
- // Windows Task Scheduler: run at every login, current user only
36
51
  execSync(
37
52
  `schtasks /create /tn "${TASK_NAME}" /tr "\\"${nodePath}\\" \\"${scriptPath}\\" start" /sc ONLOGON /f`,
38
53
  { stdio: 'ignore' }
39
54
  );
40
-
41
55
  } else if (process.platform === 'darwin') {
42
- // macOS launchd: load on login
43
56
  const plistDir = path.join(os.homedir(), 'Library', 'LaunchAgents');
44
57
  const plistPath = path.join(plistDir, 'com.aicp-tracker.plist');
45
58
  fs.mkdirSync(plistDir, { recursive: true });
@@ -59,9 +72,7 @@ function installAutoStart() {
59
72
  </dict>
60
73
  </plist>`);
61
74
  execSync(`launchctl load "${plistPath}"`, { stdio: 'ignore' });
62
-
63
75
  } else {
64
- // Linux: systemd user service
65
76
  const unitDir = path.join(os.homedir(), '.config', 'systemd', 'user');
66
77
  const unitPath = path.join(unitDir, 'aicp-tracker.service');
67
78
  fs.mkdirSync(unitDir, { recursive: true });
@@ -78,7 +89,6 @@ WantedBy=default.target
78
89
  `);
79
90
  execSync('systemctl --user daemon-reload && systemctl --user enable --now aicp-tracker', { stdio: 'ignore' });
80
91
  }
81
-
82
92
  return true;
83
93
  } catch {
84
94
  return false;
@@ -103,12 +113,12 @@ async function register(email) {
103
113
  // ── Main ──────────────────────────────────────────────────────────────────────
104
114
 
105
115
  async function main() {
106
- console.log('\n\x1b[1m AI Code Pulse Tracker — first-time setup\x1b[0m\n');
116
+ console.log('\n\x1b[1m AI Code Pulse Tracker — setup\x1b[0m\n');
107
117
 
108
118
  let existing = null;
109
119
  try { existing = config.load(); } catch {}
110
120
  if (existing?.vcsUrl) {
111
- console.log(` Already configured (${existing.vcsUrl}). Re-running setup will overwrite it.\n`);
121
+ console.log(` Already configured (${existing.vcsUrl}). Answers below will overwrite it.\n`);
112
122
  }
113
123
 
114
124
  const answers = await prompt([
@@ -162,6 +172,11 @@ async function main() {
162
172
  console.log(' \x1b[32m✔\x1b[0m Tracker running. Usage will be sent every 5 minutes.\n');
163
173
  }
164
174
 
165
- main().catch(e => {
166
- console.warn('\n [aicp-tracker] Setup skipped:', e.message, '\n Run `aicp-tracker setup` to configure later.\n');
167
- });
175
+ module.exports = { main };
176
+
177
+ // Auto-run when invoked directly (aicp-tracker setup) or required without await
178
+ if (require.main === module || process.env.npm_lifecycle_event === 'postinstall') {
179
+ main().catch(e => {
180
+ console.warn('\n [aicp-tracker] Setup error:', e.message, '\n Run `aicp-tracker setup` to try again.\n');
181
+ });
182
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aicp-tracker",
3
- "version": "1.0.1",
3
+ "version": "1.0.4",
4
4
  "description": "AI Code Pulse — Claude Code usage tracker for JIRA cost attribution",
5
5
  "main": "src/daemon.js",
6
6
  "bin": {
@@ -15,6 +15,6 @@
15
15
  "engines": {
16
16
  "node": ">=18"
17
17
  },
18
- "license": "UNLICENSED",
18
+ "license": "MIT",
19
19
  "private": false
20
20
  }
package/src/log-parser.js CHANGED
@@ -88,7 +88,7 @@ function parseNewLines(filePath) {
88
88
  enterprise_usd_per_token: null,
89
89
 
90
90
  service_tier: usage.service_tier || null,
91
- speed: usage.cache_creation_input_tokens > 0 ? 'fast' : 'normal',
91
+ speed: usage.speed || (usage.cache_creation_input_tokens > 0 ? 'fast' : 'normal'),
92
92
  });
93
93
  }
94
94
 
package/LICENSE DELETED
@@ -1,19 +0,0 @@
1
- Copyright (c) 2026 Alexey Pavlenko
2
-
3
- All rights reserved.
4
-
5
- This software is proprietary and confidential.
6
-
7
- Permission is granted to install and use this software solely for the purpose
8
- of interacting with the AICP Tracker service, and only with a valid and active subscription.
9
-
10
- You may NOT:
11
- - copy, modify, merge, publish, distribute, sublicense, or sell the software
12
- - use the software in any competing product or service
13
- - reverse engineer, decompile, or attempt to extract source code or algorithms
14
- - remove or alter any proprietary notices
15
-
16
- The software is provided "as is", without warranty of any kind.
17
-
18
- Access to the source code (if provided) is for review purposes only and does
19
- not grant any rights beyond what is explicitly stated in this license.