@aiusage/cli 1.7.0 → 1.7.1

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.
Files changed (2) hide show
  1. package/dist/cli.js +58 -8
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -3134,9 +3134,10 @@ async function buildActivityReport(range, options = {}) {
3134
3134
  return {
3135
3135
  usageDate,
3136
3136
  exactCount: sumByConfidence(dayItems, "exact"),
3137
- proxyCount: sumByConfidence(dayItems, "proxy")
3137
+ proxyCount: sumByConfidence(dayItems, "proxy"),
3138
+ userMessageCount: sumUserMessages(dayItems)
3138
3139
  };
3139
- }).filter((day) => requestedDates || day.exactCount > 0 || day.proxyCount > 0);
3140
+ }).filter((day) => requestedDates || day.exactCount > 0 || day.proxyCount > 0 || day.userMessageCount > 0);
3140
3141
  return {
3141
3142
  range,
3142
3143
  rangeLabel: getRangeLabel3(range),
@@ -3176,7 +3177,7 @@ async function buildActivityReport(range, options = {}) {
3176
3177
  notes: [
3177
3178
  "Claude Code \u7684 Skill/Agent \u6765\u81EA\u7ED3\u6784\u5316 tool_use\uFF0C\u53E3\u5F84\u4E3A exact\u3002",
3178
3179
  "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",
3179
- "\u8BE5\u62A5\u544A\u53EA\u8BFB\u53D6\u672C\u5730 Session\uFF0C\u4E0D\u53C2\u4E0E sync\uFF0C\u4E5F\u4E0D\u6539\u53D8\u670D\u52A1\u7AEF schema\u3002"
3180
+ "sync \u4F1A\u4E0A\u4F20\u6309\u65E5\u805A\u5408\u540E\u7684 activity \u6307\u6807\uFF0C\u4E0D\u4E0A\u4F20\u539F\u59CB\u6D88\u606F\u5185\u5BB9\u3002"
3180
3181
  ]
3181
3182
  };
3182
3183
  }
