@aiusage/cli 1.5.1 → 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 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 a single day and print the breakdown.
83
+ Scan local usage and print detailed breakdowns.
70
84
 
71
85
  ```bash
72
- aiusage scan --date 2026-03-31
73
- aiusage scan --date 2026-03-31 --json
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 --date 2026-03-31
71
- aiusage scan --date 2026-03-31 --json
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
@@ -1637,6 +1637,8 @@ function getRangeLabel(range) {
1637
1637
  return "\u6700\u8FD1 90 \u5929";
1638
1638
  case "all":
1639
1639
  return "\u5168\u90E8\u5386\u53F2";
1640
+ case "today":
1641
+ return "\u4ECA\u5929";
1640
1642
  }
1641
1643
  }
1642
1644
  function buildPresetDates(range) {
@@ -1975,6 +1977,8 @@ var FAST_MULTIPLIER = 6, CLAUDE_PRICING = {
1975
1977
  "claude-haiku-3-5": { input: 0.8, cache_write_5m: 1, cache_write_1h: 1.6, cache_read: 0.08, output: 4 },
1976
1978
  "claude-haiku-3": { input: 0.25, cache_write_5m: 0.3, cache_write_1h: 0.5, cache_read: 0.03, output: 1.25 }
1977
1979
  }, OPENAI_PRICING = {
1980
+ "gpt-5.5-pro": { input: 30, cached_input: null, output: 180, estimated: !1 },
1981
+ "gpt-5.5": { input: 5, cached_input: 0.5, output: 30, estimated: !1 },
1978
1982
  "gpt-5.4-pro": { input: 30, cached_input: null, output: 180, estimated: !1 },
1979
1983
  "gpt-5.4": { input: 2.5, cached_input: 0.25, output: 15, estimated: !1 },
1980
1984
  "gpt-5.4-mini": { input: 0.75, cached_input: 0.075, output: 4.5, estimated: !1 },
@@ -2027,7 +2031,8 @@ var FAST_MULTIPLIER = 6, CLAUDE_PRICING = {
2027
2031
  "text-embedding-3-small": { input: 0.02, cached_input: null, output: 0, estimated: !1 },
2028
2032
  "text-embedding-3-large": { input: 0.13, cached_input: null, output: 0, estimated: !1 },
2029
2033
  "text-embedding-ada-002": { input: 0.1, cached_input: null, output: 0, estimated: !1 },
2030
- "codex-mini-latest": { input: 1.5, cached_input: 0.375, output: 6, estimated: !1 }
2034
+ "codex-mini-latest": { input: 1.5, cached_input: 0.375, output: 6, estimated: !1 },
2035
+ "codex-auto-review": { input: 2.5, cached_input: 0.25, output: 15, estimated: !0, estimatedFrom: "GPT-5.4" }
2031
2036
  }, GEMINI_PRICING = {
2032
2037
  "gemini-3-flash": { input: 0.1, cache_read: 0.025, output: 0.4 },
2033
2038
  "gemini-2.0-flash": { input: 0.1, cache_read: 0.025, output: 0.4 },
@@ -2063,7 +2068,7 @@ function calculateBreakdownCost(breakdown, warnings) {
2063
2068
  if (!resolved)
2064
2069
  return warnings.add(`Codex/OpenAI \u6A21\u578B ${breakdown.model} \u672A\u914D\u7F6E\u516C\u5F00\u5355\u4EF7\uFF0C\u5DF2\u8DF3\u8FC7\u6210\u672C\u4F30\u7B97\u3002`), 0;
2065
2070
  let pricing = OPENAI_PRICING[resolved.model];
2066
- return resolved.normalized ? warnings.add(`${breakdown.model} \u5DF2\u6309 ${resolved.model} \u7684\u516C\u5F00\u5355\u4EF7\u4F30\u7B97\u3002`) : pricing.estimated && warnings.add(`${breakdown.model} \u672A\u5728\u516C\u5F00\u4EF7\u76EE\u8868\u5355\u5217\uFF0C\u5F53\u524D\u6309 GPT-5 \u516C\u5F00\u5355\u4EF7\u4F30\u7B97\u3002`), breakdown.inputTokens / 1e6 * pricing.input + breakdown.cachedInputTokens / 1e6 * (pricing.cached_input ?? 0) + breakdown.outputTokens / 1e6 * pricing.output;
2071
+ return resolved.normalized ? warnings.add(`${breakdown.model} \u5DF2\u6309 ${resolved.model} \u7684\u516C\u5F00\u5355\u4EF7\u4F30\u7B97\u3002`) : pricing.estimated && warnings.add(`${breakdown.model} \u672A\u5728\u516C\u5F00\u4EF7\u76EE\u8868\u5355\u5217\uFF0C\u5F53\u524D\u6309 ${pricing.estimatedFrom ?? "GPT-5"} \u516C\u5F00\u5355\u4EF7\u4F30\u7B97\u3002`), breakdown.inputTokens / 1e6 * pricing.input + breakdown.cachedInputTokens / 1e6 * (pricing.cached_input ?? 0) + breakdown.outputTokens / 1e6 * pricing.output;
2067
2072
  }
2068
2073
  if (breakdown.provider === "google" && breakdown.product === "gemini-cli") {
2069
2074
  let resolved = resolveModel(breakdown.model, GEMINI_PRICING);
@@ -3101,11 +3106,11 @@ try {
3101
3106
  if (command === "--version" || command === "-v")
3102
3107
  console.log(getVersion());
3103
3108
  else if (command === "scan") {
3104
- let parsed = parseArgs(argv.slice(1)), date = typeof parsed.flags.date == "string" ? parsed.flags.date : getYesterdayDate();
3105
- await runScan(date, !!parsed.flags.json);
3109
+ let parsed = parseArgs(argv.slice(1));
3110
+ await runScan(parsed.flags, parsed.positionals);
3106
3111
  } else if (command === "report") {
3107
3112
  let parsed = parseArgs(argv.slice(1));
3108
- await runReport(parsed.flags);
3113
+ await runReport(parsed.flags, parsed.positionals);
3109
3114
  } else if (command === "health") {
3110
3115
  let parsed = parseArgs(argv.slice(1));
3111
3116
  await runHealth(parsed.flags);
@@ -3114,7 +3119,7 @@ try {
3114
3119
  await runEnroll(parsed.flags);
3115
3120
  } else if (command === "sync") {
3116
3121
  let parsed = parseArgs(argv.slice(1));
3117
- await runSync(parsed.flags);
3122
+ await runSync(parsed.flags, parsed.positionals);
3118
3123
  } else if (command === "init") {
3119
3124
  let parsed = parseArgs(argv.slice(1));
3120
3125
  await runInit(parsed.flags);
@@ -3167,15 +3172,30 @@ try {
3167
3172
  } catch (error) {
3168
3173
  console.error(error instanceof Error ? error.message : String(error)), process.exitCode = 1;
3169
3174
  }
3170
- async function runScan(date, isJson) {
3175
+ async function runScan(flags, positionals = []) {
3171
3176
  let config = await readConfig(), zh2 = config.lang === "zh";
3172
- isJson || console.log(`${zh2 ? "\u626B\u63CF\u65E5\u671F" : "Scan date"}: ${date}
3173
- `);
3174
- 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 });
3175
3179
  if (isJson) {
3176
- console.log(JSON.stringify(result, null, 2));
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);
3186
+ return;
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.");
3177
3193
  return;
3178
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) {
3179
3199
  if (result.breakdowns.length === 0) {
3180
3200
  console.log(zh2 ? "\u8BE5\u65E5\u65E0\u6570\u636E\u3002" : "No data for this date.");
3181
3201
  return;
@@ -3191,10 +3211,12 @@ async function runScan(date, isJson) {
3191
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)}`);
3192
3212
  console.log();
