@aiusage/cli 1.8.0 → 1.8.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.
- package/dist/cli.js +19 -4
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -100,6 +100,18 @@ function emptyResult(dates) {
|
|
|
100
100
|
function normalizeModelName(name) {
|
|
101
101
|
return name.replace(/-\d{8}$/, "");
|
|
102
102
|
}
|
|
103
|
+
async function keepFilesModifiedSince(items, targetDates, pathOf) {
|
|
104
|
+
let dates = targetDates ? [...targetDates].sort() : [];
|
|
105
|
+
if (dates.length === 0) return items;
|
|
106
|
+
let cutoff = Date.parse(`${dates[0]}T00:00:00Z`) - 1440 * 60 * 1e3, keep = await Promise.all(items.map(async (item) => {
|
|
107
|
+
try {
|
|
108
|
+
return (await stat(pathOf(item))).mtimeMs >= cutoff;
|
|
109
|
+
} catch {
|
|
110
|
+
return !1;
|
|
111
|
+
}
|
|
112
|
+
}));
|
|
113
|
+
return items.filter((_, i) => keep[i]);
|
|
114
|
+
}
|
|
103
115
|
async function runWithConcurrency(items, concurrency, worker) {
|
|
104
116
|
if (items.length === 0) return;
|
|
105
117
|
let limit = Math.max(1, Math.min(concurrency, items.length)), nextIndex = 0;
|
|
@@ -239,7 +251,9 @@ async function scanClaudeDates(targetDates, claudeDir, projectAliases) {
|
|
|
239
251
|
fileJobs.push({ filePath, projectFields: fields });
|
|
240
252
|
}
|
|
241
253
|
}
|
|
242
|
-
fileJobs.sort((a, b) => a.filePath.localeCompare(b.filePath))
|
|
254
|
+
fileJobs.sort((a, b) => a.filePath.localeCompare(b.filePath));
|
|
255
|
+
let recentJobs = await keepFilesModifiedSince(fileJobs, targetDateSet, (job) => job.filePath);
|
|
256
|
+
await runWithConcurrency(recentJobs, FILE_CONCURRENCY, async (job) => {
|
|
243
257
|
await processJsonlFile(job.filePath, job.projectFields, targetDateSet, projectAliases, groupedByDate, processedHashes, sessionSets);
|
|
244
258
|
});
|
|
245
259
|
for (let [usageDate, grouped] of groupedByDate.entries())
|
|
@@ -1644,7 +1658,7 @@ var FILE_CONCURRENCY2 = 16, MAX_LINE_BYTES2 = 64 * 1024 * 1024;
|
|
|
1644
1658
|
async function scanCodexDates(targetDates, codexDir, projectAliases) {
|
|
1645
1659
|
let targetDateSet = new Set(targetDates), groupedByDate = /* @__PURE__ */ new Map();
|
|
1646
1660
|
for (let targetDate of targetDateSet) groupedByDate.set(targetDate, /* @__PURE__ */ new Map());
|
|
1647
|
-
let baseDir = codexDir ?? join4(homedir3(), ".codex"), serviceTier = await detectCodexServiceTier(baseDir), sessionFiles = await collectSessionFiles(baseDir);
|
|
1661
|
+
let baseDir = codexDir ?? join4(homedir3(), ".codex"), serviceTier = await detectCodexServiceTier(baseDir), sessionFiles = await keepFilesModifiedSince(await collectSessionFiles(baseDir), targetDateSet, (path) => path);
|
|
1648
1662
|
if (sessionFiles.length === 0)
|
|
1649
1663
|
return new Map([...targetDateSet].map((targetDate) => [targetDate, []]));
|
|
1650
1664
|
let eventsByFile = Array.from({ length: sessionFiles.length }, () => []);
|
|
@@ -4896,7 +4910,7 @@ function renderActivityReport(report, opts) {
|
|
|
4896
4910
|
`);
|
|
4897
4911
|
}
|
|
4898
4912
|
async function scanCodexActivity(targetDates, options) {
|
|
4899
|
-
let baseDir = options.codexDir ?? join17(homedir16(), ".codex"), acc = createAccumulator(targetDates, options.projectAliases), files = await collectCodexSessionFiles2(baseDir);
|
|
4913
|
+
let baseDir = options.codexDir ?? join17(homedir16(), ".codex"), acc = createAccumulator(targetDates, options.projectAliases), files = await keepFilesModifiedSince(await collectCodexSessionFiles2(baseDir), targetDates, (path) => path);
|
|
4900
4914
|
return acc.stats.filesScanned = files.length, await runWithConcurrency(files, FILE_CONCURRENCY3, async (filePath) => {
|
|
4901
4915
|
await processCodexFile2(filePath, acc);
|
|
4902
4916
|
}), finalizeActivity(acc);
|
|
@@ -5086,7 +5100,8 @@ async function scanClaudeActivity(targetDates, options) {
|
|
|
5086
5100
|
for (let filePath of jsonlFiles) fileJobs.push({ filePath, projectFields: fields });
|
|
5087
5101
|
}
|
|
5088
5102
|
}
|
|
5089
|
-
|
|
5103
|
+
let recentJobs = await keepFilesModifiedSince(fileJobs, targetDates, (job) => job.filePath);
|
|
5104
|
+
return acc.stats.filesScanned = recentJobs.length, await runWithConcurrency(recentJobs, FILE_CONCURRENCY3, async (job) => {
|
|
5090
5105
|
await processClaudeFile(job.filePath, job.projectFields, acc);
|
|
5091
5106
|
}), finalizeActivity(acc);
|
|
5092
5107
|
}
|