tokenusage-cli 0.4.5 → 0.4.7
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/CHANGELOG.md +113 -115
- package/README.md +88 -21
- package/package.json +1 -1
- package/src/cli.js +2 -0
- package/src/commands/doctor.js +3 -0
- package/src/commands/init.js +20 -2
- package/src/commands/reconcile.js +5 -0
- package/src/commands/status.js +143 -1
- package/src/commands/sync.js +101 -28
- package/src/commands/upload.js +4 -0
- package/src/lib/account-usage-dedup.js +1 -1
- package/src/lib/cursor-config.js +113 -17
- package/src/lib/device-identity.js +84 -0
- package/src/lib/doctor.js +32 -2
- package/src/lib/pricing/index.js +1 -1
- package/src/lib/pricing-coverage.js +1 -1
- package/src/lib/progress.js +29 -0
- package/src/lib/qoder-limits.js +224 -54
- package/src/lib/rollout.js +29 -6
- package/src/lib/trae-cn-config.js +36 -14
|
@@ -43,6 +43,7 @@ const { sanitizeBucketForUpload } = require("../lib/ingest-sanitize");
|
|
|
43
43
|
const { basenameKey } = require("../lib/project-key");
|
|
44
44
|
const { TOKEN_COLUMNS } = require("../lib/account-usage-dedup");
|
|
45
45
|
const { UsageError, unknownOptionError } = require("../lib/cli-errors");
|
|
46
|
+
const { buildDeviceIdentity } = require("../lib/device-identity");
|
|
46
47
|
|
|
47
48
|
const RECONCILE_SLUG = "token-usage-reconcile";
|
|
48
49
|
const DAY_MS = 86_400_000;
|
|
@@ -440,6 +441,7 @@ function renderText(summary) {
|
|
|
440
441
|
pendingCount > 0
|
|
441
442
|
? ` ${pendingCount.toLocaleString("en-US")} of them are past the upload offset (queue.state.json) and not compared yet`
|
|
442
443
|
: null,
|
|
444
|
+
`Local device: ${summary.device_name || "unknown machine"}${summary.machine_id ? ` (machine ${summary.machine_id.slice(0, 8)})` : ""}`,
|
|
443
445
|
`Cloud device: ${summary.device_id || "unknown"} — ${summary.cloud_buckets.toLocaleString("en-US")} row(s) in ${summary.pages} page(s)`,
|
|
444
446
|
].filter(Boolean);
|
|
445
447
|
|
|
@@ -506,6 +508,7 @@ async function cmdReconcile(argv = [], options = {}) {
|
|
|
506
508
|
|
|
507
509
|
const config = (await readJson(path.join(trackerDir, "config.json"))) || {};
|
|
508
510
|
const runtime = assertInsforgeRuntime(resolveRuntimeConfig({ config, env: process.env }));
|
|
511
|
+
const deviceIdentity = buildDeviceIdentity({ config, hostname: os.hostname() });
|
|
509
512
|
if (!runtime.deviceToken) {
|
|
510
513
|
throw new UsageError("This machine is not paired with a dashboard yet.", {
|
|
511
514
|
code: "NO_DEVICE_TOKEN",
|
|
@@ -542,6 +545,8 @@ async function cmdReconcile(argv = [], options = {}) {
|
|
|
542
545
|
to,
|
|
543
546
|
clamped: window.clamped,
|
|
544
547
|
device_id: deviceId,
|
|
548
|
+
device_name: deviceIdentity.name,
|
|
549
|
+
machine_id: deviceIdentity.machine_id,
|
|
545
550
|
local_buckets: local.size,
|
|
546
551
|
cloud_buckets: server.size,
|
|
547
552
|
pages,
|
package/src/commands/status.js
CHANGED
|
@@ -35,6 +35,7 @@ const {
|
|
|
35
35
|
const { collectLocalSubscriptions } = require("../lib/subscriptions");
|
|
36
36
|
const {
|
|
37
37
|
describeCopilotOtelStatus,
|
|
38
|
+
getUsageLimits,
|
|
38
39
|
readCopilotOauthToken,
|
|
39
40
|
} = require("../lib/usage-limits");
|
|
40
41
|
const {
|
|
@@ -48,6 +49,8 @@ const {
|
|
|
48
49
|
} = require("../lib/openclaw-session-plugin");
|
|
49
50
|
const { resolveTrackerPaths } = require("../lib/tracker-paths");
|
|
50
51
|
const { resolveDeviceTokenPresence } = require("../lib/cloud-device-token");
|
|
52
|
+
const { resolveLocalDeviceIdentity } = require("../lib/device-identity");
|
|
53
|
+
const { formatDeviceLine } = require("../lib/progress");
|
|
51
54
|
const { getPricingMeta } = require("../lib/pricing");
|
|
52
55
|
const {
|
|
53
56
|
isCollectionPaused,
|
|
@@ -379,6 +382,19 @@ async function cmdStatus(argv = []) {
|
|
|
379
382
|
});
|
|
380
383
|
const subscriptionLines =
|
|
381
384
|
subscriptions.length > 0 ? subscriptions.map(formatSubscriptionLine) : [];
|
|
385
|
+
// Quota panel (opt-in, `--limits`): the aggregate reads local app credentials
|
|
386
|
+
// and provider APIs, so it stays off the default status path. The payload
|
|
387
|
+
// carries per-provider provenance, which is what makes a stale log snapshot
|
|
388
|
+
// distinguishable from a live reading.
|
|
389
|
+
const usageLimits = opts.limits
|
|
390
|
+
? await getUsageLimits({
|
|
391
|
+
home,
|
|
392
|
+
env: process.env,
|
|
393
|
+
platform: process.platform,
|
|
394
|
+
})
|
|
395
|
+
: null;
|
|
396
|
+
const usageLimitRows = formatUsageLimitRows(usageLimits);
|
|
397
|
+
const usageLimitLines = usageLimitRows.map(([label, value]) => `- ${label}: ${value}`);
|
|
382
398
|
|
|
383
399
|
const kimiWireFiles = resolveKimiWireFiles(process.env);
|
|
384
400
|
const kimiHome = process.env.KIMI_HOME || path.join(home, ".kimi");
|
|
@@ -1059,12 +1075,22 @@ async function cmdStatus(argv = []) {
|
|
|
1059
1075
|
config: config || {},
|
|
1060
1076
|
});
|
|
1061
1077
|
|
|
1078
|
+
// Which collector machine is this? Two machines report into one account, so
|
|
1079
|
+
// every status output has to name itself — see lib/device-identity.js.
|
|
1080
|
+
const deviceIdentity = resolveLocalDeviceIdentity({ config: config || {}, home });
|
|
1081
|
+
|
|
1062
1082
|
if (opts.json || opts.light) {
|
|
1063
1083
|
const summary = {
|
|
1064
1084
|
version: pkg.version,
|
|
1065
1085
|
generated_at: new Date().toISOString(),
|
|
1066
1086
|
base_url: config?.baseUrl || null,
|
|
1067
1087
|
device_token_set: deviceTokenPresence.set,
|
|
1088
|
+
device: {
|
|
1089
|
+
name: deviceIdentity.name,
|
|
1090
|
+
hostname: deviceIdentity.hostname,
|
|
1091
|
+
machine_id: deviceIdentity.machine_id,
|
|
1092
|
+
device_id: deviceIdentity.device_id,
|
|
1093
|
+
},
|
|
1068
1094
|
queue: {
|
|
1069
1095
|
pending_bytes: pendingBytes,
|
|
1070
1096
|
size_bytes: queueSize,
|
|
@@ -1282,6 +1308,7 @@ async function cmdStatus(argv = []) {
|
|
|
1282
1308
|
}
|
|
1283
1309
|
: {}),
|
|
1284
1310
|
subscriptions,
|
|
1311
|
+
...(usageLimits ? { limits: usageLimits } : {}),
|
|
1285
1312
|
// Pricing data provenance + staleness, so a $0 cost row can be triaged
|
|
1286
1313
|
// as "not collected" vs "not priced" from `status --json` alone.
|
|
1287
1314
|
pricing: getPricingMeta(),
|
|
@@ -1301,6 +1328,7 @@ async function cmdStatus(argv = []) {
|
|
|
1301
1328
|
"Status:",
|
|
1302
1329
|
`- Base URL: ${config?.baseUrl || "unset"}`,
|
|
1303
1330
|
`- Device token: ${deviceTokenPresence.set ? "set" : "unset"}`,
|
|
1331
|
+
formatDeviceLine(deviceIdentity),
|
|
1304
1332
|
collectionPaused
|
|
1305
1333
|
? "- Collection: PAUSED (auto/notify/watch syncs skip; manual sync runs; `tokenusage resume` to re-enable)"
|
|
1306
1334
|
: "- Collection: active",
|
|
@@ -1501,6 +1529,7 @@ async function cmdStatus(argv = []) {
|
|
|
1501
1529
|
return lines;
|
|
1502
1530
|
})() : []),
|
|
1503
1531
|
...subscriptionLines,
|
|
1532
|
+
...usageLimitLines,
|
|
1504
1533
|
"",
|
|
1505
1534
|
]
|
|
1506
1535
|
.filter(Boolean)
|
|
@@ -1597,11 +1626,111 @@ function formatSubscriptionLine(entry = {}) {
|
|
|
1597
1626
|
return `- ${toolLabel} ${productLabel}: ${planType}`;
|
|
1598
1627
|
}
|
|
1599
1628
|
|
|
1629
|
+
const USAGE_LIMIT_PROVIDERS = [
|
|
1630
|
+
["claude", "Claude"],
|
|
1631
|
+
["codex", "Codex"],
|
|
1632
|
+
["cursor", "Cursor"],
|
|
1633
|
+
["grok", "Grok"],
|
|
1634
|
+
["kimi", "Kimi"],
|
|
1635
|
+
["gemini", "Gemini"],
|
|
1636
|
+
["kiro", "Kiro"],
|
|
1637
|
+
["antigravity", "Antigravity"],
|
|
1638
|
+
["copilot", "Copilot"],
|
|
1639
|
+
["zcode", "ZCode"],
|
|
1640
|
+
["opencodeGo", "OpenCode Go"],
|
|
1641
|
+
["commandCode", "CommandCode"],
|
|
1642
|
+
["devin", "Devin"],
|
|
1643
|
+
["qoder", "Qoder"],
|
|
1644
|
+
["qoderCn", "Qoder CN"],
|
|
1645
|
+
["codingPlan", "Ark Coding Plan"],
|
|
1646
|
+
["agentPlan", "Ark Agent Plan"],
|
|
1647
|
+
["deepseek", "DeepSeek"],
|
|
1648
|
+
];
|
|
1649
|
+
|
|
1650
|
+
// Primary window first and unprefixed (it is the headline quota); the rest keep
|
|
1651
|
+
// their role so a three-window provider stays readable on one row.
|
|
1652
|
+
const USAGE_LIMIT_WINDOWS = [
|
|
1653
|
+
["primary_window", null],
|
|
1654
|
+
["secondary_window", "secondary"],
|
|
1655
|
+
["tertiary_window", "add-on"],
|
|
1656
|
+
["quaternary_window", "other"],
|
|
1657
|
+
];
|
|
1658
|
+
|
|
1659
|
+
function formatLimitAge(seconds) {
|
|
1660
|
+
const value = Number(seconds);
|
|
1661
|
+
if (!Number.isFinite(value) || value < 0) return null;
|
|
1662
|
+
if (value < 60) return `${Math.round(value)}s ago`;
|
|
1663
|
+
if (value < 3600) return `${Math.round(value / 60)}m ago`;
|
|
1664
|
+
if (value < 86_400) return `${Math.round(value / 3600)}h ago`;
|
|
1665
|
+
return `${Math.round(value / 86_400)}d ago`;
|
|
1666
|
+
}
|
|
1667
|
+
|
|
1668
|
+
function formatLimitCredits(value) {
|
|
1669
|
+
const number = Number(value);
|
|
1670
|
+
if (!Number.isFinite(number)) return null;
|
|
1671
|
+
return String(Math.round(number * 100) / 100);
|
|
1672
|
+
}
|
|
1673
|
+
|
|
1674
|
+
function formatUsageLimitWindow(window) {
|
|
1675
|
+
if (!window || typeof window !== "object") return null;
|
|
1676
|
+
const parts = [];
|
|
1677
|
+
const percent = Number(window.used_percent);
|
|
1678
|
+
if (Number.isFinite(percent)) parts.push(`${Math.round(percent * 10) / 10}%`);
|
|
1679
|
+
const used = formatLimitCredits(window.used_credits);
|
|
1680
|
+
const limit = formatLimitCredits(window.limit_credits);
|
|
1681
|
+
if (used !== null && limit !== null && Number(window.limit_credits) > 0) {
|
|
1682
|
+
parts.push(`${used}/${limit} credits`);
|
|
1683
|
+
}
|
|
1684
|
+
if (window.reset_at) parts.push(`resets ${window.reset_at}`);
|
|
1685
|
+
return parts.length > 0 ? parts.join(", ") : null;
|
|
1686
|
+
}
|
|
1687
|
+
|
|
1688
|
+
/**
|
|
1689
|
+
* Pure formatter for the opt-in quota panel (`status --limits`). One row per
|
|
1690
|
+
* configured provider; plan, windows, error and provenance share a row so
|
|
1691
|
+
* `--light` output stays greppable by provider name.
|
|
1692
|
+
*/
|
|
1693
|
+
function formatUsageLimitRows(limits) {
|
|
1694
|
+
if (!limits || typeof limits !== "object") return [];
|
|
1695
|
+
const rows = [];
|
|
1696
|
+
|
|
1697
|
+
for (const [key, label] of USAGE_LIMIT_PROVIDERS) {
|
|
1698
|
+
const entry = limits[key];
|
|
1699
|
+
if (!entry || typeof entry !== "object" || entry.configured === false) continue;
|
|
1700
|
+
const parts = [];
|
|
1701
|
+
if (entry.error) parts.push(`error: ${entry.error}`);
|
|
1702
|
+
const plan = entry.plan_label || entry.plan_name || entry.plan_type || null;
|
|
1703
|
+
if (plan) parts.push(String(plan));
|
|
1704
|
+
for (const [windowKey, prefix] of USAGE_LIMIT_WINDOWS) {
|
|
1705
|
+
const windowText = formatUsageLimitWindow(entry[windowKey]);
|
|
1706
|
+
if (!windowText) continue;
|
|
1707
|
+
parts.push(prefix ? `${prefix}: ${windowText}` : windowText);
|
|
1708
|
+
}
|
|
1709
|
+
const provenance = entry.provenance;
|
|
1710
|
+
if (provenance && typeof provenance === "object") {
|
|
1711
|
+
const age = formatLimitAge(provenance.age_seconds);
|
|
1712
|
+
parts.push(
|
|
1713
|
+
[
|
|
1714
|
+
provenance.source || "unknown",
|
|
1715
|
+
provenance.stale === true ? "stale" : null,
|
|
1716
|
+
age,
|
|
1717
|
+
]
|
|
1718
|
+
.filter(Boolean)
|
|
1719
|
+
.join(", "),
|
|
1720
|
+
);
|
|
1721
|
+
}
|
|
1722
|
+
rows.push([`Limit · ${label}`, parts.length > 0 ? parts.join(", ") : "—"]);
|
|
1723
|
+
}
|
|
1724
|
+
|
|
1725
|
+
return rows;
|
|
1726
|
+
}
|
|
1727
|
+
|
|
1600
1728
|
function parseArgs(argv) {
|
|
1601
1729
|
const out = {
|
|
1602
1730
|
diagnostics: false,
|
|
1603
1731
|
json: false,
|
|
1604
1732
|
light: false,
|
|
1733
|
+
limits: false,
|
|
1605
1734
|
noSpinner: false,
|
|
1606
1735
|
probeKeychain: false,
|
|
1607
1736
|
probeKeychainDetails: false,
|
|
@@ -1612,6 +1741,7 @@ function parseArgs(argv) {
|
|
|
1612
1741
|
if (a === "--diagnostics") out.diagnostics = true;
|
|
1613
1742
|
else if (a === "--json") out.json = true;
|
|
1614
1743
|
else if (a === "--light") out.light = true;
|
|
1744
|
+
else if (a === "--limits") out.limits = true;
|
|
1615
1745
|
else if (a === "--no-spinner") out.noSpinner = true;
|
|
1616
1746
|
else if (a === "--probe-keychain") out.probeKeychain = true;
|
|
1617
1747
|
else if (a === "--probe-keychain-details") {
|
|
@@ -1634,6 +1764,8 @@ function renderLightTable(summary) {
|
|
|
1634
1764
|
push("Version", summary.version);
|
|
1635
1765
|
push("Base URL", summary.base_url);
|
|
1636
1766
|
push("Device token", summary.device_token_set ? "set" : "unset");
|
|
1767
|
+
push("Device", summary.device?.name);
|
|
1768
|
+
push("Device ID", summary.device?.device_id);
|
|
1637
1769
|
push("Queue pending (bytes)", summary.queue.pending_bytes);
|
|
1638
1770
|
push("Queue size (bytes)", summary.queue.size_bytes);
|
|
1639
1771
|
push("Last parse", summary.last_parse);
|
|
@@ -1670,6 +1802,10 @@ function renderLightTable(summary) {
|
|
|
1670
1802
|
push(`Provider · ${name}`, detail.length ? detail.join(", ") : "—");
|
|
1671
1803
|
}
|
|
1672
1804
|
|
|
1805
|
+
for (const [label, value] of formatUsageLimitRows(summary.limits)) {
|
|
1806
|
+
push(label, value);
|
|
1807
|
+
}
|
|
1808
|
+
|
|
1673
1809
|
// Mirror formatCopilotLines(): stay silent for machines with no Copilot
|
|
1674
1810
|
// signal at all instead of printing "not found" rows for everyone.
|
|
1675
1811
|
const copilotDetected =
|
|
@@ -1762,4 +1898,10 @@ function parseEpochMsToIso(v) {
|
|
|
1762
1898
|
return d.toISOString();
|
|
1763
1899
|
}
|
|
1764
1900
|
|
|
1765
|
-
module.exports = {
|
|
1901
|
+
module.exports = {
|
|
1902
|
+
cmdStatus,
|
|
1903
|
+
formatUsageLimitRows,
|
|
1904
|
+
parseArgs,
|
|
1905
|
+
renderLightTable,
|
|
1906
|
+
summarizeQoderDetail,
|
|
1907
|
+
};
|
package/src/commands/sync.js
CHANGED
|
@@ -158,7 +158,8 @@ const {
|
|
|
158
158
|
resolveZcodeInstallPaths,
|
|
159
159
|
} = require("../lib/rollout");
|
|
160
160
|
const { computeClaudeGroundTruthBuckets } = require("../lib/claude-categorizer");
|
|
161
|
-
const { createProgress, renderBar, formatNumber, formatBytes } = require("../lib/progress");
|
|
161
|
+
const { createProgress, renderBar, formatNumber, formatBytes, formatDuration, formatDeviceLine } = require("../lib/progress");
|
|
162
|
+
const { buildDeviceIdentity } = require("../lib/device-identity");
|
|
162
163
|
const {
|
|
163
164
|
DEFAULTS: AUTO_UPLOAD_DEFAULTS,
|
|
164
165
|
normalizeState: normalizeUploadState,
|
|
@@ -182,6 +183,7 @@ const {
|
|
|
182
183
|
isCursorInstalled,
|
|
183
184
|
extractCursorSessionToken,
|
|
184
185
|
fetchCursorUsageCsv,
|
|
186
|
+
fetchCursorUsageCsvWithFallback,
|
|
185
187
|
parseCursorCsv,
|
|
186
188
|
} = require("../lib/cursor-config");
|
|
187
189
|
const { purgeProjectUsage } = require("../lib/project-usage-purge");
|
|
@@ -571,6 +573,58 @@ async function clearSyncSkip(trackerDir) {
|
|
|
571
573
|
}
|
|
572
574
|
}
|
|
573
575
|
|
|
576
|
+
/**
|
|
577
|
+
* The human summary of one sync run.
|
|
578
|
+
*
|
|
579
|
+
* Pure on purpose: the summary is what ends up pasted into runbooks and issue
|
|
580
|
+
* trackers, so it has to state WHICH machine ran, how much was uploaded (in
|
|
581
|
+
* tokens, not just rows), how many sessions moved, what is still pending and
|
|
582
|
+
* how long it took. Extracted from cmdSync so it can be unit-tested.
|
|
583
|
+
*/
|
|
584
|
+
function buildSyncSummaryLines({
|
|
585
|
+
deviceIdentity = null,
|
|
586
|
+
totalParsed = 0,
|
|
587
|
+
totalBuckets = 0,
|
|
588
|
+
uploadResult = {},
|
|
589
|
+
sessionUploadSummary = null,
|
|
590
|
+
hasDeviceToken = false,
|
|
591
|
+
pendingBytes = 0,
|
|
592
|
+
drain = false,
|
|
593
|
+
durationMs = 0,
|
|
594
|
+
uploadError = null,
|
|
595
|
+
warning = null,
|
|
596
|
+
} = {}) {
|
|
597
|
+
const uploadedTokens = Number(uploadResult.tokens || 0);
|
|
598
|
+
const uploadedCredits = Number(uploadResult.credits || 0);
|
|
599
|
+
const inserted = Number(uploadResult.inserted || 0);
|
|
600
|
+
const rowWord = inserted === 1 ? "row" : "rows";
|
|
601
|
+
const lines = ["Sync finished:"];
|
|
602
|
+
if (deviceIdentity) lines.push(formatDeviceLine(deviceIdentity));
|
|
603
|
+
lines.push(
|
|
604
|
+
`- Parsed files: ${formatNumber(totalParsed)}`,
|
|
605
|
+
`- New 30-min buckets queued: ${formatNumber(totalBuckets)}`,
|
|
606
|
+
hasDeviceToken
|
|
607
|
+
? `- Uploaded: ${formatNumber(inserted)} ${rowWord} (${formatNumber(uploadedTokens)} tokens), ${formatNumber(uploadResult.skipped)} skipped`
|
|
608
|
+
: "- Uploaded: skipped (no device token)",
|
|
609
|
+
);
|
|
610
|
+
if (hasDeviceToken && uploadedCredits > 0) {
|
|
611
|
+
lines.push(`- Credits: ${formatNumber(uploadedCredits)}`);
|
|
612
|
+
}
|
|
613
|
+
if (sessionUploadSummary) {
|
|
614
|
+
lines.push(
|
|
615
|
+
`- Sessions: ${formatNumber(sessionUploadSummary.uploaded)}/${formatNumber(sessionUploadSummary.pending)} uploaded (upserted ${formatNumber(sessionUploadSummary.upserted)}, skipped ${formatNumber(sessionUploadSummary.skipped)})`,
|
|
616
|
+
);
|
|
617
|
+
}
|
|
618
|
+
if (hasDeviceToken && pendingBytes > 0 && !drain) {
|
|
619
|
+
lines.push(`- Remaining: ${formatBytes(pendingBytes)} pending (run sync again, or use --drain)`);
|
|
620
|
+
}
|
|
621
|
+
lines.push(`- Duration: ${formatDuration(durationMs)}`);
|
|
622
|
+
if (uploadError) lines.push(`- Upload error: ${uploadError.message || uploadError}`);
|
|
623
|
+
if (warning) lines.push(`- Warning: ${warning}`);
|
|
624
|
+
lines.push("");
|
|
625
|
+
return lines;
|
|
626
|
+
}
|
|
627
|
+
|
|
574
628
|
async function cmdSync(argv, context = {}) {
|
|
575
629
|
context = context && typeof context === "object" ? context : {};
|
|
576
630
|
const opts = parseArgs(argv);
|
|
@@ -596,6 +650,8 @@ async function cmdSync(argv, context = {}) {
|
|
|
596
650
|
const syncDiagnostics = diagnostics && typeof diagnostics === "object" ? diagnostics : null;
|
|
597
651
|
const home = context.home || os.homedir();
|
|
598
652
|
const trackerDir = context.trackerDataDir || (await resolveTrackerPaths({ home })).trackerDir;
|
|
653
|
+
// Wall clock for the run summary (the §2.11 run record keeps its own).
|
|
654
|
+
const syncStartedAtMs = Date.now();
|
|
599
655
|
// Collection pause (0.2.0): auto-flavored runs exit silently — no lock, no
|
|
600
656
|
// log line, no run record. A manual sync is the user's explicit request
|
|
601
657
|
// and runs regardless of the flag.
|
|
@@ -2259,7 +2315,11 @@ async function cmdSync(argv, context = {}) {
|
|
|
2259
2315
|
if (progress?.enabled) {
|
|
2260
2316
|
progress.start(`Fetching Cursor usage...`);
|
|
2261
2317
|
}
|
|
2262
|
-
const csvText = await
|
|
2318
|
+
const csvText = await fetchCursorUsageCsvWithFallback({
|
|
2319
|
+
cookies: cursorAuth.cookies,
|
|
2320
|
+
cookie: cursorAuth.cookie,
|
|
2321
|
+
cookieFetcher: cursorUsageFetcher,
|
|
2322
|
+
});
|
|
2263
2323
|
const records = parseCursorCsv(csvText);
|
|
2264
2324
|
if (records.length > 0) {
|
|
2265
2325
|
if (progress?.enabled) {
|
|
@@ -3636,6 +3696,9 @@ async function cmdSync(argv, context = {}) {
|
|
|
3636
3696
|
let uploadAttempted = false;
|
|
3637
3697
|
let uploadError = null;
|
|
3638
3698
|
let autoUploadDecision = null;
|
|
3699
|
+
// Session upload counters, folded into the final summary instead of being
|
|
3700
|
+
// printed on their own line before it.
|
|
3701
|
+
let sessionUploadSummary = null;
|
|
3639
3702
|
|
|
3640
3703
|
if (canUpload() && (opts.auto || opts.publishAccount) && runtime.deviceToken && runtime.baseUrl &&
|
|
3641
3704
|
(!isBackgroundLightweightSync || opts.publishAccount)) {
|
|
@@ -3826,17 +3889,21 @@ async function cmdSync(argv, context = {}) {
|
|
|
3826
3889
|
canUpload,
|
|
3827
3890
|
});
|
|
3828
3891
|
if (result.pending > 0) {
|
|
3829
|
-
|
|
3830
|
-
|
|
3831
|
-
|
|
3832
|
-
|
|
3833
|
-
|
|
3834
|
-
|
|
3835
|
-
|
|
3836
|
-
|
|
3837
|
-
|
|
3838
|
-
|
|
3839
|
-
|
|
3892
|
+
sessionUploadSummary = {
|
|
3893
|
+
uploaded: result.uploaded,
|
|
3894
|
+
pending: result.pending,
|
|
3895
|
+
upserted: result.upserted,
|
|
3896
|
+
skipped: (result.skippedServer || 0) + (result.skippedLocal || 0),
|
|
3897
|
+
};
|
|
3898
|
+
// Auto runs keep the rolling log line; a manual run reports the same
|
|
3899
|
+
// counters inside the final summary block (printing here would put
|
|
3900
|
+
// the sessions line above the summary it belongs to).
|
|
3901
|
+
if (opts.auto) {
|
|
3902
|
+
const sessionSuffix =
|
|
3903
|
+
result.upserted || result.skippedServer
|
|
3904
|
+
? ` (upserted ${result.upserted}, skipped ${result.skippedServer})`
|
|
3905
|
+
: "";
|
|
3906
|
+
autoLog(`Sessions: ${result.uploaded}/${result.pending} uploaded${sessionSuffix}`);
|
|
3840
3907
|
}
|
|
3841
3908
|
}
|
|
3842
3909
|
syncRun?.noteSessions({
|
|
@@ -3899,28 +3966,28 @@ async function cmdSync(argv, context = {}) {
|
|
|
3899
3966
|
|
|
3900
3967
|
if (!autoishSync) {
|
|
3901
3968
|
const codexRecordOnlyWarning = formatRecordOnlyWarning(countRecordOnlyFiles(cursors));
|
|
3969
|
+
const deviceIdentity = buildDeviceIdentity({ config: runtimeConfig, hostname: os.hostname() });
|
|
3902
3970
|
process.stdout.write(
|
|
3903
|
-
|
|
3904
|
-
|
|
3905
|
-
|
|
3906
|
-
|
|
3907
|
-
|
|
3908
|
-
|
|
3909
|
-
|
|
3910
|
-
|
|
3911
|
-
|
|
3912
|
-
|
|
3913
|
-
|
|
3914
|
-
|
|
3915
|
-
|
|
3916
|
-
.filter(Boolean)
|
|
3917
|
-
.join("\n"),
|
|
3971
|
+
buildSyncSummaryLines({
|
|
3972
|
+
deviceIdentity,
|
|
3973
|
+
totalParsed,
|
|
3974
|
+
totalBuckets,
|
|
3975
|
+
uploadResult,
|
|
3976
|
+
sessionUploadSummary,
|
|
3977
|
+
hasDeviceToken: Boolean(runtime.deviceToken),
|
|
3978
|
+
pendingBytes,
|
|
3979
|
+
drain: Boolean(opts.drain),
|
|
3980
|
+
durationMs: Date.now() - syncStartedAtMs,
|
|
3981
|
+
uploadError,
|
|
3982
|
+
warning: codexRecordOnlyWarning,
|
|
3983
|
+
}).join("\n"),
|
|
3918
3984
|
);
|
|
3919
3985
|
} else {
|
|
3920
3986
|
autoLog(
|
|
3921
3987
|
`Auto sync finished — parsed ${totalParsed} files, +${totalBuckets} buckets, ` +
|
|
3922
3988
|
(runtime.deviceToken
|
|
3923
3989
|
? `uploaded ${uploadResult.inserted}, skipped ${uploadResult.skipped}` +
|
|
3990
|
+
`, ${uploadResult.tokens || 0} tokens` +
|
|
3924
3991
|
(pendingBytes > 0 ? `, pending ${formatBytes(pendingBytes)}` : ", queue drained")
|
|
3925
3992
|
: "upload skipped (no device token)"),
|
|
3926
3993
|
{
|
|
@@ -3929,7 +3996,12 @@ async function cmdSync(argv, context = {}) {
|
|
|
3929
3996
|
buckets: totalBuckets,
|
|
3930
3997
|
inserted: uploadResult.inserted,
|
|
3931
3998
|
skipped: uploadResult.skipped,
|
|
3999
|
+
tokens: uploadResult.tokens || 0,
|
|
4000
|
+
credits: uploadResult.credits || 0,
|
|
4001
|
+
sessions_uploaded: sessionUploadSummary ? sessionUploadSummary.uploaded : 0,
|
|
4002
|
+
sessions_skipped: sessionUploadSummary ? sessionUploadSummary.skipped : 0,
|
|
3932
4003
|
pending_bytes: pendingBytes,
|
|
4004
|
+
duration_ms: Date.now() - syncStartedAtMs,
|
|
3933
4005
|
uploaded: Boolean(runtime.deviceToken),
|
|
3934
4006
|
},
|
|
3935
4007
|
);
|
|
@@ -4107,6 +4179,7 @@ function recordCodexColdScanAudit(
|
|
|
4107
4179
|
module.exports = {
|
|
4108
4180
|
cmdSync,
|
|
4109
4181
|
acquireSyncLock,
|
|
4182
|
+
buildSyncSummaryLines,
|
|
4110
4183
|
readQueueBatch,
|
|
4111
4184
|
drainQueueToCloud,
|
|
4112
4185
|
normalizeSyncSource,
|
package/src/commands/upload.js
CHANGED
|
@@ -18,6 +18,8 @@ const path = require("node:path");
|
|
|
18
18
|
const fs = require("node:fs/promises");
|
|
19
19
|
|
|
20
20
|
const { resolveTrackerPaths } = require("../lib/tracker-paths");
|
|
21
|
+
const { formatDeviceLine } = require("../lib/progress");
|
|
22
|
+
const { buildDeviceIdentity } = require("../lib/device-identity");
|
|
21
23
|
const { readJson } = require("../lib/fs");
|
|
22
24
|
const { cloudUsageResetBlocksUpload } = require("../lib/cloud-usage-reset");
|
|
23
25
|
const { compactPendingQueue } = require("../lib/upload-queue");
|
|
@@ -134,9 +136,11 @@ async function cmdUpload(argv, options = {}) {
|
|
|
134
136
|
process.stdout.write(
|
|
135
137
|
[
|
|
136
138
|
"Upload complete.",
|
|
139
|
+
formatDeviceLine(buildDeviceIdentity({ config, hostname: os.hostname() })),
|
|
137
140
|
`- Requests: ${result.batches}`,
|
|
138
141
|
`- Rows inserted: ${result.inserted.toLocaleString("en-US")} (skipped ${result.skipped.toLocaleString("en-US")})`,
|
|
139
142
|
`- Tokens in this upload: ${result.tokens.toLocaleString("en-US")}`,
|
|
143
|
+
result.credits > 0 ? `- Credits in this upload: ${result.credits.toLocaleString("en-US")}` : null,
|
|
140
144
|
`- Pending bytes: ${beforeBytes} → ${afterBytes}`,
|
|
141
145
|
afterBytes > 0 ? "- Backlog remains; run `tokenusage upload --drain` or retry later." : null,
|
|
142
146
|
"",
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
/**
|
|
4
4
|
* Account-level cross-device truth - JS reference implementation.
|
|
5
5
|
*
|
|
6
|
-
* Account-level sources (ACCOUNT_LEVEL_SOURCES in src/lib/
|
|
6
|
+
* Account-level sources (ACCOUNT_LEVEL_SOURCES in src/lib/session-upload.js)
|
|
7
7
|
* come from a per-ACCOUNT cloud API, so every device that syncs them stores
|
|
8
8
|
* its own copy of the SAME account data. How to dedup depends on the source:
|
|
9
9
|
*
|