@statforge/claudestat 1.5.0 → 1.5.1
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/dist/daemon.js +1 -1
- package/dist/enricher.js +1 -1
- package/dist/paths.js +1 -1
- package/dist/routes/events.d.ts +0 -2
- package/dist/routes/events.js +2 -16
- package/dist/routes/helpers.d.ts +2 -0
- package/dist/routes/helpers.js +21 -0
- package/dist/routes/projects.d.ts +0 -2
- package/dist/routes/projects.js +3 -17
- package/dist/watch.js +0 -1
- package/dist/watchdog.d.ts +5 -0
- package/dist/watchdog.js +6 -1
- package/dist/watchers/claude-code.js +9 -9
- package/package.json +3 -2
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Deiby Gorrin
|
|
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/dist/daemon.js
CHANGED
package/dist/enricher.js
CHANGED
package/dist/paths.js
CHANGED
|
@@ -79,7 +79,7 @@ function getDashboardDir() {
|
|
|
79
79
|
* Empirically verified: Claude Code CLI stores settings at ~/.claude on macOS, Linux, and Windows.
|
|
80
80
|
*/
|
|
81
81
|
function getClaudeDir() {
|
|
82
|
-
return path_1.default.join(os_1.default.homedir(), '.claude');
|
|
82
|
+
return process.env.CLAUDE_DIR ?? path_1.default.join(os_1.default.homedir(), '.claude');
|
|
83
83
|
}
|
|
84
84
|
// ─── ClaudeStat data directory ─────────────────────────────────────────────────
|
|
85
85
|
/**
|
package/dist/routes/events.d.ts
CHANGED
|
@@ -5,8 +5,6 @@ export declare const lastAgentByCwd: Map<string, {
|
|
|
5
5
|
session_id: string;
|
|
6
6
|
}>;
|
|
7
7
|
export declare const taggedSessionParents: Set<string>;
|
|
8
|
-
/** Sube el árbol desde un file_path hasta encontrar HANDOFF.md → directorio del proyecto */
|
|
9
|
-
export declare function findProjectCwdForFile(filePath: string): string | undefined;
|
|
10
8
|
/**
|
|
11
9
|
* Cuando el enricher detecta nuevos tokens en un JSONL:
|
|
12
10
|
* 1. Corre el análisis de inteligencia
|
package/dist/routes/events.js
CHANGED
|
@@ -5,9 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
};
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.processLatestForSession = exports.onCompactDetected = exports.onCostUpdate = exports.taggedSessionParents = exports.lastAgentByCwd = exports.eventsRouter = void 0;
|
|
8
|
-
exports.findProjectCwdForFile = findProjectCwdForFile;
|
|
9
8
|
const path_1 = __importDefault(require("path"));
|
|
10
|
-
const fs_1 = __importDefault(require("fs"));
|
|
11
9
|
const express_1 = require("express");
|
|
12
10
|
const db_1 = require("../db");
|
|
13
11
|
const intelligence_1 = require("../intelligence");
|
|
@@ -18,6 +16,7 @@ const config_1 = require("../config");
|
|
|
18
16
|
const rate_limiter_1 = require("../middleware/rate-limiter");
|
|
19
17
|
const stream_1 = require("./stream");
|
|
20
18
|
const notifier_1 = require("../notifier");
|
|
19
|
+
const helpers_1 = require("./helpers");
|
|
21
20
|
const enricher_1 = require("../enricher");
|
|
22
21
|
Object.defineProperty(exports, "processLatestForSession", { enumerable: true, get: function () { return enricher_1.processLatestForSession; } });
|
|
23
22
|
// ─── Loop alert cooldown (toolName:sessionId → last alert ts) ─────────────────
|
|
@@ -56,19 +55,6 @@ function shouldFireAlert(level, pct) {
|
|
|
56
55
|
alertCooldown.set(level, Date.now());
|
|
57
56
|
return true;
|
|
58
57
|
}
|
|
59
|
-
/** Sube el árbol desde un file_path hasta encontrar HANDOFF.md → directorio del proyecto */
|
|
60
|
-
function findProjectCwdForFile(filePath) {
|
|
61
|
-
let dir = path_1.default.dirname(filePath);
|
|
62
|
-
for (let i = 0; i < 6; i++) {
|
|
63
|
-
if (fs_1.default.existsSync(path_1.default.join(dir, 'HANDOFF.md')))
|
|
64
|
-
return dir;
|
|
65
|
-
const parent = path_1.default.dirname(dir);
|
|
66
|
-
if (parent === dir)
|
|
67
|
-
break;
|
|
68
|
-
dir = parent;
|
|
69
|
-
}
|
|
70
|
-
return undefined;
|
|
71
|
-
}
|
|
72
58
|
exports.eventsRouter.post('/event', (req, res) => {
|
|
73
59
|
const ip = req.ip ?? '127.0.0.1';
|
|
74
60
|
if ((0, rate_limiter_1.isRateLimited)(ip)) {
|
|
@@ -132,7 +118,7 @@ exports.eventsRouter.post('/event', (req, res) => {
|
|
|
132
118
|
const inp = typeof tool_input === 'string' ? JSON.parse(tool_input) : (tool_input ?? {});
|
|
133
119
|
const filePath = inp?.file_path ?? inp?.path;
|
|
134
120
|
if (typeof filePath === 'string' && path_1.default.isAbsolute(filePath)) {
|
|
135
|
-
const projectCwd = findProjectCwdForFile(filePath);
|
|
121
|
+
const projectCwd = (0, helpers_1.findProjectCwdForFile)(filePath);
|
|
136
122
|
if (projectCwd)
|
|
137
123
|
db_1.dbOps.updateSessionProject(session_id, projectCwd);
|
|
138
124
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.findProjectCwdForFile = findProjectCwdForFile;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const fs_1 = __importDefault(require("fs"));
|
|
9
|
+
/** Sube el árbol desde un file_path hasta encontrar HANDOFF.md → directorio del proyecto */
|
|
10
|
+
function findProjectCwdForFile(filePath) {
|
|
11
|
+
let dir = path_1.default.dirname(filePath);
|
|
12
|
+
for (let i = 0; i < 6; i++) {
|
|
13
|
+
if (fs_1.default.existsSync(path_1.default.join(dir, 'HANDOFF.md')))
|
|
14
|
+
return dir;
|
|
15
|
+
const parent = path_1.default.dirname(dir);
|
|
16
|
+
if (parent === dir)
|
|
17
|
+
break;
|
|
18
|
+
dir = parent;
|
|
19
|
+
}
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { type EventRow } from '../db';
|
|
2
2
|
export declare const projectsRouter: import("express-serve-static-core").Router;
|
|
3
|
-
/** Sube el árbol desde un file_path hasta encontrar HANDOFF.md → directorio del proyecto */
|
|
4
|
-
export declare function findProjectCwdForFile(filePath: string): string | undefined;
|
|
5
3
|
/** Infiere el proyecto activo mirando los eventos de archivo de una sesión */
|
|
6
4
|
export declare function inferProjectCwd(events: EventRow[]): string | undefined;
|
|
7
5
|
/**
|
package/dist/routes/projects.js
CHANGED
|
@@ -5,29 +5,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
};
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.projectsRouter = void 0;
|
|
8
|
-
exports.findProjectCwdForFile = findProjectCwdForFile;
|
|
9
8
|
exports.inferProjectCwd = inferProjectCwd;
|
|
10
9
|
exports.inferActiveProjectByMajority = inferActiveProjectByMajority;
|
|
11
10
|
const path_1 = __importDefault(require("path"));
|
|
12
|
-
const fs_1 = __importDefault(require("fs"));
|
|
13
11
|
const express_1 = require("express");
|
|
14
12
|
const db_1 = require("../db");
|
|
15
13
|
const projects_cache_1 = require("../cache/projects-cache");
|
|
16
14
|
const pattern_analyzer_1 = require("../pattern-analyzer");
|
|
15
|
+
const helpers_1 = require("./helpers");
|
|
17
16
|
exports.projectsRouter = (0, express_1.Router)();
|
|
18
|
-
/** Sube el árbol desde un file_path hasta encontrar HANDOFF.md → directorio del proyecto */
|
|
19
|
-
function findProjectCwdForFile(filePath) {
|
|
20
|
-
let dir = path_1.default.dirname(filePath);
|
|
21
|
-
for (let i = 0; i < 6; i++) {
|
|
22
|
-
if (fs_1.default.existsSync(path_1.default.join(dir, 'HANDOFF.md')))
|
|
23
|
-
return dir;
|
|
24
|
-
const parent = path_1.default.dirname(dir);
|
|
25
|
-
if (parent === dir)
|
|
26
|
-
break;
|
|
27
|
-
dir = parent;
|
|
28
|
-
}
|
|
29
|
-
return undefined;
|
|
30
|
-
}
|
|
31
17
|
/** Infiere el proyecto activo mirando los eventos de archivo de una sesión */
|
|
32
18
|
function inferProjectCwd(events) {
|
|
33
19
|
const FILE_TOOLS = new Set(['Read', 'Write', 'Edit', 'Glob', 'Grep']);
|
|
@@ -41,7 +27,7 @@ function inferProjectCwd(events) {
|
|
|
41
27
|
const filePath = (inp.file_path || inp.path);
|
|
42
28
|
if (!filePath || !path_1.default.isAbsolute(filePath))
|
|
43
29
|
continue;
|
|
44
|
-
const cwd = findProjectCwdForFile(filePath);
|
|
30
|
+
const cwd = (0, helpers_1.findProjectCwdForFile)(filePath);
|
|
45
31
|
if (cwd)
|
|
46
32
|
return cwd;
|
|
47
33
|
}
|
|
@@ -73,7 +59,7 @@ function inferActiveProjectByMajority(events, windowMs) {
|
|
|
73
59
|
const filePath = (inp.file_path || inp.path);
|
|
74
60
|
if (!filePath || !path_1.default.isAbsolute(filePath))
|
|
75
61
|
continue;
|
|
76
|
-
const project = findProjectCwdForFile(filePath);
|
|
62
|
+
const project = (0, helpers_1.findProjectCwdForFile)(filePath);
|
|
77
63
|
if (!project)
|
|
78
64
|
continue;
|
|
79
65
|
const entry = hits.get(project) ?? { count: 0, lastTs: 0 };
|
package/dist/watch.js
CHANGED
|
@@ -80,7 +80,6 @@ async function startWatch() {
|
|
|
80
80
|
}
|
|
81
81
|
fetchQuota().then(pct => { state.cyclePct = pct; });
|
|
82
82
|
setInterval(async () => { state.cyclePct = await fetchQuota(); }, 30000);
|
|
83
|
-
// Refrescar stats semanales cada 5 minutos
|
|
84
83
|
setInterval(() => { state.weekly = (0, weekly_1.readWeeklyStats)(); }, 5 * 60 * 1000);
|
|
85
84
|
function draw() {
|
|
86
85
|
if (state.sessionId) {
|
package/dist/watchdog.d.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* watchdog.ts — Daemon auto-restart mechanism
|
|
3
3
|
*
|
|
4
|
+
* NOTE: The watchdog currently runs in the same process as the daemon.
|
|
5
|
+
* This means it cannot restart the daemon if the process crashes.
|
|
6
|
+
* For true resilience, the watchdog should be spawned as a separate
|
|
7
|
+
* process via `child_process.spawn()` with `detached: true`.
|
|
8
|
+
*
|
|
4
9
|
* If the daemon process crashes or is killed unexpectedly, the watchdog
|
|
5
10
|
* detects the stale PID file and relaunches the daemon automatically.
|
|
6
11
|
*
|
package/dist/watchdog.js
CHANGED
|
@@ -2,6 +2,11 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* watchdog.ts — Daemon auto-restart mechanism
|
|
4
4
|
*
|
|
5
|
+
* NOTE: The watchdog currently runs in the same process as the daemon.
|
|
6
|
+
* This means it cannot restart the daemon if the process crashes.
|
|
7
|
+
* For true resilience, the watchdog should be spawned as a separate
|
|
8
|
+
* process via `child_process.spawn()` with `detached: true`.
|
|
9
|
+
*
|
|
5
10
|
* If the daemon process crashes or is killed unexpectedly, the watchdog
|
|
6
11
|
* detects the stale PID file and relaunches the daemon automatically.
|
|
7
12
|
*
|
|
@@ -69,7 +74,7 @@ function startWatchdog() {
|
|
|
69
74
|
catch { }
|
|
70
75
|
restartDaemon();
|
|
71
76
|
}
|
|
72
|
-
}, CHECK_INTERVAL_MS);
|
|
77
|
+
}, CHECK_INTERVAL_MS).unref();
|
|
73
78
|
process.on('SIGTERM', () => { clearInterval(interval); process.exit(0); });
|
|
74
79
|
process.on('SIGINT', () => { clearInterval(interval); process.exit(0); });
|
|
75
80
|
}
|
|
@@ -19,7 +19,7 @@ const fs_1 = __importDefault(require("fs"));
|
|
|
19
19
|
const adapter_1 = require("./adapter");
|
|
20
20
|
const paths_1 = require("../paths");
|
|
21
21
|
const pricing_1 = require("../pricing");
|
|
22
|
-
|
|
22
|
+
function projectsDir() { return path_1.default.join((0, paths_1.getClaudeDir)(), 'projects'); }
|
|
23
23
|
const KNOWN_CONTEXT_WINDOWS = {
|
|
24
24
|
'claude-opus-4-6': 200000,
|
|
25
25
|
'claude-sonnet-4-6': 200000,
|
|
@@ -119,14 +119,14 @@ exports.claudeCodeAdapter = {
|
|
|
119
119
|
get shortName() { return 'CC'; },
|
|
120
120
|
detect() {
|
|
121
121
|
try {
|
|
122
|
-
return fs_1.default.existsSync(
|
|
122
|
+
return fs_1.default.existsSync(projectsDir());
|
|
123
123
|
}
|
|
124
124
|
catch {
|
|
125
125
|
return false;
|
|
126
126
|
}
|
|
127
127
|
},
|
|
128
128
|
getWatchPaths() {
|
|
129
|
-
return [`${
|
|
129
|
+
return [`${projectsDir()}/**/*.jsonl`];
|
|
130
130
|
},
|
|
131
131
|
parseEvent(raw, _filePath) {
|
|
132
132
|
try {
|
|
@@ -164,11 +164,11 @@ async function getAllBlockCostsForSession(sessionId) {
|
|
|
164
164
|
return cached?.data ?? [];
|
|
165
165
|
costCacheLocks.set(sessionId, true);
|
|
166
166
|
try {
|
|
167
|
-
if (!fs_1.default.existsSync(
|
|
167
|
+
if (!fs_1.default.existsSync(projectsDir()))
|
|
168
168
|
return [];
|
|
169
|
-
const dirs = await promises_1.default.readdir(
|
|
169
|
+
const dirs = await promises_1.default.readdir(projectsDir());
|
|
170
170
|
for (const dir of dirs) {
|
|
171
|
-
const dirPath = path_1.default.join(
|
|
171
|
+
const dirPath = path_1.default.join(projectsDir(), dir);
|
|
172
172
|
try {
|
|
173
173
|
const stat = await promises_1.default.stat(dirPath);
|
|
174
174
|
if (!stat.isDirectory())
|
|
@@ -241,11 +241,11 @@ async function getAllBlockCostsForSession(sessionId) {
|
|
|
241
241
|
}
|
|
242
242
|
async function getSessionPrompts(sessionId) {
|
|
243
243
|
try {
|
|
244
|
-
if (!fs_1.default.existsSync(
|
|
244
|
+
if (!fs_1.default.existsSync(projectsDir()))
|
|
245
245
|
return [];
|
|
246
|
-
const dirs = await promises_1.default.readdir(
|
|
246
|
+
const dirs = await promises_1.default.readdir(projectsDir());
|
|
247
247
|
for (const dir of dirs) {
|
|
248
|
-
const dirPath = path_1.default.join(
|
|
248
|
+
const dirPath = path_1.default.join(projectsDir(), dir);
|
|
249
249
|
try {
|
|
250
250
|
const stat = await promises_1.default.stat(dirPath);
|
|
251
251
|
if (!stat.isDirectory())
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@statforge/claudestat",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -51,6 +51,8 @@
|
|
|
51
51
|
"hooks/",
|
|
52
52
|
"dashboard/dist/"
|
|
53
53
|
],
|
|
54
|
+
"main": "dist/index.js",
|
|
55
|
+
"types": "dist/index.d.ts",
|
|
54
56
|
"bin": {
|
|
55
57
|
"claudestat": "dist/index.js",
|
|
56
58
|
"claudestat-mcp": "dist/mcp-server.js"
|
|
@@ -61,7 +63,6 @@
|
|
|
61
63
|
"build:bun": "bun run scripts/build-binary.ts",
|
|
62
64
|
"build:bun:all": "bun run scripts/build-binary.ts --all",
|
|
63
65
|
"prepublishOnly": "npm run build",
|
|
64
|
-
"prepack": "npm run build",
|
|
65
66
|
"dev": "tsx src/index.ts",
|
|
66
67
|
"dev:full": "tsx src/index.ts start & sleep 1 && cd dashboard && npm run dev",
|
|
67
68
|
"start": "node dist/index.js",
|