@aiusage/cli 1.8.1 → 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 +27 -24
- 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 }, () => []);
|
|
@@ -4792,7 +4806,7 @@ function fmtDateShort(dateStr) {
|
|
|
4792
4806
|
}
|
|
4793
4807
|
|
|
4794
4808
|
// src/activity.ts
|
|
4795
|
-
import { open, readdir as readdir7
|
|
4809
|
+
import { open, readdir as readdir7 } from "node:fs/promises";
|
|
4796
4810
|
import { createInterface as createInterface3 } from "node:readline";
|
|
4797
4811
|
import { homedir as homedir16 } from "node:os";
|
|
4798
4812
|
import { basename as basename12, join as join17 } from "node:path";
|
|
@@ -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
|
|
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,7 @@ async function scanClaudeActivity(targetDates, options) {
|
|
|
5086
5100
|
for (let filePath of jsonlFiles) fileJobs.push({ filePath, projectFields: fields });
|
|
5087
5101
|
}
|
|
5088
5102
|
}
|
|
5089
|
-
let recentJobs = await
|
|
5103
|
+
let recentJobs = await keepFilesModifiedSince(fileJobs, targetDates, (job) => job.filePath);
|
|
5090
5104
|
return acc.stats.filesScanned = recentJobs.length, await runWithConcurrency(recentJobs, FILE_CONCURRENCY3, async (job) => {
|
|
5091
5105
|
await processClaudeFile(job.filePath, job.projectFields, acc);
|
|
5092
5106
|
}), finalizeActivity(acc);
|
|
@@ -5229,17 +5243,6 @@ function addUserMessage(acc, input) {
|
|
|
5229
5243
|
amount: input.chars
|
|
5230
5244
|
}));
|
|
5231
5245
|
}
|
|
5232
|
-
async function keepRecentFiles(items, targetDates, pathOf) {
|
|
5233
|
-
if (!targetDates?.size) return items;
|
|
5234
|
-
let earliest = [...targetDates].sort()[0], cutoff = Date.parse(`${earliest}T00:00:00Z`) - 1440 * 60 * 1e3, keep = await Promise.all(items.map(async (item) => {
|
|
5235
|
-
try {
|
|
5236
|
-
return (await stat4(pathOf(item))).mtimeMs >= cutoff;
|
|
5237
|
-
} catch {
|
|
5238
|
-
return !1;
|
|
5239
|
-
}
|
|
5240
|
-
}));
|
|
5241
|
-
return items.filter((_, i) => keep[i]);
|
|
5242
|
-
}
|
|
5243
5246
|
function acceptsDate(acc, usageDate) {
|
|
5244
5247
|
return !acc.targetDates || acc.targetDates.has(usageDate);
|
|
5245
5248
|
}
|
|
@@ -5675,7 +5678,7 @@ async function requestJson(url, init) {
|
|
|
5675
5678
|
|
|
5676
5679
|
// src/schedule.ts
|
|
5677
5680
|
import { realpathSync } from "node:fs";
|
|
5678
|
-
import { mkdir as mkdir2, readFile as readFile16, stat as
|
|
5681
|
+
import { mkdir as mkdir2, readFile as readFile16, stat as stat4, unlink, writeFile as writeFile2 } from "node:fs/promises";
|
|
5679
5682
|
import { execFile as execFile2 } from "node:child_process";
|
|
5680
5683
|
import { promisify } from "node:util";
|
|
5681
5684
|
import { homedir as homedir18, platform, tmpdir as tmpdir2 } from "node:os";
|
|
@@ -5776,7 +5779,7 @@ async function disableLaunchd() {
|
|
|
5776
5779
|
}
|
|
5777
5780
|
async function getLaunchdStatus() {
|
|
5778
5781
|
try {
|
|
5779
|
-
await
|
|
5782
|
+
await stat4(PLIST_PATH);
|
|
5780
5783
|
} catch {
|
|
5781
5784
|
return { enabled: !1 };
|
|
5782
5785
|
}
|
|
@@ -5886,7 +5889,7 @@ function escapeXml(value) {
|
|
|
5886
5889
|
}
|
|
5887
5890
|
|
|
5888
5891
|
// src/doctor.ts
|
|
5889
|
-
import { readdir as readdir8, stat as
|
|
5892
|
+
import { readdir as readdir8, stat as stat5 } from "node:fs/promises";
|
|
5890
5893
|
import { homedir as homedir19 } from "node:os";
|
|
5891
5894
|
import { join as join20 } from "node:path";
|
|
5892
5895
|
var msgs = {
|
|
@@ -5965,7 +5968,7 @@ async function countFiles(dir, exts, cap = 1e3) {
|
|
|
5965
5968
|
async function runDoctor(lang = "zh") {
|
|
5966
5969
|
let s = msgs[lang], checks = [], config = await readConfig(), g1 = s.groupConfig, configPath = getConfigPath();
|
|
5967
5970
|
try {
|
|
5968
|
-
await
|
|
5971
|
+
await stat5(configPath), checks.push({ group: g1, name: s.config, status: "ok", message: configPath });
|
|
5969
5972
|
} catch {
|
|
5970
5973
|
checks.push({ group: g1, name: s.config, status: "fail", message: s.configMissing });
|
|
5971
5974
|
}
|
|
@@ -6012,7 +6015,7 @@ async function runDoctor(lang = "zh") {
|
|
|
6012
6015
|
let installed = !1, installedDirs = 0, n = 0;
|
|
6013
6016
|
for (let dir of tool.dirs)
|
|
6014
6017
|
try {
|
|
6015
|
-
await
|
|
6018
|
+
await stat5(dir), installed = !0, installedDirs++, n += await countFiles(dir, tool.exts);
|
|
6016
6019
|
} catch {
|
|
6017
6020
|
}
|
|
6018
6021
|
if (!installed) {
|
|
@@ -6031,7 +6034,7 @@ async function runDoctor(lang = "zh") {
|
|
|
6031
6034
|
}), openCodeLegacyCount = await countFiles(openCodeSources.legacyDir, [".json"]), openCodeInstalled = openCodeSources.dbPaths.length > 0 || openCodeLegacyCount > 0;
|
|
6032
6035
|
if (!openCodeInstalled)
|
|
6033
6036
|
try {
|
|
6034
|
-
await
|
|
6037
|
+
await stat5(openCodeSources.dataDir), openCodeInstalled = !0;
|
|
6035
6038
|
} catch {
|
|
6036
6039
|
}
|
|
6037
6040
|
openCodeInstalled ? openCodeSources.dbPaths.length === 0 && openCodeLegacyCount === 0 ? checks.push({ group: g3, name: "OpenCode", status: "warn", message: s.installedNoData }) : openCodeSources.dbPaths.length > 0 && await detectOpenCodeSqliteRuntime() === "unavailable" ? checks.push({
|
|
@@ -6520,7 +6523,7 @@ function assertPricingCatalog(value) {
|
|
|
6520
6523
|
import { execFile as execFile3 } from "node:child_process";
|
|
6521
6524
|
import { createHash as createHash2 } from "node:crypto";
|
|
6522
6525
|
import { existsSync as existsSync2 } from "node:fs";
|
|
6523
|
-
import { mkdir as mkdir4, open as open3, readdir as readdir10, rename, stat as
|
|
6526
|
+
import { mkdir as mkdir4, open as open3, readdir as readdir10, rename, stat as stat6, writeFile as writeFile4 } from "node:fs/promises";
|
|
6524
6527
|
import { createServer } from "node:net";
|
|
6525
6528
|
import { homedir as homedir22 } from "node:os";
|
|
6526
6529
|
import { join as join23 } from "node:path";
|
|
@@ -6841,7 +6844,7 @@ async function findCompletionLogs(dir) {
|
|
|
6841
6844
|
if (entry.isDirectory()) files.push(...await findCompletionLogs(path));
|
|
6842
6845
|
else if (entry.name === "completion.log" && path.includes("trae.ai-code-completion"))
|
|
6843
6846
|
try {
|
|
6844
|
-
files.push({ path, mtimeMs: (await
|
|
6847
|
+
files.push({ path, mtimeMs: (await stat6(path)).mtimeMs });
|
|
6845
6848
|
} catch {
|
|
6846
6849
|
}
|
|
6847
6850
|
}
|