@aiusage/cli 0.4.3 → 0.4.5

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 +92 -21
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -946,13 +946,74 @@ function buildPresetDates(range) {
946
946
  return result;
947
947
  }
948
948
  async function discoverAllDates() {
949
- let dates = /* @__PURE__ */ new Set();
949
+ let dates = /* @__PURE__ */ new Set(), home = homedir11();
950
950
  return await Promise.all([
951
951
  discoverClaudeDates(dates),
952
952
  discoverCodexDates(dates),
953
- discoverGeminiDates(dates)
953
+ discoverGeminiDates(dates),
954
+ discoverGenericJsonlDates(join11(home, ".copilot", "session-state"), dates),
955
+ discoverGenericJsonlDates(join11(home, ".qwen", "tmp"), dates),
956
+ discoverGenericJsonlDates(join11(home, ".kimi", "sessions"), dates),
957
+ discoverGenericJsonDates(join11(home, ".local", "share", "amp", "threads"), dates),
958
+ discoverGenericJsonlDates(join11(home, ".factory", "sessions"), dates),
959
+ discoverGenericJsonDates(join11(home, ".local", "share", "opencode"), dates),
960
+ discoverGenericJsonlDates(join11(home, ".pi", "agent", "sessions"), dates)
954
961
  ]), [...dates].sort();
955
962
  }
