@pickagent/cli 0.1.0 → 0.1.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.
- package/README.md +6 -3
- package/dist/cli.js +688 -111
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -25,6 +25,8 @@ npx @pickagent/cli scan --help
|
|
|
25
25
|
--days N Last N days, including today (1–366).
|
|
26
26
|
--plan SLUG Plan you pay for today. Repeatable. E.g. claude-pro.
|
|
27
27
|
--base-url URL Verdict origin. Default https://pickagent.dev.
|
|
28
|
+
--lang es|en Verdict language. Default: es when LC_ALL, LC_MESSAGES,
|
|
29
|
+
or LANG starts with es; otherwise en.
|
|
28
30
|
--json Write only the JSON profile to stdout.
|
|
29
31
|
--yes Open the browser without asking.
|
|
30
32
|
--no-open Do not open the browser.
|
|
@@ -55,10 +57,11 @@ Every agent ccusage detects, by default.
|
|
|
55
57
|
- `session` with the same flags
|
|
56
58
|
- `blocks` with `--json --no-cost --offline` and the same range (Claude 5-hour windows)
|
|
57
59
|
2. The `--by-agent` JSON is split by harness. Totals go into the profile metrics and the breakdown into `by_source` (hours, sessions, provenance per source).
|
|
58
|
-
3. If ccusage fails to start or fails validation, the local parser reads `~/.claude/
|
|
60
|
+
3. If ccusage fails to start or fails validation, the local parser reads every Claude config directory: comma-separated `CLAUDE_CONFIG_DIR`, each `config_dir` in `~/.claude-subs/registry.json` (that field only), and the defaults `~/.claude` and `~/.config/claude`. Usage is summed as one `claude-code` source.
|
|
59
61
|
4. If local Codex rollouts exist and ccusage did not contribute Codex, they are merged into the profile.
|
|
60
62
|
5. If Cursor agent-transcripts or `ai-tracking` exist and ccusage did not contribute Cursor, they are merged (estimated hours; chat text is not read).
|
|
61
|
-
6. Plans (no network): it reads the Claude tier in
|
|
63
|
+
6. Plans (no network): it reads the Claude tier in every config directory (`default_claude_ai` is Claude Pro; Max 5× / 20× map to `claude-max-5x` / `claude-ultra`), the `chatgpt_plan_type` JWT claim in `~/.codex/auth.json`, and Cursor `stripeMembershipType` in `state.vscdb`. Old Stripe ids `pro` and `pro_plus` map to `cursor-pro-legacy` and `cursor-pro-plus-legacy`, not Premium or Super. `ultra` is ambiguous, so an interactive terminal asks. Several Claude profiles can contribute several plans. `--plan` replaces detection. Tokens and email are not uploaded.
|
|
64
|
+
7. OpenCode, Kimi (`~/.kimi` and `~/.kimi-code`), and Codex hours that ccusage leaves at 0 are estimated from session timestamps. Gemini CLI (`~/.gemini/tmp`) and Antigravity (`~/.gemini/antigravity`) are included the same way: tokens by family when the file has a usage object, otherwise hours and days only.
|
|
62
65
|
|
|
63
66
|
ccusage is not part of pickagent. It is third-party code, and each run resolves it with `npx` as `ccusage@latest`, with no pinned version.
|
|
64
67
|
|
|
@@ -130,7 +133,7 @@ A block counts when `rate_limits.rate_limit_reached_type` is a non-empty string.
|
|
|
130
133
|
|
|
131
134
|
Without `--json`, an English summary and the URL. It asks before opening the browser. `--yes` opens without asking. `--no-open` does not open. `--json` writes only the profile to stdout; the browser opens only when you also pass `--yes` and not `--no-open`.
|
|
132
135
|
|
|
133
|
-
The URL is `{base}/
|
|
136
|
+
The URL is `{base}/es/veredicto` when `LC_ALL`, `LC_MESSAGES`, or `LANG` starts with `es`, and `{base}/en/verdict` otherwise, plus `profileToHash()`. `--lang es` or `--lang en` overrides that. Default base: `https://pickagent.dev`. `/en/veredicto` redirects on the site.
|
|
134
137
|
|
|
135
138
|
The profile goes through `parseProfile` before use. If it does not match the schema, the issues are printed and the process exits with code 1. With no measurable usage (no hours with a distinct start and end) it also exits with code 1: an empty profile does not fit the schema, because `agent_hours`, `activity`, and `by_model` are required.
|
|
136
139
|
|
package/dist/cli.js
CHANGED
|
@@ -19800,6 +19800,11 @@ var SOURCES = [...SOURCES_CORE, ...SOURCES_EXTRA];
|
|
|
19800
19800
|
var SourceSchema = external_exports.enum(SOURCES);
|
|
19801
19801
|
var PROVENANCE = ["measured", "estimated"];
|
|
19802
19802
|
var ProvenanceSchema = external_exports.enum(PROVENANCE);
|
|
19803
|
+
var CURSOR_LEGACY_PLAN_IDS = [
|
|
19804
|
+
"cursor-pro-legacy",
|
|
19805
|
+
"cursor-pro-plus-legacy",
|
|
19806
|
+
"cursor-ultra-legacy"
|
|
19807
|
+
];
|
|
19803
19808
|
var PlanIdSchema = external_exports.string().regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/).max(48);
|
|
19804
19809
|
var FAMILY_PATTERNS = [
|
|
19805
19810
|
[/opus/, "claude-opus"],
|
|
@@ -20593,16 +20598,23 @@ function breakdownOf2(profile) {
|
|
|
20593
20598
|
sessions: profile.sessions?.value.count
|
|
20594
20599
|
};
|
|
20595
20600
|
}
|
|
20596
|
-
function dominantSource(bySource) {
|
|
20597
|
-
let
|
|
20598
|
-
let
|
|
20601
|
+
function dominantSource(bySource, provenance = {}) {
|
|
20602
|
+
let bestMeasured = null;
|
|
20603
|
+
let measuredHours = -1;
|
|
20604
|
+
let bestAny = null;
|
|
20605
|
+
let anyHours = -1;
|
|
20599
20606
|
for (const [source, slice] of Object.entries(bySource)) {
|
|
20600
|
-
if (slice.agent_hours >
|
|
20601
|
-
|
|
20602
|
-
|
|
20607
|
+
if (slice.agent_hours > anyHours) {
|
|
20608
|
+
anyHours = slice.agent_hours;
|
|
20609
|
+
bestAny = source;
|
|
20610
|
+
}
|
|
20611
|
+
const method = provenance[source] ?? slice.provenance;
|
|
20612
|
+
if (method === "measured" && slice.agent_hours > 0 && slice.agent_hours > measuredHours) {
|
|
20613
|
+
measuredHours = slice.agent_hours;
|
|
20614
|
+
bestMeasured = source;
|
|
20603
20615
|
}
|
|
20604
20616
|
}
|
|
20605
|
-
return
|
|
20617
|
+
return bestMeasured ?? bestAny ?? "claude-code";
|
|
20606
20618
|
}
|
|
20607
20619
|
function retarget(metric, source) {
|
|
20608
20620
|
return { ...metric, source };
|
|
@@ -20665,7 +20677,7 @@ function profileFromMultiAgent(reports, options) {
|
|
|
20665
20677
|
by_source[source] = breakdownOf2(base);
|
|
20666
20678
|
provenance[source] = base.provenance[source] ?? base.agent_hours.provenance;
|
|
20667
20679
|
}
|
|
20668
|
-
const dominant = dominantSource(by_source);
|
|
20680
|
+
const dominant = dominantSource(by_source, provenance);
|
|
20669
20681
|
const next = {
|
|
20670
20682
|
...base,
|
|
20671
20683
|
provenance,
|
|
@@ -20735,8 +20747,11 @@ function mergeProfileParts(profiles, plans) {
|
|
|
20735
20747
|
let modelsCount = 0;
|
|
20736
20748
|
for (const profile of profiles) {
|
|
20737
20749
|
for (const [source, method] of Object.entries(profile.provenance)) {
|
|
20738
|
-
|
|
20739
|
-
provenance[source] = method;
|
|
20750
|
+
const prev = provenance[source];
|
|
20751
|
+
if (prev == null) provenance[source] = method;
|
|
20752
|
+
else if (prev === "estimated" || method === "estimated") {
|
|
20753
|
+
provenance[source] = "estimated";
|
|
20754
|
+
}
|
|
20740
20755
|
}
|
|
20741
20756
|
if (profile.by_source) {
|
|
20742
20757
|
for (const [source, slice] of Object.entries(profile.by_source)) {
|
|
@@ -20758,7 +20773,9 @@ function mergeProfileParts(profiles, plans) {
|
|
|
20758
20773
|
active_days: Math.max(prev.active_days ?? 0, slice.active_days ?? 0) || void 0,
|
|
20759
20774
|
sessions: (prev.sessions ?? 0) + (slice.sessions ?? 0) || void 0
|
|
20760
20775
|
} : slice;
|
|
20761
|
-
|
|
20776
|
+
const method = profile.agent_hours.provenance;
|
|
20777
|
+
const prevMethod = provenance[source];
|
|
20778
|
+
provenance[source] = prevMethod == null ? method : prevMethod === "measured" && method === "measured" ? "measured" : "estimated";
|
|
20762
20779
|
}
|
|
20763
20780
|
agentHours += profile.agent_hours.value;
|
|
20764
20781
|
if (profile.agent_hours.provenance !== "measured") hoursMeasured = false;
|
|
@@ -20779,7 +20796,7 @@ function mergeProfileParts(profiles, plans) {
|
|
|
20779
20796
|
});
|
|
20780
20797
|
}
|
|
20781
20798
|
}
|
|
20782
|
-
if (profile.sessions) {
|
|
20799
|
+
if (profile.sessions && profile.sessions.provenance === "measured") {
|
|
20783
20800
|
sessionCount += profile.sessions.value.count;
|
|
20784
20801
|
sessionMedianWeight += profile.sessions.value.count;
|
|
20785
20802
|
sessionMedianAcc += profile.sessions.value.median_minutes * profile.sessions.value.count;
|
|
@@ -20801,8 +20818,9 @@ function mergeProfileParts(profiles, plans) {
|
|
|
20801
20818
|
modelsCount = Math.max(modelsCount, profile.models_count.value);
|
|
20802
20819
|
}
|
|
20803
20820
|
}
|
|
20804
|
-
const dominant = dominantSource(by_source);
|
|
20821
|
+
const dominant = dominantSource(by_source, provenance);
|
|
20805
20822
|
const hoursProv = hoursMeasured ? "measured" : "estimated";
|
|
20823
|
+
const dominantProv = provenance[dominant] === "estimated" ? "estimated" : "measured";
|
|
20806
20824
|
const hourMetric = {
|
|
20807
20825
|
value: Math.round(agentHours * 10) / 10,
|
|
20808
20826
|
provenance: hoursProv,
|
|
@@ -20835,7 +20853,7 @@ function mergeProfileParts(profiles, plans) {
|
|
|
20835
20853
|
provenance,
|
|
20836
20854
|
by_source,
|
|
20837
20855
|
agent_hours: hourMetric,
|
|
20838
|
-
activity: { value: activity, provenance:
|
|
20856
|
+
activity: { value: activity, provenance: dominantProv, source: dominant },
|
|
20839
20857
|
by_model: {
|
|
20840
20858
|
value: byModelValue,
|
|
20841
20859
|
provenance: tokenRows.length ? hoursProv : profiles[0].by_model.provenance,
|
|
@@ -20911,6 +20929,8 @@ Options
|
|
|
20911
20929
|
--plan SLUG Plan you pay for today. Repeatable. E.g. claude-pro.
|
|
20912
20930
|
When passed, replaces automatic detection.
|
|
20913
20931
|
--base-url URL Verdict origin. Default ${DEFAULT_BASE_URL}.
|
|
20932
|
+
--lang es|en Verdict language. Default: es when LC_ALL, LC_MESSAGES,
|
|
20933
|
+
or LANG starts with es; otherwise en.
|
|
20914
20934
|
--json Write only the JSON profile to stdout.
|
|
20915
20935
|
--yes Open the browser without asking.
|
|
20916
20936
|
--no-open Do not open the browser.
|
|
@@ -20995,6 +21015,7 @@ function parseArgs(argv, now, offsetMinutes) {
|
|
|
20995
21015
|
let yes = false;
|
|
20996
21016
|
let noOpen = false;
|
|
20997
21017
|
let baseUrl = DEFAULT_BASE_URL;
|
|
21018
|
+
let lang = null;
|
|
20998
21019
|
let codex = false;
|
|
20999
21020
|
for (let i = 0; i < rest.length; i++) {
|
|
21000
21021
|
const flag = rest[i] ?? "";
|
|
@@ -21009,7 +21030,13 @@ function parseArgs(argv, now, offsetMinutes) {
|
|
|
21009
21030
|
else if (flag === "--yes") yes = true;
|
|
21010
21031
|
else if (flag === "--no-open") noOpen = true;
|
|
21011
21032
|
else if (flag === "--codex") codex = true;
|
|
21012
|
-
else if (flag === "--
|
|
21033
|
+
else if (flag === "--lang") {
|
|
21034
|
+
const value = take()?.toLowerCase();
|
|
21035
|
+
if (value !== "es" && value !== "en") {
|
|
21036
|
+
return { ok: false, error: "--lang expects es or en." };
|
|
21037
|
+
}
|
|
21038
|
+
lang = value;
|
|
21039
|
+
} else if (flag === "--period") {
|
|
21013
21040
|
const value = take();
|
|
21014
21041
|
if (!value || !MONTH_RE2.test(value)) {
|
|
21015
21042
|
return { ok: false, error: "--period expects YYYY-MM." };
|
|
@@ -21043,11 +21070,18 @@ function parseArgs(argv, now, offsetMinutes) {
|
|
|
21043
21070
|
return {
|
|
21044
21071
|
ok: true,
|
|
21045
21072
|
help: false,
|
|
21046
|
-
args: { period: resolved, plans, json: json2, yes, noOpen, baseUrl, codex }
|
|
21073
|
+
args: { period: resolved, plans, json: json2, yes, noOpen, baseUrl, lang, codex }
|
|
21047
21074
|
};
|
|
21048
21075
|
}
|
|
21049
|
-
function
|
|
21050
|
-
|
|
21076
|
+
function verdictLangFromEnv(env) {
|
|
21077
|
+
const raw = env.LC_ALL || env.LC_MESSAGES || env.LANG || "";
|
|
21078
|
+
return raw.trim().toLowerCase().startsWith("es") ? "es" : "en";
|
|
21079
|
+
}
|
|
21080
|
+
function verdictPath(lang) {
|
|
21081
|
+
return lang === "es" ? "/es/veredicto" : "/en/verdict";
|
|
21082
|
+
}
|
|
21083
|
+
function verdictUrl(baseUrl, hash2, lang = "en") {
|
|
21084
|
+
return `${baseUrl.replace(/\/+$/, "")}${verdictPath(lang)}${hash2}`;
|
|
21051
21085
|
}
|
|
21052
21086
|
|
|
21053
21087
|
// src/assemble.ts
|
|
@@ -21085,6 +21119,25 @@ function withEstimatedTokens(profile, source) {
|
|
|
21085
21119
|
if (profile.tokens) next.tokens = estimated(profile.tokens.value, source);
|
|
21086
21120
|
return next;
|
|
21087
21121
|
}
|
|
21122
|
+
function withEstimatedTime(profile, source) {
|
|
21123
|
+
const next = {
|
|
21124
|
+
...profile,
|
|
21125
|
+
provenance: { ...profile.provenance, [source]: "estimated" }
|
|
21126
|
+
};
|
|
21127
|
+
for (const key of METRIC_KEYS) {
|
|
21128
|
+
const metric = next[key];
|
|
21129
|
+
if (!metric || metric.source !== source) continue;
|
|
21130
|
+
next[key] = { ...metric, provenance: "estimated" };
|
|
21131
|
+
}
|
|
21132
|
+
const slice = next.by_source?.[source];
|
|
21133
|
+
if (slice) {
|
|
21134
|
+
next.by_source = {
|
|
21135
|
+
...next.by_source,
|
|
21136
|
+
[source]: { ...slice, provenance: "estimated" }
|
|
21137
|
+
};
|
|
21138
|
+
}
|
|
21139
|
+
return next;
|
|
21140
|
+
}
|
|
21088
21141
|
function assembleProfile(input2) {
|
|
21089
21142
|
const result = profileFromCcusage(input2.reports, {
|
|
21090
21143
|
period: input2.period,
|
|
@@ -21102,6 +21155,7 @@ function assembleProfile(input2) {
|
|
|
21102
21155
|
if (index >= 0) warnings.splice(index, 1);
|
|
21103
21156
|
}
|
|
21104
21157
|
if (draft && input2.estimateTokens) draft = withEstimatedTokens(draft, input2.source);
|
|
21158
|
+
if (draft && input2.estimateTime) draft = withEstimatedTime(draft, input2.source);
|
|
21105
21159
|
const parsed = parseProfile(draft ?? result.draft);
|
|
21106
21160
|
if (!parsed.ok) return { profile: null, issues: parsed.issues, warnings };
|
|
21107
21161
|
return { profile: parsed.profile, issues: [], warnings };
|
|
@@ -21463,7 +21517,7 @@ async function loadCcusage(input2) {
|
|
|
21463
21517
|
|
|
21464
21518
|
// src/claude-jsonl.ts
|
|
21465
21519
|
import { createReadStream } from "node:fs";
|
|
21466
|
-
import { readdir } from "node:fs/promises";
|
|
21520
|
+
import { readdir, readFile, realpath } from "node:fs/promises";
|
|
21467
21521
|
import { createInterface } from "node:readline";
|
|
21468
21522
|
import { join } from "node:path";
|
|
21469
21523
|
|
|
@@ -21678,12 +21732,56 @@ function toReports(agg) {
|
|
|
21678
21732
|
|
|
21679
21733
|
// src/claude-jsonl.ts
|
|
21680
21734
|
var isDict4 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
21681
|
-
function claudeConfigDirs(env, home) {
|
|
21735
|
+
async function claudeConfigDirs(env, home) {
|
|
21736
|
+
const found = [];
|
|
21682
21737
|
const raw = env.CLAUDE_CONFIG_DIR?.trim();
|
|
21683
21738
|
if (raw) {
|
|
21684
|
-
|
|
21739
|
+
for (const entry of raw.split(",")) {
|
|
21740
|
+
const expanded = expandHome(entry.trim(), home);
|
|
21741
|
+
if (expanded) found.push(expanded);
|
|
21742
|
+
}
|
|
21743
|
+
}
|
|
21744
|
+
found.push(...await registryConfigDirs(home));
|
|
21745
|
+
found.push(join(home, ".config", "claude"), join(home, ".claude"));
|
|
21746
|
+
return dedupePaths(found);
|
|
21747
|
+
}
|
|
21748
|
+
async function registryConfigDirs(home) {
|
|
21749
|
+
let text;
|
|
21750
|
+
try {
|
|
21751
|
+
text = await readFile(join(home, ".claude-subs", "registry.json"), "utf8");
|
|
21752
|
+
} catch {
|
|
21753
|
+
return [];
|
|
21754
|
+
}
|
|
21755
|
+
let data;
|
|
21756
|
+
try {
|
|
21757
|
+
data = JSON.parse(text);
|
|
21758
|
+
} catch {
|
|
21759
|
+
return [];
|
|
21760
|
+
}
|
|
21761
|
+
if (!isDict4(data) || !isDict4(data.profiles)) return [];
|
|
21762
|
+
const dirs = [];
|
|
21763
|
+
for (const profile of Object.values(data.profiles)) {
|
|
21764
|
+
if (!isDict4(profile) || typeof profile.config_dir !== "string") continue;
|
|
21765
|
+
const expanded = expandHome(profile.config_dir.trim(), home);
|
|
21766
|
+
if (expanded) dirs.push(expanded);
|
|
21685
21767
|
}
|
|
21686
|
-
return
|
|
21768
|
+
return dirs;
|
|
21769
|
+
}
|
|
21770
|
+
async function dedupePaths(paths) {
|
|
21771
|
+
const seen = /* @__PURE__ */ new Set();
|
|
21772
|
+
const out = [];
|
|
21773
|
+
for (const path2 of paths) {
|
|
21774
|
+
let key = path2;
|
|
21775
|
+
try {
|
|
21776
|
+
key = await realpath(path2);
|
|
21777
|
+
} catch {
|
|
21778
|
+
key = path2;
|
|
21779
|
+
}
|
|
21780
|
+
if (seen.has(key)) continue;
|
|
21781
|
+
seen.add(key);
|
|
21782
|
+
out.push(key);
|
|
21783
|
+
}
|
|
21784
|
+
return out;
|
|
21687
21785
|
}
|
|
21688
21786
|
function expandHome(path2, home) {
|
|
21689
21787
|
if (path2 === "~") return home;
|
|
@@ -21980,7 +22078,7 @@ async function readCodexLogs(home, bounds, offsetMinutes) {
|
|
|
21980
22078
|
}
|
|
21981
22079
|
|
|
21982
22080
|
// src/detect-plans.ts
|
|
21983
|
-
import { readFile } from "node:fs/promises";
|
|
22081
|
+
import { readFile as readFile2, realpath as realpath2 } from "node:fs/promises";
|
|
21984
22082
|
import { join as join4 } from "node:path";
|
|
21985
22083
|
|
|
21986
22084
|
// src/cursor-paths.ts
|
|
@@ -22158,10 +22256,10 @@ function mapClaudeTier(raw) {
|
|
|
22158
22256
|
}
|
|
22159
22257
|
if (/max[_-]?20x|ultra/.test(s)) return "claude-ultra";
|
|
22160
22258
|
if (/max[_-]?5x/.test(s)) return "claude-max-5x";
|
|
22161
|
-
if (/(^|_)pro($|_)/.test(s) || s === "pro" || s.endsWith("_pro")) {
|
|
22259
|
+
if (s === "default_claude_ai" || s === "claude_ai" || s === "claude_pro" || /(^|_)pro($|_)/.test(s) || s === "pro" || s.endsWith("_pro")) {
|
|
22162
22260
|
return "claude-pro";
|
|
22163
22261
|
}
|
|
22164
|
-
if (s === "max" || s.endsWith("_max")) return
|
|
22262
|
+
if (s === "max" || s === "claude_max" || s.endsWith("_max")) return null;
|
|
22165
22263
|
return null;
|
|
22166
22264
|
}
|
|
22167
22265
|
function mapCodexPlanType(raw) {
|
|
@@ -22193,23 +22291,23 @@ function mapCursorMembership(raw) {
|
|
|
22193
22291
|
case "plus":
|
|
22194
22292
|
case "cursor_plus":
|
|
22195
22293
|
return "cursor-plus";
|
|
22196
|
-
case "pro":
|
|
22197
22294
|
case "premium":
|
|
22198
22295
|
case "cursor_premium":
|
|
22199
22296
|
return "cursor-premium";
|
|
22200
|
-
case "pro_plus":
|
|
22201
|
-
case "proplus":
|
|
22202
22297
|
case "super":
|
|
22203
22298
|
case "cursor_super":
|
|
22204
22299
|
return "cursor-super";
|
|
22205
|
-
case "
|
|
22206
|
-
|
|
22207
|
-
|
|
22300
|
+
case "pro":
|
|
22301
|
+
return CURSOR_LEGACY_PLAN_IDS[0];
|
|
22302
|
+
case "pro_plus":
|
|
22303
|
+
case "proplus":
|
|
22304
|
+
return CURSOR_LEGACY_PLAN_IDS[1];
|
|
22208
22305
|
case "free":
|
|
22209
22306
|
case "hobby":
|
|
22210
22307
|
case "free_trial":
|
|
22211
22308
|
case "trial":
|
|
22212
|
-
|
|
22309
|
+
case "ultra":
|
|
22310
|
+
case "cursor_ultra":
|
|
22213
22311
|
case "enterprise":
|
|
22214
22312
|
case "team":
|
|
22215
22313
|
case "teams":
|
|
@@ -22247,64 +22345,87 @@ function planTypeFromClaims(data) {
|
|
|
22247
22345
|
}
|
|
22248
22346
|
async function readText(path2) {
|
|
22249
22347
|
try {
|
|
22250
|
-
return await
|
|
22348
|
+
return await readFile2(path2, "utf8");
|
|
22251
22349
|
} catch {
|
|
22252
22350
|
return null;
|
|
22253
22351
|
}
|
|
22254
22352
|
}
|
|
22255
|
-
|
|
22256
|
-
|
|
22257
|
-
|
|
22258
|
-
|
|
22259
|
-
|
|
22260
|
-
|
|
22261
|
-
|
|
22262
|
-
|
|
22263
|
-
|
|
22264
|
-
if (
|
|
22265
|
-
|
|
22266
|
-
|
|
22267
|
-
|
|
22268
|
-
|
|
22269
|
-
"subscriptionType"
|
|
22270
|
-
]) {
|
|
22271
|
-
const raw = jsonStringValue(accountText, key);
|
|
22272
|
-
if (raw) candidates.push({ key, raw });
|
|
22273
|
-
}
|
|
22274
|
-
}
|
|
22275
|
-
for (const root of roots) {
|
|
22276
|
-
const credText = await readText(join4(root, ".credentials.json"));
|
|
22277
|
-
if (!credText) continue;
|
|
22278
|
-
for (const key of ["rateLimitTier", "subscriptionType"]) {
|
|
22279
|
-
const raw = jsonStringValue(credText, key);
|
|
22280
|
-
if (raw) candidates.push({ key, raw });
|
|
22281
|
-
}
|
|
22353
|
+
var CLAUDE_TIER_KEYS = [
|
|
22354
|
+
"rateLimitTier",
|
|
22355
|
+
"organizationRateLimitTier",
|
|
22356
|
+
"userRateLimitTier",
|
|
22357
|
+
"subscriptionType",
|
|
22358
|
+
"organizationType",
|
|
22359
|
+
"seatTier"
|
|
22360
|
+
];
|
|
22361
|
+
function tierCandidates(text) {
|
|
22362
|
+
if (!text) return [];
|
|
22363
|
+
const found = [];
|
|
22364
|
+
for (const key of CLAUDE_TIER_KEYS) {
|
|
22365
|
+
const raw = jsonStringValue(text, key);
|
|
22366
|
+
if (raw) found.push({ key, raw });
|
|
22282
22367
|
}
|
|
22283
|
-
|
|
22368
|
+
return found;
|
|
22369
|
+
}
|
|
22370
|
+
function rankTiers(candidates) {
|
|
22371
|
+
return [...candidates].sort((a, b) => {
|
|
22284
22372
|
const score = (c) => {
|
|
22285
|
-
if (/max|ultra|pro/.test(c.raw.toLowerCase())) return 0;
|
|
22373
|
+
if (/max|ultra|pro|claude_ai/.test(c.raw.toLowerCase())) return 0;
|
|
22286
22374
|
if (c.key.toLowerCase().includes("ratelimit")) return 1;
|
|
22287
22375
|
return 2;
|
|
22288
22376
|
};
|
|
22289
22377
|
return score(a) - score(b);
|
|
22290
22378
|
});
|
|
22291
|
-
|
|
22292
|
-
|
|
22293
|
-
|
|
22294
|
-
|
|
22379
|
+
}
|
|
22380
|
+
async function detectClaudePlans(home, env) {
|
|
22381
|
+
const roots = await claudeConfigDirs(env, home);
|
|
22382
|
+
const detections = [];
|
|
22383
|
+
const warnings = [];
|
|
22384
|
+
const seen = /* @__PURE__ */ new Set();
|
|
22385
|
+
const homeAccount = await readText(join4(home, ".claude.json"));
|
|
22386
|
+
const defaultDir = join4(home, ".claude");
|
|
22387
|
+
let defaultReal = defaultDir;
|
|
22388
|
+
try {
|
|
22389
|
+
defaultReal = await realpath2(defaultDir);
|
|
22390
|
+
} catch {
|
|
22391
|
+
defaultReal = defaultDir;
|
|
22392
|
+
}
|
|
22393
|
+
const buckets = [];
|
|
22394
|
+
let attachedHome = false;
|
|
22395
|
+
for (const root of roots) {
|
|
22396
|
+
const own2 = [
|
|
22397
|
+
...tierCandidates(await readText(join4(root, ".credentials.json"))),
|
|
22398
|
+
...tierCandidates(await readText(join4(root, ".claude.json")))
|
|
22399
|
+
];
|
|
22400
|
+
if (root === defaultReal || root === defaultDir) {
|
|
22401
|
+
own2.push(...tierCandidates(homeAccount));
|
|
22402
|
+
attachedHome = true;
|
|
22403
|
+
}
|
|
22404
|
+
if (own2.length) buckets.push(own2);
|
|
22405
|
+
}
|
|
22406
|
+
if (!attachedHome && homeAccount) buckets.push(tierCandidates(homeAccount));
|
|
22407
|
+
for (const candidates of buckets) {
|
|
22408
|
+
const ranked = rankTiers(candidates);
|
|
22409
|
+
let mapped = false;
|
|
22410
|
+
for (const { raw } of ranked) {
|
|
22411
|
+
const plan = mapClaudeTier(raw);
|
|
22412
|
+
if (!plan) continue;
|
|
22413
|
+
mapped = true;
|
|
22414
|
+
if (seen.has(plan)) break;
|
|
22415
|
+
seen.add(plan);
|
|
22416
|
+
detections.push({
|
|
22295
22417
|
source: "claude-code",
|
|
22296
22418
|
plan,
|
|
22297
22419
|
raw,
|
|
22298
22420
|
confidence: "measured"
|
|
22299
|
-
};
|
|
22421
|
+
});
|
|
22422
|
+
break;
|
|
22423
|
+
}
|
|
22424
|
+
if (!mapped && ranked.length) {
|
|
22425
|
+
warnings.push(`plan_unmapped:claude-code:${ranked[0].raw}`);
|
|
22300
22426
|
}
|
|
22301
22427
|
}
|
|
22302
|
-
|
|
22303
|
-
return {
|
|
22304
|
-
warning: `plan_unmapped:claude-code:${ranked[0].raw}`
|
|
22305
|
-
};
|
|
22306
|
-
}
|
|
22307
|
-
return null;
|
|
22428
|
+
return { detections, warnings };
|
|
22308
22429
|
}
|
|
22309
22430
|
async function detectCodexPlan(home, env) {
|
|
22310
22431
|
const codexHome = env.CODEX_HOME?.trim() || join4(home, ".codex");
|
|
@@ -22349,6 +22470,10 @@ async function detectCursorPlan(home, env) {
|
|
|
22349
22470
|
CURSOR_MEMBERSHIP_KEY
|
|
22350
22471
|
);
|
|
22351
22472
|
if (!raw) return null;
|
|
22473
|
+
const normalized = raw.trim().toLowerCase().replace(/[\s-]+/g, "_");
|
|
22474
|
+
if (normalized === "free" || normalized === "hobby" || normalized === "free_trial" || normalized === "trial" || normalized === "enterprise" || normalized === "team" || normalized === "teams") {
|
|
22475
|
+
return null;
|
|
22476
|
+
}
|
|
22352
22477
|
const plan = mapCursorMembership(raw);
|
|
22353
22478
|
if (plan) {
|
|
22354
22479
|
return {
|
|
@@ -22364,9 +22489,11 @@ async function detectPlans(input2) {
|
|
|
22364
22489
|
const warnings = [];
|
|
22365
22490
|
const detections = [];
|
|
22366
22491
|
const allow = input2.sources ? new Set(input2.sources) : null;
|
|
22367
|
-
const claude = await
|
|
22368
|
-
|
|
22369
|
-
|
|
22492
|
+
const claude = await detectClaudePlans(input2.home, input2.env);
|
|
22493
|
+
warnings.push(...claude.warnings);
|
|
22494
|
+
for (const found of claude.detections) {
|
|
22495
|
+
if (!allow || allow.has("claude-code")) detections.push(found);
|
|
22496
|
+
}
|
|
22370
22497
|
const codex = await detectCodexPlan(input2.home, input2.env);
|
|
22371
22498
|
if (codex && "warning" in codex) warnings.push(codex.warning);
|
|
22372
22499
|
else if (codex && (!allow || allow.has("codex"))) detections.push(codex);
|
|
@@ -22385,18 +22512,26 @@ async function detectPlans(input2) {
|
|
|
22385
22512
|
function applyDetectedPlans(profile, detected, opts) {
|
|
22386
22513
|
const by_source = { ...profile.by_source ?? {} };
|
|
22387
22514
|
const provenance = { ...profile.provenance };
|
|
22515
|
+
const plansBySource = /* @__PURE__ */ new Map();
|
|
22388
22516
|
for (const d of detected.detections) {
|
|
22389
|
-
const
|
|
22517
|
+
const list = plansBySource.get(d.source) ?? [];
|
|
22518
|
+
if (!list.includes(d.plan)) list.push(d.plan);
|
|
22519
|
+
plansBySource.set(d.source, list);
|
|
22520
|
+
if (provenance[d.source] == null) provenance[d.source] = d.confidence;
|
|
22521
|
+
}
|
|
22522
|
+
for (const [source, planList] of plansBySource) {
|
|
22523
|
+
const prev = by_source[source];
|
|
22524
|
+
const plan = planList.length === 1 ? planList[0] : void 0;
|
|
22390
22525
|
if (prev) {
|
|
22391
|
-
by_source[
|
|
22392
|
-
} else {
|
|
22393
|
-
|
|
22526
|
+
by_source[source] = plan ? { ...prev, plan } : { ...prev };
|
|
22527
|
+
} else if (plan) {
|
|
22528
|
+
const sample = detected.detections.find((d) => d.source === source);
|
|
22529
|
+
by_source[source] = {
|
|
22394
22530
|
agent_hours: 0,
|
|
22395
|
-
provenance:
|
|
22396
|
-
plan
|
|
22531
|
+
provenance: sample?.confidence ?? "measured",
|
|
22532
|
+
plan
|
|
22397
22533
|
};
|
|
22398
22534
|
}
|
|
22399
|
-
if (provenance[d.source] == null) provenance[d.source] = d.confidence;
|
|
22400
22535
|
}
|
|
22401
22536
|
const plans = opts.cliPlans.length ? [...opts.cliPlans] : detected.plans.length ? [...detected.plans] : [...profile.plans];
|
|
22402
22537
|
return {
|
|
@@ -22408,7 +22543,7 @@ function applyDetectedPlans(profile, detected, opts) {
|
|
|
22408
22543
|
}
|
|
22409
22544
|
|
|
22410
22545
|
// src/scanner-config.ts
|
|
22411
|
-
import { mkdir, readFile as
|
|
22546
|
+
import { mkdir, readFile as readFile3, writeFile } from "node:fs/promises";
|
|
22412
22547
|
import { dirname, join as join5 } from "node:path";
|
|
22413
22548
|
var PlanIdRe = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
22414
22549
|
var ScannerConfigSchema = external_exports.strictObject({
|
|
@@ -22420,7 +22555,7 @@ function scannerConfigPath(home) {
|
|
|
22420
22555
|
}
|
|
22421
22556
|
async function loadScannerConfig(path2) {
|
|
22422
22557
|
try {
|
|
22423
|
-
const text = await
|
|
22558
|
+
const text = await readFile3(path2, "utf8");
|
|
22424
22559
|
const parsed = ScannerConfigSchema.safeParse(JSON.parse(text));
|
|
22425
22560
|
if (!parsed.success) return {};
|
|
22426
22561
|
const config2 = parsed.data;
|
|
@@ -22552,13 +22687,20 @@ async function askPrice(io, planId, config2) {
|
|
|
22552
22687
|
if (!billing) return null;
|
|
22553
22688
|
return declaredPrice({ amount, currency, billing });
|
|
22554
22689
|
}
|
|
22555
|
-
async function runInterview(profile, config2, io, args) {
|
|
22690
|
+
async function runInterview(profile, config2, io, args, opts) {
|
|
22556
22691
|
const warnings = [];
|
|
22557
22692
|
let next = { ...profile };
|
|
22558
22693
|
const saved = {
|
|
22559
22694
|
plans: [...config2.plans ?? []],
|
|
22560
22695
|
plan_prices: { ...config2.plan_prices ?? {} }
|
|
22561
22696
|
};
|
|
22697
|
+
if (opts?.askUnmapped && next.plans.length && !args.plans.length) {
|
|
22698
|
+
const extra = await askPlan(io, config2);
|
|
22699
|
+
if (extra && !next.plans.includes(extra)) {
|
|
22700
|
+
next = { ...next, plans: [...next.plans, extra].slice(0, 10) };
|
|
22701
|
+
saved.plans = [...next.plans];
|
|
22702
|
+
}
|
|
22703
|
+
}
|
|
22562
22704
|
if (!args.plans.length && !next.plans.length) {
|
|
22563
22705
|
const planId = await askPlan(io, config2);
|
|
22564
22706
|
if (planId) {
|
|
@@ -22585,7 +22727,7 @@ async function runInterview(profile, config2, io, args) {
|
|
|
22585
22727
|
}
|
|
22586
22728
|
return { profile: next, config: saved, warnings };
|
|
22587
22729
|
}
|
|
22588
|
-
async function withDeclaredPlans(profile, args, io) {
|
|
22730
|
+
async function withDeclaredPlans(profile, args, io, extra) {
|
|
22589
22731
|
const configPath = scannerConfigPath(io.home);
|
|
22590
22732
|
const config2 = await loadScannerConfig(configPath);
|
|
22591
22733
|
const warnings = [];
|
|
@@ -22598,9 +22740,10 @@ async function withDeclaredPlans(profile, args, io) {
|
|
|
22598
22740
|
const prefilled = applyConfigSilently(profile, config2);
|
|
22599
22741
|
const noPlans = !args.plans.length && !prefilled.plans.length;
|
|
22600
22742
|
const missingPrices = plansMissingPrice(prefilled, {});
|
|
22743
|
+
const askUnmapped = Boolean(extra?.unmapped) && !args.plans.length && prefilled.plans.length > 0;
|
|
22601
22744
|
let next = profile;
|
|
22602
|
-
if (noPlans || missingPrices.length > 0) {
|
|
22603
|
-
const interviewed = await runInterview(next, config2, io, args);
|
|
22745
|
+
if (noPlans || missingPrices.length > 0 || askUnmapped) {
|
|
22746
|
+
const interviewed = await runInterview(next, config2, io, args, { askUnmapped });
|
|
22604
22747
|
next = interviewed.profile;
|
|
22605
22748
|
warnings.push(...interviewed.warnings);
|
|
22606
22749
|
if (interviewed.config.plans?.length || interviewed.config.plan_prices && Object.keys(interviewed.config.plan_prices).length > 0) {
|
|
@@ -22618,7 +22761,7 @@ async function withDeclaredPlans(profile, args, io) {
|
|
|
22618
22761
|
|
|
22619
22762
|
// src/cursor-usage.ts
|
|
22620
22763
|
import { readdir as readdir3, stat } from "node:fs/promises";
|
|
22621
|
-
import { join as join6 } from "node:path";
|
|
22764
|
+
import { join as join6, relative, sep } from "node:path";
|
|
22622
22765
|
function birthMs(st) {
|
|
22623
22766
|
const b = st.birthtimeMs;
|
|
22624
22767
|
if (Number.isFinite(b) && b > 0) return b;
|
|
@@ -22658,7 +22801,7 @@ async function fromTranscripts(projectsDir, bounds, offsetMinutes, agg) {
|
|
|
22658
22801
|
} catch {
|
|
22659
22802
|
return 0;
|
|
22660
22803
|
}
|
|
22661
|
-
|
|
22804
|
+
const groups = /* @__PURE__ */ new Map();
|
|
22662
22805
|
for (const project of projectEntries) {
|
|
22663
22806
|
if (!project.isDirectory()) continue;
|
|
22664
22807
|
const transcriptsRoot = join6(
|
|
@@ -22687,21 +22830,35 @@ async function fromTranscripts(projectsDir, bounds, offsetMinutes, agg) {
|
|
|
22687
22830
|
if (!overlaps(start, end, bounds)) continue;
|
|
22688
22831
|
const clipped = clip(start, end, bounds);
|
|
22689
22832
|
if (!(clipped.end > clipped.start)) continue;
|
|
22690
|
-
|
|
22691
|
-
|
|
22692
|
-
|
|
22693
|
-
|
|
22694
|
-
|
|
22695
|
-
|
|
22696
|
-
|
|
22697
|
-
weight: 1
|
|
22698
|
-
},
|
|
22699
|
-
offsetMinutes
|
|
22700
|
-
);
|
|
22701
|
-
added += 1;
|
|
22833
|
+
const key = conversationKey(transcriptsRoot, file2);
|
|
22834
|
+
const prev = groups.get(key);
|
|
22835
|
+
if (!prev) groups.set(key, { start: clipped.start, end: clipped.end });
|
|
22836
|
+
else {
|
|
22837
|
+
prev.start = Math.min(prev.start, clipped.start);
|
|
22838
|
+
prev.end = Math.max(prev.end, clipped.end);
|
|
22839
|
+
}
|
|
22702
22840
|
}
|
|
22703
22841
|
}
|
|
22704
|
-
|
|
22842
|
+
for (const [key, span] of groups) {
|
|
22843
|
+
addSessionSpan(
|
|
22844
|
+
agg,
|
|
22845
|
+
{
|
|
22846
|
+
session: hashKey(key),
|
|
22847
|
+
start: span.start,
|
|
22848
|
+
end: span.end,
|
|
22849
|
+
model: "composer",
|
|
22850
|
+
weight: 1
|
|
22851
|
+
},
|
|
22852
|
+
offsetMinutes
|
|
22853
|
+
);
|
|
22854
|
+
}
|
|
22855
|
+
return groups.size;
|
|
22856
|
+
}
|
|
22857
|
+
function conversationKey(transcriptsRoot, file2) {
|
|
22858
|
+
const rel = relative(transcriptsRoot, file2);
|
|
22859
|
+
const parts = rel.split(sep).filter((part) => part && part !== ".");
|
|
22860
|
+
const folder = parts.length > 1 ? parts[0] : parts[0]?.replace(/\.jsonl$/, "") ?? rel;
|
|
22861
|
+
return `${transcriptsRoot}${sep}${folder}`;
|
|
22705
22862
|
}
|
|
22706
22863
|
async function fromTrackingDb(dbPath, bounds, offsetMinutes, agg) {
|
|
22707
22864
|
const sql = `
|
|
@@ -22928,6 +23085,402 @@ function renderPreview(profile, meta3) {
|
|
|
22928
23085
|
return lines.join("\n");
|
|
22929
23086
|
}
|
|
22930
23087
|
|
|
23088
|
+
// src/local-hours.ts
|
|
23089
|
+
import { readdir as readdir4, readFile as readFile4, stat as stat2 } from "node:fs/promises";
|
|
23090
|
+
import { join as join7 } from "node:path";
|
|
23091
|
+
var MIN_MS = 6e4;
|
|
23092
|
+
var CAP_MS = 8 * 36e5;
|
|
23093
|
+
var round1 = (n) => Math.round(n * 10) / 10;
|
|
23094
|
+
function roundHours2(ms) {
|
|
23095
|
+
const hours = ms / 36e5;
|
|
23096
|
+
return hours > 0 ? Math.max(0.1, round1(hours)) : 0;
|
|
23097
|
+
}
|
|
23098
|
+
function summarizeSpans(spans, bounds, offsetMinutes) {
|
|
23099
|
+
const days = /* @__PURE__ */ new Set();
|
|
23100
|
+
let ms = 0;
|
|
23101
|
+
let sessions = 0;
|
|
23102
|
+
for (const span of spans) {
|
|
23103
|
+
const start = Math.max(bounds.start, Math.min(span.start, span.end));
|
|
23104
|
+
const end = Math.min(bounds.end, Math.max(span.start, span.end));
|
|
23105
|
+
if (!(end >= bounds.start && start < bounds.end)) continue;
|
|
23106
|
+
if (end < start) continue;
|
|
23107
|
+
const overlap = Math.max(0, end - start);
|
|
23108
|
+
let duration3 = overlap;
|
|
23109
|
+
if (duration3 < MIN_MS) duration3 = MIN_MS;
|
|
23110
|
+
if (duration3 > CAP_MS) duration3 = CAP_MS;
|
|
23111
|
+
ms += duration3;
|
|
23112
|
+
sessions += 1;
|
|
23113
|
+
const last = Math.min(bounds.end - 1, start + duration3 - 1);
|
|
23114
|
+
for (let t = start; t <= last; t += 36e5) {
|
|
23115
|
+
days.add(localDay(t, offsetMinutes));
|
|
23116
|
+
if (days.size > 400) break;
|
|
23117
|
+
}
|
|
23118
|
+
days.add(localDay(last, offsetMinutes));
|
|
23119
|
+
}
|
|
23120
|
+
return { hours: roundHours2(ms), activeDays: days.size, sessions };
|
|
23121
|
+
}
|
|
23122
|
+
function safeModel(value) {
|
|
23123
|
+
const name = value.trim();
|
|
23124
|
+
if (!name || name.length > 80 || name.startsWith("<")) return null;
|
|
23125
|
+
if (name.startsWith("/") || name.startsWith("~") || name.includes("\\") || name.includes("..")) {
|
|
23126
|
+
return null;
|
|
23127
|
+
}
|
|
23128
|
+
return name;
|
|
23129
|
+
}
|
|
23130
|
+
function addFamily(into, model, part) {
|
|
23131
|
+
const family = modelFamily(model);
|
|
23132
|
+
const prev = into.get(family) ?? {
|
|
23133
|
+
model: family,
|
|
23134
|
+
input: 0,
|
|
23135
|
+
output: 0,
|
|
23136
|
+
cache_read: 0,
|
|
23137
|
+
cache_write: 0
|
|
23138
|
+
};
|
|
23139
|
+
prev.input += part.input;
|
|
23140
|
+
prev.output += part.output;
|
|
23141
|
+
prev.cache_read += part.cache_read;
|
|
23142
|
+
prev.cache_write += part.cache_write;
|
|
23143
|
+
into.set(family, prev);
|
|
23144
|
+
}
|
|
23145
|
+
function rowsOf3(map2) {
|
|
23146
|
+
const rows = [...map2.values()].map((row) => ({
|
|
23147
|
+
...row,
|
|
23148
|
+
input: Math.round(row.input),
|
|
23149
|
+
output: Math.round(row.output),
|
|
23150
|
+
cache_read: Math.round(row.cache_read),
|
|
23151
|
+
cache_write: Math.round(row.cache_write)
|
|
23152
|
+
})).filter((row) => row.input + row.output + row.cache_read + row.cache_write > 0);
|
|
23153
|
+
return rows.length ? rows : void 0;
|
|
23154
|
+
}
|
|
23155
|
+
function kimiHomes(home) {
|
|
23156
|
+
return [join7(home, ".kimi-code"), join7(home, ".kimi")];
|
|
23157
|
+
}
|
|
23158
|
+
function epochField(text, key) {
|
|
23159
|
+
const match = new RegExp(`"${key}"\\s*:\\s*(\\d{10,16})`).exec(text);
|
|
23160
|
+
if (!match) return null;
|
|
23161
|
+
const n = Number(match[1]);
|
|
23162
|
+
return Number.isFinite(n) ? n : null;
|
|
23163
|
+
}
|
|
23164
|
+
async function walkFiles(dir, depth, visit2, accept) {
|
|
23165
|
+
if (depth > 6) return;
|
|
23166
|
+
let entries;
|
|
23167
|
+
try {
|
|
23168
|
+
entries = await readdir4(dir, { withFileTypes: true });
|
|
23169
|
+
} catch {
|
|
23170
|
+
return;
|
|
23171
|
+
}
|
|
23172
|
+
for (const entry of entries) {
|
|
23173
|
+
if (entry.isSymbolicLink()) continue;
|
|
23174
|
+
if (entry.name === "node_modules" || entry.name === ".git" || entry.name === "skills") {
|
|
23175
|
+
continue;
|
|
23176
|
+
}
|
|
23177
|
+
const path2 = join7(dir, entry.name);
|
|
23178
|
+
if (entry.isDirectory()) await walkFiles(path2, depth + 1, visit2, accept);
|
|
23179
|
+
else if (entry.isFile() && accept(entry.name)) await visit2(path2);
|
|
23180
|
+
}
|
|
23181
|
+
}
|
|
23182
|
+
async function readKimiFill(home, bounds, offsetMinutes) {
|
|
23183
|
+
const spans = [];
|
|
23184
|
+
for (const root of kimiHomes(home)) {
|
|
23185
|
+
await walkFiles(join7(root, "sessions"), 0, async (file2) => {
|
|
23186
|
+
let text;
|
|
23187
|
+
try {
|
|
23188
|
+
text = await readFile4(file2, "utf8");
|
|
23189
|
+
} catch {
|
|
23190
|
+
return;
|
|
23191
|
+
}
|
|
23192
|
+
const created = epochField(text, "createdAt");
|
|
23193
|
+
const updated = epochField(text, "updatedAt");
|
|
23194
|
+
if (created == null || updated == null) return;
|
|
23195
|
+
spans.push({ start: Math.min(created, updated), end: Math.max(created, updated) });
|
|
23196
|
+
}, (name) => name === "state.json");
|
|
23197
|
+
}
|
|
23198
|
+
const stats = summarizeSpans(spans, bounds, offsetMinutes);
|
|
23199
|
+
if (stats.hours <= 0 && stats.activeDays <= 0) return null;
|
|
23200
|
+
return { source: "kimi-cli", ...stats };
|
|
23201
|
+
}
|
|
23202
|
+
async function readOpenCodeFill(home, bounds, offsetMinutes) {
|
|
23203
|
+
const db = join7(home, ".local", "share", "opencode", "opencode.db");
|
|
23204
|
+
const sql = `
|
|
23205
|
+
SELECT time_created, time_updated,
|
|
23206
|
+
COALESCE(tokens_input, 0), COALESCE(tokens_output, 0),
|
|
23207
|
+
COALESCE(tokens_reasoning, 0), COALESCE(tokens_cache_read, 0),
|
|
23208
|
+
COALESCE(tokens_cache_write, 0), COALESCE(model, '')
|
|
23209
|
+
FROM session_v2
|
|
23210
|
+
WHERE time_created < ${Math.floor(bounds.end)}
|
|
23211
|
+
AND time_updated >= ${Math.floor(bounds.start)}
|
|
23212
|
+
`.trim();
|
|
23213
|
+
let rows = await querySqliteStrings(db, sql);
|
|
23214
|
+
let withModel = true;
|
|
23215
|
+
if (!rows) {
|
|
23216
|
+
withModel = false;
|
|
23217
|
+
rows = await querySqliteStrings(
|
|
23218
|
+
db,
|
|
23219
|
+
`SELECT time_created, time_updated FROM session
|
|
23220
|
+
WHERE time_created < ${Math.floor(bounds.end)}
|
|
23221
|
+
AND time_updated >= ${Math.floor(bounds.start)}`
|
|
23222
|
+
);
|
|
23223
|
+
}
|
|
23224
|
+
if (!rows?.length) return null;
|
|
23225
|
+
const spans = [];
|
|
23226
|
+
const tokens = /* @__PURE__ */ new Map();
|
|
23227
|
+
for (const row of rows) {
|
|
23228
|
+
const created = Number(row[0]);
|
|
23229
|
+
const updated = Number(row[1]);
|
|
23230
|
+
if (!Number.isFinite(created) || !Number.isFinite(updated)) continue;
|
|
23231
|
+
spans.push({ start: Math.min(created, updated), end: Math.max(created, updated) });
|
|
23232
|
+
if (!withModel) continue;
|
|
23233
|
+
const model = safeModel(row[7] ?? "");
|
|
23234
|
+
if (!model) continue;
|
|
23235
|
+
const reasoning = Number(row[4]) || 0;
|
|
23236
|
+
addFamily(tokens, model, {
|
|
23237
|
+
input: Number(row[2]) || 0,
|
|
23238
|
+
output: (Number(row[3]) || 0) + reasoning,
|
|
23239
|
+
cache_read: Number(row[5]) || 0,
|
|
23240
|
+
cache_write: Number(row[6]) || 0
|
|
23241
|
+
});
|
|
23242
|
+
}
|
|
23243
|
+
const stats = summarizeSpans(spans, bounds, offsetMinutes);
|
|
23244
|
+
if (stats.hours <= 0) return null;
|
|
23245
|
+
return { source: "opencode", ...stats, tokens: rowsOf3(tokens) };
|
|
23246
|
+
}
|
|
23247
|
+
async function readCodexHourFill(env, home, bounds, offsetMinutes) {
|
|
23248
|
+
const logs = await readCodexLogs(codexHomeDir(env, home), bounds, offsetMinutes);
|
|
23249
|
+
const fromUsage = summarizeSpans(spansOf(logs), bounds, offsetMinutes);
|
|
23250
|
+
const stats = fromUsage.hours > 0 ? fromUsage : summarizeSpans(await codexFileSpans(codexHomeDir(env, home)), bounds, offsetMinutes);
|
|
23251
|
+
if (stats.hours <= 0) return null;
|
|
23252
|
+
return { source: "codex", ...stats };
|
|
23253
|
+
}
|
|
23254
|
+
function spansOf(logs) {
|
|
23255
|
+
return [...logs.sessions.values()].map((session) => ({
|
|
23256
|
+
start: session.start,
|
|
23257
|
+
end: session.end
|
|
23258
|
+
}));
|
|
23259
|
+
}
|
|
23260
|
+
async function codexFileSpans(home) {
|
|
23261
|
+
const spans = [];
|
|
23262
|
+
const files = [];
|
|
23263
|
+
for (const sub of ["sessions", "archived_sessions"]) {
|
|
23264
|
+
await walkFiles(join7(home, sub), 0, async (file2) => {
|
|
23265
|
+
files.push(file2);
|
|
23266
|
+
}, (name) => name.startsWith("rollout-") && name.endsWith(".jsonl"));
|
|
23267
|
+
}
|
|
23268
|
+
for (const file2 of files) {
|
|
23269
|
+
let text;
|
|
23270
|
+
try {
|
|
23271
|
+
text = await readFile4(file2, "utf8");
|
|
23272
|
+
} catch {
|
|
23273
|
+
continue;
|
|
23274
|
+
}
|
|
23275
|
+
let min = Number.POSITIVE_INFINITY;
|
|
23276
|
+
let max = 0;
|
|
23277
|
+
for (const line of text.split("\n")) {
|
|
23278
|
+
if (!line.includes('"timestamp"') || line.includes('"response_item"')) continue;
|
|
23279
|
+
const match = /"timestamp"\s*:\s*"([^"]+)"/.exec(line);
|
|
23280
|
+
if (!match) continue;
|
|
23281
|
+
const at = Date.parse(match[1]);
|
|
23282
|
+
if (Number.isNaN(at)) continue;
|
|
23283
|
+
if (at < min) min = at;
|
|
23284
|
+
if (at > max) max = at;
|
|
23285
|
+
}
|
|
23286
|
+
if (max > min) spans.push({ start: min, end: max });
|
|
23287
|
+
}
|
|
23288
|
+
return spans;
|
|
23289
|
+
}
|
|
23290
|
+
async function readGeminiFill(home, bounds, offsetMinutes) {
|
|
23291
|
+
const root = join7(home, ".gemini", "tmp");
|
|
23292
|
+
const spans = [];
|
|
23293
|
+
const tokens = /* @__PURE__ */ new Map();
|
|
23294
|
+
await walkFiles(root, 0, async (file2) => {
|
|
23295
|
+
const lower = file2.toLowerCase();
|
|
23296
|
+
if (lower.endsWith(".json") || lower.endsWith(".jsonl")) {
|
|
23297
|
+
await geminiFile(file2, spans, tokens);
|
|
23298
|
+
return;
|
|
23299
|
+
}
|
|
23300
|
+
const clock = await fileSpan(file2);
|
|
23301
|
+
if (clock) spans.push(clock);
|
|
23302
|
+
}, (name) => {
|
|
23303
|
+
if (name === "projects.json" || name.startsWith("settings")) return false;
|
|
23304
|
+
return name.endsWith(".json") || name.endsWith(".jsonl") || name.endsWith(".log");
|
|
23305
|
+
});
|
|
23306
|
+
const stats = summarizeSpans(spans, bounds, offsetMinutes);
|
|
23307
|
+
if (stats.hours <= 0 && stats.activeDays <= 0) return null;
|
|
23308
|
+
return { source: "gemini-cli", ...stats, tokens: rowsOf3(tokens) };
|
|
23309
|
+
}
|
|
23310
|
+
async function geminiFile(file2, spans, tokens) {
|
|
23311
|
+
let text;
|
|
23312
|
+
try {
|
|
23313
|
+
text = await readFile4(file2, "utf8");
|
|
23314
|
+
} catch {
|
|
23315
|
+
return;
|
|
23316
|
+
}
|
|
23317
|
+
const times = [];
|
|
23318
|
+
const takeTime = (raw) => {
|
|
23319
|
+
const at = /^\d{10,16}$/.test(raw) ? Number(raw) : Date.parse(raw);
|
|
23320
|
+
if (!Number.isNaN(at) && at > 1e12) times.push(at);
|
|
23321
|
+
else if (!Number.isNaN(at) && at > 1e9) times.push(at * 1e3);
|
|
23322
|
+
};
|
|
23323
|
+
for (const match of text.matchAll(/"(?:timestamp|createdAt|updatedAt|startTime|endTime|firstActivity|lastActivity)"\s*:\s*"?([^",}\s]+)"?/g)) {
|
|
23324
|
+
takeTime(match[1] ?? "");
|
|
23325
|
+
}
|
|
23326
|
+
const usage = /"(?:usage|tokens)"\s*:\s*\{([^}]{0,400})\}/.exec(text);
|
|
23327
|
+
if (usage) {
|
|
23328
|
+
const body = usage[1] ?? "";
|
|
23329
|
+
const num2 = (key) => {
|
|
23330
|
+
const found = new RegExp(`"${key}"\\s*:\\s*(\\d+)`).exec(body);
|
|
23331
|
+
return found ? Number(found[1]) : 0;
|
|
23332
|
+
};
|
|
23333
|
+
const modelMatch = /"(?:model|modelName|modelId)"\s*:\s*"([^"]+)"/.exec(text);
|
|
23334
|
+
const model = modelMatch ? safeModel(modelMatch[1] ?? "") : null;
|
|
23335
|
+
if (model) {
|
|
23336
|
+
addFamily(tokens, model, {
|
|
23337
|
+
input: num2("input") || num2("inputTokens") || num2("input_tokens"),
|
|
23338
|
+
output: num2("output") || num2("outputTokens") || num2("output_tokens"),
|
|
23339
|
+
cache_read: num2("cacheRead") || num2("cache_read") || num2("cacheReadTokens"),
|
|
23340
|
+
cache_write: num2("cacheWrite") || num2("cache_write") || num2("cacheCreationTokens")
|
|
23341
|
+
});
|
|
23342
|
+
}
|
|
23343
|
+
}
|
|
23344
|
+
if (times.length >= 1) {
|
|
23345
|
+
const start = Math.min(...times);
|
|
23346
|
+
const end = Math.max(...times);
|
|
23347
|
+
spans.push({ start, end: end > start ? end : start + MIN_MS });
|
|
23348
|
+
return;
|
|
23349
|
+
}
|
|
23350
|
+
const clock = await fileSpan(file2);
|
|
23351
|
+
if (clock) spans.push(clock);
|
|
23352
|
+
}
|
|
23353
|
+
async function fileSpan(file2) {
|
|
23354
|
+
try {
|
|
23355
|
+
const st = await stat2(file2);
|
|
23356
|
+
if (st.size <= 0) return null;
|
|
23357
|
+
const birth = st.birthtimeMs > 0 ? st.birthtimeMs : st.mtimeMs;
|
|
23358
|
+
const start = Math.min(birth, st.mtimeMs);
|
|
23359
|
+
const end = Math.max(birth, st.mtimeMs);
|
|
23360
|
+
return { start, end: end > start ? end : start + MIN_MS };
|
|
23361
|
+
} catch {
|
|
23362
|
+
return null;
|
|
23363
|
+
}
|
|
23364
|
+
}
|
|
23365
|
+
async function readAntigravityFill(home, bounds, offsetMinutes) {
|
|
23366
|
+
const root = join7(home, ".gemini", "antigravity");
|
|
23367
|
+
const spans = [];
|
|
23368
|
+
for (const sub of ["conversations", "implicit"]) {
|
|
23369
|
+
await walkFiles(join7(root, sub), 0, async (file2) => {
|
|
23370
|
+
const clock = await fileSpan(file2);
|
|
23371
|
+
if (clock) spans.push(clock);
|
|
23372
|
+
}, (name) => name.endsWith(".pb") || name.endsWith(".json"));
|
|
23373
|
+
}
|
|
23374
|
+
const stats = summarizeSpans(spans, bounds, offsetMinutes);
|
|
23375
|
+
if (stats.hours <= 0 && stats.activeDays <= 0) return null;
|
|
23376
|
+
return { source: "antigravity", ...stats };
|
|
23377
|
+
}
|
|
23378
|
+
function sharesOf(rows) {
|
|
23379
|
+
const work2 = (row) => row.input + row.output + row.cache_write;
|
|
23380
|
+
const total = rows.reduce((sum, row) => sum + work2(row), 0);
|
|
23381
|
+
const value = {};
|
|
23382
|
+
if (total <= 0) return value;
|
|
23383
|
+
for (const row of rows) {
|
|
23384
|
+
value[row.model] = Math.round(work2(row) / total * 1e3) / 1e3;
|
|
23385
|
+
}
|
|
23386
|
+
const entries = Object.entries(value);
|
|
23387
|
+
if (!entries.length) return value;
|
|
23388
|
+
const largest = entries.reduce((a, b) => b[1] > a[1] ? b : a);
|
|
23389
|
+
const drift = 1 - entries.reduce((sum, [, v]) => sum + v, 0);
|
|
23390
|
+
value[largest[0]] = Math.round(((value[largest[0]] ?? 0) + drift) * 1e3) / 1e3;
|
|
23391
|
+
return value;
|
|
23392
|
+
}
|
|
23393
|
+
function mergeTokens(profile, extra, source) {
|
|
23394
|
+
const map2 = /* @__PURE__ */ new Map();
|
|
23395
|
+
for (const row of profile.tokens?.value ?? []) map2.set(row.model, { ...row });
|
|
23396
|
+
for (const row of extra) {
|
|
23397
|
+
const prev = map2.get(row.model) ?? {
|
|
23398
|
+
model: row.model,
|
|
23399
|
+
input: 0,
|
|
23400
|
+
output: 0,
|
|
23401
|
+
cache_read: 0,
|
|
23402
|
+
cache_write: 0
|
|
23403
|
+
};
|
|
23404
|
+
prev.input += row.input;
|
|
23405
|
+
prev.output += row.output;
|
|
23406
|
+
prev.cache_read += row.cache_read;
|
|
23407
|
+
prev.cache_write += row.cache_write;
|
|
23408
|
+
map2.set(row.model, prev);
|
|
23409
|
+
}
|
|
23410
|
+
const rows = [...map2.values()];
|
|
23411
|
+
if (!rows.length) return profile;
|
|
23412
|
+
const next = {
|
|
23413
|
+
...profile,
|
|
23414
|
+
tokens: { value: rows, provenance: "estimated", source },
|
|
23415
|
+
by_model: { value: sharesOf(rows), provenance: "estimated", source }
|
|
23416
|
+
};
|
|
23417
|
+
if (!next.models_count || rows.length > next.models_count.value) {
|
|
23418
|
+
next.models_count = { value: rows.length, provenance: "estimated", source };
|
|
23419
|
+
}
|
|
23420
|
+
return next;
|
|
23421
|
+
}
|
|
23422
|
+
function applyHourFills(profile, fills) {
|
|
23423
|
+
const useful = fills.filter((fill) => fill.hours > 0);
|
|
23424
|
+
if (!useful.length) return profile;
|
|
23425
|
+
let next = profile;
|
|
23426
|
+
for (const fill of useful) {
|
|
23427
|
+
const prev = next.by_source?.[fill.source];
|
|
23428
|
+
if (prev && prev.agent_hours > 0) continue;
|
|
23429
|
+
const by_source = { ...next.by_source ?? {} };
|
|
23430
|
+
const dayCap = periodDays(next.period) ?? 366;
|
|
23431
|
+
by_source[fill.source] = {
|
|
23432
|
+
agent_hours: fill.hours,
|
|
23433
|
+
provenance: "estimated",
|
|
23434
|
+
active_days: Math.min(dayCap, Math.max(prev?.active_days ?? 0, fill.activeDays)) || void 0,
|
|
23435
|
+
sessions: fill.sessions > 0 ? fill.sessions : prev?.sessions,
|
|
23436
|
+
plan: prev?.plan
|
|
23437
|
+
};
|
|
23438
|
+
const provenance = { ...next.provenance };
|
|
23439
|
+
provenance[fill.source] = "estimated";
|
|
23440
|
+
const agent_hours = {
|
|
23441
|
+
...next.agent_hours,
|
|
23442
|
+
value: round1(next.agent_hours.value + fill.hours),
|
|
23443
|
+
provenance: "estimated"
|
|
23444
|
+
};
|
|
23445
|
+
const draft = { ...next, by_source, provenance, agent_hours };
|
|
23446
|
+
const days = Math.min(fill.activeDays, dayCap);
|
|
23447
|
+
if (days > (next.active_days?.value ?? 0)) {
|
|
23448
|
+
draft.active_days = {
|
|
23449
|
+
value: days,
|
|
23450
|
+
provenance: "estimated",
|
|
23451
|
+
source: next.active_days?.source ?? fill.source
|
|
23452
|
+
};
|
|
23453
|
+
}
|
|
23454
|
+
next = draft;
|
|
23455
|
+
if (!prev && fill.tokens?.length) next = mergeTokens(next, fill.tokens, fill.source);
|
|
23456
|
+
}
|
|
23457
|
+
const dominant = dominantSource(next.by_source ?? {}, next.provenance);
|
|
23458
|
+
const labeled = { ...next };
|
|
23459
|
+
if (labeled.agent_hours.source !== dominant) {
|
|
23460
|
+
labeled.agent_hours = { ...labeled.agent_hours, source: dominant };
|
|
23461
|
+
}
|
|
23462
|
+
if (labeled.activity) labeled.activity = { ...labeled.activity, source: dominant };
|
|
23463
|
+
if (labeled.by_model) labeled.by_model = { ...labeled.by_model, source: dominant };
|
|
23464
|
+
if (labeled.active_days) labeled.active_days = { ...labeled.active_days, source: dominant };
|
|
23465
|
+
if (labeled.sessions && labeled.sessions.provenance === "measured") {
|
|
23466
|
+
labeled.sessions = { ...labeled.sessions, source: dominant };
|
|
23467
|
+
}
|
|
23468
|
+
if (labeled.tokens && next.tokens?.provenance === "estimated" && !profile.tokens) {
|
|
23469
|
+
labeled.tokens = { ...labeled.tokens, source: dominant };
|
|
23470
|
+
}
|
|
23471
|
+
if (labeled.models_count) labeled.models_count = { ...labeled.models_count, source: dominant };
|
|
23472
|
+
for (const key of METRIC_KEYS) {
|
|
23473
|
+
const metric = labeled[key];
|
|
23474
|
+
if (!metric) continue;
|
|
23475
|
+
if (labeled.provenance[metric.source] !== "estimated") continue;
|
|
23476
|
+
if (metric.provenance !== "measured") continue;
|
|
23477
|
+
const dominantMethod = labeled.provenance[dominant];
|
|
23478
|
+
labeled[key] = dominantMethod === "measured" ? { ...metric, source: dominant } : { ...metric, source: dominant, provenance: "estimated" };
|
|
23479
|
+
}
|
|
23480
|
+
const parsed = parseProfile(labeled);
|
|
23481
|
+
return parsed.ok ? parsed.profile : profile;
|
|
23482
|
+
}
|
|
23483
|
+
|
|
22931
23484
|
// src/scan.ts
|
|
22932
23485
|
var CCUSAGE_READER = "npx ccusage@latest daily|session --json --by-agent y blocks --offline --breakdown";
|
|
22933
23486
|
var PROMPT = "Open the verdict in the browser? [y/N] ";
|
|
@@ -22984,7 +23537,7 @@ async function fromLocalClaude(args, io, offset, extraWarnings) {
|
|
|
22984
23537
|
{ path: "period", message: "invalid period" }
|
|
22985
23538
|
]);
|
|
22986
23539
|
}
|
|
22987
|
-
const logs = await readClaudeLogs(claudeConfigDirs(io.env, io.home), bounds, offset);
|
|
23540
|
+
const logs = await readClaudeLogs(await claudeConfigDirs(io.env, io.home), bounds, offset);
|
|
22988
23541
|
const local = assembleProfile({
|
|
22989
23542
|
period: args.period,
|
|
22990
23543
|
plans: args.plans,
|
|
@@ -23030,9 +23583,8 @@ async function maybeMergeLocalCodex(profile, args, io, offset, warnings) {
|
|
|
23030
23583
|
};
|
|
23031
23584
|
}
|
|
23032
23585
|
async function maybeMergeLocalCursor(profile, args, io, offset, warnings) {
|
|
23033
|
-
|
|
23034
|
-
|
|
23035
|
-
}
|
|
23586
|
+
const cursorHours = profile.by_source?.cursor?.agent_hours ?? 0;
|
|
23587
|
+
if (cursorHours > 0) return { profile, warnings };
|
|
23036
23588
|
const bounds = boundsOf(args.period, offset);
|
|
23037
23589
|
if (!bounds) return { profile, warnings };
|
|
23038
23590
|
const logs = await readCursorUsage(io.env, io.home, bounds, offset);
|
|
@@ -23047,6 +23599,7 @@ async function maybeMergeLocalCursor(profile, args, io, offset, warnings) {
|
|
|
23047
23599
|
source: "cursor",
|
|
23048
23600
|
utcOffsetMinutes: offset,
|
|
23049
23601
|
estimateTokens: true,
|
|
23602
|
+
estimateTime: true,
|
|
23050
23603
|
limitHitsKnown: true,
|
|
23051
23604
|
extraWarnings: [
|
|
23052
23605
|
"cursor_experimental",
|
|
@@ -23156,6 +23709,26 @@ async function withDetectedPlans(profile, args, io, warnings) {
|
|
|
23156
23709
|
warnings: [...warnings, ...detected.warnings]
|
|
23157
23710
|
};
|
|
23158
23711
|
}
|
|
23712
|
+
async function fillZeroHours(profile, args, io, offset) {
|
|
23713
|
+
const bounds = boundsOf(args.period, offset);
|
|
23714
|
+
if (!bounds) return profile;
|
|
23715
|
+
const missing = (source) => {
|
|
23716
|
+
const slice = profile.by_source?.[source];
|
|
23717
|
+
return !slice || slice.agent_hours <= 0;
|
|
23718
|
+
};
|
|
23719
|
+
const fills = [];
|
|
23720
|
+
const take = async (source, read) => {
|
|
23721
|
+
if (!missing(source)) return;
|
|
23722
|
+
const fill = await read();
|
|
23723
|
+
if (fill) fills.push(fill);
|
|
23724
|
+
};
|
|
23725
|
+
await take("opencode", () => readOpenCodeFill(io.home, bounds, offset));
|
|
23726
|
+
await take("kimi-cli", () => readKimiFill(io.home, bounds, offset));
|
|
23727
|
+
await take("codex", () => readCodexHourFill(io.env, io.home, bounds, offset));
|
|
23728
|
+
await take("gemini-cli", () => readGeminiFill(io.home, bounds, offset));
|
|
23729
|
+
await take("antigravity", () => readAntigravityFill(io.home, bounds, offset));
|
|
23730
|
+
return applyHourFills(profile, fills);
|
|
23731
|
+
}
|
|
23159
23732
|
async function maybeOpen(args, io, url2) {
|
|
23160
23733
|
if (args.noOpen) return;
|
|
23161
23734
|
const openNow = args.yes || (args.json ? false : io.isTTY && accepted(await io.prompt(PROMPT)));
|
|
@@ -23190,16 +23763,20 @@ async function runScan(argv, io) {
|
|
|
23190
23763
|
io.stderr(renderFailure(args.period, assembled.issues, assembled.warnings));
|
|
23191
23764
|
return 1;
|
|
23192
23765
|
}
|
|
23766
|
+
const timed = await fillZeroHours(assembled.profile, args, io, offset);
|
|
23193
23767
|
const enriched = await withDetectedPlans(
|
|
23194
|
-
|
|
23768
|
+
timed,
|
|
23195
23769
|
args,
|
|
23196
23770
|
io,
|
|
23197
23771
|
assembled.warnings
|
|
23198
23772
|
);
|
|
23199
|
-
const declared = await withDeclaredPlans(enriched.profile, args, io
|
|
23773
|
+
const declared = await withDeclaredPlans(enriched.profile, args, io, {
|
|
23774
|
+
unmapped: enriched.warnings.some((warning) => warning.startsWith("plan_unmapped:"))
|
|
23775
|
+
});
|
|
23200
23776
|
const profile = declared.profile;
|
|
23201
23777
|
const scanWarnings = [...enriched.warnings, ...declared.warnings];
|
|
23202
|
-
const
|
|
23778
|
+
const lang = args.lang ?? verdictLangFromEnv(io.env);
|
|
23779
|
+
const url2 = verdictUrl(args.baseUrl, profileToHash(profile), lang);
|
|
23203
23780
|
if (args.json) {
|
|
23204
23781
|
io.stdout(`${JSON.stringify(profile, null, 2)}
|
|
23205
23782
|
`);
|