@aiusage/cli 1.7.10 → 1.8.0
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/README.md +2 -2
- package/dist/cli.js +432 -188
- package/package.json +4 -4
- package/pricing-catalog.json +180 -36
package/dist/cli.js
CHANGED
|
@@ -180,26 +180,47 @@ function upsertSessionDate(sessionDates, sessionId, timestamp) {
|
|
|
180
180
|
|
|
181
181
|
// src/scanners/claude.ts
|
|
182
182
|
import { createReadStream } from "node:fs";
|
|
183
|
-
import { readdir as readdir3 } from "node:fs/promises";
|
|
183
|
+
import { readdir as readdir3, realpath } from "node:fs/promises";
|
|
184
184
|
import { join as join3 } from "node:path";
|
|
185
185
|
import { homedir as homedir2 } from "node:os";
|
|
186
186
|
import { createInterface } from "node:readline";
|
|
187
|
-
var FILE_CONCURRENCY = 16, MAX_LINE_BYTES = 64 * 1024 * 1024;
|
|
188
|
-
function
|
|
187
|
+
var FILE_CONCURRENCY = 16, MAX_LINE_BYTES = 64 * 1024 * 1024, MAX_COWORK_DISCOVERY_DEPTH = 8, COWORK_IGNORED_DIRS = /* @__PURE__ */ new Set(["rpm", "skills"]);
|
|
188
|
+
async function discoverClaudeProjectDirs(claudeDir, options = {}) {
|
|
189
189
|
if (claudeDir) return [claudeDir];
|
|
190
|
-
let
|
|
191
|
-
if (envVar)
|
|
192
|
-
return envVar.split(",").map((p) => p.trim()).filter(Boolean).map((p) => join3(p, "projects"));
|
|
193
|
-
let home = homedir2();
|
|
194
|
-
return [
|
|
190
|
+
let home = options.homeDir ?? homedir2(), platform2 = options.platform ?? process.platform, env = options.env ?? process.env, candidates = [
|
|
195
191
|
join3(home, ".config", "claude", "projects"),
|
|
196
192
|
join3(home, ".claude", "projects")
|
|
197
|
-
];
|
|
193
|
+
], configured = env.CLAUDE_CONFIG_DIR?.trim();
|
|
194
|
+
if (configured)
|
|
195
|
+
for (let root of configured.split(",").map((p) => p.trim()).filter(Boolean))
|
|
196
|
+
candidates.push(join3(root, "projects"));
|
|
197
|
+
try {
|
|
198
|
+
let entries = await readdir3(home, { withFileTypes: !0 });
|
|
199
|
+
for (let entry of entries)
|
|
200
|
+
/^\.claude-.+/.test(entry.name) && (!entry.isDirectory() && !entry.isSymbolicLink() || candidates.push(join3(home, entry.name, "projects")));
|
|
201
|
+
} catch {
|
|
202
|
+
}
|
|
203
|
+
let desktopDataDir = platform2 === "darwin" ? join3(home, "Library", "Application Support", "Claude") : platform2 === "win32" ? join3(env.APPDATA?.trim() || join3(home, "AppData", "Roaming"), "Claude") : join3(env.XDG_CONFIG_HOME?.trim() || join3(home, ".config"), "Claude");
|
|
204
|
+
await discoverCoworkProjectDirs(
|
|
205
|
+
join3(desktopDataDir, "local-agent-mode-sessions"),
|
|
206
|
+
0,
|
|
207
|
+
candidates
|
|
208
|
+
);
|
|
209
|
+
let seen = /* @__PURE__ */ new Set(), unique = [];
|
|
210
|
+
for (let candidate of candidates) {
|
|
211
|
+
let canonical = candidate;
|
|
212
|
+
try {
|
|
213
|
+
canonical = await realpath(candidate);
|
|
214
|
+
} catch {
|
|
215
|
+
}
|
|
216
|
+
seen.has(canonical) || (seen.add(canonical), unique.push(candidate));
|
|
217
|
+
}
|
|
218
|
+
return unique;
|
|
198
219
|
}
|
|
199
220
|
async function scanClaudeDates(targetDates, claudeDir, projectAliases) {
|
|
200
221
|
let targetDateSet = new Set(targetDates), groupedByDate = /* @__PURE__ */ new Map();
|
|
201
222
|
for (let targetDate of targetDateSet) groupedByDate.set(targetDate, /* @__PURE__ */ new Map());
|
|
202
|
-
let baseDirs =
|
|
223
|
+
let baseDirs = await discoverClaudeProjectDirs(claudeDir), processedHashes = /* @__PURE__ */ new Map(), sessionSets = /* @__PURE__ */ new Map(), fileJobs = [];
|
|
203
224
|
for (let baseDir of baseDirs) {
|
|
204
225
|
let projectDirs;
|
|
205
226
|
try {
|
|
@@ -351,6 +372,21 @@ async function walkForJsonl(dir, result) {
|
|
|
351
372
|
entry.isDirectory() ? await walkForJsonl(fullPath, result) : entry.name.endsWith(".jsonl") && result.push(fullPath);
|
|
352
373
|
}
|
|
353
374
|
}
|
|
375
|
+
async function discoverCoworkProjectDirs(dir, depth, result) {
|
|
376
|
+
let entries;
|
|
377
|
+
try {
|
|
378
|
+
entries = await readdir3(dir, { withFileTypes: !0 });
|
|
379
|
+
} catch {
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
if (entries.find((entry) => entry.name === ".claude" && entry.isDirectory())) {
|
|
383
|
+
result.push(join3(dir, ".claude", "projects"));
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
386
|
+
if (!(depth >= MAX_COWORK_DISCOVERY_DEPTH))
|
|
387
|
+
for (let entry of entries)
|
|
388
|
+
!entry.isDirectory() || COWORK_IGNORED_DIRS.has(entry.name) || await discoverCoworkProjectDirs(join3(dir, entry.name), depth + 1, result);
|
|
389
|
+
}
|
|
354
390
|
|
|
355
391
|
// src/scanners/codex.ts
|
|
356
392
|
import { createReadStream as createReadStream2 } from "node:fs";
|
|
@@ -363,6 +399,15 @@ import { createInterface as createInterface2 } from "node:readline";
|
|
|
363
399
|
var anthropic = {
|
|
364
400
|
"claude-code": {
|
|
365
401
|
models: {
|
|
402
|
+
"claude-fable-5-1": {
|
|
403
|
+
currency: "USD",
|
|
404
|
+
effective_from: "2026-09-01",
|
|
405
|
+
input_per_million: 10,
|
|
406
|
+
output_per_million: 50,
|
|
407
|
+
cache_write_5m_per_million: 12.5,
|
|
408
|
+
cache_write_1h_per_million: 20,
|
|
409
|
+
cached_input_per_million: 0.25
|
|
410
|
+
},
|
|
366
411
|
"claude-fable-5": {
|
|
367
412
|
currency: "USD",
|
|
368
413
|
input_per_million: 10,
|
|
@@ -380,6 +425,15 @@ var anthropic = {
|
|
|
380
425
|
cache_write_1h_per_million: 20,
|
|
381
426
|
cached_input_per_million: 1
|
|
382
427
|
},
|
|
428
|
+
"claude-opus-5-5": {
|
|
429
|
+
currency: "USD",
|
|
430
|
+
effective_from: "2026-09-22",
|
|
431
|
+
input_per_million: 4,
|
|
432
|
+
output_per_million: 20,
|
|
433
|
+
cache_write_5m_per_million: 5,
|
|
434
|
+
cache_write_1h_per_million: 8,
|
|
435
|
+
cached_input_per_million: 0.2
|
|
436
|
+
},
|
|
383
437
|
"claude-opus-5": {
|
|
384
438
|
currency: "USD",
|
|
385
439
|
input_per_million: 5,
|
|
@@ -497,73 +551,143 @@ var anthropic = {
|
|
|
497
551
|
var openai = {
|
|
498
552
|
codex: {
|
|
499
553
|
models: {
|
|
500
|
-
// ── GPT-
|
|
501
|
-
"gpt-
|
|
554
|
+
// ── GPT-6 系列 ──
|
|
555
|
+
"gpt-6-astra": {
|
|
502
556
|
currency: "USD",
|
|
503
557
|
notes: "prompts over 272K input tokens bill the full request at long-context rates",
|
|
504
|
-
input_per_million:
|
|
505
|
-
cached_input_per_million:
|
|
506
|
-
cache_write_per_million:
|
|
507
|
-
output_per_million:
|
|
558
|
+
input_per_million: 10,
|
|
559
|
+
cached_input_per_million: 1,
|
|
560
|
+
cache_write_per_million: 12.5,
|
|
561
|
+
output_per_million: 50,
|
|
508
562
|
tiers: [
|
|
509
563
|
{
|
|
510
564
|
threshold: 272e3,
|
|
511
|
-
input_per_million: 5,
|
|
512
|
-
cached_input_per_million: 0.5,
|
|
513
|
-
cache_write_per_million: 6.25,
|
|
514
|
-
output_per_million: 30
|
|
515
|
-
},
|
|
516
|
-
{
|
|
517
565
|
input_per_million: 10,
|
|
518
566
|
cached_input_per_million: 1,
|
|
519
567
|
cache_write_per_million: 12.5,
|
|
520
|
-
output_per_million:
|
|
568
|
+
output_per_million: 50
|
|
569
|
+
},
|
|
570
|
+
{
|
|
571
|
+
input_per_million: 20,
|
|
572
|
+
cached_input_per_million: 2,
|
|
573
|
+
cache_write_per_million: 25,
|
|
574
|
+
output_per_million: 75
|
|
521
575
|
}
|
|
522
576
|
]
|
|
523
577
|
},
|
|
524
|
-
"gpt-
|
|
578
|
+
"gpt-6-sol": {
|
|
525
579
|
currency: "USD",
|
|
526
580
|
notes: "prompts over 272K input tokens bill the full request at long-context rates",
|
|
527
|
-
input_per_million: 2
|
|
528
|
-
cached_input_per_million: 0.
|
|
529
|
-
cache_write_per_million:
|
|
530
|
-
output_per_million:
|
|
581
|
+
input_per_million: 2,
|
|
582
|
+
cached_input_per_million: 0.2,
|
|
583
|
+
cache_write_per_million: 2.5,
|
|
584
|
+
output_per_million: 10,
|
|
531
585
|
tiers: [
|
|
532
586
|
{
|
|
533
587
|
threshold: 272e3,
|
|
534
|
-
input_per_million: 2
|
|
535
|
-
cached_input_per_million: 0.
|
|
536
|
-
cache_write_per_million:
|
|
537
|
-
output_per_million:
|
|
588
|
+
input_per_million: 2,
|
|
589
|
+
cached_input_per_million: 0.2,
|
|
590
|
+
cache_write_per_million: 2.5,
|
|
591
|
+
output_per_million: 10
|
|
538
592
|
},
|
|
539
593
|
{
|
|
540
|
-
input_per_million:
|
|
541
|
-
cached_input_per_million: 0.
|
|
542
|
-
cache_write_per_million:
|
|
543
|
-
output_per_million:
|
|
594
|
+
input_per_million: 4,
|
|
595
|
+
cached_input_per_million: 0.4,
|
|
596
|
+
cache_write_per_million: 5,
|
|
597
|
+
output_per_million: 15
|
|
544
598
|
}
|
|
545
599
|
]
|
|
546
600
|
},
|
|
547
|
-
"gpt-
|
|
601
|
+
"gpt-6-luna": {
|
|
548
602
|
currency: "USD",
|
|
549
603
|
notes: "prompts over 272K input tokens bill the full request at long-context rates",
|
|
550
|
-
input_per_million: 1,
|
|
551
|
-
cached_input_per_million: 0.
|
|
552
|
-
cache_write_per_million:
|
|
553
|
-
output_per_million:
|
|
604
|
+
input_per_million: 0.1,
|
|
605
|
+
cached_input_per_million: 0.01,
|
|
606
|
+
cache_write_per_million: 0.125,
|
|
607
|
+
output_per_million: 0.5,
|
|
608
|
+
tiers: [
|
|
609
|
+
{
|
|
610
|
+
threshold: 272e3,
|
|
611
|
+
input_per_million: 0.1,
|
|
612
|
+
cached_input_per_million: 0.01,
|
|
613
|
+
cache_write_per_million: 0.125,
|
|
614
|
+
output_per_million: 0.5
|
|
615
|
+
},
|
|
616
|
+
{
|
|
617
|
+
input_per_million: 0.2,
|
|
618
|
+
cached_input_per_million: 0.02,
|
|
619
|
+
cache_write_per_million: 0.25,
|
|
620
|
+
output_per_million: 0.75
|
|
621
|
+
}
|
|
622
|
+
]
|
|
623
|
+
},
|
|
624
|
+
// ── GPT-5.6 系列 ──
|
|
625
|
+
"gpt-5.6-sol": {
|
|
626
|
+
currency: "USD",
|
|
627
|
+
notes: "promotional pricing available at least through 2026-11-21; prompts over 272K input tokens bill the full request at long-context rates",
|
|
628
|
+
input_per_million: 4,
|
|
629
|
+
cached_input_per_million: 0.4,
|
|
630
|
+
cache_write_per_million: 5,
|
|
631
|
+
output_per_million: 20,
|
|
554
632
|
tiers: [
|
|
555
633
|
{
|
|
556
634
|
threshold: 272e3,
|
|
557
|
-
input_per_million:
|
|
558
|
-
cached_input_per_million: 0.
|
|
559
|
-
cache_write_per_million:
|
|
560
|
-
output_per_million:
|
|
635
|
+
input_per_million: 4,
|
|
636
|
+
cached_input_per_million: 0.4,
|
|
637
|
+
cache_write_per_million: 5,
|
|
638
|
+
output_per_million: 20
|
|
561
639
|
},
|
|
562
640
|
{
|
|
641
|
+
input_per_million: 8,
|
|
642
|
+
cached_input_per_million: 0.8,
|
|
643
|
+
cache_write_per_million: 10,
|
|
644
|
+
output_per_million: 30
|
|
645
|
+
}
|
|
646
|
+
]
|
|
647
|
+
},
|
|
648
|
+
"gpt-5.6-terra": {
|
|
649
|
+
currency: "USD",
|
|
650
|
+
notes: "prompts over 272K input tokens bill the full request at long-context rates",
|
|
651
|
+
input_per_million: 2,
|
|
652
|
+
cached_input_per_million: 0.2,
|
|
653
|
+
cache_write_per_million: 2.5,
|
|
654
|
+
output_per_million: 12,
|
|
655
|
+
tiers: [
|
|
656
|
+
{
|
|
657
|
+
threshold: 272e3,
|
|
563
658
|
input_per_million: 2,
|
|
564
659
|
cached_input_per_million: 0.2,
|
|
565
660
|
cache_write_per_million: 2.5,
|
|
566
|
-
output_per_million:
|
|
661
|
+
output_per_million: 12
|
|
662
|
+
},
|
|
663
|
+
{
|
|
664
|
+
input_per_million: 4,
|
|
665
|
+
cached_input_per_million: 0.4,
|
|
666
|
+
cache_write_per_million: 5,
|
|
667
|
+
output_per_million: 18
|
|
668
|
+
}
|
|
669
|
+
]
|
|
670
|
+
},
|
|
671
|
+
"gpt-5.6-luna": {
|
|
672
|
+
currency: "USD",
|
|
673
|
+
notes: "prompts over 272K input tokens bill the full request at long-context rates",
|
|
674
|
+
input_per_million: 0.2,
|
|
675
|
+
cached_input_per_million: 0.02,
|
|
676
|
+
cache_write_per_million: 0.25,
|
|
677
|
+
output_per_million: 1.2,
|
|
678
|
+
tiers: [
|
|
679
|
+
{
|
|
680
|
+
threshold: 272e3,
|
|
681
|
+
input_per_million: 0.2,
|
|
682
|
+
cached_input_per_million: 0.02,
|
|
683
|
+
cache_write_per_million: 0.25,
|
|
684
|
+
output_per_million: 1.2
|
|
685
|
+
},
|
|
686
|
+
{
|
|
687
|
+
input_per_million: 0.4,
|
|
688
|
+
cached_input_per_million: 0.04,
|
|
689
|
+
cache_write_per_million: 0.5,
|
|
690
|
+
output_per_million: 1.8
|
|
567
691
|
}
|
|
568
692
|
]
|
|
569
693
|
},
|
|
@@ -1350,6 +1474,36 @@ var sourcegraph = {
|
|
|
1350
1474
|
}
|
|
1351
1475
|
};
|
|
1352
1476
|
|
|
1477
|
+
// ../shared/src/pricing/data/xai.ts
|
|
1478
|
+
var models = {
|
|
1479
|
+
"grok-4.7": {
|
|
1480
|
+
currency: "USD",
|
|
1481
|
+
notes: "prompts of 200K+ input tokens bill the full request at long-context rates; -fast is 2x",
|
|
1482
|
+
input_per_million: 2,
|
|
1483
|
+
cached_input_per_million: 0.5,
|
|
1484
|
+
cache_write_per_million: 2,
|
|
1485
|
+
output_per_million: 6,
|
|
1486
|
+
tiers: [
|
|
1487
|
+
{
|
|
1488
|
+
threshold: 199999,
|
|
1489
|
+
input_per_million: 2,
|
|
1490
|
+
cached_input_per_million: 0.5,
|
|
1491
|
+
cache_write_per_million: 2,
|
|
1492
|
+
output_per_million: 6
|
|
1493
|
+
},
|
|
1494
|
+
{
|
|
1495
|
+
input_per_million: 4,
|
|
1496
|
+
cached_input_per_million: 1,
|
|
1497
|
+
cache_write_per_million: 4,
|
|
1498
|
+
output_per_million: 12
|
|
1499
|
+
}
|
|
1500
|
+
]
|
|
1501
|
+
}
|
|
1502
|
+
}, xai = {
|
|
1503
|
+
opencode: { models },
|
|
1504
|
+
"copilot-cli": { models }
|
|
1505
|
+
};
|
|
1506
|
+
|
|
1353
1507
|
// ../shared/src/pricing/data/placeholders.ts
|
|
1354
1508
|
var inflection = {
|
|
1355
1509
|
pi: { models: {} }
|
|
@@ -1362,10 +1516,11 @@ var inflection = {
|
|
|
1362
1516
|
};
|
|
1363
1517
|
|
|
1364
1518
|
// ../shared/src/pricing/catalog.ts
|
|
1365
|
-
var PRICING_VERSION = "2026-
|
|
1519
|
+
var PRICING_VERSION = "2026-09-24-gpt-6-opus-5-5-grok-4-7-v1", aliases = {
|
|
1366
1520
|
"claude-fibre-5": "claude-fable-5",
|
|
1367
1521
|
"claude-fiber-5": "claude-fable-5",
|
|
1368
1522
|
"claude-ops-5": "claude-opus-5",
|
|
1523
|
+
"claude-opus-5.5": "claude-opus-5-5",
|
|
1369
1524
|
"claude-opus-4-7-20260201": "claude-opus-4-7",
|
|
1370
1525
|
"claude-sonnet-4-6-20250301": "claude-sonnet-4-6",
|
|
1371
1526
|
"claude-opus-4-6-20250301": "claude-opus-4-6",
|
|
@@ -1392,6 +1547,7 @@ var PRICING_VERSION = "2026-07-26-claude-5-v1", aliases = {
|
|
|
1392
1547
|
zhipu,
|
|
1393
1548
|
github,
|
|
1394
1549
|
sourcegraph,
|
|
1550
|
+
xai,
|
|
1395
1551
|
inflection,
|
|
1396
1552
|
cursor,
|
|
1397
1553
|
droid,
|
|
@@ -1400,11 +1556,16 @@ var PRICING_VERSION = "2026-07-26-claude-5-v1", aliases = {
|
|
|
1400
1556
|
};
|
|
1401
1557
|
|
|
1402
1558
|
// ../shared/src/pricing/calculate.ts
|
|
1403
|
-
var
|
|
1559
|
+
var FAST_MULTIPLIERS = {
|
|
1560
|
+
"claude-opus-5-5": 2,
|
|
1404
1561
|
"claude-opus-5": 2,
|
|
1405
1562
|
"claude-opus-4-8": 2,
|
|
1406
|
-
"claude-opus-4-7": 6
|
|
1563
|
+
"claude-opus-4-7": 6,
|
|
1564
|
+
"grok-4.7": 2
|
|
1407
1565
|
}, OPENAI_CODEX_TIER_MULTIPLIERS = {
|
|
1566
|
+
"gpt-6-astra": 2,
|
|
1567
|
+
"gpt-6-sol": 2,
|
|
1568
|
+
"gpt-6-luna": 2,
|
|
1408
1569
|
"gpt-5.6-sol": 2,
|
|
1409
1570
|
"gpt-5.6-terra": 2,
|
|
1410
1571
|
"gpt-5.6-luna": 2,
|
|
@@ -1415,21 +1576,21 @@ function splitServiceTierSuffix(model) {
|
|
|
1415
1576
|
return model.endsWith("-priority") ? { baseModel: model.replace(/-priority$/, ""), tier: "priority" } : model.endsWith("-fast") ? { baseModel: model.replace(/-fast$/, ""), tier: "fast" } : { baseModel: model, tier: null };
|
|
1416
1577
|
}
|
|
1417
1578
|
function getServiceTierMultiplier(provider, product, resolvedModel, tier) {
|
|
1418
|
-
return tier ? provider === "openai" && product === "codex" ? tier === "fast" && resolvedModel.startsWith("gpt-5.6-") ? 1 : OPENAI_CODEX_TIER_MULTIPLIERS[resolvedModel] ?? 1 : tier === "fast" ?
|
|
1579
|
+
return tier ? provider === "openai" && product === "codex" ? tier === "fast" && resolvedModel.startsWith("gpt-5.6-") ? 1 : OPENAI_CODEX_TIER_MULTIPLIERS[resolvedModel] ?? 1 : tier === "fast" ? FAST_MULTIPLIERS[resolvedModel] ?? 1 : 1 : 1;
|
|
1419
1580
|
}
|
|
1420
1581
|
function resolveModelPricing(catalog2, provider, product, model) {
|
|
1421
|
-
let
|
|
1422
|
-
if (!
|
|
1582
|
+
let models2 = catalog2.providers[provider]?.[product]?.models;
|
|
1583
|
+
if (!models2) return null;
|
|
1423
1584
|
let aliasResolved = catalog2.aliases[model];
|
|
1424
|
-
if (aliasResolved &&
|
|
1425
|
-
return { resolvedModel: aliasResolved, pricing:
|
|
1426
|
-
if (
|
|
1427
|
-
return { resolvedModel: model, pricing:
|
|
1428
|
-
for (let knownModel of Object.keys(
|
|
1585
|
+
if (aliasResolved && models2[aliasResolved])
|
|
1586
|
+
return { resolvedModel: aliasResolved, pricing: models2[aliasResolved], normalized: !1 };
|
|
1587
|
+
if (models2[model])
|
|
1588
|
+
return { resolvedModel: model, pricing: models2[model], normalized: !1 };
|
|
1589
|
+
for (let knownModel of Object.keys(models2).sort((a, b) => b.length - a.length)) {
|
|
1429
1590
|
if (!model.startsWith(`${knownModel}-`)) continue;
|
|
1430
1591
|
let suffix = model.slice(knownModel.length + 1);
|
|
1431
1592
|
if (!/^\d+(?:[-.]\d+)*(?:-\d{6,8})?$/.test(suffix))
|
|
1432
|
-
return { resolvedModel: knownModel, pricing:
|
|
1593
|
+
return { resolvedModel: knownModel, pricing: models2[knownModel], normalized: !0 };
|
|
1433
1594
|
}
|
|
1434
1595
|
return null;
|
|
1435
1596
|
}
|
|
@@ -1560,14 +1721,16 @@ async function processCodexFile(filePath, projectAliases, serviceTier) {
|
|
|
1560
1721
|
state.previousTotals = parsed.nextTotals;
|
|
1561
1722
|
continue;
|
|
1562
1723
|
}
|
|
1563
|
-
let { tokens, nextTotals } = parsed, cachedInput = Math.min(tokens.cached, tokens.input), nonCachedInput = Math.max(tokens.input - cachedInput, 0),
|
|
1564
|
-
if (nonCachedInput + cachedInput + output + reasoning === 0) continue;
|
|
1724
|
+
let { tokens, nextTotals } = parsed, cachedInput = Math.min(tokens.cached, tokens.input), cacheWriteInput = Math.min(tokens.cacheWrite, Math.max(tokens.input - cachedInput, 0)), nonCachedInput = Math.max(tokens.input - cachedInput - cacheWriteInput, 0), reasoning = Math.min(tokens.reasoning, tokens.output), output = Math.max(tokens.output - reasoning, 0);
|
|
1725
|
+
if (nonCachedInput + cachedInput + cacheWriteInput + output + reasoning === 0) continue;
|
|
1565
1726
|
state.previousTotals = nextTotals;
|
|
1566
|
-
let dedupScope = state.sessionForkedFromId ?? state.sessionIdFromMeta ?? fileSessionId, signature = total ? `codex|${dedupScope}|${state.currentModel}|${total.input}|${total.cached}|${total.output}|${total.reasoning}` : `codex|${dedupScope}|${state.currentModel}|${ts.getTime()}|${tokens.input}|${tokens.cached}|${tokens.output}|${tokens.reasoning}`, eventCost = calculateCost("openai", "codex", state.currentModel, {
|
|
1727
|
+
let dedupScope = state.sessionForkedFromId ?? state.sessionIdFromMeta ?? fileSessionId, signature = total ? `codex|${dedupScope}|${state.currentModel}|${total.input}|${total.cached}|${total.cacheWrite}|${total.output}|${total.reasoning}` : `codex|${dedupScope}|${state.currentModel}|${ts.getTime()}|${tokens.input}|${tokens.cached}|${tokens.cacheWrite}|${tokens.output}|${tokens.reasoning}`, eventCost = calculateCost("openai", "codex", state.currentModel, {
|
|
1567
1728
|
inputTokens: nonCachedInput,
|
|
1568
1729
|
cachedInputTokens: cachedInput,
|
|
1569
|
-
cacheWriteTokens:
|
|
1570
|
-
|
|
1730
|
+
cacheWriteTokens: cacheWriteInput,
|
|
1731
|
+
// Reasoning is billed at the output rate, so pricing still uses the
|
|
1732
|
+
// inclusive raw Codex output total.
|
|
1733
|
+
outputTokens: tokens.output
|
|
1571
1734
|
}), exactEventCost = eventCost.costStatus === "exact" ? eventCost.estimatedCostUsd : void 0;
|
|
1572
1735
|
events.push({
|
|
1573
1736
|
usageDate,
|
|
@@ -1576,6 +1739,7 @@ async function processCodexFile(filePath, projectAliases, serviceTier) {
|
|
|
1576
1739
|
projectFields: { ...state.projectFields },
|
|
1577
1740
|
inputTokens: nonCachedInput,
|
|
1578
1741
|
cachedInputTokens: cachedInput,
|
|
1742
|
+
cacheWriteTokens: cacheWriteInput,
|
|
1579
1743
|
outputTokens: output,
|
|
1580
1744
|
reasoningOutputTokens: reasoning,
|
|
1581
1745
|
costUSD: exactEventCost,
|
|
@@ -1593,7 +1757,7 @@ function mergeCodexEvent(groupedByDate, event) {
|
|
|
1593
1757
|
if (!grouped) return;
|
|
1594
1758
|
let key = `${event.model}|${event.projectFields.project}`, existing = grouped.get(key);
|
|
1595
1759
|
if (existing) {
|
|
1596
|
-
existing.eventCount += 1, existing.inputTokens += event.inputTokens, existing.cachedInputTokens += event.cachedInputTokens, existing.outputTokens += event.outputTokens, existing.reasoningOutputTokens += event.reasoningOutputTokens, event.costUSD !== void 0 && (existing.costUSD = (existing.costUSD ?? 0) + event.costUSD, existing.pricingVersion = event.pricingVersion);
|
|
1760
|
+
existing.eventCount += 1, existing.inputTokens += event.inputTokens, existing.cachedInputTokens += event.cachedInputTokens, existing.cacheWriteTokens += event.cacheWriteTokens, existing.outputTokens += event.outputTokens, existing.reasoningOutputTokens += event.reasoningOutputTokens, event.costUSD !== void 0 && (existing.costUSD = (existing.costUSD ?? 0) + event.costUSD, existing.pricingVersion = event.pricingVersion);
|
|
1597
1761
|
return;
|
|
1598
1762
|
}
|
|
1599
1763
|
let breakdown = {
|
|
@@ -1607,7 +1771,7 @@ function mergeCodexEvent(groupedByDate, event) {
|
|
|
1607
1771
|
eventCount: 1,
|
|
1608
1772
|
inputTokens: event.inputTokens,
|
|
1609
1773
|
cachedInputTokens: event.cachedInputTokens,
|
|
1610
|
-
cacheWriteTokens:
|
|
1774
|
+
cacheWriteTokens: event.cacheWriteTokens,
|
|
1611
1775
|
outputTokens: event.outputTokens,
|
|
1612
1776
|
reasoningOutputTokens: event.reasoningOutputTokens
|
|
1613
1777
|
};
|
|
@@ -1635,18 +1799,20 @@ function totalsFromUsage(usage) {
|
|
|
1635
1799
|
clampToken2(usage.cached_input_tokens),
|
|
1636
1800
|
clampToken2(usage.cache_read_input_tokens)
|
|
1637
1801
|
),
|
|
1802
|
+
cacheWrite: clampToken2(usage.cache_write_input_tokens),
|
|
1638
1803
|
output: clampToken2(usage.output_tokens),
|
|
1639
1804
|
reasoning: clampToken2(usage.reasoning_output_tokens)
|
|
1640
1805
|
};
|
|
1641
1806
|
}
|
|
1642
1807
|
function totalsEqual(a, b) {
|
|
1643
|
-
return a.input === b.input && a.cached === b.cached && a.output === b.output && a.reasoning === b.reasoning;
|
|
1808
|
+
return a.input === b.input && a.cached === b.cached && a.cacheWrite === b.cacheWrite && a.output === b.output && a.reasoning === b.reasoning;
|
|
1644
1809
|
}
|
|
1645
1810
|
function totalsDelta(current, previous) {
|
|
1646
|
-
if (!(current.input < previous.input || current.cached < previous.cached || current.output < previous.output || current.reasoning < previous.reasoning))
|
|
1811
|
+
if (!(current.input < previous.input || current.cached < previous.cached || current.cacheWrite < previous.cacheWrite || current.output < previous.output || current.reasoning < previous.reasoning))
|
|
1647
1812
|
return {
|
|
1648
1813
|
input: current.input - previous.input,
|
|
1649
1814
|
cached: current.cached - previous.cached,
|
|
1815
|
+
cacheWrite: current.cacheWrite - previous.cacheWrite,
|
|
1650
1816
|
output: current.output - previous.output,
|
|
1651
1817
|
reasoning: current.reasoning - previous.reasoning
|
|
1652
1818
|
};
|
|
@@ -1655,12 +1821,13 @@ function totalsAdd(a, b) {
|
|
|
1655
1821
|
return {
|
|
1656
1822
|
input: a.input + b.input,
|
|
1657
1823
|
cached: a.cached + b.cached,
|
|
1824
|
+
cacheWrite: a.cacheWrite + b.cacheWrite,
|
|
1658
1825
|
output: a.output + b.output,
|
|
1659
1826
|
reasoning: a.reasoning + b.reasoning
|
|
1660
1827
|
};
|
|
1661
1828
|
}
|
|
1662
1829
|
function totalsSum(value) {
|
|
1663
|
-
return value.input + value.cached + value.output + value.reasoning;
|
|
1830
|
+
return value.input + value.cached + value.cacheWrite + value.output + value.reasoning;
|
|
1664
1831
|
}
|
|
1665
1832
|
function looksLikeStaleRegression(current, previous, last) {
|
|
1666
1833
|
let previousSum = totalsSum(previous), currentSum = totalsSum(current), lastSum = totalsSum(last);
|
|
@@ -1689,7 +1856,7 @@ function shouldSkipInheritedSnapshot(state, usage, totals) {
|
|
|
1689
1856
|
let reported = usage ? reportedTotalTokens(usage) : void 0;
|
|
1690
1857
|
if (reported != null && state.inheritedReportedTotal != null && reported <= state.inheritedReportedTotal) return !0;
|
|
1691
1858
|
let baseline = state.inheritedBaseline;
|
|
1692
|
-
return !!(totals && baseline && totals.input <= baseline.input && totals.cached <= baseline.cached && totals.output <= baseline.output && totals.reasoning <= baseline.reasoning);
|
|
1859
|
+
return !!(totals && baseline && totals.input <= baseline.input && totals.cached <= baseline.cached && totals.cacheWrite <= baseline.cacheWrite && totals.output <= baseline.output && totals.reasoning <= baseline.reasoning);
|
|
1693
1860
|
}
|
|
1694
1861
|
function reportedTotalTokens(usage) {
|
|
1695
1862
|
return typeof usage.total_tokens == "number" && usage.total_tokens >= 0 ? usage.total_tokens : void 0;
|
|
@@ -1738,7 +1905,7 @@ async function detectCodexServiceTier(baseDir) {
|
|
|
1738
1905
|
}
|
|
1739
1906
|
function applyCodexServiceTier(model, serviceTier) {
|
|
1740
1907
|
if (!serviceTier || model.endsWith("-fast") || model.endsWith("-priority")) return model;
|
|
1741
|
-
let supportsFast = model === "gpt-5.5" || model === "gpt-5.4";
|
|
1908
|
+
let supportsFast = model === "gpt-6-astra" || model === "gpt-6-sol" || model === "gpt-6-luna" || model === "gpt-5.5" || model === "gpt-5.4";
|
|
1742
1909
|
return serviceTier === "fast" && supportsFast || serviceTier === "priority" && (model === "gpt-5.6" || model === "gpt-5.6-sol" || model === "gpt-5.6-terra" || model === "gpt-5.6-luna" || supportsFast) ? `${model}-${serviceTier}` : model;
|
|
1743
1910
|
}
|
|
1744
1911
|
async function walkDir(dir, result) {
|
|
@@ -2491,8 +2658,8 @@ function parseDirectGeminiEvent(value, modelHint, sessionId, fallbackTs) {
|
|
|
2491
2658
|
};
|
|
2492
2659
|
}
|
|
2493
2660
|
function parseGeminiStats(stats, modelHint, sessionId, timestamp) {
|
|
2494
|
-
let
|
|
2495
|
-
return (
|
|
2661
|
+
let models2 = isObject2(stats.models) ? stats.models : void 0;
|
|
2662
|
+
return (models2 ? Object.entries(models2) : [[modelHint ?? "unknown", stats]]).flatMap(([model, raw], index) => {
|
|
2496
2663
|
if (!isObject2(raw)) return [];
|
|
2497
2664
|
let wrapped = isObject2(raw.tokens), source = wrapped ? raw.tokens : raw, inclusive = hasAny(source, ["prompt", "prompt_tokens", "input_tokens"]) || wrapped, tokens = extractTokenValues(source, inclusive);
|
|
2498
2665
|
return tokenTotal(tokens) === 0 ? [] : [{ model, timestamp, tokens, dedupKey: `gemini:${sessionId}:stats:${model}:${index}:${timestamp.getTime()}` }];
|
|
@@ -3089,7 +3256,7 @@ async function extractModelFromTranscript(filePath) {
|
|
|
3089
3256
|
|
|
3090
3257
|
// src/scanners/opencode.ts
|
|
3091
3258
|
import { execFile } from "node:child_process";
|
|
3092
|
-
import { readdir as readdir5, readFile as readFile10, realpath, stat as stat3 } from "node:fs/promises";
|
|
3259
|
+
import { readdir as readdir5, readFile as readFile10, realpath as realpath2, stat as stat3 } from "node:fs/promises";
|
|
3093
3260
|
import { homedir as homedir12 } from "node:os";
|
|
3094
3261
|
import { basename as basename9, dirname as dirname5, isAbsolute, join as join13, resolve as resolve2 } from "node:path";
|
|
3095
3262
|
var nodeSqliteModulePromise, sqliteRuntimePromise;
|
|
@@ -3136,7 +3303,7 @@ async function discoverOpenCodeDatabases(dataDir, extraPaths = [], home = homedi
|
|
|
3136
3303
|
for (let path of candidates.sort((a, b) => a.localeCompare(b)))
|
|
3137
3304
|
try {
|
|
3138
3305
|
if (!(await stat3(path)).isFile()) continue;
|
|
3139
|
-
let canonical = await
|
|
3306
|
+
let canonical = await realpath2(path).catch(() => path);
|
|
3140
3307
|
if (seen.has(canonical)) continue;
|
|
3141
3308
|
seen.add(canonical), result.push(path);
|
|
3142
3309
|
} catch {
|
|
@@ -4420,7 +4587,7 @@ var en = {
|
|
|
4420
4587
|
reportTitle: "AIUsage Report",
|
|
4421
4588
|
period: "Period",
|
|
4422
4589
|
events: "Events",
|
|
4423
|
-
tokens: "
|
|
4590
|
+
tokens: "Processed",
|
|
4424
4591
|
cost: "Cost",
|
|
4425
4592
|
pricing: "Pricing",
|
|
4426
4593
|
sources: "Sources",
|
|
@@ -4449,7 +4616,7 @@ var en = {
|
|
|
4449
4616
|
reportTitle: "AIUsage \u62A5\u544A",
|
|
4450
4617
|
period: "\u65F6\u6BB5",
|
|
4451
4618
|
events: "\u4E8B\u4EF6",
|
|
4452
|
-
tokens: "\
|
|
4619
|
+
tokens: "\u5904\u7406 Token",
|
|
4453
4620
|
cost: "\u8D39\u7528",
|
|
4454
4621
|
pricing: "\u5B9A\u4EF7",
|
|
4455
4622
|
sources: "\u6765\u6E90",
|
|
@@ -4629,6 +4796,7 @@ import { open, readdir as readdir7 } from "node:fs/promises";
|
|
|
4629
4796
|
import { createInterface as createInterface3 } from "node:readline";
|
|
4630
4797
|
import { homedir as homedir16 } from "node:os";
|
|
4631
4798
|
import { basename as basename12, join as join17 } from "node:path";
|
|
4799
|
+
import * as zlib from "node:zlib";
|
|
4632
4800
|
var FILE_CONCURRENCY3 = 16, MAX_LINE_BYTES3 = 64 * 1024 * 1024;
|
|
4633
4801
|
async function buildActivityReport(range, options = {}) {
|
|
4634
4802
|
let targetDates = options.dates ? new Set(options.dates) : void 0, [codex, claude] = await Promise.all([
|
|
@@ -4640,7 +4808,8 @@ async function buildActivityReport(range, options = {}) {
|
|
|
4640
4808
|
usageDate,
|
|
4641
4809
|
exactCount: sumByConfidence(dayItems, "exact"),
|
|
4642
4810
|
proxyCount: sumByConfidence(dayItems, "proxy"),
|
|
4643
|
-
userMessageCount:
|
|
4811
|
+
userMessageCount: sumKind(dayItems, "user_message"),
|
|
4812
|
+
userMessageChars: sumKind(dayItems, "user_message_chars")
|
|
4644
4813
|
};
|
|
4645
4814
|
}).filter((day) => requestedDates || day.exactCount > 0 || day.proxyCount > 0 || day.userMessageCount > 0);
|
|
4646
4815
|
return {
|
|
@@ -4654,12 +4823,13 @@ async function buildActivityReport(range, options = {}) {
|
|
|
4654
4823
|
exactCount: sumByConfidence(items, "exact"),
|
|
4655
4824
|
proxyCount: sumByConfidence(items, "proxy"),
|
|
4656
4825
|
userMessageCount: codex.stats.userMessages.size + claude.stats.userMessages.size,
|
|
4826
|
+
userMessageChars: sumKind(items, "user_message_chars"),
|
|
4657
4827
|
filesScanned: codex.stats.filesScanned + claude.stats.filesScanned,
|
|
4658
4828
|
sessionsScanned: (/* @__PURE__ */ new Set([...codex.stats.sessions, ...claude.stats.sessions])).size
|
|
4659
4829
|
},
|
|
4660
4830
|
daily,
|
|
4661
4831
|
bySource: summarize(items, (item) => item.source, (item) => item.source),
|
|
4662
|
-
byKind: summarize(items, (item) => item.kind, (item) => labelKind(item.kind)),
|
|
4832
|
+
byKind: summarize(items.filter((item) => item.kind !== "user_message_chars"), (item) => item.kind, (item) => labelKind(item.kind)),
|
|
4663
4833
|
topTools: summarize(
|
|
4664
4834
|
items.filter((item) => isToolLikeKind(item.kind)),
|
|
4665
4835
|
(item) => `${item.source}|${item.name}`,
|
|
@@ -4682,13 +4852,14 @@ async function buildActivityReport(range, options = {}) {
|
|
|
4682
4852
|
notes: [
|
|
4683
4853
|
"Claude Code \u7684 Skill/Agent \u6765\u81EA\u7ED3\u6784\u5316 tool_use\uFF0C\u53E3\u5F84\u4E3A exact\u3002",
|
|
4684
4854
|
"Codex \u7684 skill_proxy \u6765\u81EA\u547D\u4EE4\u4E2D\u8BFB\u53D6 SKILL.md \u7684\u75D5\u8FF9\uFF0C\u53EA\u80FD\u8868\u793A\u4EE3\u7406\u4FE1\u53F7\u3002",
|
|
4855
|
+
"\u7528\u6237\u6D88\u606F\u53EA\u8BA1\u4EBA\u5DE5\u8F93\u5165\uFF1A\u5254\u9664\u7CFB\u7EDF\u6CE8\u5165\u3001\u5B50\u4EE3\u7406\u3001\u81EA\u52A8\u5316\u4E0E\u5B9A\u65F6\u4EFB\u52A1\uFF1B\u5B57\u6570\u4E3A\u53BB\u7A7A\u767D\u5B57\u7B26\u6570\uFF0CClaude Code \u4E0D\u542B\u7C98\u8D34\u5757\u3002",
|
|
4685
4856
|
"sync \u4F1A\u4E0A\u4F20\u6309\u65E5\u805A\u5408\u540E\u7684 activity \u6307\u6807\uFF0C\u4E0D\u4E0A\u4F20\u539F\u59CB\u6D88\u606F\u5185\u5BB9\u3002"
|
|
4686
4857
|
]
|
|
4687
4858
|
};
|
|
4688
4859
|
}
|
|
4689
4860
|
function renderActivityReport(report, opts) {
|
|
4690
4861
|
let lines = [], title = opts.emoji ? "\u{1F9ED} AIUsage Activity" : "AIUsage Activity";
|
|
4691
|
-
if (lines.push(title), lines.push("\u2500".repeat(stripAnsi(title).length)), lines.push(`\u5468\u671F ${report.rangeLabel} (${report.startDate ?? "-"} ~ ${report.endDate ?? "-"})`), lines.push(`\u786E\u5207\u4E8B\u4EF6 ${fmt(report.totals.exactCount)}`), lines.push(`\u4EE3\u7406\u4FE1\u53F7 ${fmt(report.totals.proxyCount)}`), lines.push(`\u7528\u6237\u6D88\u606F ${fmt(report.totals.userMessageCount)}`), lines.push(`Session ${fmt(report.totals.sessionsScanned)}`), lines.push(`\u6587\u4EF6 ${fmt(report.totals.filesScanned)}`), report.daysWithData === 0)
|
|
4862
|
+
if (lines.push(title), lines.push("\u2500".repeat(stripAnsi(title).length)), lines.push(`\u5468\u671F ${report.rangeLabel} (${report.startDate ?? "-"} ~ ${report.endDate ?? "-"})`), lines.push(`\u786E\u5207\u4E8B\u4EF6 ${fmt(report.totals.exactCount)}`), lines.push(`\u4EE3\u7406\u4FE1\u53F7 ${fmt(report.totals.proxyCount)}`), lines.push(`\u7528\u6237\u6D88\u606F ${fmt(report.totals.userMessageCount)}`), lines.push(`\u7528\u6237\u5B57\u6570 ${fmt(report.totals.userMessageChars)}`), lines.push(`Session ${fmt(report.totals.sessionsScanned)}`), lines.push(`\u6587\u4EF6 ${fmt(report.totals.filesScanned)}`), report.daysWithData === 0)
|
|
4692
4863
|
return lines.push(""), lines.push("\u8BE5\u8303\u56F4\u65E0\u6D3B\u52A8\u6570\u636E\u3002"), lines.join(`
|
|
4693
4864
|
`);
|
|
4694
4865
|
lines.push(""), lines.push("\u6309\u6765\u6E90");
|
|
@@ -4715,7 +4886,7 @@ function renderActivityReport(report, opts) {
|
|
|
4715
4886
|
if (opts.detail && report.daily.length > 0) {
|
|
4716
4887
|
lines.push(""), lines.push("\u6BCF\u65E5");
|
|
4717
4888
|
for (let day of report.daily)
|
|
4718
|
-
lines.push(` ${day.usageDate}: exact ${fmt(day.exactCount)} / proxy ${fmt(day.proxyCount)} / user ${fmt(day.userMessageCount)}`);
|
|
4889
|
+
lines.push(` ${day.usageDate}: exact ${fmt(day.exactCount)} / proxy ${fmt(day.proxyCount)} / user ${fmt(day.userMessageCount)} (${fmt(day.userMessageChars)} \u5B57)`);
|
|
4719
4890
|
}
|
|
4720
4891
|
if (opts.detail) {
|
|
4721
4892
|
lines.push(""), lines.push("\u53E3\u5F84");
|
|
@@ -4731,16 +4902,18 @@ async function scanCodexActivity(targetDates, options) {
|
|
|
4731
4902
|
}), finalizeActivity(acc);
|
|
4732
4903
|
}
|
|
4733
4904
|
async function processCodexFile2(filePath, acc) {
|
|
4905
|
+
let compressed = filePath.endsWith(".zst");
|
|
4906
|
+
if (compressed && typeof zlib.createZstdDecompress != "function") return;
|
|
4734
4907
|
let fh;
|
|
4735
4908
|
try {
|
|
4736
4909
|
fh = await open(filePath, "r");
|
|
4737
4910
|
} catch {
|
|
4738
4911
|
return;
|
|
4739
4912
|
}
|
|
4740
|
-
let sessionId = basename12(filePath).replace(/\.jsonl
|
|
4913
|
+
let sessionId = basename12(filePath).replace(/\.jsonl(\.zst)?$/, ""), projectFields = { project: "unknown", projectDisplay: "unknown" }, automated = !1, itemMessages = [], eventMessages = [];
|
|
4741
4914
|
try {
|
|
4742
|
-
let rl = createInterface3({
|
|
4743
|
-
input:
|
|
4915
|
+
let stream = fh.createReadStream(), rl = createInterface3({
|
|
4916
|
+
input: compressed ? stream.pipe(zlib.createZstdDecompress()) : stream.setEncoding("utf-8"),
|
|
4744
4917
|
crlfDelay: 1 / 0
|
|
4745
4918
|
});
|
|
4746
4919
|
for await (let line of rl) {
|
|
@@ -4753,7 +4926,7 @@ async function processCodexFile2(filePath, acc) {
|
|
|
4753
4926
|
}
|
|
4754
4927
|
if (record.type === "session_meta") {
|
|
4755
4928
|
let id = stringValue3(record.payload?.id);
|
|
4756
|
-
id && (sessionId = id), acc.stats.sessions.add(`codex:${sessionId}`);
|
|
4929
|
+
id && (sessionId = id), automated = isAutomatedCodexSession(record.payload), acc.stats.sessions.add(`codex:${sessionId}`);
|
|
4757
4930
|
continue;
|
|
4758
4931
|
}
|
|
4759
4932
|
if (record.type === "turn_context") {
|
|
@@ -4769,98 +4942,119 @@ async function processCodexFile2(filePath, acc) {
|
|
|
4769
4942
|
handleCodexResponseItem(record.payload?.item ?? record.payload, usageDate, projectFields, sessionId, filePath, record.timestamp ?? "", acc);
|
|
4770
4943
|
continue;
|
|
4771
4944
|
}
|
|
4772
|
-
record.type === "event_msg"
|
|
4945
|
+
if (record.type === "event_msg") {
|
|
4946
|
+
let message = codexUserMessage(record);
|
|
4947
|
+
if (message) {
|
|
4948
|
+
(record.payload?.type === "item_completed" ? itemMessages : eventMessages).push({ ...message, usageDate, projectFields });
|
|
4949
|
+
continue;
|
|
4950
|
+
}
|
|
4951
|
+
handleCodexEvent(record, usageDate, projectFields, sessionId, filePath, acc);
|
|
4952
|
+
}
|
|
4773
4953
|
}
|
|
4774
4954
|
}
|
|
4955
|
+
} catch {
|
|
4775
4956
|
} finally {
|
|
4776
4957
|
await fh.close();
|
|
4777
4958
|
}
|
|
4959
|
+
if (!automated)
|
|
4960
|
+
for (let message of itemMessages.length ? itemMessages : eventMessages) {
|
|
4961
|
+
let text = codexTypedText(message.text);
|
|
4962
|
+
text && addUserMessage(acc, {
|
|
4963
|
+
provider: "openai",
|
|
4964
|
+
product: "codex",
|
|
4965
|
+
usageDate: message.usageDate,
|
|
4966
|
+
projectFields: message.projectFields,
|
|
4967
|
+
sessionId,
|
|
4968
|
+
timestamp: message.timestamp,
|
|
4969
|
+
content: text,
|
|
4970
|
+
chars: countChars(text),
|
|
4971
|
+
fallbackKey: `${filePath}:${message.usageDate}:${sessionId}:user:${message.timestamp}`
|
|
4972
|
+
});
|
|
4973
|
+
}
|
|
4974
|
+
}
|
|
4975
|
+
function codexUserMessage(record) {
|
|
4976
|
+
let payload = record.payload;
|
|
4977
|
+
if (payload?.type === "user_message")
|
|
4978
|
+
return { timestamp: record.timestamp ?? "", text: stringValue3(payload.message) ?? "" };
|
|
4979
|
+
if (payload?.type === "item_completed" && payload.item?.type === "UserMessage")
|
|
4980
|
+
return { timestamp: record.timestamp ?? "", text: extractCodexMessageText(payload.item.content) ?? "" };
|
|
4981
|
+
}
|
|
4982
|
+
function isAutomatedCodexSession(payload) {
|
|
4983
|
+
if (payload?.originator === "codex_exec") return !0;
|
|
4984
|
+
let source = payload?.source;
|
|
4985
|
+
return typeof source == "object" && source !== null && "subagent" in source;
|
|
4986
|
+
}
|
|
4987
|
+
var CODEX_MY_REQUEST = /^## My request[^\n]*:[ \t]*$/gm, CODEX_BROWSER_COMMENT = /^Comment:\n([\s\S]*?)(?=\n\n## User Comment|\n\n#|\nThe next image|$(?![\s\S]))/gm;
|
|
4988
|
+
function codexTypedText(raw) {
|
|
4989
|
+
let text = raw, requests = [...raw.matchAll(CODEX_MY_REQUEST)];
|
|
4990
|
+
if (requests.length) {
|
|
4991
|
+
let last = requests[requests.length - 1];
|
|
4992
|
+
text = raw.slice(last.index + last[0].length);
|
|
4993
|
+
} else raw.trimStart().startsWith("# Browser comments") && (text = [...raw.matchAll(CODEX_BROWSER_COMMENT)].map((m) => m[1]).join(`
|
|
4994
|
+
`));
|
|
4995
|
+
if (!text.trimStart().startsWith("<"))
|
|
4996
|
+
return text.trim() ? text : void 0;
|
|
4778
4997
|
}
|
|
4779
4998
|
function handleCodexResponseItem(item, usageDate, projectFields, sessionId, filePath, timestamp, acc) {
|
|
4780
4999
|
if (!item?.type) return;
|
|
4781
5000
|
let callId = item.call_id, baseKey = callId ? `codex:${item.type}:${callId}` : `codex:${filePath}:${usageDate}:${item.type}:${item.name ?? ""}:${item.arguments ?? ""}`;
|
|
4782
|
-
if (item.type
|
|
4783
|
-
item.
|
|
4784
|
-
|
|
4785
|
-
product: "codex",
|
|
4786
|
-
usageDate,
|
|
4787
|
-
projectFields,
|
|
4788
|
-
sessionId,
|
|
4789
|
-
timestamp,
|
|
4790
|
-
content: extractCodexMessageText(item.content),
|
|
4791
|
-
fallbackKey: `${filePath}:${usageDate}:${sessionId}:${JSON.stringify(item.content ?? "")}`
|
|
4792
|
-
});
|
|
4793
|
-
return;
|
|
4794
|
-
}
|
|
4795
|
-
if (item.type === "function_call") {
|
|
4796
|
-
let name = item.name ?? "unknown", args = parseJsonObject(item.arguments), kind = name === "spawn_agent" ? "agent_call" : "function_call";
|
|
4797
|
-
addActivity(acc, {
|
|
4798
|
-
usageDate,
|
|
4799
|
-
provider: "openai",
|
|
4800
|
-
product: "codex",
|
|
4801
|
-
projectFields,
|
|
4802
|
-
sessionId,
|
|
4803
|
-
kind,
|
|
4804
|
-
name: kind === "agent_call" ? stringValue3(args.agent_type) ?? name : name,
|
|
4805
|
-
confidence: "exact",
|
|
4806
|
-
dedupeKey: baseKey
|
|
4807
|
-
});
|
|
4808
|
-
for (let skillName of extractSkillProxyNames(item.arguments))
|
|
5001
|
+
if (item.type !== "message") {
|
|
5002
|
+
if (item.type === "function_call") {
|
|
5003
|
+
let name = item.name ?? "unknown", args = parseJsonObject(item.arguments), kind = name === "spawn_agent" ? "agent_call" : "function_call";
|
|
4809
5004
|
addActivity(acc, {
|
|
4810
5005
|
usageDate,
|
|
4811
5006
|
provider: "openai",
|
|
4812
5007
|
product: "codex",
|
|
4813
5008
|
projectFields,
|
|
4814
5009
|
sessionId,
|
|
4815
|
-
kind
|
|
4816
|
-
name:
|
|
4817
|
-
confidence: "
|
|
4818
|
-
dedupeKey:
|
|
5010
|
+
kind,
|
|
5011
|
+
name: kind === "agent_call" ? stringValue3(args.agent_type) ?? name : name,
|
|
5012
|
+
confidence: "exact",
|
|
5013
|
+
dedupeKey: baseKey
|
|
4819
5014
|
});
|
|
4820
|
-
|
|
4821
|
-
|
|
4822
|
-
|
|
4823
|
-
|
|
5015
|
+
for (let skillName of extractSkillProxyNames(item.arguments))
|
|
5016
|
+
addActivity(acc, {
|
|
5017
|
+
usageDate,
|
|
5018
|
+
provider: "openai",
|
|
5019
|
+
product: "codex",
|
|
5020
|
+
projectFields,
|
|
5021
|
+
sessionId,
|
|
5022
|
+
kind: "skill_proxy",
|
|
5023
|
+
name: skillName,
|
|
5024
|
+
confidence: "proxy",
|
|
5025
|
+
dedupeKey: `${baseKey}:skill:${skillName}`
|
|
5026
|
+
});
|
|
5027
|
+
return;
|
|
5028
|
+
}
|
|
5029
|
+
if (item.type === "custom_tool_call") {
|
|
5030
|
+
addActivity(acc, {
|
|
5031
|
+
usageDate,
|
|
5032
|
+
provider: "openai",
|
|
5033
|
+
product: "codex",
|
|
5034
|
+
projectFields,
|
|
5035
|
+
sessionId,
|
|
5036
|
+
kind: "custom_tool_call",
|
|
5037
|
+
name: item.name ?? "unknown",
|
|
5038
|
+
confidence: "exact",
|
|
5039
|
+
dedupeKey: baseKey
|
|
5040
|
+
});
|
|
5041
|
+
return;
|
|
5042
|
+
}
|
|
5043
|
+
(item.type === "web_search_call" || item.type === "tool_search_call" || item.type === "image_generation_call") && addActivity(acc, {
|
|
4824
5044
|
usageDate,
|
|
4825
5045
|
provider: "openai",
|
|
4826
5046
|
product: "codex",
|
|
4827
5047
|
projectFields,
|
|
4828
5048
|
sessionId,
|
|
4829
|
-
kind: "
|
|
4830
|
-
name: item.name ??
|
|
5049
|
+
kind: item.type === "web_search_call" ? "web_search" : item.type === "tool_search_call" ? "tool_search" : "image_generation",
|
|
5050
|
+
name: item.name ?? item.type,
|
|
4831
5051
|
confidence: "exact",
|
|
4832
5052
|
dedupeKey: baseKey
|
|
4833
5053
|
});
|
|
4834
|
-
return;
|
|
4835
5054
|
}
|
|
4836
|
-
(item.type === "web_search_call" || item.type === "tool_search_call" || item.type === "image_generation_call") && addActivity(acc, {
|
|
4837
|
-
usageDate,
|
|
4838
|
-
provider: "openai",
|
|
4839
|
-
product: "codex",
|
|
4840
|
-
projectFields,
|
|
4841
|
-
sessionId,
|
|
4842
|
-
kind: item.type === "web_search_call" ? "web_search" : item.type === "tool_search_call" ? "tool_search" : "image_generation",
|
|
4843
|
-
name: item.name ?? item.type,
|
|
4844
|
-
confidence: "exact",
|
|
4845
|
-
dedupeKey: baseKey
|
|
4846
|
-
});
|
|
4847
5055
|
}
|
|
4848
5056
|
function handleCodexEvent(record, usageDate, projectFields, sessionId, filePath, acc) {
|
|
4849
|
-
let payloadType = record.payload?.type;
|
|
4850
|
-
if (payloadType === "user_message") {
|
|
4851
|
-
addUserMessage(acc, {
|
|
4852
|
-
provider: "openai",
|
|
4853
|
-
product: "codex",
|
|
4854
|
-
usageDate,
|
|
4855
|
-
projectFields,
|
|
4856
|
-
sessionId,
|
|
4857
|
-
timestamp: record.timestamp ?? "",
|
|
4858
|
-
content: stringValue3(record.payload?.message),
|
|
4859
|
-
fallbackKey: `${filePath}:${usageDate}:${sessionId}:event_user_message:${record.timestamp ?? ""}`
|
|
4860
|
-
});
|
|
4861
|
-
return;
|
|
4862
|
-
}
|
|
4863
|
-
let kind = payloadType === "task_started" || payloadType === "task_complete" ? "task" : payloadType === "context_compacted" ? "compaction" : payloadType === "thread_rolled_back" ? "rollback" : payloadType === "turn_aborted" ? "interruption" : payloadType === "mcp_tool_call_end" ? "mcp_tool_call" : void 0;
|
|
5057
|
+
let payloadType = record.payload?.type, kind = payloadType === "task_started" || payloadType === "task_complete" ? "task" : payloadType === "context_compacted" ? "compaction" : payloadType === "thread_rolled_back" ? "rollback" : payloadType === "turn_aborted" ? "interruption" : payloadType === "mcp_tool_call_end" ? "mcp_tool_call" : void 0;
|
|
4864
5058
|
if (!kind) return;
|
|
4865
5059
|
let callId = stringValue3(record.payload?.call_id);
|
|
4866
5060
|
addActivity(acc, {
|
|
@@ -4877,7 +5071,7 @@ function handleCodexEvent(record, usageDate, projectFields, sessionId, filePath,
|
|
|
4877
5071
|
}
|
|
4878
5072
|
async function scanClaudeActivity(targetDates, options) {
|
|
4879
5073
|
let acc = createAccumulator(targetDates, options.projectAliases), fileJobs = [];
|
|
4880
|
-
for (let baseDir of
|
|
5074
|
+
for (let baseDir of getClaudeProjectDirs(options.claudeProjectsDirs)) {
|
|
4881
5075
|
let projectDirs;
|
|
4882
5076
|
try {
|
|
4883
5077
|
projectDirs = await readdir7(baseDir, { withFileTypes: !0 });
|
|
@@ -4923,18 +5117,22 @@ async function processClaudeFile(filePath, fallbackFields, acc) {
|
|
|
4923
5117
|
if (!acceptsDate(acc, usageDate)) continue;
|
|
4924
5118
|
let sessionId = record.sessionId ?? fallbackSessionId;
|
|
4925
5119
|
acc.stats.sessions.add(`claude:${sessionId}`);
|
|
4926
|
-
let projectFields = record.cwd ? resolveProjectFields(record.cwd, acc.projectAliases) : fallbackFields;
|
|
4927
|
-
|
|
4928
|
-
|
|
4929
|
-
|
|
4930
|
-
|
|
4931
|
-
|
|
4932
|
-
|
|
4933
|
-
|
|
4934
|
-
|
|
4935
|
-
|
|
4936
|
-
|
|
4937
|
-
|
|
5120
|
+
let projectFields = record.cwd ? resolveProjectFields(record.cwd, acc.projectAliases) : fallbackFields, prompt2 = claudeHumanPrompt(record);
|
|
5121
|
+
if (prompt2) {
|
|
5122
|
+
let typed = claudeTypedText(prompt2.text);
|
|
5123
|
+
typed !== void 0 && addUserMessage(acc, {
|
|
5124
|
+
provider: "anthropic",
|
|
5125
|
+
product: "claude-code",
|
|
5126
|
+
usageDate,
|
|
5127
|
+
projectFields,
|
|
5128
|
+
sessionId,
|
|
5129
|
+
timestamp: record.timestamp ?? "",
|
|
5130
|
+
content: prompt2.text,
|
|
5131
|
+
chars: countChars(typed),
|
|
5132
|
+
fallbackKey: `${filePath}:${usageDate}:${sessionId}:user:${record.timestamp ?? ""}`,
|
|
5133
|
+
id: prompt2.id
|
|
5134
|
+
});
|
|
5135
|
+
}
|
|
4938
5136
|
let blocks = Array.isArray(record.message?.content) ? record.message.content : [];
|
|
4939
5137
|
for (let block of blocks) {
|
|
4940
5138
|
if (block?.type !== "tool_use") continue;
|
|
@@ -4976,6 +5174,7 @@ function finalizeActivity(acc) {
|
|
|
4976
5174
|
};
|
|
4977
5175
|
}
|
|
4978
5176
|
function addActivity(acc, input) {
|
|
5177
|
+
let amount = input.amount ?? 1;
|
|
4979
5178
|
if (acc.seen.has(input.dedupeKey)) return;
|
|
4980
5179
|
acc.seen.add(input.dedupeKey);
|
|
4981
5180
|
let source = `${input.provider}/${input.product}`, key = [
|
|
@@ -4987,7 +5186,7 @@ function addActivity(acc, input) {
|
|
|
4987
5186
|
input.confidence
|
|
4988
5187
|
].join("|"), existing = acc.items.get(key);
|
|
4989
5188
|
if (existing) {
|
|
4990
|
-
existing.count +=
|
|
5189
|
+
existing.count += amount;
|
|
4991
5190
|
return;
|
|
4992
5191
|
}
|
|
4993
5192
|
acc.items.set(key, {
|
|
@@ -5000,7 +5199,7 @@ function addActivity(acc, input) {
|
|
|
5000
5199
|
projectAlias: input.projectFields.projectAlias,
|
|
5001
5200
|
kind: input.kind,
|
|
5002
5201
|
name: input.name,
|
|
5003
|
-
count:
|
|
5202
|
+
count: amount,
|
|
5004
5203
|
confidence: input.confidence
|
|
5005
5204
|
});
|
|
5006
5205
|
}
|
|
@@ -5016,6 +5215,17 @@ function addUserMessage(acc, input) {
|
|
|
5016
5215
|
name: "user_message",
|
|
5017
5216
|
confidence: "exact",
|
|
5018
5217
|
dedupeKey: `activity:${key}`
|
|
5218
|
+
}), input.chars > 0 && addActivity(acc, {
|
|
5219
|
+
usageDate: input.usageDate,
|
|
5220
|
+
provider: input.provider,
|
|
5221
|
+
product: input.product,
|
|
5222
|
+
projectFields: input.projectFields,
|
|
5223
|
+
sessionId: input.sessionId,
|
|
5224
|
+
kind: "user_message_chars",
|
|
5225
|
+
name: "user_message_chars",
|
|
5226
|
+
confidence: "exact",
|
|
5227
|
+
dedupeKey: `activity:${key}:chars`,
|
|
5228
|
+
amount: input.chars
|
|
5019
5229
|
}));
|
|
5020
5230
|
}
|
|
5021
5231
|
function acceptsDate(acc, usageDate) {
|
|
@@ -5026,12 +5236,12 @@ async function collectCodexSessionFiles2(baseDir) {
|
|
|
5026
5236
|
try {
|
|
5027
5237
|
let files = await readdir7(join17(baseDir, "archived_sessions"));
|
|
5028
5238
|
for (let file of files)
|
|
5029
|
-
file
|
|
5239
|
+
isCodexSessionFile(file) && paths.push(join17(baseDir, "archived_sessions", file));
|
|
5030
5240
|
} catch {
|
|
5031
5241
|
}
|
|
5032
|
-
return await walkJsonl(join17(baseDir, "sessions"), paths), paths;
|
|
5242
|
+
return await walkJsonl(join17(baseDir, "sessions"), paths, isCodexSessionFile), paths;
|
|
5033
5243
|
}
|
|
5034
|
-
function
|
|
5244
|
+
function getClaudeProjectDirs(configured) {
|
|
5035
5245
|
if (configured?.length) return configured;
|
|
5036
5246
|
let envVar = process.env.CLAUDE_CONFIG_DIR?.trim();
|
|
5037
5247
|
if (envVar)
|
|
@@ -5042,7 +5252,10 @@ function getClaudeProjectDirs2(configured) {
|
|
|
5042
5252
|
join17(home, ".claude", "projects")
|
|
5043
5253
|
];
|
|
5044
5254
|
}
|
|
5045
|
-
|
|
5255
|
+
function isCodexSessionFile(name) {
|
|
5256
|
+
return name.endsWith(".jsonl") || name.endsWith(".jsonl.zst");
|
|
5257
|
+
}
|
|
5258
|
+
async function walkJsonl(dir, result, accept = (name) => name.endsWith(".jsonl")) {
|
|
5046
5259
|
let entries;
|
|
5047
5260
|
try {
|
|
5048
5261
|
entries = await readdir7(dir, { withFileTypes: !0 });
|
|
@@ -5051,7 +5264,7 @@ async function walkJsonl(dir, result) {
|
|
|
5051
5264
|
}
|
|
5052
5265
|
for (let entry of entries) {
|
|
5053
5266
|
let fullPath = join17(dir, entry.name);
|
|
5054
|
-
entry.isDirectory() ? await walkJsonl(fullPath, result) : entry.name
|
|
5267
|
+
entry.isDirectory() ? await walkJsonl(fullPath, result, accept) : accept(entry.name) && result.push(fullPath);
|
|
5055
5268
|
}
|
|
5056
5269
|
}
|
|
5057
5270
|
function resolveClaudeProject(projectPath, aliases2) {
|
|
@@ -5068,13 +5281,29 @@ function classifyClaudeTool(name) {
|
|
|
5068
5281
|
function getClaudeMetricName(toolName, input) {
|
|
5069
5282
|
return toolName === "Skill" ? stringValue3(input?.skill) ?? "unknown" : toolName === "Agent" ? stringValue3(input?.description) ?? stringValue3(input?.subagent_type) ?? "unknown" : toolName;
|
|
5070
5283
|
}
|
|
5071
|
-
function
|
|
5072
|
-
|
|
5284
|
+
function claudeHumanPrompt(record) {
|
|
5285
|
+
let attachment = record.attachment;
|
|
5286
|
+
if (attachment?.type === "queued_command")
|
|
5287
|
+
return attachment.origin?.kind !== "human" ? void 0 : { text: extractClaudeMessageText(attachment.prompt) ?? "", id: attachment.source_uuid };
|
|
5288
|
+
if (record.type !== "user" || record.message?.role !== "user" || record.isMeta || record.isSidechain || record.isCompactSummary || record.isVisibleInTranscriptOnly) return;
|
|
5289
|
+
if (record.origin) {
|
|
5290
|
+
if (record.origin.kind !== "human") return;
|
|
5291
|
+
} else if (record.promptSource === "sdk" || record.promptSource === "system")
|
|
5292
|
+
return;
|
|
5293
|
+
if (record.toolUseResult || record.sourceToolAssistantUUID || record.sourceToolUseID) return;
|
|
5073
5294
|
let content = record.message.content;
|
|
5074
|
-
|
|
5295
|
+
if (Array.isArray(content) && content.some((block) => block?.type === "tool_result")) return;
|
|
5296
|
+
let text = extractClaudeMessageText(content);
|
|
5297
|
+
return text ? { text, id: record.uuid } : void 0;
|
|
5298
|
+
}
|
|
5299
|
+
var CLAUDE_REMINDER = /<system-reminder>[\s\S]*?<\/system-reminder>/g, CLAUDE_PASTE = /<pasted_content[^>]*>[\s\S]*?<\/pasted_content[^>]*>/g, CLAUDE_PLACEHOLDER = /\[(?:Pasted text #\d+(?: \+\d+ lines)?|Image #\d+)\]/g;
|
|
5300
|
+
function claudeTypedText(raw) {
|
|
5301
|
+
let text = raw.replace(CLAUDE_REMINDER, "").replace(CLAUDE_PASTE, ""), trimmed = text.trimStart();
|
|
5302
|
+
if (!(!trimmed || trimmed.startsWith("<") || trimmed.startsWith("Caveat:") || trimmed.startsWith("[Request interrupted")))
|
|
5303
|
+
return text.replace(CLAUDE_PLACEHOLDER, "");
|
|
5075
5304
|
}
|
|
5076
|
-
function
|
|
5077
|
-
return
|
|
5305
|
+
function countChars(text) {
|
|
5306
|
+
return [...text.replace(/\s+/g, "")].length;
|
|
5078
5307
|
}
|
|
5079
5308
|
function extractCodexMessageText(content) {
|
|
5080
5309
|
return typeof content == "string" ? content : Array.isArray(content) && content.map((block) => stringValue3(block.text)).filter(Boolean).join(`
|
|
@@ -5132,10 +5361,13 @@ function summarize(items, keyFn, labelFn, limit) {
|
|
|
5132
5361
|
return limit ? rows.slice(0, limit) : rows;
|
|
5133
5362
|
}
|
|
5134
5363
|
function sumByConfidence(items, confidence) {
|
|
5135
|
-
return items.reduce((sum, item) => sum + (item.kind
|
|
5364
|
+
return items.reduce((sum, item) => sum + (!isUserMessageKind(item.kind) && item.confidence === confidence ? item.count : 0), 0);
|
|
5365
|
+
}
|
|
5366
|
+
function sumKind(items, kind) {
|
|
5367
|
+
return items.reduce((sum, item) => sum + (item.kind === kind ? item.count : 0), 0);
|
|
5136
5368
|
}
|
|
5137
|
-
function
|
|
5138
|
-
return
|
|
5369
|
+
function isUserMessageKind(kind) {
|
|
5370
|
+
return kind === "user_message" || kind === "user_message_chars";
|
|
5139
5371
|
}
|
|
5140
5372
|
function isToolLikeKind(kind) {
|
|
5141
5373
|
return kind === "function_call" || kind === "custom_tool_call" || kind === "tool_call" || kind === "web_search" || kind === "tool_search" || kind === "image_generation" || kind === "mcp_tool_call";
|
|
@@ -5144,6 +5376,8 @@ function labelKind(kind) {
|
|
|
5144
5376
|
switch (kind) {
|
|
5145
5377
|
case "user_message":
|
|
5146
5378
|
return "User Message";
|
|
5379
|
+
case "user_message_chars":
|
|
5380
|
+
return "User Message Chars";
|
|
5147
5381
|
case "function_call":
|
|
5148
5382
|
return "Function Call";
|
|
5149
5383
|
case "custom_tool_call":
|
|
@@ -5663,6 +5897,7 @@ var msgs = {
|
|
|
5663
5897
|
notInstalled: "Not installed",
|
|
5664
5898
|
installedNoData: "Installed, no usage data yet",
|
|
5665
5899
|
hasData: (n) => `${n} session${n > 1 ? "s" : ""} found`,
|
|
5900
|
+
hasDataInDirs: (n, dirs) => `${n} session${n > 1 ? "s" : ""} found across ${dirs} data director${dirs === 1 ? "y" : "ies"}`,
|
|
5666
5901
|
openCodeData: (dbs, legacy) => `${dbs} database(s), ${legacy} legacy message(s) found`,
|
|
5667
5902
|
openCodeSqliteUnavailable: "Database found, but this Node version requires the system sqlite3 executable",
|
|
5668
5903
|
schedule: "Schedule",
|
|
@@ -5689,6 +5924,7 @@ var msgs = {
|
|
|
5689
5924
|
notInstalled: "\u672A\u5B89\u88C5",
|
|
5690
5925
|
installedNoData: "\u5DF2\u5B89\u88C5\uFF0C\u6682\u65E0\u4F7F\u7528\u6570\u636E",
|
|
5691
5926
|
hasData: (n) => `\u53D1\u73B0 ${n} \u4E2A\u4F1A\u8BDD`,
|
|
5927
|
+
hasDataInDirs: (n, dirs) => `\u5728 ${dirs} \u4E2A\u6570\u636E\u76EE\u5F55\u4E2D\u53D1\u73B0 ${n} \u4E2A\u4F1A\u8BDD`,
|
|
5692
5928
|
openCodeData: (dbs, legacy) => `\u53D1\u73B0 ${dbs} \u4E2A\u6570\u636E\u5E93\u3001${legacy} \u6761\u65E7\u7248\u6D88\u606F`,
|
|
5693
5929
|
openCodeSqliteUnavailable: "\u5DF2\u53D1\u73B0\u6570\u636E\u5E93\uFF0C\u4F46\u5F53\u524D Node \u7248\u672C\u9700\u8981\u5B89\u88C5\u7CFB\u7EDF sqlite3 \u624D\u80FD\u8BFB\u53D6",
|
|
5694
5930
|
schedule: "\u5B9A\u65F6\u540C\u6B65",
|
|
@@ -5738,7 +5974,7 @@ async function runDoctor(lang = "zh") {
|
|
|
5738
5974
|
target.lastSuccessfulUploadAt ? checks.push({ group: g2, name: `${prefix} ${s.lastSync}`, status: "ok", message: target.lastSuccessfulUploadAt }) : checks.push({ group: g2, name: `${prefix} ${s.lastSync}`, status: "warn", message: s.lastSyncNone });
|
|
5739
5975
|
}
|
|
5740
5976
|
let g3 = s.groupTools, home = homedir19(), tools = [
|
|
5741
|
-
{ dirs:
|
|
5977
|
+
{ dirs: await discoverClaudeProjectDirs(), label: "Claude Code", exts: [".jsonl"] },
|
|
5742
5978
|
{ dirs: [join20(home, ".codex")], label: "Codex CLI", exts: [".jsonl"] },
|
|
5743
5979
|
{ dirs: [join20(home, "Library", "Application Support", "Cursor", "User", "globalStorage")], label: "Cursor", exts: [".vscdb"] },
|
|
5744
5980
|
{ dirs: [join20(home, ".copilot", "session-state"), join20(home, ".copilot", "otel")], label: "Copilot CLI", exts: [".jsonl"] },
|
|
@@ -5761,17 +5997,22 @@ async function runDoctor(lang = "zh") {
|
|
|
5761
5997
|
{ dirs: [resolveTraeNativeCacheDir(home), resolveTokscaleTraeCacheDir(home)], label: "Trae", exts: [".json"] }
|
|
5762
5998
|
];
|
|
5763
5999
|
for (let tool of tools) {
|
|
5764
|
-
let installed = !1, n = 0;
|
|
6000
|
+
let installed = !1, installedDirs = 0, n = 0;
|
|
5765
6001
|
for (let dir of tool.dirs)
|
|
5766
6002
|
try {
|
|
5767
|
-
await stat5(dir), installed = !0, n += await countFiles(dir, tool.exts);
|
|
6003
|
+
await stat5(dir), installed = !0, installedDirs++, n += await countFiles(dir, tool.exts);
|
|
5768
6004
|
} catch {
|
|
5769
6005
|
}
|
|
5770
6006
|
if (!installed) {
|
|
5771
6007
|
checks.push({ group: g3, name: tool.label, status: "warn", message: s.notInstalled });
|
|
5772
6008
|
continue;
|
|
5773
6009
|
}
|
|
5774
|
-
n > 0 ? checks.push({
|
|
6010
|
+
n > 0 ? checks.push({
|
|
6011
|
+
group: g3,
|
|
6012
|
+
name: tool.label,
|
|
6013
|
+
status: "ok",
|
|
6014
|
+
message: tool.label === "Claude Code" ? s.hasDataInDirs(n, installedDirs) : s.hasData(n)
|
|
6015
|
+
}) : checks.push({ group: g3, name: tool.label, status: "warn", message: s.installedNoData });
|
|
5775
6016
|
}
|
|
5776
6017
|
let openCodeSources = await resolveOpenCodeSources({
|
|
5777
6018
|
dbPaths: config.scanner?.opencodeDbPaths
|
|
@@ -6171,22 +6412,22 @@ var CACHE_DIR = join22(homedir21(), ".aiusage"), CACHE_PATH = join22(CACHE_DIR,
|
|
|
6171
6412
|
"https://unpkg.com/@aiusage/pricing@latest/catalog.json"
|
|
6172
6413
|
];
|
|
6173
6414
|
async function resolvePricingCatalog(config, options = {}) {
|
|
6174
|
-
let mode = config.pricing?.mode ?? "auto", cache = await readPricingCache(), ttlHours = config.pricing?.cacheTtlHours ?? DEFAULT_CACHE_TTL_HOURS;
|
|
6415
|
+
let mode = config.pricing?.mode ?? "auto", cache = await readPricingCache(), ttlHours = config.pricing?.cacheTtlHours ?? DEFAULT_CACHE_TTL_HOURS, preferNewer = (resolved) => mode === "auto" && !options.explicitUrl && isOlderVersion(resolved.info.version, catalog.version) ? { catalog, info: { source: "bundled", version: catalog.version } } : resolved;
|
|
6175
6416
|
if (!options.forceRefresh && cache && (mode === "manual" || mode === "offline" || isCacheFresh(cache, ttlHours)))
|
|
6176
|
-
return fromCache(cache);
|
|
6417
|
+
return preferNewer(fromCache(cache));
|
|
6177
6418
|
if ((mode !== "offline" || options.forceRefresh) && (mode === "auto" || options.forceRefresh)) {
|
|
6178
6419
|
let candidates = getPricingUrls(config, options);
|
|
6179
6420
|
for (let url of candidates)
|
|
6180
6421
|
try {
|
|
6181
6422
|
let catalog2 = await fetchPricingCatalog(url), fetchedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
6182
|
-
return await writePricingCache({ fetchedAt, sourceUrl: url, catalog: catalog2 }), {
|
|
6423
|
+
return await writePricingCache({ fetchedAt, sourceUrl: url, catalog: catalog2 }), preferNewer({
|
|
6183
6424
|
catalog: catalog2,
|
|
6184
6425
|
info: { source: "remote", version: catalog2.version, url, fetchedAt }
|
|
6185
|
-
};
|
|
6426
|
+
});
|
|
6186
6427
|
} catch {
|
|
6187
6428
|
}
|
|
6188
6429
|
}
|
|
6189
|
-
return cache ? fromCache(cache) : {
|
|
6430
|
+
return cache ? preferNewer(fromCache(cache)) : {
|
|
6190
6431
|
catalog,
|
|
6191
6432
|
info: { source: "bundled", version: catalog.version }
|
|
6192
6433
|
};
|
|
@@ -6216,6 +6457,9 @@ function getPricingUrls(config, options) {
|
|
|
6216
6457
|
].filter((url) => !!url);
|
|
6217
6458
|
return [...new Set(urls.map((url) => url.trim()).filter(Boolean))];
|
|
6218
6459
|
}
|
|
6460
|
+
function isOlderVersion(version, than) {
|
|
6461
|
+
return version.localeCompare(than) < 0;
|
|
6462
|
+
}
|
|
6219
6463
|
function isCacheFresh(cache, ttlHours) {
|
|
6220
6464
|
let fetched = new Date(cache.fetchedAt).getTime();
|
|
6221
6465
|
return Number.isFinite(fetched) ? Date.now() - fetched < ttlHours * 60 * 60 * 1e3 : !1;
|
|
@@ -7171,8 +7415,8 @@ await (async () => {
|
|
|
7171
7415
|
await runImport(parsed.flags, parsed.positionals);
|
|
7172
7416
|
} else if (command === "setup")
|
|
7173
7417
|
console.log(`To deploy the server, clone the repo and run the setup wizard:
|
|
7174
|
-
`), console.log(" git clone https://github.com/
|
|
7175
|
-
`), console.log("See: https://github.com/
|
|
7418
|
+
`), console.log(" git clone https://github.com/imetn/aiusage.git"), console.log(" cd aiusage && pnpm install"), console.log(` pnpm setup
|
|
7419
|
+
`), console.log("See: https://github.com/imetn/aiusage#deploy-your-own-server");
|
|
7176
7420
|
else if (command === "--help" || command === "-h" || command === "help") {
|
|
7177
7421
|
let zh2 = (await readConfig()).lang === "zh";
|
|
7178
7422
|
printHelp(zh2);
|