codetime-cli 0.3.2 → 0.3.3

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 +12 -40
  2. package/package.json +2 -2
package/bin/codetime.mjs CHANGED
@@ -972,7 +972,7 @@ import { readFile as readFile2, stat as stat2 } from "node:fs/promises";
972
972
  import path2 from "node:path";
973
973
 
974
974
  // src/lib/constants.ts
975
- var PACKAGE_VERSION = true ? "0.3.2" : "0.1.1";
975
+ var PACKAGE_VERSION = true ? "0.3.3" : "0.1.1";
976
976
  var DEFAULT_API_URL = "https://codetime.dev";
977
977
  var DEFAULT_BACKFILL_BATCH_SIZE = 50;
978
978
  var DEFAULT_BACKFILL_BATCH_BYTES = 800 * 1024;
@@ -2223,12 +2223,12 @@ async function parseCodexSessionFile(filePath, options) {
2223
2223
  const text = await readFile4(filePath, "utf8");
2224
2224
  const lines = text.split("\n").filter(Boolean);
2225
2225
  const sourcePathHash = `sha256:${createStableHash(filePath)}`;
2226
- const serviceTier = await resolveCodexServiceTier(filePath);
2227
2226
  const events = [];
2228
2227
  let sessionId = sessionIdFromFilePath(filePath, "codex");
2229
2228
  let cwd;
2230
2229
  let project;
2231
2230
  let model;
2231
+ let serviceTier;
2232
2232
  let currentTurnId;
2233
2233
  let lastTurnIdForComplete;
2234
2234
  let turnIdAtLastUserMessage;
@@ -2274,6 +2274,10 @@ async function parseCodexSessionFile(filePath, options) {
2274
2274
  cwd = stringField(payload, "cwd") || cwd;
2275
2275
  project = cwd ? path7.basename(cwd) : project;
2276
2276
  model = stringField(payload, "model") || model;
2277
+ const tier = stringField(payload, "service_tier");
2278
+ if (tier) {
2279
+ serviceTier = tier.toLowerCase();
2280
+ }
2277
2281
  continue;
2278
2282
  }
2279
2283
  if (topType !== "event_msg" && topType !== "response_item") {
@@ -2333,6 +2337,11 @@ async function parseCodexSessionFile(filePath, options) {
2333
2337
  break;
2334
2338
  }
2335
2339
  case "token_count": {
2340
+ const info = objectField(payload, "info");
2341
+ const tierFromInfo = stringField(info, "service_tier") || stringField(payload, "service_tier");
2342
+ if (tierFromInfo) {
2343
+ serviceTier = tierFromInfo.toLowerCase();
2344
+ }
2336
2345
  const usage = tokenUsageFromPayload(payload);
2337
2346
  if (usage) {
2338
2347
  const usageKey = [
@@ -2545,43 +2554,6 @@ async function parseCodexSessionFile(filePath, options) {
2545
2554
  }
2546
2555
  return events.filter((event) => validateCanonicalEvent(event).valid);
2547
2556
  }
2548
- var codexServiceTierCache = /* @__PURE__ */ new Map();
2549
- async function resolveCodexServiceTier(sessionFilePath) {
2550
- const home = inferCodexHomeFromSessionPath(sessionFilePath);
2551
- if (!home) {
2552
- return void 0;
2553
- }
2554
- if (!codexServiceTierCache.has(home)) {
2555
- codexServiceTierCache.set(home, await readCodexServiceTier(home));
2556
- }
2557
- return codexServiceTierCache.get(home) ?? void 0;
2558
- }
2559
- function inferCodexHomeFromSessionPath(sessionFilePath) {
2560
- if (path7.basename(sessionFilePath) === "history.jsonl") {
2561
- return path7.dirname(sessionFilePath);
2562
- }
2563
- let dir = path7.dirname(sessionFilePath);
2564
- for (let depth = 0; depth < 10; depth += 1) {
2565
- const parent = path7.dirname(dir);
2566
- if (parent === dir) {
2567
- return void 0;
2568
- }
2569
- if (path7.basename(dir) === "sessions") {
2570
- return parent;
2571
- }
2572
- dir = parent;
2573
- }
2574
- return void 0;
2575
- }
2576
- async function readCodexServiceTier(codexHomePath) {
2577
- try {
2578
- const text = await readFile4(path7.join(codexHomePath, "config.toml"), "utf8");
2579
- const match = text.match(/(?:^|\n)\s*service_tier\s*=\s*["']?([a-z_]+)["']?/i);
2580
- return match ? match[1].toLowerCase() : null;
2581
- } catch {
2582
- return null;
2583
- }
2584
- }
2585
2557
  function rewriteCodexModelForTier(model, serviceTier) {
2586
2558
  if (!model) {
2587
2559
  return model;
@@ -4406,7 +4378,7 @@ async function deleteMachine(remote, id) {
4406
4378
  }
4407
4379
 
4408
4380
  // src/lib/types.ts
4409
- var BACKFILL_STATE_SCHEMA_VERSION = 3;
4381
+ var BACKFILL_STATE_SCHEMA_VERSION = 4;
4410
4382
 
4411
4383
  // src/cli.ts
4412
4384
  function createRegistry() {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "codetime-cli",
3
3
  "type": "module",
4
- "version": "0.3.2",
4
+ "version": "0.3.3",
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": {
@@ -35,7 +35,7 @@
35
35
  "devDependencies": {
36
36
  "cac": "^7.0.0",
37
37
  "esbuild": "^0.28.0",
38
- "@codetime/shared": "0.3.2"
38
+ "@codetime/shared": "0.3.3"
39
39
  },
40
40
  "scripts": {
41
41
  "build": "tsc -p tsconfig.json",