@@ -3209,7 +3210,7 @@ function renderActivityReport(report, opts) {
3209
3210
  if (opts.detail && report.daily.length > 0) {
3210
3211
  lines.push(""), lines.push("\u6BCF\u65E5");
3211
3212
  for (let day of report.daily)
3212
- lines.push(` ${day.usageDate}: exact ${fmt(day.exactCount)} / proxy ${fmt(day.proxyCount)}`);
3213
+ lines.push(` ${day.usageDate}: exact ${fmt(day.exactCount)} / proxy ${fmt(day.proxyCount)} / user ${fmt(day.userMessageCount)}`);
3213
3214
  }
3214
3215
  if (opts.detail) {
3215
3216
  lines.push(""), lines.push("\u53E3\u5F84");
@@ -3277,6 +3278,8 @@ function handleCodexResponseItem(item, usageDate, projectFields, sessionId, file
3277
3278
  item.role === "user" && hasCodexUserMessageContent(item.content) && addUserMessage(acc, {
3278
3279
  provider: "openai",
3279
3280
  product: "codex",
3281
+ usageDate,
3282
+ projectFields,
3280
3283
  sessionId,
3281
3284
  timestamp,
3282
3285
  content: extractCodexMessageText(item.content),
@@ -3343,6 +3346,8 @@ function handleCodexEvent(record, usageDate, projectFields, sessionId, filePath,
3343
3346
  addUserMessage(acc, {
3344
3347
  provider: "openai",
3345
3348
  product: "codex",
3349
+ usageDate,
3350
+ projectFields,
3346
3351
  sessionId,
3347
3352
  timestamp: record.timestamp ?? "",
3348
3353
  content: stringValue(record.payload?.message),
@@ -3417,6 +3422,8 @@ async function processClaudeFile(filePath, fallbackFields, acc) {
3417
3422
  isClaudeUserMessage(record) && addUserMessage(acc, {
3418
3423
  provider: "anthropic",
3419
3424
  product: "claude-code",
3425
+ usageDate,
3426
+ projectFields,
3420
3427
  sessionId,
3421
3428
  timestamp: record.timestamp ?? "",
3422
3429
  content: extractClaudeMessageText(record.message?.content),
@@ -3494,7 +3501,17 @@ function addActivity(acc, input) {
3494
3501
  }
3495
3502
  function addUserMessage(acc, input) {
3496
3503
  let source = `${input.provider}/${input.product}`, normalized = normalizeMessageText(input.content), key = input.id ? `${source}:user_message:${input.id}` : normalized ? `${source}:user_message:${input.sessionId}:${input.timestamp}:${normalized}` : `${source}:user_message:${input.fallbackKey}`;
3497
- acc.stats.userMessages.add(key);
3504
+ acc.stats.userMessages.has(key) || (acc.stats.userMessages.add(key), addActivity(acc, {
3505
+ usageDate: input.usageDate,
3506
+ provider: input.provider,
3507
+ product: input.product,
3508
+ projectFields: input.projectFields,
3509
+ sessionId: input.sessionId,
3510
+ kind: "user_message",
3511
+ name: "user_message",
3512
+ confidence: "exact",
3513
+ dedupeKey: `activity:${key}`
3514
+ }));
3498
3515
  }
3499
3516
  function acceptsDate(acc, usageDate) {
3500
3517
  return !acc.targetDates || acc.targetDates.has(usageDate);
@@ -3610,13 +3627,18 @@ function summarize(items, keyFn, labelFn, limit) {
3610
3627
  return limit ? rows.slice(0, limit) : rows;
3611
3628
  }
3612
3629
  function sumByConfidence(items, confidence) {
3613
- return items.reduce((sum, item) => sum + (item.confidence === confidence ? item.count : 0), 0);
3630
+ return items.reduce((sum, item) => sum + (item.kind !== "user_message" && item.confidence === confidence ? item.count : 0), 0);
3631
+ }
3632
+ function sumUserMessages(items) {
3633
+ return items.reduce((sum, item) => sum + (item.kind === "user_message" ? item.count : 0), 0);
3614
3634
  }
3615
3635
  function isToolLikeKind(kind) {
3616
3636
  return kind === "function_call" || kind === "custom_tool_call" || kind === "tool_call" || kind === "web_search" || kind === "tool_search" || kind === "image_generation" || kind === "mcp_tool_call";
3617
3637
  }
3618
3638
  function labelKind(kind) {
3619
3639
  switch (kind) {
3640
+ case "user_message":
3641
+ return "User Message";
3620
3642
  case "function_call":
3621
3643
  return "Function Call";
3622
3644
  case "custom_tool_call":
@@ -4502,8 +4524,11 @@ function getClaudeDirs() {
4502
4524
  import { createHash } from "node:crypto";
4503
4525
  var DEFAULT_VISIBILITY = "masked";
4504
4526
  function applyPrivacy(breakdowns, visibility) {
4527
+ return applyProjectPrivacy(breakdowns, visibility);
4528
+ }
4529
+ function applyProjectPrivacy(items, visibility) {
4505
4530
  let mode = visibility ?? DEFAULT_VISIBILITY;
4506
- return breakdowns.map((b) => transformOne(b, mode));
4531
+ return items.map((item) => transformOne(item, mode));
4507
4532
  }
4508
4533
  function transformOne(b, mode) {
4509
4534
  let original = b.project ?? "", display = b.projectDisplay ?? deriveBasename(original);
@@ -4862,7 +4887,13 @@ async function runSync(flags, positionals = []) {
4862
4887
  if (!targetDates)
4863
4888
  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");
4864
4889
  console.log(`\u626B\u63CF ${targetDates.length} \u5929 (${targetDates[0]} ~ ${targetDates[targetDates.length - 1]}) ...`);
4865
- let results = await scanDates(targetDates, { projectAliases: config.projectAliases }), visibility = config.privacy?.projectVisibility, allDays = results.filter((r) => r.breakdowns.length > 0).map((r) => ({ usageDate: r.usageDate, breakdowns: applyPrivacy(r.breakdowns, visibility) }));
4890
+ let [results, activityReport] = await Promise.all([
4891
+ scanDates(targetDates, { projectAliases: config.projectAliases }),
4892
+ buildActivityReport("all", { dates: targetDates, projectAliases: config.projectAliases })
4893
+ ]), visibility = config.privacy?.projectVisibility, resultsByDate = new Map(results.map((result) => [result.usageDate, result])), activityByDate = buildActivityPayloadByDate(activityReport.items, visibility), allDays = targetDates.map((usageDate) => {
4894
+ let breakdowns = applyPrivacy(resultsByDate.get(usageDate)?.breakdowns ?? [], visibility), activity = activityByDate.get(usageDate);
4895
+ return { usageDate, breakdowns, activity };
4896
+ }).filter((day) => day.breakdowns.length > 0 || (day.activity?.items.length ?? 0) > 0);
4866
4897
  if (allDays.length === 0) {
4867
4898
  console.log("\u6CA1\u6709\u53EF\u4E0A\u4F20\u7684\u6570\u636E\u3002");
4868
4899
  return;
@@ -4897,6 +4928,25 @@ async function runSync(flags, positionals = []) {
4897
4928
  results: uploadResults
4898
4929
  }, null, 2));
4899
4930
  }
4931
+ function buildActivityPayloadByDate(items, visibility) {
4932
+ let map = /* @__PURE__ */ new Map(), sanitized = applyProjectPrivacy(items, visibility);
4933
+ for (let item of sanitized) {
4934
+ let day = map.get(item.usageDate) ?? { items: [] };
4935
+ day.items.push({
4936
+ provider: item.provider,
4937
+ product: item.product,
4938
+ source: item.source,
4939
+ project: item.project,
4940
+ projectDisplay: item.projectDisplay,
4941
+ projectAlias: item.projectAlias,
4942
+ kind: item.kind,
4943
+ name: item.name,
4944
+ count: item.count,
4945
+ confidence: item.confidence
4946
+ }), map.set(item.usageDate, day);
4947
+ }
4948
+ return map;
4949
+ }
4900
4950
  async function runImport(flags, positionals = []) {
4901
4951
  let config = await readConfig(), targetName = resolveOptionalString(flags.target, void 0), allTargets = config.targets ?? [];
4902
4952
  if (allTargets.length === 0) throw new Error("\u672A\u914D\u7F6E\u4EFB\u4F55\u4E0A\u62A5\u76EE\u6807\uFF0C\u8BF7\u5148\u6267\u884C aiusage enroll");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiusage/cli",
3
- "version": "1.7.0",
3
+ "version": "1.7.1",
4
4
  "description": "Track and sync AI tool token usage across devices.",
5
5
  "license": "MIT",
6
6
  "private": false,