claude-stats 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.
Files changed (2) hide show
  1. package/dist/index.js +21 -1
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -536,6 +536,14 @@ function getStats() {
536
536
  }
537
537
  return {};
538
538
  }
539
+ function getDedupeHash(msg) {
540
+ const messageId = msg.message?.id;
541
+ const requestId = msg.requestId;
542
+ if (messageId && requestId) {
543
+ return `${messageId}:${requestId}`;
544
+ }
545
+ return null;
546
+ }
539
547
  function parseSessionTokens(sessionFile) {
540
548
  const result = {
541
549
  input_tokens: 0,
@@ -545,6 +553,7 @@ function parseSessionTokens(sessionFile) {
545
553
  model: null,
546
554
  messages: 0
547
555
  };
556
+ const seen = /* @__PURE__ */ new Set();
548
557
  try {
549
558
  const content = fs2.readFileSync(sessionFile, "utf-8");
550
559
  const lines = content.trim().split("\n");
@@ -552,6 +561,11 @@ function parseSessionTokens(sessionFile) {
552
561
  try {
553
562
  const msg = JSON.parse(line);
554
563
  if (msg.type === "assistant") {
564
+ const hash = getDedupeHash(msg);
565
+ if (hash) {
566
+ if (seen.has(hash)) continue;
567
+ seen.add(hash);
568
+ }
555
569
  result.messages++;
556
570
  const usage = msg.message?.usage || {};
557
571
  result.input_tokens += usage.input_tokens || 0;
@@ -798,6 +812,7 @@ function getTodayUsageFromSessions() {
798
812
  const modelTokens = {};
799
813
  let messages = 0;
800
814
  let sessions = 0;
815
+ const seen = /* @__PURE__ */ new Set();
801
816
  if (!fs2.existsSync(PROJECTS_DIR)) {
802
817
  return {
803
818
  date: today,
@@ -830,6 +845,11 @@ function getTodayUsageFromSessions() {
830
845
  const msgLocalDate = getLocalDateString(msgDate);
831
846
  if (msgLocalDate !== today) continue;
832
847
  if (msg.type === "assistant") {
848
+ const hash = getDedupeHash(msg);
849
+ if (hash) {
850
+ if (seen.has(hash)) continue;
851
+ seen.add(hash);
852
+ }
833
853
  messages++;
834
854
  const usage = msg.message?.usage || {};
835
855
  const model = msg.message?.model || "unknown";
@@ -1222,7 +1242,7 @@ function setupDaemonCleanup() {
1222
1242
  // src/index.ts
1223
1243
  var DEFAULT_SERVER = "https://cm.cban.top";
1224
1244
  var program = new import_commander.Command();
1225
- program.name("claude-stats").description("Monitor and stream Claude Code usage statistics").version("0.2.0");
1245
+ program.name("claude-stats").description("Monitor and stream Claude Code usage statistics").version("0.2.2");
1226
1246
  function promptForInput(question, hidden = false) {
1227
1247
  return new Promise((resolve) => {
1228
1248
  const rl = readline.createInterface({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-stats",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "Monitor and stream Claude Code usage statistics to a remote dashboard",
5
5
  "keywords": [
6
6
  "claude",