codetime-cli 0.7.1 → 0.7.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/bin/codetime.mjs +41 -1
  2. package/package.json +1 -1
package/bin/codetime.mjs CHANGED
@@ -1030,7 +1030,7 @@ import { readFile as readFile2, stat as stat2 } from "node:fs/promises";
1030
1030
  import path2 from "node:path";
1031
1031
 
1032
1032
  // src/lib/constants.ts
1033
- var PACKAGE_VERSION = true ? "0.7.1" : "0.1.1";
1033
+ var PACKAGE_VERSION = true ? "0.7.2" : "0.1.1";
1034
1034
  var DEFAULT_API_URL = "https://codetime.dev";
1035
1035
  var DEFAULT_BACKFILL_BATCH_SIZE = 50;
1036
1036
  var DEFAULT_BACKFILL_BATCH_BYTES = 800 * 1024;
@@ -2316,6 +2316,8 @@ async function parseCodexSessionFile(filePath, options) {
2316
2316
  let turnIdAtLastUserMessage;
2317
2317
  let sessionMetaLocked = false;
2318
2318
  let lastTokenUsageKey;
2319
+ const replaySecond = detectSubagentReplaySecond(text, lines);
2320
+ let skipReplay = replaySecond !== void 0;
2319
2321
  const pendingToolCalls = /* @__PURE__ */ new Map();
2320
2322
  const turnLastEventAt = /* @__PURE__ */ new Map();
2321
2323
  const turnStartedAt = /* @__PURE__ */ new Map();
@@ -2475,6 +2477,12 @@ async function parseCodexSessionFile(filePath, options) {
2475
2477
  }
2476
2478
  const usage = tokenUsageFromPayload(payload);
2477
2479
  if (usage) {
2480
+ if (skipReplay) {
2481
+ if (ts.slice(0, 19) === replaySecond) {
2482
+ break;
2483
+ }
2484
+ skipReplay = false;
2485
+ }
2478
2486
  const usageKey = [
2479
2487
  usage.tokensInput,
2480
2488
  usage.tokensCachedInput,
@@ -2755,6 +2763,38 @@ function headlessCodexTimestamp(raw) {
2755
2763
  }
2756
2764
  return void 0;
2757
2765
  }
2766
+ function detectSubagentReplaySecond(text, lines) {
2767
+ if (!text.includes("thread_spawn")) {
2768
+ return void 0;
2769
+ }
2770
+ let firstSecond;
2771
+ for (const line of lines) {
2772
+ const raw = parseJsonLine(line);
2773
+ if (!raw || stringField(raw, "type") !== "event_msg") {
2774
+ continue;
2775
+ }
2776
+ const payload = objectField(raw, "payload");
2777
+ if (stringField(payload, "type") !== "token_count") {
2778
+ continue;
2779
+ }
2780
+ const info = objectField(payload, "info");
2781
+ const hasUsage = Object.keys(objectField(info, "last_token_usage")).length > 0 || Object.keys(objectField(info, "total_token_usage")).length > 0;
2782
+ if (!hasUsage) {
2783
+ continue;
2784
+ }
2785
+ const ts = timestampFrom(raw.timestamp) || timestampFrom(payload.timestamp);
2786
+ if (!ts) {
2787
+ continue;
2788
+ }
2789
+ const second = ts.slice(0, 19);
2790
+ if (firstSecond === void 0) {
2791
+ firstSecond = second;
2792
+ } else {
2793
+ return firstSecond === second ? firstSecond : void 0;
2794
+ }
2795
+ }
2796
+ return void 0;
2797
+ }
2758
2798
  function tokenUsageFromPayload(payload) {
2759
2799
  const info = objectField(payload, "info");
2760
2800
  const usage = objectField(info, "last_token_usage");
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "codetime-cli",
3
3
  "type": "module",
4
- "version": "0.7.1",
4
+ "version": "0.7.2",
5
5
  "description": "codetime CLI — install AI-agent hooks (Claude Code, Codex, OpenCode, Pi) and report activity to codetime.dev.",
6
6
  "license": "MIT",
7
7
  "publishConfig": {