@aiusage/cli 1.5.2 → 1.5.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.
- package/README.md +21 -4
- package/README.zh-CN.md +21 -4
- package/dist/cli.js +68 -41
- package/package.json +9 -9
package/README.md
CHANGED
|
@@ -50,7 +50,7 @@ Project aliases are applied locally before upload. If two devices set the same a
|
|
|
50
50
|
Local usage report. No cloud upload required.
|
|
51
51
|
|
|
52
52
|
```bash
|
|
53
|
-
aiusage report # default: last 7 days, English, compact
|
|
53
|
+
aiusage report # default: last 7 days + today, English, compact
|
|
54
54
|
aiusage report --range 1m # last 30 days
|
|
55
55
|
aiusage report --range 3m # last 90 days
|
|
56
56
|
aiusage report --range all # all history
|
|
@@ -64,13 +64,29 @@ Reads data from local tool data directories including `~/.claude/projects` (Clau
|
|
|
64
64
|
|
|
65
65
|
**Compact mode** (default) shows Sources and Daily tables with merged Cache column and 2-decimal cost. **Detail mode** (`--detail`) expands all columns (CacheRead, CacheWrite, Reasoning), adds Top Models and Pricing Notes sections, and shows 4-decimal cost.
|
|
66
66
|
|
|
67
|
+
### Shared date options
|
|
68
|
+
|
|
69
|
+
`scan`, `report`, and `sync` use the same date options:
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
aiusage scan --today # today only
|
|
73
|
+
aiusage report --date 2026-03-31 # specific date
|
|
74
|
+
aiusage sync --range 1m # last 30 days
|
|
75
|
+
aiusage sync --lookback 14 # last 14 days + today
|
|
76
|
+
aiusage scan --from 2025-01-01 --to 2026-04-05
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Use `--range 1m`, not `range -1m`. `report` also supports `--range all`; `scan` and `sync` require explicit `--from/--to` for large historical ranges.
|
|
80
|
+
|
|
67
81
|
### scan
|
|
68
82
|
|
|
69
|
-
Scan
|
|
83
|
+
Scan local usage and print detailed breakdowns.
|
|
70
84
|
|
|
71
85
|
```bash
|
|
72
|
-
aiusage scan
|
|
73
|
-
aiusage scan --date 2026-03-31
|
|
86
|
+
aiusage scan # yesterday
|
|
87
|
+
aiusage scan --date 2026-03-31 # specific date
|
|
88
|
+
aiusage scan --range 1m # last 30 days
|
|
89
|
+
aiusage scan --date 2026-03-31 --json # JSON output
|
|
74
90
|
```
|
|
75
91
|
|
|
76
92
|
Defaults to yesterday when `--date` is omitted.
|
|
@@ -111,6 +127,7 @@ Upload usage data to the Worker. Default: last 7 days + today.
|
|
|
111
127
|
aiusage sync # last 7 days + today
|
|
112
128
|
aiusage sync --today # today only
|
|
113
129
|
aiusage sync --date 2026-03-31 # specific date
|
|
130
|
+
aiusage sync --range 1m # last 30 days
|
|
114
131
|
aiusage sync --lookback 14 # last 14 days + today
|
|
115
132
|
aiusage sync --from 2025-01-01 --to 2026-04-05 # date range
|
|
116
133
|
```
|
package/README.zh-CN.md
CHANGED
|
@@ -50,7 +50,7 @@ aiusage project alias --remove myapp # 移除别名
|
|
|
50
50
|
本地用量报告,无需服务端。
|
|
51
51
|
|
|
52
52
|
```bash
|
|
53
|
-
aiusage report # 默认: 最近 7
|
|
53
|
+
aiusage report # 默认: 最近 7 天 + 今天,英文,紧凑模式
|
|
54
54
|
aiusage report --range 1m # 最近 30 天
|
|
55
55
|
aiusage report --range 3m # 最近 90 天
|
|
56
56
|
aiusage report --range all # 全部历史
|
|
@@ -62,13 +62,29 @@ aiusage report --json # JSON 输出
|
|
|
62
62
|
|
|
63
63
|
**紧凑模式**(默认)显示来源和每日汇总表,合并缓存列,保留 2 位小数成本。**详细模式**(`--detail`)展开所有列(CacheRead、CacheWrite、Reasoning),增加热门模型和定价说明,显示 4 位小数成本。
|
|
64
64
|
|
|
65
|
+
### 统一日期参数
|
|
66
|
+
|
|
67
|
+
`scan`、`report`、`sync` 使用同一套日期参数:
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
aiusage scan --today # 仅今天
|
|
71
|
+
aiusage report --date 2026-03-31 # 指定日期
|
|
72
|
+
aiusage sync --range 1m # 最近 30 天
|
|
73
|
+
aiusage sync --lookback 14 # 最近 14 天 + 今天
|
|
74
|
+
aiusage scan --from 2025-01-01 --to 2026-04-05
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
使用 `--range 1m`,不要写成 `range -1m`。`report` 额外支持 `--range all`;`scan` 和 `sync` 如需很长历史范围,请明确使用 `--from/--to`。
|
|
78
|
+
|
|
65
79
|
### scan
|
|
66
80
|
|
|
67
|
-
|
|
81
|
+
扫描本地用量数据并打印明细。
|
|
68
82
|
|
|
69
83
|
```bash
|
|
70
|
-
aiusage scan
|
|
71
|
-
aiusage scan --date 2026-03-31
|
|
84
|
+
aiusage scan # 昨天
|
|
85
|
+
aiusage scan --date 2026-03-31 # 指定日期
|
|
86
|
+
aiusage scan --range 1m # 最近 30 天
|
|
87
|
+
aiusage scan --date 2026-03-31 --json # JSON 输出
|
|
72
88
|
```
|
|
73
89
|
|
|
74
90
|
省略 `--date` 时默认扫描昨天。
|
|
@@ -81,6 +97,7 @@ aiusage scan --date 2026-03-31 --json
|
|
|
81
97
|
aiusage sync # 最近 7 天 + 今天
|
|
82
98
|
aiusage sync --today # 仅今天
|
|
83
99
|
aiusage sync --date 2026-03-31 # 指定日期
|
|
100
|
+
aiusage sync --range 1m # 最近 30 天
|
|
84
101
|
aiusage sync --lookback 14 # 最近 14 天 + 今天
|
|
85
102
|
aiusage sync --from 2025-01-01 --to 2026-04-05 # 指定日期范围
|
|
86
103
|
```
|
package/dist/cli.js
CHANGED
|
@@ -2477,13 +2477,7 @@ function defaultLookbackDays(config) {
|
|
|
2477
2477
|
return config.lookbackDays ?? DEFAULT_LOOKBACK_DAYS;
|
|
2478
2478
|
}
|
|
2479
2479
|
async function requestJson(url, init) {
|
|
2480
|
-
let response;
|
|
2481
|
-
try {
|
|
2482
|
-
response = await fetch(url, init);
|
|
2483
|
-
} catch (err) {
|
|
2484
|
-
throw new Error(`\u65E0\u6CD5\u8FDE\u63A5 ${url}\uFF1A${describeFetchError(err)}`, { cause: err });
|
|
2485
|
-
}
|
|
2486
|
-
let text = await response.text(), data = null;
|
|
2480
|
+
let response = await fetch(url, init), text = await response.text(), data = null;
|
|
2487
2481
|
if (text)
|
|
2488
2482
|
try {
|
|
2489
2483
|
data = JSON.parse(text);
|
|
@@ -2498,13 +2492,6 @@ async function requestJson(url, init) {
|
|
|
2498
2492
|
throw new Error("\u670D\u52A1\u7AEF\u8FD4\u56DE\u4E86\u7A7A\u54CD\u5E94");
|
|
2499
2493
|
return data;
|
|
2500
2494
|
}
|
|
2501
|
-
function describeFetchError(err) {
|
|
2502
|
-
if (!(err instanceof Error)) return String(err);
|
|
2503
|
-
let cause = err.cause, parts = [];
|
|
2504
|
-
cause?.code && parts.push(cause.code);
|
|
2505
|
-
let causeMsg = cause?.message ?? cause?.errors?.[0]?.message;
|
|
2506
|
-
return causeMsg && causeMsg !== err.message && parts.push(causeMsg), parts.length === 0 ? err.message : `${err.message} (${parts.join(": ")})`;
|
|
2507
|
-
}
|
|
2508
2495
|
|
|
2509
2496
|
// src/schedule.ts
|
|
2510
2497
|
import { mkdir as mkdir2, readFile as readFile15, stat, unlink, writeFile as writeFile2 } from "node:fs/promises";
|
|
@@ -3119,11 +3106,11 @@ try {
|
|
|
3119
3106
|
if (command === "--version" || command === "-v")
|
|
3120
3107
|
console.log(getVersion());
|
|
3121
3108
|
else if (command === "scan") {
|
|
3122
|
-
let parsed = parseArgs(argv.slice(1))
|
|
3123
|
-
await runScan(
|
|
3109
|
+
let parsed = parseArgs(argv.slice(1));
|
|
3110
|
+
await runScan(parsed.flags, parsed.positionals);
|
|
3124
3111
|
} else if (command === "report") {
|
|
3125
3112
|
let parsed = parseArgs(argv.slice(1));
|
|
3126
|
-
await runReport(parsed.flags);
|
|
3113
|
+
await runReport(parsed.flags, parsed.positionals);
|
|
3127
3114
|
} else if (command === "health") {
|
|
3128
3115
|
let parsed = parseArgs(argv.slice(1));
|
|
3129
3116
|
await runHealth(parsed.flags);
|
|
@@ -3132,7 +3119,7 @@ try {
|
|
|
3132
3119
|
await runEnroll(parsed.flags);
|
|
3133
3120
|
} else if (command === "sync") {
|
|
3134
3121
|
let parsed = parseArgs(argv.slice(1));
|
|
3135
|
-
await runSync(parsed.flags);
|
|
3122
|
+
await runSync(parsed.flags, parsed.positionals);
|
|
3136
3123
|
} else if (command === "init") {
|
|
3137
3124
|
let parsed = parseArgs(argv.slice(1));
|
|
3138
3125
|
await runInit(parsed.flags);
|
|
@@ -3185,15 +3172,30 @@ try {
|
|
|
3185
3172
|
} catch (error) {
|
|
3186
3173
|
console.error(error instanceof Error ? error.message : String(error)), process.exitCode = 1;
|
|
3187
3174
|
}
|
|
3188
|
-
async function runScan(
|
|
3175
|
+
async function runScan(flags, positionals = []) {
|
|
3189
3176
|
let config = await readConfig(), zh2 = config.lang === "zh";
|
|
3190
|
-
|
|
3191
|
-
|
|
3192
|
-
let result = await scanDate(date, { projectAliases: config.projectAliases });
|
|
3177
|
+
assertNoPositionals("scan", positionals, zh2);
|
|
3178
|
+
let isJson = !!flags.json, dates = resolveScanDates(flags, config), results = dates.length === 1 ? [await scanDate(dates[0], { projectAliases: config.projectAliases })] : await scanDates(dates, { projectAliases: config.projectAliases });
|
|
3193
3179
|
if (isJson) {
|
|
3194
|
-
console.log(JSON.stringify(
|
|
3180
|
+
console.log(JSON.stringify(results.length === 1 ? results[0] : results, null, 2));
|
|
3181
|
+
return;
|
|
3182
|
+
}
|
|
3183
|
+
if (results.length === 1) {
|
|
3184
|
+
console.log(`${zh2 ? "\u626B\u63CF\u65E5\u671F" : "Scan date"}: ${results[0].usageDate}
|
|
3185
|
+
`), printScanResult(results[0], zh2);
|
|
3195
3186
|
return;
|
|
3196
3187
|
}
|
|
3188
|
+
console.log(`${zh2 ? "\u626B\u63CF\u8303\u56F4" : "Scan range"}: ${dates[0]} ~ ${dates[dates.length - 1]} (${dates.length} ${zh2 ? "\u5929" : "days"})
|
|
3189
|
+
`);
|
|
3190
|
+
let daysWithData = results.filter((result) => result.breakdowns.length > 0);
|
|
3191
|
+
if (daysWithData.length === 0) {
|
|
3192
|
+
console.log(zh2 ? "\u8BE5\u8303\u56F4\u65E0\u6570\u636E\u3002" : "No data in this range.");
|
|
3193
|
+
return;
|
|
3194
|
+
}
|
|
3195
|
+
for (let result of daysWithData)
|
|
3196
|
+
console.log(`\u2550\u2550 ${result.usageDate} \u2550\u2550`), printScanResult(result, zh2);
|
|
3197
|
+
}
|
|
3198
|
+
function printScanResult(result, zh2) {
|
|
3197
3199
|
if (result.breakdowns.length === 0) {
|
|
3198
3200
|
console.log(zh2 ? "\u8BE5\u65E5\u65E0\u6570\u636E\u3002" : "No data for this date.");
|
|
3199
3201
|
return;
|
|
@@ -3209,10 +3211,12 @@ async function runScan(date, isJson) {
|
|
|
3209
3211
|
console.log(` ${b.model} | ${b.projectAlias ?? b.projectDisplay ?? b.project}`), console.log(` \u4E8B\u4EF6: ${b.eventCount} \u8F93\u5165: ${fmt(b.inputTokens)} \u7F13\u5B58\u8BFB: ${fmt(b.cachedInputTokens)} \u7F13\u5B58\u5199: ${fmt(b.cacheWriteTokens)} \u8F93\u51FA: ${fmt(b.outputTokens)} \u63A8\u7406: ${fmt(b.reasoningOutputTokens)}`);
|
|
3210
3212
|
console.log();
|
|
3211
3213
|
}
|
|
3212
|
-
console.log("\u2500\u2500 \u5408\u8BA1 \u2500\u2500"), console.log(` \u4E8B\u4EF6: ${result.totals.eventCount} \u8F93\u5165: ${fmt(result.totals.inputTokens)} \u7F13\u5B58\u8BFB: ${fmt(result.totals.cachedInputTokens)} \u7F13\u5B58\u5199: ${fmt(result.totals.cacheWriteTokens)} \u8F93\u51FA: ${fmt(result.totals.outputTokens)} \u63A8\u7406: ${fmt(result.totals.reasoningOutputTokens)}`);
|
|
3214
|
+
console.log("\u2500\u2500 \u5408\u8BA1 \u2500\u2500"), console.log(` \u4E8B\u4EF6: ${result.totals.eventCount} \u8F93\u5165: ${fmt(result.totals.inputTokens)} \u7F13\u5B58\u8BFB: ${fmt(result.totals.cachedInputTokens)} \u7F13\u5B58\u5199: ${fmt(result.totals.cacheWriteTokens)} \u8F93\u51FA: ${fmt(result.totals.outputTokens)} \u63A8\u7406: ${fmt(result.totals.reasoningOutputTokens)}`), console.log();
|
|
3213
3215
|
}
|
|
3214
|
-
async function runReport(flags) {
|
|
3215
|
-
let config = await readConfig()
|
|
3216
|
+
async function runReport(flags, positionals = []) {
|
|
3217
|
+
let config = await readConfig();
|
|
3218
|
+
assertNoPositionals("report", positionals, config.lang === "zh");
|
|
3219
|
+
let { dates, range } = resolveDateParams(flags, config), report = await buildLocalReport(range, { projectAliases: config.projectAliases, dates });
|
|
3216
3220
|
if (flags.json) {
|
|
3217
3221
|
console.log(JSON.stringify(report, null, 2));
|
|
3218
3222
|
return;
|
|
@@ -3263,13 +3267,15 @@ function prompt(question) {
|
|
|
3263
3267
|
});
|
|
3264
3268
|
});
|
|
3265
3269
|
}
|
|
3266
|
-
async function runSync(flags) {
|
|
3267
|
-
let config = await readConfig()
|
|
3270
|
+
async function runSync(flags, positionals = []) {
|
|
3271
|
+
let config = await readConfig();
|
|
3272
|
+
assertNoPositionals("sync", positionals, config.lang === "zh");
|
|
3273
|
+
let allTargets = config.targets ?? [];
|
|
3268
3274
|
if (allTargets.length === 0)
|
|
3269
3275
|
throw new Error("\u672A\u914D\u7F6E\u4EFB\u4F55\u4E0A\u62A5\u76EE\u6807\uFF0C\u8BF7\u5148\u6267\u884C aiusage enroll");
|
|
3270
3276
|
let deviceId = resolveRequiredString(void 0, config.deviceId, "\u7F3A\u5C11 deviceId\uFF0C\u8BF7\u5148\u6267\u884C enroll"), targetName = resolveOptionalString(flags.target, void 0), targets = targetName ? [findTargetOrThrow(config, targetName)] : allTargets, { dates: targetDates } = resolveDateParams(flags, config);
|
|
3271
3277
|
if (!targetDates)
|
|
3272
|
-
throw new Error("sync \
|
|
3278
|
+
throw new Error("sync --range all \u9700\u8981\u660E\u786E\u65E5\u671F\u8303\u56F4\uFF0C\u8BF7\u6539\u7528 --from YYYY-MM-DD --to YYYY-MM-DD");
|
|
3273
3279
|
console.log(`\u626B\u63CF ${targetDates.length} \u5929 (${targetDates[0]} ~ ${targetDates[targetDates.length - 1]}) ...`);
|
|
3274
3280
|
let allDays = (await scanDates(targetDates, { projectAliases: config.projectAliases })).filter((r) => r.breakdowns.length > 0).map((r) => ({ usageDate: r.usageDate, breakdowns: r.breakdowns }));
|
|
3275
3281
|
if (allDays.length === 0) {
|
|
@@ -3460,10 +3466,10 @@ function printHelp(zh2 = !1) {
|
|
|
3460
3466
|
console.log(`aiusage v${getVersion()}
|
|
3461
3467
|
`);
|
|
3462
3468
|
let cmds = zh2 ? [
|
|
3463
|
-
["scan [--date YYYY-MM-DD] [--json]", "\u626B\u63CF\
|
|
3469
|
+
["scan [--date YYYY-MM-DD|--today|--range 7d|1m|3m] [--json]", "\u626B\u63CF\u7528\u91CF\u660E\u7EC6"],
|
|
3464
3470
|
["report [--today] [--range 7d|1m|3m|all] [--detail] [--json]", "\u672C\u5730\u7528\u91CF\u62A5\u544A"],
|
|
3465
|
-
["sync [--today] [--range 7d|1m|3m
|
|
3466
|
-
["report/sync --from YYYY-MM-DD [--to YYYY-MM-DD]", "\u6307\u5B9A\u65E5\u671F\u8303\u56F4\uFF08--start/--end \u540C\u4E49\uFF09"],
|
|
3471
|
+
["sync [--today] [--range 7d|1m|3m]", "\u4E0A\u4F20\u7528\u91CF\u5230\u670D\u52A1\u7AEF"],
|
|
3472
|
+
["scan/report/sync --from YYYY-MM-DD [--to YYYY-MM-DD]", "\u6307\u5B9A\u65E5\u671F\u8303\u56F4\uFF08--start/--end \u540C\u4E49\uFF09"],
|
|
3467
3473
|
["project [list|alias]", "\u9879\u76EE\u7BA1\u7406\u4E0E\u522B\u540D\u8BBE\u7F6E"],
|
|
3468
3474
|
["schedule [on|off|status] [--every 5m]", "\u5B9A\u65F6\u540C\u6B65\u7BA1\u7406"],
|
|
3469
3475
|
["doctor", "\u8BCA\u65AD\u68C0\u67E5"],
|
|
@@ -3472,10 +3478,10 @@ function printHelp(zh2 = !1) {
|
|
|
3472
3478
|
["enroll --server URL --site-id ID --enroll-token TOKEN", "\u6CE8\u518C\u8BBE\u5907\u5230\u670D\u52A1\u7AEF"],
|
|
3473
3479
|
["health [--server URL]", "\u6D4B\u8BD5\u670D\u52A1\u7AEF\u8FDE\u901A\u6027"]
|
|
3474
3480
|
] : [
|
|
3475
|
-
["scan [--date YYYY-MM-DD] [--json]", "Scan
|
|
3481
|
+
["scan [--date YYYY-MM-DD|--today|--range 7d|1m|3m] [--json]", "Scan usage breakdown"],
|
|
3476
3482
|
["report [--today] [--range 7d|1m|3m|all] [--detail] [--json]", "Local usage report"],
|
|
3477
|
-
["sync [--today] [--range 7d|1m|3m
|
|
3478
|
-
["report/sync --from YYYY-MM-DD [--to YYYY-MM-DD]", "Date range (--start/--end aliases)"],
|
|
3483
|
+
["sync [--today] [--range 7d|1m|3m]", "Upload usage to server"],
|
|
3484
|
+
["scan/report/sync --from YYYY-MM-DD [--to YYYY-MM-DD]", "Date range (--start/--end aliases)"],
|
|
3479
3485
|
["project [list|alias]", "Project management & aliases"],
|
|
3480
3486
|
["schedule [on|off|status] [--every 5m]", "Scheduled sync management"],
|
|
3481
3487
|
["doctor", "Run diagnostics"],
|
|
@@ -3493,17 +3499,17 @@ function printUsageHint(zh2 = !1) {
|
|
|
3493
3499
|
console.log(`aiusage v${getVersion()}
|
|
3494
3500
|
`);
|
|
3495
3501
|
let cmds = zh2 ? [
|
|
3496
|
-
["scan [--date YYYY-MM-DD]", "\u626B\u63CF\
|
|
3502
|
+
["scan [--date YYYY-MM-DD|--range 1m]", "\u626B\u63CF\u7528\u91CF\u660E\u7EC6"],
|
|
3497
3503
|
["report [--today] [--range 7d|1m|3m|all]", "\u672C\u5730\u7528\u91CF\u62A5\u544A"],
|
|
3498
|
-
["sync [--today] [--range 7d|1m|3m
|
|
3504
|
+
["sync [--today] [--range 7d|1m|3m]", "\u4E0A\u4F20\u7528\u91CF\u5230\u670D\u52A1\u7AEF"],
|
|
3499
3505
|
["project [list|alias]", "\u9879\u76EE\u7BA1\u7406\u4E0E\u522B\u540D\u8BBE\u7F6E"],
|
|
3500
3506
|
["schedule [on|off|status]", "\u5B9A\u65F6\u540C\u6B65\u7BA1\u7406"],
|
|
3501
3507
|
["doctor", "\u8BCA\u65AD\u68C0\u67E5"],
|
|
3502
3508
|
["config set <key> <value>", "\u4FEE\u6539\u914D\u7F6E"]
|
|
3503
3509
|
] : [
|
|
3504
|
-
["scan [--date YYYY-MM-DD]", "Scan
|
|
3510
|
+
["scan [--date YYYY-MM-DD|--range 1m]", "Scan usage breakdown"],
|
|
3505
3511
|
["report [--today] [--range 7d|1m|3m|all]", "Local usage report"],
|
|
3506
|
-
["sync [--today] [--range 7d|1m|3m
|
|
3512
|
+
["sync [--today] [--range 7d|1m|3m]", "Upload usage to server"],
|
|
3507
3513
|
["project [list|alias]", "Project management & aliases"],
|
|
3508
3514
|
["schedule [on|off|status]", "Scheduled sync management"],
|
|
3509
3515
|
["doctor", "Run diagnostics"],
|
|
@@ -3536,6 +3542,13 @@ function parseArgs(args) {
|
|
|
3536
3542
|
}
|
|
3537
3543
|
return { flags, positionals };
|
|
3538
3544
|
}
|
|
3545
|
+
function assertNoPositionals(command2, positionals, zh2 = !1) {
|
|
3546
|
+
if (positionals.length === 0) return;
|
|
3547
|
+
let value = positionals.join(" "), rangeHint = positionals.includes("range") || positionals.some((arg) => /^-\d+[dm]$/.test(arg));
|
|
3548
|
+
throw zh2 ? new Error(rangeHint ? `${command2} \u4E0D\u652F\u6301\u4F4D\u7F6E\u53C2\u6570: ${value}
|
|
3549
|
+
\u65F6\u95F4\u8303\u56F4\u8BF7\u4F7F\u7528 --range 1m\uFF0C\u4F8B\u5982: aiusage ${command2} --range 1m` : `${command2} \u4E0D\u652F\u6301\u4F4D\u7F6E\u53C2\u6570: ${value}`) : new Error(rangeHint ? `${command2} does not accept positional arguments: ${value}
|
|
3550
|
+
Use --range 1m, for example: aiusage ${command2} --range 1m` : `${command2} does not accept positional arguments: ${value}`);
|
|
3551
|
+
}
|
|
3539
3552
|
function localDateKey(d) {
|
|
3540
3553
|
return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}-${String(d.getDate()).padStart(2, "0")}`;
|
|
3541
3554
|
}
|
|
@@ -3545,6 +3558,8 @@ function getYesterdayDate() {
|
|
|
3545
3558
|
}
|
|
3546
3559
|
function resolveDateParams(flags, config) {
|
|
3547
3560
|
let requestedDate = typeof flags.date == "string" ? flags.date : void 0, fromDate = typeof flags.from == "string" ? flags.from : typeof flags.start == "string" ? flags.start : void 0, toDate = typeof flags.to == "string" ? flags.to : typeof flags.end == "string" ? flags.end : void 0;
|
|
3561
|
+
if (toDate && !fromDate)
|
|
3562
|
+
throw new Error("--to \u9700\u8981\u642D\u914D --from \u4F7F\u7528");
|
|
3548
3563
|
if (requestedDate)
|
|
3549
3564
|
return { dates: [requestedDate], range: "today" };
|
|
3550
3565
|
if (fromDate)
|
|
@@ -3552,8 +3567,10 @@ function resolveDateParams(flags, config) {
|
|
|
3552
3567
|
if (flags.today === !0)
|
|
3553
3568
|
return { dates: [getTodayDate()], range: "today" };
|
|
3554
3569
|
let rangeFlag = flags.range;
|
|
3555
|
-
if (typeof rangeFlag == "string")
|
|
3556
|
-
|
|
3570
|
+
if (typeof rangeFlag == "string") {
|
|
3571
|
+
let range = parseReportRange(rangeFlag);
|
|
3572
|
+
return range === "today" ? { dates: [getTodayDate()], range } : range === "7d" ? { dates: [...getClosedDates(6), getTodayDate()], range } : range === "1m" ? { dates: [...getClosedDates(29), getTodayDate()], range } : range === "3m" ? { dates: [...getClosedDates(89), getTodayDate()], range } : { range };
|
|
3573
|
+
}
|
|
3557
3574
|
if (typeof flags.lookback == "string") {
|
|
3558
3575
|
let lookbackDays2 = parsePositiveInt2(flags.lookback, "--lookback"), dates2 = getClosedDates(lookbackDays2);
|
|
3559
3576
|
return dates2.push(getTodayDate()), { dates: dates2, range: "7d" };
|
|
@@ -3561,6 +3578,16 @@ function resolveDateParams(flags, config) {
|
|
|
3561
3578
|
let lookbackDays = defaultLookbackDays(config), dates = getClosedDates(lookbackDays);
|
|
3562
3579
|
return dates.push(getTodayDate()), { dates, range: "7d" };
|
|
3563
3580
|
}
|
|
3581
|
+
function resolveScanDates(flags, config) {
|
|
3582
|
+
if (!hasDateSelection(flags)) return [getYesterdayDate()];
|
|
3583
|
+
let { dates } = resolveDateParams(flags, config);
|
|
3584
|
+
if (!dates)
|
|
3585
|
+
throw new Error("scan --range all \u9700\u8981\u660E\u786E\u65E5\u671F\u8303\u56F4\uFF0C\u8BF7\u6539\u7528 --from YYYY-MM-DD --to YYYY-MM-DD");
|
|
3586
|
+
return dates;
|
|
3587
|
+
}
|
|
3588
|
+
function hasDateSelection(flags) {
|
|
3589
|
+
return typeof flags.date == "string" || flags.today === !0 || typeof flags.from == "string" || typeof flags.start == "string" || typeof flags.to == "string" || typeof flags.end == "string" || typeof flags.range == "string" || typeof flags.lookback == "string";
|
|
3590
|
+
}
|
|
3564
3591
|
function resolveGlobalLang(flags, config) {
|
|
3565
3592
|
let lang = (typeof flags.lang == "string" ? flags.lang : config.lang) || "en";
|
|
3566
3593
|
if (lang !== "en" && lang !== "zh") throw new Error("--lang only supports en or zh");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aiusage/cli",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.3",
|
|
4
4
|
"description": "Track and sync AI tool token usage across devices.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"private": false,
|
|
@@ -36,17 +36,17 @@
|
|
|
36
36
|
"engines": {
|
|
37
37
|
"node": ">=18"
|
|
38
38
|
},
|
|
39
|
-
"devDependencies": {
|
|
40
|
-
"@types/node": "^22",
|
|
41
|
-
"esbuild": "^0.27.4",
|
|
42
|
-
"typescript": "^5",
|
|
43
|
-
"vitest": "^4.1.2",
|
|
44
|
-
"@aiusage/shared": "1.0.0"
|
|
45
|
-
},
|
|
46
39
|
"scripts": {
|
|
47
40
|
"build": "rm -rf dist && node build.mjs",
|
|
48
41
|
"dev": "tsc --watch",
|
|
49
42
|
"lint": "tsc --noEmit",
|
|
50
43
|
"test": "vitest run"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@aiusage/shared": "workspace:*",
|
|
47
|
+
"@types/node": "^22",
|
|
48
|
+
"esbuild": "^0.27.4",
|
|
49
|
+
"typescript": "^5",
|
|
50
|
+
"vitest": "^4.1.2"
|
|
51
51
|
}
|
|
52
|
-
}
|
|
52
|
+
}
|