claude-roi 0.2.1 → 0.2.2
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/LICENSE +21 -0
- package/README.md +1 -30
- package/package.json +15 -5
- package/src/correlator.js +74 -42
- package/src/index.js +4 -1
- package/playwright.config.js +0 -9
- package/tests/dashboard.spec.js +0 -1507
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Akshat Sahu
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -151,36 +151,7 @@ Codelens-AI/
|
|
|
151
151
|
|
|
152
152
|
## Contributing
|
|
153
153
|
|
|
154
|
-
Contributions welcome!
|
|
155
|
-
|
|
156
|
-
```bash
|
|
157
|
-
# 1. Fork the repo on GitHub
|
|
158
|
-
|
|
159
|
-
# 2. Clone your fork
|
|
160
|
-
git clone https://github.com/YOUR_USERNAME/Codelens-AI.git
|
|
161
|
-
cd Codelens-AI
|
|
162
|
-
|
|
163
|
-
# 3. Install dependencies
|
|
164
|
-
npm install
|
|
165
|
-
|
|
166
|
-
# 4. Run in dev mode (no auto-open browser)
|
|
167
|
-
node src/index.js --no-open
|
|
168
|
-
|
|
169
|
-
# 5. Make your changes and test
|
|
170
|
-
node src/index.js --json | head -30 # verify JSON output
|
|
171
|
-
node src/index.js --no-open # test dashboard at localhost:3457
|
|
172
|
-
|
|
173
|
-
# 6. Submit a pull request
|
|
174
|
-
```
|
|
175
|
-
|
|
176
|
-
### Ideas for contributions
|
|
177
|
-
|
|
178
|
-
- Support for other AI coding tools (Copilot, Cursor, etc.)
|
|
179
|
-
- Git blame-based line survival tracking (more accurate than the 24h heuristic)
|
|
180
|
-
- Export dashboard as PDF/PNG
|
|
181
|
-
- Historical trend tracking across multiple runs
|
|
182
|
-
- Team/multi-user support
|
|
183
|
-
- Custom pricing configuration via CLI flag or config file
|
|
154
|
+
Contributions are welcome! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for development setup, guidelines, and ideas for contributions.
|
|
184
155
|
|
|
185
156
|
## Privacy
|
|
186
157
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "claude-roi",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "Correlate Claude Code token usage with git output to measure AI coding agent ROI",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
"main": "./src/index.js",
|
|
10
10
|
"scripts": {
|
|
11
11
|
"start": "node src/index.js",
|
|
12
|
-
"dev": "node src/index.js --no-open"
|
|
12
|
+
"dev": "node src/index.js --no-open",
|
|
13
|
+
"test": "npx playwright test"
|
|
13
14
|
},
|
|
14
15
|
"keywords": [
|
|
15
16
|
"claude",
|
|
@@ -21,17 +22,26 @@
|
|
|
21
22
|
"git",
|
|
22
23
|
"dashboard"
|
|
23
24
|
],
|
|
25
|
+
"author": "Akshat Sahu",
|
|
24
26
|
"license": "MIT",
|
|
27
|
+
"repository": {
|
|
28
|
+
"type": "git",
|
|
29
|
+
"url": "git+https://github.com/Akshat2634/Codelens-AI.git"
|
|
30
|
+
},
|
|
31
|
+
"bugs": {
|
|
32
|
+
"url": "https://github.com/Akshat2634/Codelens-AI/issues"
|
|
33
|
+
},
|
|
34
|
+
"homepage": "https://github.com/Akshat2634/Codelens-AI#readme",
|
|
25
35
|
"engines": {
|
|
26
36
|
"node": ">=18.0.0"
|
|
27
37
|
},
|
|
28
38
|
"dependencies": {
|
|
29
39
|
"commander": "^13.0.0",
|
|
30
40
|
"express": "^5.0.0",
|
|
31
|
-
"open": "^10.0.0"
|
|
32
|
-
"playwright": "^1.58.2"
|
|
41
|
+
"open": "^10.0.0"
|
|
33
42
|
},
|
|
34
43
|
"devDependencies": {
|
|
35
|
-
"@playwright/test": "^1.56.1"
|
|
44
|
+
"@playwright/test": "^1.56.1",
|
|
45
|
+
"playwright": "^1.58.2"
|
|
36
46
|
}
|
|
37
47
|
}
|
package/src/correlator.js
CHANGED
|
@@ -14,67 +14,100 @@ function computeOverlappingLines(commits, sessionFiles) {
|
|
|
14
14
|
return { linesAdded, linesDeleted };
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
+
/**
|
|
18
|
+
* Compute the temporal distance between a commit and a session.
|
|
19
|
+
* Returns the minimum absolute distance from the commit to the session's
|
|
20
|
+
* time range (0 if the commit falls within the session window).
|
|
21
|
+
*/
|
|
22
|
+
function temporalDistance(commitMs, sessionStartMs, sessionEndMs) {
|
|
23
|
+
if (commitMs >= sessionStartMs && commitMs <= sessionEndMs) return 0;
|
|
24
|
+
return Math.min(
|
|
25
|
+
Math.abs(commitMs - sessionStartMs),
|
|
26
|
+
Math.abs(commitMs - sessionEndMs)
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
|
|
17
30
|
/**
|
|
18
31
|
* Correlate sessions to commits using file-based matching.
|
|
19
32
|
*
|
|
33
|
+
* Uses a two-pass "nearest session wins" approach:
|
|
34
|
+
* 1. For each commit, find all candidate sessions (file overlap + time window)
|
|
35
|
+
* and assign it to the temporally closest one.
|
|
36
|
+
* 2. Build correlated results from those assignments.
|
|
37
|
+
*
|
|
20
38
|
* Primary: match commits whose changed files overlap with session.filesWritten.
|
|
21
|
-
* Time constraint: commit is
|
|
39
|
+
* Time constraint: commit is within [sessionStart, sessionEnd + 2 hours].
|
|
22
40
|
* Fallback: for sessions with no filesWritten (chat-only), use time window
|
|
23
41
|
* [sessionStart, sessionEnd + 2 hours].
|
|
24
42
|
*/
|
|
25
43
|
export function correlateSessions(sessions, commitsByRepo) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
// Sort sessions by end time so earlier sessions claim commits first
|
|
30
|
-
const sorted = [...sessions].sort(
|
|
31
|
-
(a, b) => new Date(a.endTime).getTime() - new Date(b.endTime).getTime()
|
|
32
|
-
);
|
|
44
|
+
// Phase 1: Build candidate map — for each commit, find the best session
|
|
45
|
+
// commitHash -> { session, hasFileOverlap }
|
|
46
|
+
const commitAssignment = new Map();
|
|
33
47
|
|
|
34
|
-
for (const session of
|
|
48
|
+
for (const session of sessions) {
|
|
35
49
|
const repoAnalysis = commitsByRepo[session.repoPath];
|
|
36
50
|
const repoCommits = repoAnalysis?.commits || [];
|
|
37
51
|
|
|
38
|
-
const
|
|
39
|
-
const
|
|
52
|
+
const sessionStartMs = new Date(session.startTime).getTime();
|
|
53
|
+
const sessionEndMs = new Date(session.endTime).getTime();
|
|
40
54
|
const sessionFiles = new Set(session.filesWritten || []);
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
55
|
+
const windowEnd = sessionEndMs + FALLBACK_BUFFER_MS;
|
|
56
|
+
|
|
57
|
+
for (const commit of repoCommits) {
|
|
58
|
+
// Time constraint: commit must fall within [sessionStart, sessionEnd + 2h]
|
|
59
|
+
if (commit.timestampMs < sessionStartMs || commit.timestampMs > windowEnd) continue;
|
|
60
|
+
|
|
61
|
+
const hasFileOverlap = sessionFiles.size > 0 &&
|
|
62
|
+
commit.files.some(f => sessionFiles.has(f.path));
|
|
63
|
+
const isChatOnly = sessionFiles.size === 0;
|
|
64
|
+
|
|
65
|
+
// Must have file overlap, or be a chat-only session (time-based fallback)
|
|
66
|
+
if (!hasFileOverlap && !isChatOnly) continue;
|
|
67
|
+
|
|
68
|
+
const distance = temporalDistance(commit.timestampMs, sessionStartMs, sessionEndMs);
|
|
69
|
+
const existing = commitAssignment.get(commit.hash);
|
|
70
|
+
|
|
71
|
+
if (!existing) {
|
|
72
|
+
commitAssignment.set(commit.hash, { session, hasFileOverlap, distance });
|
|
73
|
+
} else {
|
|
74
|
+
// Prefer file-based match over time-only match
|
|
75
|
+
if (hasFileOverlap && !existing.hasFileOverlap) {
|
|
76
|
+
commitAssignment.set(commit.hash, { session, hasFileOverlap, distance });
|
|
77
|
+
} else if (hasFileOverlap === existing.hasFileOverlap && distance < existing.distance) {
|
|
78
|
+
// Same match type — prefer temporally closer session
|
|
79
|
+
commitAssignment.set(commit.hash, { session, hasFileOverlap, distance });
|
|
80
|
+
}
|
|
81
|
+
}
|
|
65
82
|
}
|
|
83
|
+
}
|
|
66
84
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
85
|
+
// Phase 2: Group commits by assigned session
|
|
86
|
+
const sessionCommits = new Map(); // sessionId -> commit[]
|
|
87
|
+
for (const [hash, { session }] of commitAssignment) {
|
|
88
|
+
if (!sessionCommits.has(session.sessionId)) {
|
|
89
|
+
sessionCommits.set(session.sessionId, []);
|
|
90
|
+
}
|
|
91
|
+
// Find the actual commit object from the repo
|
|
92
|
+
const repoAnalysis = commitsByRepo[session.repoPath];
|
|
93
|
+
const commit = repoAnalysis?.commits?.find(c => c.hash === hash);
|
|
94
|
+
if (commit) {
|
|
95
|
+
sessionCommits.get(session.sessionId).push(commit);
|
|
70
96
|
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// Phase 3: Build correlated results
|
|
100
|
+
const claimedCommits = new Set(commitAssignment.keys());
|
|
101
|
+
const result = [];
|
|
102
|
+
|
|
103
|
+
for (const session of sessions) {
|
|
104
|
+
const sessionFiles = new Set(session.filesWritten || []);
|
|
105
|
+
const matched = sessionCommits.get(session.sessionId) || [];
|
|
71
106
|
|
|
72
107
|
let linesAdded, linesDeleted;
|
|
73
108
|
if (sessionFiles.size > 0) {
|
|
74
|
-
// Only count lines from files Claude actually edited
|
|
75
109
|
({ linesAdded, linesDeleted } = computeOverlappingLines(matched, sessionFiles));
|
|
76
110
|
} else {
|
|
77
|
-
// Fallback (chat-only): count all lines in matched commits
|
|
78
111
|
linesAdded = matched.reduce((s, c) => s + c.totalAdded, 0);
|
|
79
112
|
linesDeleted = matched.reduce((s, c) => s + c.totalDeleted, 0);
|
|
80
113
|
}
|
|
@@ -87,7 +120,6 @@ export function correlateSessions(sessions, commitsByRepo) {
|
|
|
87
120
|
const messageCount = session.userMessageCount + session.assistantMessageCount;
|
|
88
121
|
const isOrphaned = messageCount > 10 && matched.length === 0;
|
|
89
122
|
|
|
90
|
-
// Calculate which session files were committed vs not
|
|
91
123
|
const committedFiles = new Set(matched.flatMap(c => c.files.map(f => f.path)));
|
|
92
124
|
const uncommittedFiles = [...sessionFiles].filter(f => !committedFiles.has(f));
|
|
93
125
|
|
|
@@ -119,7 +151,7 @@ export function correlateSessions(sessions, commitsByRepo) {
|
|
|
119
151
|
}
|
|
120
152
|
}
|
|
121
153
|
|
|
122
|
-
//
|
|
154
|
+
// Sort result by start time descending (most recent first for display)
|
|
123
155
|
result.sort((a, b) => new Date(b.startTime).getTime() - new Date(a.startTime).getTime());
|
|
124
156
|
|
|
125
157
|
return { correlatedSessions: result, organicCommits };
|
package/src/index.js
CHANGED
|
@@ -9,8 +9,11 @@ import { correlateSessions } from './correlator.js';
|
|
|
9
9
|
import { computeMetrics } from './metrics.js';
|
|
10
10
|
import { loadCache, saveCache, deleteCache, getStaleFiles } from './cache.js';
|
|
11
11
|
import { createServer } from './server.js';
|
|
12
|
+
import { readFileSync } from 'node:fs';
|
|
12
13
|
|
|
13
|
-
const VERSION =
|
|
14
|
+
const { version: VERSION } = JSON.parse(
|
|
15
|
+
readFileSync(new URL('../package.json', import.meta.url), 'utf8')
|
|
16
|
+
);
|
|
14
17
|
|
|
15
18
|
async function main() {
|
|
16
19
|
const program = new Command();
|