963
+ async function discoverGenericJsonlDates(baseDir, dates) {
964
+ let files = [];
965
+ await walkForFiles(baseDir, ".jsonl", files);
966
+ for (let filePath of files) {
967
+ let content = await safeReadUtf8(filePath);
968
+ if (content)
969
+ for (let line of content.split(`
970
+ `)) {
971
+ if (!line.trim()) continue;
972
+ let record;
973
+ try {
974
+ record = JSON.parse(line);
975
+ } catch {
976
+ continue;
977
+ }
978
+ let ts = parseTimestamp3(record.timestamp);
979
+ ts && dates.add(toDateKey3(ts));
980
+ }
981
+ }
982
+ }
983
+ async function discoverGenericJsonDates(baseDir, dates) {
984
+ let files = [];
985
+ await walkForFiles(baseDir, ".json", files);
986
+ for (let filePath of files) {
987
+ let content = await safeReadUtf8(filePath);
988
+ if (!content) continue;
989
+ let data;
990
+ try {
991
+ data = JSON.parse(content);
992
+ } catch {
993
+ continue;
994
+ }
995
+ let topTs = parseTimestamp3(data.timestamp ?? data.createTime);
996
+ topTs && dates.add(toDateKey3(topTs));
997
+ let msgs2 = data.messages ?? data.history ?? [];
998
+ if (Array.isArray(msgs2))
999
+ for (let msg of msgs2) {
1000
+ let ts = parseTimestamp3(msg.timestamp ?? msg.createTime);
1001
+ ts && dates.add(toDateKey3(ts));
1002
+ }
1003
+ }
1004
+ }
1005
+ async function walkForFiles(dir, ext, result) {
1006
+ let entries;
1007
+ try {
1008
+ entries = await readdir5(dir, { withFileTypes: !0 });
1009
+ } catch {
1010
+ return;
1011
+ }
1012
+ for (let entry of entries) {
1013
+ let fullPath = join11(dir, entry.name);
1014
+ entry.isDirectory() ? await walkForFiles(fullPath, ext, result) : entry.name.endsWith(ext) && result.push(fullPath);
1015
+ }
1016
+ }
956
1017
  async function discoverGeminiDates(dates) {
957
1018
  let baseDir = join11(homedir11(), ".gemini", "tmp"), files = [];
958
1019
  try {
@@ -1831,13 +1892,17 @@ import { homedir as homedir14 } from "node:os";
1831
1892
  import { join as join14 } from "node:path";
1832
1893
  var msgs = {
1833
1894
  en: {
1895
+ groupConfig: "Configuration",
1896
+ groupSync: "Sync Targets",
1897
+ groupTools: "Tools",
1898
+ groupSchedule: "Schedule",
1834
1899
  config: "Config",
1835
1900
  configMissing: "Not found, run aiusage init first",
1836
1901
  deviceId: "Device ID",
1837
1902
  deviceIdMissing: "Not configured, run aiusage init",
1838
1903
  targetMissing: "Not configured, run aiusage enroll",
1839
1904
  targets: "Targets",
1840
- deviceToken: "Device token",
1905
+ deviceToken: "Device",
1841
1906
  tokenMissing: "Not registered",
1842
1907
  server: "Server",
1843
1908
  lastSync: "Last sync",
@@ -1851,13 +1916,17 @@ var msgs = {
1851
1916
  scheduleOff: "Not enabled, run aiusage schedule on"
1852
1917
  },
1853
1918
  zh: {
1919
+ groupConfig: "\u57FA\u672C\u914D\u7F6E",
1920
+ groupSync: "\u540C\u6B65\u76EE\u6807",
1921
+ groupTools: "\u5DE5\u5177\u68C0\u6D4B",
1922
+ groupSchedule: "\u5B9A\u65F6\u4EFB\u52A1",
1854
1923
  config: "\u914D\u7F6E\u6587\u4EF6",
1855
1924
  configMissing: "\u672A\u627E\u5230\uFF0C\u8BF7\u5148\u6267\u884C aiusage init",
1856
1925
  deviceId: "\u8BBE\u5907 ID",
1857
1926
  deviceIdMissing: "\u672A\u914D\u7F6E\uFF0C\u8BF7\u6267\u884C aiusage init",
1858
1927
  targetMissing: "\u672A\u914D\u7F6E\uFF0C\u8BF7\u6267\u884C aiusage enroll",
1859
1928
  targets: "\u4E0A\u62A5\u76EE\u6807",
1860
- deviceToken: "\u8BBE\u5907\u4EE4\u724C",
1929
+ deviceToken: "\u6CE8\u518C\u4EE4\u724C",
1861
1930
  tokenMissing: "\u672A\u6CE8\u518C",
1862
1931
  server: "\u670D\u52A1\u7AEF",
1863
1932
  lastSync: "\u4E0A\u6B21\u540C\u6B65",
@@ -1889,29 +1958,29 @@ async function countFiles(dir, exts, cap = 1e3) {
1889
1958
  return count;
1890
1959
  }
1891
1960
  async function runDoctor(lang = "zh") {
1892
- let s = msgs[lang], checks = [], config = await readConfig(), configPath = getConfigPath();
1961
+ let s = msgs[lang], checks = [], config = await readConfig(), g1 = s.groupConfig, configPath = getConfigPath();
1893
1962
  try {
1894
- await stat2(configPath), checks.push({ name: s.config, status: "ok", message: configPath });
1963
+ await stat2(configPath), checks.push({ group: g1, name: s.config, status: "ok", message: configPath });
1895
1964
  } catch {
1896
- checks.push({ name: s.config, status: "fail", message: s.configMissing });
1965
+ checks.push({ group: g1, name: s.config, status: "fail", message: s.configMissing });
1897
1966
  }
1898
- config.deviceId ? checks.push({ name: s.deviceId, status: "ok", message: config.deviceId }) : checks.push({ name: s.deviceId, status: "warn", message: s.deviceIdMissing });
1899
- let targets = config.targets ?? [];
1967
+ config.deviceId ? checks.push({ group: g1, name: s.deviceId, status: "ok", message: config.deviceId }) : checks.push({ group: g1, name: s.deviceId, status: "warn", message: s.deviceIdMissing });
1968
+ let g2 = s.groupSync, targets = config.targets ?? [];
1900
1969
  if (targets.length === 0)
1901
- checks.push({ name: s.targets, status: "warn", message: s.targetMissing });
1970
+ checks.push({ group: g2, name: s.targets, status: "warn", message: s.targetMissing });
1902
1971
  else
1903
1972
  for (let target of targets) {
1904
1973
  let prefix = `[${target.name}]`;
1905
- target.deviceToken ? checks.push({ name: `${prefix} ${s.deviceToken}`, status: "ok", message: `${target.deviceToken.slice(0, 12)}\u2026` }) : checks.push({ name: `${prefix} ${s.deviceToken}`, status: "fail", message: s.tokenMissing });
1974
+ target.deviceToken ? checks.push({ group: g2, name: `${prefix} ${s.deviceToken}`, status: "ok", message: `${target.deviceToken.slice(0, 12)}\u2026` }) : checks.push({ group: g2, name: `${prefix} ${s.deviceToken}`, status: "fail", message: s.tokenMissing });
1906
1975
  try {
1907
1976
  let health = await fetchHealth(target.apiBaseUrl);
1908
- checks.push({ name: `${prefix} ${s.server}`, status: "ok", message: health.siteId });
1977
+ checks.push({ group: g2, name: `${prefix} ${s.server}`, status: "ok", message: health.siteId });
1909
1978
  } catch (err) {
1910
- checks.push({ name: `${prefix} ${s.server}`, status: "fail", message: err instanceof Error ? err.message : String(err) });
1979
+ checks.push({ group: g2, name: `${prefix} ${s.server}`, status: "fail", message: err instanceof Error ? err.message : String(err) });
1911
1980
  }
1912
- target.lastSuccessfulUploadAt ? checks.push({ name: `${prefix} ${s.lastSync}`, status: "ok", message: target.lastSuccessfulUploadAt }) : checks.push({ name: `${prefix} ${s.lastSync}`, status: "warn", message: s.lastSyncNone });
1981
+ target.lastSuccessfulUploadAt ? checks.push({ group: g2, name: `${prefix} ${s.lastSync}`, status: "ok", message: target.lastSuccessfulUploadAt }) : checks.push({ group: g2, name: `${prefix} ${s.lastSync}`, status: "warn", message: s.lastSyncNone });
1913
1982
  }
1914
- let home = homedir14(), tools = [
1983
+ let g3 = s.groupTools, home = homedir14(), tools = [
1915
1984
  { dir: join14(home, ".claude", "projects"), label: "Claude Code", exts: [".jsonl"] },
1916
1985
  { dir: join14(home, ".codex"), label: "Codex CLI", exts: [".jsonl"] },
1917
1986
  { dir: join14(home, ".copilot", "session-state"), label: "Copilot CLI", exts: [".jsonl"] },
@@ -1927,18 +1996,19 @@ async function runDoctor(lang = "zh") {
1927
1996
  try {
1928
1997
  await stat2(tool.dir);
1929
1998
  } catch {
1930
- checks.push({ name: tool.label, status: "warn", message: s.notInstalled });
1999
+ checks.push({ group: g3, name: tool.label, status: "warn", message: s.notInstalled });
1931
2000
  continue;
1932
2001
  }
1933
2002
  let n = await countFiles(tool.dir, tool.exts);
1934
- n > 0 ? checks.push({ name: tool.label, status: "ok", message: s.hasData(n) }) : checks.push({ name: tool.label, status: "warn", message: s.installedNoData });
2003
+ n > 0 ? checks.push({ group: g3, name: tool.label, status: "ok", message: s.hasData(n) }) : checks.push({ group: g3, name: tool.label, status: "warn", message: s.installedNoData });
1935
2004
  }
1936
- let schedule = await getScheduleStatus();
2005
+ let g4 = s.groupSchedule, schedule = await getScheduleStatus();
1937
2006
  return schedule.enabled ? checks.push({
2007
+ group: g4,
1938
2008
  name: s.schedule,
1939
2009
  status: "ok",
1940
2010
  message: schedule.intervalLabel ? `${s.scheduleEvery} ${schedule.intervalLabel}` : s.scheduleEnabled
1941
- }) : checks.push({ name: s.schedule, status: "warn", message: s.scheduleOff }), checks;
2011
+ }) : checks.push({ group: g4, name: s.schedule, status: "warn", message: s.scheduleOff }), checks;
1942
2012
  }
1943
2013
 
1944
2014
  // src/cli.ts
@@ -2122,10 +2192,11 @@ async function runSchedule(sub, flags) {
2122
2192
  }
2123
2193
  }
2124
2194
  async function runDoctorCommand(flags) {
2125
- let config = await readConfig(), lang = (typeof flags.lang == "string" ? flags.lang : config.lang) || "en", checks = await runDoctor(lang);
2195
+ let config = await readConfig(), lang = (typeof flags.lang == "string" ? flags.lang : config.lang) || "en", checks = await runDoctor(lang), lastGroup = "";
2126
2196
  for (let check of checks) {
2197
+ check.group !== lastGroup && (lastGroup && console.log(""), console.log(`\u2500\u2500 ${check.group} \u2500\u2500`), lastGroup = check.group);
2127
2198
  let icon = check.status === "ok" ? "\u2713" : check.status === "warn" ? "\u26A0" : "\u2717";
2128
- console.log(`${icon} ${check.name}: ${check.message}`);
2199
+ console.log(` ${icon} ${check.name}: ${check.message}`);
2129
2200
  }
2130
2201
  checks.filter((c) => c.status === "fail").length > 0 && (process.exitCode = 1);
2131
2202
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiusage/cli",
3
- "version": "0.4.3",
3
+ "version": "0.4.5",
4
4
  "description": "Track and sync AI tool token usage across devices.",
5
5
  "license": "MIT",
6
6
  "private": false,