3193
3213
  }
3194
- 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();
3195
3215
  }
3196
- async function runReport(flags) {
3197
- let config = await readConfig(), { dates, range } = resolveDateParams(flags, config), report = await buildLocalReport(range, { projectAliases: config.projectAliases, dates });
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 });
3198
3220
  if (flags.json) {
3199
3221
  console.log(JSON.stringify(report, null, 2));
3200
3222
  return;
@@ -3245,11 +3267,15 @@ function prompt(question) {
3245
3267
  });
3246
3268
  });
3247
3269
  }
3248
- async function runSync(flags) {
3249
- let config = await readConfig(), allTargets = config.targets ?? [];
3270
+ async function runSync(flags, positionals = []) {
3271
+ let config = await readConfig();
3272
+ assertNoPositionals("sync", positionals, config.lang === "zh");
3273
+ let allTargets = config.targets ?? [];
3250
3274
  if (allTargets.length === 0)
3251
3275
  throw new Error("\u672A\u914D\u7F6E\u4EFB\u4F55\u4E0A\u62A5\u76EE\u6807\uFF0C\u8BF7\u5148\u6267\u884C aiusage enroll");
3252
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);
3277
+ if (!targetDates)
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");
3253
3279
  console.log(`\u626B\u63CF ${targetDates.length} \u5929 (${targetDates[0]} ~ ${targetDates[targetDates.length - 1]}) ...`);
3254
3280
  let allDays = (await scanDates(targetDates, { projectAliases: config.projectAliases })).filter((r) => r.breakdowns.length > 0).map((r) => ({ usageDate: r.usageDate, breakdowns: r.breakdowns }));
3255
3281
  if (allDays.length === 0) {
@@ -3440,10 +3466,10 @@ function printHelp(zh2 = !1) {
3440
3466
  console.log(`aiusage v${getVersion()}
3441
3467
  `);
3442
3468
  let cmds = zh2 ? [
3443
- ["scan [--date YYYY-MM-DD] [--json]", "\u626B\u63CF\u67D0\u65E5\u7528\u91CF\u660E\u7EC6"],
3469
+ ["scan [--date YYYY-MM-DD|--today|--range 7d|1m|3m] [--json]", "\u626B\u63CF\u7528\u91CF\u660E\u7EC6"],
3444
3470
  ["report [--today] [--range 7d|1m|3m|all] [--detail] [--json]", "\u672C\u5730\u7528\u91CF\u62A5\u544A"],
3445
- ["sync [--today] [--range 7d|1m|3m|all]", "\u4E0A\u4F20\u7528\u91CF\u5230\u670D\u52A1\u7AEF"],
3446
- ["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"],
3447
3473
  ["project [list|alias]", "\u9879\u76EE\u7BA1\u7406\u4E0E\u522B\u540D\u8BBE\u7F6E"],
3448
3474
  ["schedule [on|off|status] [--every 5m]", "\u5B9A\u65F6\u540C\u6B65\u7BA1\u7406"],
3449
3475
  ["doctor", "\u8BCA\u65AD\u68C0\u67E5"],
@@ -3452,10 +3478,10 @@ function printHelp(zh2 = !1) {
3452
3478
  ["enroll --server URL --site-id ID --enroll-token TOKEN", "\u6CE8\u518C\u8BBE\u5907\u5230\u670D\u52A1\u7AEF"],
3453
3479
  ["health [--server URL]", "\u6D4B\u8BD5\u670D\u52A1\u7AEF\u8FDE\u901A\u6027"]
3454
3480
  ] : [
3455
- ["scan [--date YYYY-MM-DD] [--json]", "Scan daily usage breakdown"],
3481
+ ["scan [--date YYYY-MM-DD|--today|--range 7d|1m|3m] [--json]", "Scan usage breakdown"],
3456
3482
  ["report [--today] [--range 7d|1m|3m|all] [--detail] [--json]", "Local usage report"],
3457
- ["sync [--today] [--range 7d|1m|3m|all]", "Upload usage to server"],
3458
- ["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)"],
3459
3485
  ["project [list|alias]", "Project management & aliases"],
3460
3486
  ["schedule [on|off|status] [--every 5m]", "Scheduled sync management"],
3461
3487
  ["doctor", "Run diagnostics"],
@@ -3473,17 +3499,17 @@ function printUsageHint(zh2 = !1) {
3473
3499
  console.log(`aiusage v${getVersion()}
3474
3500
  `);
3475
3501
  let cmds = zh2 ? [
3476
- ["scan [--date YYYY-MM-DD]", "\u626B\u63CF\u67D0\u65E5\u7528\u91CF\u660E\u7EC6"],
3502
+ ["scan [--date YYYY-MM-DD|--range 1m]", "\u626B\u63CF\u7528\u91CF\u660E\u7EC6"],
3477
3503
  ["report [--today] [--range 7d|1m|3m|all]", "\u672C\u5730\u7528\u91CF\u62A5\u544A"],
3478
- ["sync [--today] [--range 7d|1m|3m|all]", "\u4E0A\u4F20\u7528\u91CF\u5230\u670D\u52A1\u7AEF"],
3504
+ ["sync [--today] [--range 7d|1m|3m]", "\u4E0A\u4F20\u7528\u91CF\u5230\u670D\u52A1\u7AEF"],
3479
3505
  ["project [list|alias]", "\u9879\u76EE\u7BA1\u7406\u4E0E\u522B\u540D\u8BBE\u7F6E"],
3480
3506
  ["schedule [on|off|status]", "\u5B9A\u65F6\u540C\u6B65\u7BA1\u7406"],
3481
3507
  ["doctor", "\u8BCA\u65AD\u68C0\u67E5"],
3482
3508
  ["config set <key> <value>", "\u4FEE\u6539\u914D\u7F6E"]
3483
3509
  ] : [
3484
- ["scan [--date YYYY-MM-DD]", "Scan daily usage breakdown"],
3510
+ ["scan [--date YYYY-MM-DD|--range 1m]", "Scan usage breakdown"],
3485
3511
  ["report [--today] [--range 7d|1m|3m|all]", "Local usage report"],
3486
- ["sync [--today] [--range 7d|1m|3m|all]", "Upload usage to server"],
3512
+ ["sync [--today] [--range 7d|1m|3m]", "Upload usage to server"],
3487
3513
  ["project [list|alias]", "Project management & aliases"],
3488
3514
  ["schedule [on|off|status]", "Scheduled sync management"],
3489
3515
  ["doctor", "Run diagnostics"],
@@ -3516,6 +3542,13 @@ function parseArgs(args) {
3516
3542
  }
3517
3543
  return { flags, positionals };
3518
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
+ }
3519
3552
  function localDateKey(d) {
3520
3553
  return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}-${String(d.getDate()).padStart(2, "0")}`;
3521
3554
  }
@@ -3525,6 +3558,8 @@ function getYesterdayDate() {
3525
3558
  }
3526
3559
  function resolveDateParams(flags, config) {
3527
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");
3528
3563
  if (requestedDate)
3529
3564
  return { dates: [requestedDate], range: "today" };
3530
3565
  if (fromDate)
@@ -3532,8 +3567,10 @@ function resolveDateParams(flags, config) {
3532
3567
  if (flags.today === !0)
3533
3568
  return { dates: [getTodayDate()], range: "today" };
3534
3569
  let rangeFlag = flags.range;
3535
- if (typeof rangeFlag == "string")
3536
- return { range: parseReportRange(rangeFlag) };
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
+ }
3537
3574
  if (typeof flags.lookback == "string") {
3538
3575
  let lookbackDays2 = parsePositiveInt2(flags.lookback, "--lookback"), dates2 = getClosedDates(lookbackDays2);
3539
3576
  return dates2.push(getTodayDate()), { dates: dates2, range: "7d" };
@@ -3541,6 +3578,16 @@ function resolveDateParams(flags, config) {
3541
3578
  let lookbackDays = defaultLookbackDays(config), dates = getClosedDates(lookbackDays);
3542
3579
  return dates.push(getTodayDate()), { dates, range: "7d" };
3543
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
+ }
3544
3591
  function resolveGlobalLang(flags, config) {
3545
3592
  let lang = (typeof flags.lang == "string" ? flags.lang : config.lang) || "en";
3546
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.1",
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,