@aiusage/cli 0.4.2 → 0.4.4
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 +107 -21
- 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 {
|
|
@@ -1826,7 +1887,7 @@ function escapeXml(value) {
|
|
|
1826
1887
|
}
|
|
1827
1888
|
|
|
1828
1889
|
// src/doctor.ts
|
|
1829
|
-
import { stat as stat2 } from "node:fs/promises";
|
|
1890
|
+
import { readdir as readdir6, stat as stat2 } from "node:fs/promises";
|
|
1830
1891
|
import { homedir as homedir14 } from "node:os";
|
|
1831
1892
|
import { join as join14 } from "node:path";
|
|
1832
1893
|
var msgs = {
|
|
@@ -1837,12 +1898,14 @@ var msgs = {
|
|
|
1837
1898
|
deviceIdMissing: "Not configured, run aiusage init",
|
|
1838
1899
|
targetMissing: "Not configured, run aiusage enroll",
|
|
1839
1900
|
targets: "Targets",
|
|
1840
|
-
deviceToken: "Device
|
|
1901
|
+
deviceToken: "Device",
|
|
1841
1902
|
tokenMissing: "Not registered",
|
|
1842
1903
|
server: "Server",
|
|
1843
1904
|
lastSync: "Last sync",
|
|
1844
1905
|
lastSyncNone: "No record",
|
|
1845
|
-
|
|
1906
|
+
notInstalled: "Not installed",
|
|
1907
|
+
installedNoData: "Installed, no usage data yet",
|
|
1908
|
+
hasData: (n) => `${n} session${n > 1 ? "s" : ""} found`,
|
|
1846
1909
|
schedule: "Schedule",
|
|
1847
1910
|
scheduleEvery: "every",
|
|
1848
1911
|
scheduleEnabled: "Enabled",
|
|
@@ -1855,18 +1918,37 @@ var msgs = {
|
|
|
1855
1918
|
deviceIdMissing: "\u672A\u914D\u7F6E\uFF0C\u8BF7\u6267\u884C aiusage init",
|
|
1856
1919
|
targetMissing: "\u672A\u914D\u7F6E\uFF0C\u8BF7\u6267\u884C aiusage enroll",
|
|
1857
1920
|
targets: "\u4E0A\u62A5\u76EE\u6807",
|
|
1858
|
-
deviceToken: "\
|
|
1921
|
+
deviceToken: "\u6CE8\u518C\u4EE4\u724C",
|
|
1859
1922
|
tokenMissing: "\u672A\u6CE8\u518C",
|
|
1860
1923
|
server: "\u670D\u52A1\u7AEF",
|
|
1861
1924
|
lastSync: "\u4E0A\u6B21\u540C\u6B65",
|
|
1862
1925
|
lastSyncNone: "\u6682\u65E0\u8BB0\u5F55",
|
|
1863
|
-
|
|
1926
|
+
notInstalled: "\u672A\u5B89\u88C5",
|
|
1927
|
+
installedNoData: "\u5DF2\u5B89\u88C5\uFF0C\u6682\u65E0\u4F7F\u7528\u6570\u636E",
|
|
1928
|
+
hasData: (n) => `\u53D1\u73B0 ${n} \u4E2A\u4F1A\u8BDD`,
|
|
1864
1929
|
schedule: "\u5B9A\u65F6\u540C\u6B65",
|
|
1865
1930
|
scheduleEvery: "\u6BCF",
|
|
1866
1931
|
scheduleEnabled: "\u5DF2\u542F\u7528",
|
|
1867
1932
|
scheduleOff: "\u672A\u542F\u7528\uFF0C\u53EF\u6267\u884C aiusage schedule on"
|
|
1868
1933
|
}
|
|
1869
1934
|
};
|
|
1935
|
+
async function countFiles(dir, exts, cap = 1e3) {
|
|
1936
|
+
let count = 0, queue = [dir];
|
|
1937
|
+
for (; queue.length > 0 && count < cap; ) {
|
|
1938
|
+
let current = queue.pop(), entries;
|
|
1939
|
+
try {
|
|
1940
|
+
entries = await readdir6(current, { withFileTypes: !0 });
|
|
1941
|
+
} catch {
|
|
1942
|
+
continue;
|
|
1943
|
+
}
|
|
1944
|
+
for (let e of entries) {
|
|
1945
|
+
if (count >= cap) break;
|
|
1946
|
+
let full = join14(current, e.name);
|
|
1947
|
+
e.isDirectory() ? queue.push(full) : exts.some((ext) => e.name.endsWith(ext)) && count++;
|
|
1948
|
+
}
|
|
1949
|
+
}
|
|
1950
|
+
return count;
|
|
1951
|
+
}
|
|
1870
1952
|
async function runDoctor(lang = "zh") {
|
|
1871
1953
|
let s = msgs[lang], checks = [], config = await readConfig(), configPath = getConfigPath();
|
|
1872
1954
|
try {
|
|
@@ -1890,24 +1972,28 @@ async function runDoctor(lang = "zh") {
|
|
|
1890
1972
|
}
|
|
1891
1973
|
target.lastSuccessfulUploadAt ? checks.push({ name: `${prefix} ${s.lastSync}`, status: "ok", message: target.lastSuccessfulUploadAt }) : checks.push({ name: `${prefix} ${s.lastSync}`, status: "warn", message: s.lastSyncNone });
|
|
1892
1974
|
}
|
|
1893
|
-
let home = homedir14(),
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1975
|
+
let home = homedir14(), tools = [
|
|
1976
|
+
{ dir: join14(home, ".claude", "projects"), label: "Claude Code", exts: [".jsonl"] },
|
|
1977
|
+
{ dir: join14(home, ".codex"), label: "Codex CLI", exts: [".jsonl"] },
|
|
1978
|
+
{ dir: join14(home, ".copilot", "session-state"), label: "Copilot CLI", exts: [".jsonl"] },
|
|
1979
|
+
{ dir: join14(home, ".gemini", "tmp"), label: "Gemini CLI", exts: [".json"] },
|
|
1980
|
+
{ dir: join14(home, ".qwen", "tmp"), label: "Qwen Code", exts: [".jsonl"] },
|
|
1981
|
+
{ dir: join14(home, ".kimi", "sessions"), label: "Kimi Code", exts: [".jsonl"] },
|
|
1982
|
+
{ dir: join14(home, ".local", "share", "amp", "threads"), label: "Amp", exts: [".json"] },
|
|
1983
|
+
{ dir: join14(home, ".factory", "sessions"), label: "Droid", exts: [".jsonl", ".json"] },
|
|
1984
|
+
{ dir: join14(home, ".local", "share", "opencode"), label: "OpenCode", exts: [".json"] },
|
|
1985
|
+
{ dir: join14(home, ".pi", "agent", "sessions"), label: "Pi", exts: [".jsonl"] }
|
|
1904
1986
|
];
|
|
1905
|
-
for (let
|
|
1987
|
+
for (let tool of tools) {
|
|
1906
1988
|
try {
|
|
1907
|
-
await stat2(
|
|
1989
|
+
await stat2(tool.dir);
|
|
1908
1990
|
} catch {
|
|
1909
|
-
checks.push({ name: label, status: "warn", message: s.
|
|
1991
|
+
checks.push({ name: tool.label, status: "warn", message: s.notInstalled });
|
|
1992
|
+
continue;
|
|
1910
1993
|
}
|
|
1994
|
+
let n = await countFiles(tool.dir, tool.exts);
|
|
1995
|
+
n > 0 ? checks.push({ name: tool.label, status: "ok", message: s.hasData(n) }) : checks.push({ name: tool.label, status: "warn", message: s.installedNoData });
|
|
1996
|
+
}
|
|
1911
1997
|
let schedule = await getScheduleStatus();
|
|
1912
1998
|
return schedule.enabled ? checks.push({
|
|
1913
1999
|
name: s.schedule,
|