tokenusage-cli 0.1.0 → 0.2.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/CHANGELOG.md +46 -19
- package/LICENSE +22 -22
- package/README.md +123 -94
- package/THIRD_PARTY_NOTICES.md +140 -140
- package/bin/tokenusage.js +69 -69
- package/package.json +59 -59
- package/src/cli.js +146 -134
- package/src/commands/device-login.js +205 -205
- package/src/commands/diagnostics.js +38 -38
- package/src/commands/doctor.js +110 -110
- package/src/commands/init.js +2484 -2436
- package/src/commands/pause.js +77 -0
- package/src/commands/sessions.js +29 -29
- package/src/commands/status.js +1758 -1747
- package/src/commands/sync.js +8048 -7934
- package/src/commands/uninstall.js +322 -312
- package/src/lib/account-usage-dedup.js +267 -267
- package/src/lib/antigravity-paths.js +48 -48
- package/src/lib/ark-agent-plan-limits.js +438 -438
- package/src/lib/ark-coding-plan-limits.js +537 -537
- package/src/lib/async-queue-reader.js +138 -138
- package/src/lib/atomic-json.js +27 -27
- package/src/lib/bearer-token.js +11 -11
- package/src/lib/categorizer-utils.js +232 -232
- package/src/lib/claude-categorizer.js +1343 -1343
- package/src/lib/claude-config.js +279 -279
- package/src/lib/claude-user-identity.js +56 -56
- package/src/lib/cli-ui.js +179 -179
- package/src/lib/cloud-account.js +541 -541
- package/src/lib/cloud-device-token.js +141 -141
- package/src/lib/cloud-sync-prefs.js +14 -14
- package/src/lib/cloud-usage-reset.js +115 -115
- package/src/lib/codex-config.js +595 -595
- package/src/lib/codex-context-breakdown.js +806 -806
- package/src/lib/codex-model-attribution.js +128 -128
- package/src/lib/codex-rollout-parser.js +1471 -1471
- package/src/lib/codex-service-tier.js +49 -49
- package/src/lib/codex-token-refresh.js +140 -140
- package/src/lib/codex-token-usage.js +195 -195
- package/src/lib/codex-usage-record.js +195 -195
- package/src/lib/collection-pause.js +77 -0
- package/src/lib/command-runner.js +313 -313
- package/src/lib/commandcode-limits.js +317 -317
- package/src/lib/context-health.js +124 -124
- package/src/lib/cursor-config.js +605 -605
- package/src/lib/cursor-store.js +1918 -1918
- package/src/lib/debug-flags.js +7 -7
- package/src/lib/devin-limits.js +249 -249
- package/src/lib/devin-usage.js +212 -212
- package/src/lib/diagnostics.js +383 -383
- package/src/lib/doctor.js +385 -385
- package/src/lib/dumate.js +95 -95
- package/src/lib/fs.js +455 -455
- package/src/lib/function-url.js +14 -14
- package/src/lib/gemini-config.js +291 -291
- package/src/lib/git-outcomes.js +243 -243
- package/src/lib/grok-context-breakdown.js +890 -890
- package/src/lib/grok-hook.js +360 -360
- package/src/lib/grok-limits.js +865 -865
- package/src/lib/grok-usage.js +98 -98
- package/src/lib/heatmap-compact.js +114 -114
- package/src/lib/ingest-sanitize.js +41 -41
- package/src/lib/init-flow.js +42 -42
- package/src/lib/install-resolver.js +170 -170
- package/src/lib/jsonl-lines.js +134 -134
- package/src/lib/kimi-model-repair.js +173 -173
- package/src/lib/kimi-profile.js +61 -61
- package/src/lib/kimi-session.js +216 -216
- package/src/lib/local-api.js +3588 -3588
- package/src/lib/machine-id.js +238 -238
- package/src/lib/multi-install-parser.js +113 -113
- package/src/lib/notify-command.js +38 -38
- package/src/lib/omp-hook.js +589 -589
- package/src/lib/openclaw-cli.js +104 -104
- package/src/lib/openclaw-hook.js +375 -375
- package/src/lib/openclaw-session-plugin.js +560 -560
- package/src/lib/opencode-config.js +121 -121
- package/src/lib/opencode-go-limits.js +807 -807
- package/src/lib/outcomes-engine.js +253 -253
- package/src/lib/passive-mode.js +219 -219
- package/src/lib/pet-packages.js +722 -722
- package/src/lib/pricing/curated-overrides.json +822 -822
- package/src/lib/pricing/index.js +379 -379
- package/src/lib/pricing/litellm-fetcher.js +172 -172
- package/src/lib/pricing/matcher.js +456 -456
- package/src/lib/pricing/seed-snapshot.json +1 -1
- package/src/lib/progress.js +76 -76
- package/src/lib/project-usage-purge.js +117 -117
- package/src/lib/prompt.js +24 -24
- package/src/lib/provider-status.js +104 -104
- package/src/lib/proxy-env.js +489 -489
- package/src/lib/proxy-settings.js +163 -163
- package/src/lib/qoder-cn-cli-limits.js +119 -119
- package/src/lib/qoder-limits.js +880 -880
- package/src/lib/quiet-warnings.js +26 -26
- package/src/lib/rollout.js +26005 -25966
- package/src/lib/runtime-config.js +9 -4
- package/src/lib/scan-roots.js +277 -277
- package/src/lib/scheduled-task.js +145 -0
- package/src/lib/sentry.js +231 -231
- package/src/lib/session-analytics.js +2972 -2972
- package/src/lib/session-performance.js +237 -237
- package/src/lib/session-upload.js +379 -379
- package/src/lib/skill-usage.js +267 -267
- package/src/lib/skills-manager.js +1591 -1591
- package/src/lib/source-metadata.js +48 -48
- package/src/lib/sqlite-reader.js +215 -215
- package/src/lib/star-cta.js +73 -73
- package/src/lib/subscription-manager.js +293 -293
- package/src/lib/subscriptions.js +508 -508
- package/src/lib/sync-report.js +138 -0
- package/src/lib/telemetry.js +193 -193
- package/src/lib/tracker-paths.js +16 -16
- package/src/lib/trae-cn-config.js +548 -548
- package/src/lib/trae-db.js +127 -127
- package/src/lib/trae-snapshot.js +230 -230
- package/src/lib/trae-sqlite.js +143 -143
- package/src/lib/trae-usage.js +121 -121
- package/src/lib/upload-queue.js +134 -134
- package/src/lib/upload-throttle.js +171 -171
- package/src/lib/usage-limits.js +4552 -4552
- package/src/lib/wrapped-aggregator.js +236 -236
- package/src/lib/wsl-probe.js +281 -281
- package/src/lib/zcode-limits.js +1172 -1172
- package/src/lib/zcode-reset-credits.js +66 -66
- package/test/audit-fixes.test.js +200 -0
- package/test/cli-smoke.test.js +53 -53
- package/test/collection-controls.test.js +210 -0
- package/test/ingest-sanitize.test.js +162 -162
- package/test/quiet-warnings.test.js +53 -53
- package/test/session-upload.test.js +427 -427
package/src/lib/diagnostics.js
CHANGED
|
@@ -1,383 +1,383 @@
|
|
|
1
|
-
const os = require("node:os");
|
|
2
|
-
const path = require("node:path");
|
|
3
|
-
const fs = require("node:fs/promises");
|
|
4
|
-
|
|
5
|
-
const { readJson } = require("./fs");
|
|
6
|
-
const { resolveEnvRoot, resolveScanRoots } = require("./scan-roots");
|
|
7
|
-
const { readCursorStateSummary } = require("./cursor-store");
|
|
8
|
-
const { readCodexNotify, readEveryCodeNotify } = require("./codex-config");
|
|
9
|
-
const { areClaudeUsageHooksConfigured, buildClaudeHookCommand } = require("./claude-config");
|
|
10
|
-
const {
|
|
11
|
-
resolveGeminiConfigDir,
|
|
12
|
-
resolveGeminiSettingsPath,
|
|
13
|
-
buildGeminiHookCommand,
|
|
14
|
-
isGeminiHookConfigured,
|
|
15
|
-
} = require("./gemini-config");
|
|
16
|
-
const { resolveOpencodeConfigDir, isOpencodePluginInstalled } = require("./opencode-config");
|
|
17
|
-
const { normalizeState: normalizeUploadState } = require("./upload-throttle");
|
|
18
|
-
const { probeOpenclawHookState } = require("./openclaw-hook");
|
|
19
|
-
const { probeOpenclawSessionPluginState } = require("./openclaw-session-plugin");
|
|
20
|
-
const { probeGrokHookState } = require("./grok-hook");
|
|
21
|
-
const { resolveTrackerPaths } = require("./tracker-paths");
|
|
22
|
-
const { resolveDeviceTokenPresence } = require("./cloud-device-token");
|
|
23
|
-
const wsl = require("./wsl-probe");
|
|
24
|
-
// TASK-011: Kiro paths inlined here to avoid pulling the ~4000-line
|
|
25
|
-
// rollout module on every `tokenusage status` / `diagnostics` call.
|
|
26
|
-
// rollout.js still exports resolveKiroCliDbPath / resolveKiroBasePath for
|
|
27
|
-
// external callers; keep the platform branches in lockstep.
|
|
28
|
-
function resolveKiroIdeBaseInline(env, home) {
|
|
29
|
-
const suffix = ["Kiro", "User", "globalStorage", "kiro.kiroagent"];
|
|
30
|
-
if (process.platform === "win32") {
|
|
31
|
-
const appData = typeof env.APPDATA === "string" && env.APPDATA.trim().length > 0
|
|
32
|
-
? env.APPDATA.trim()
|
|
33
|
-
: path.join(home, "AppData", "Roaming");
|
|
34
|
-
return path.join(appData, ...suffix);
|
|
35
|
-
}
|
|
36
|
-
if (process.platform === "linux") {
|
|
37
|
-
const configHome = typeof env.XDG_CONFIG_HOME === "string" && env.XDG_CONFIG_HOME.trim().length > 0
|
|
38
|
-
? env.XDG_CONFIG_HOME.trim()
|
|
39
|
-
: path.join(home, ".config");
|
|
40
|
-
return path.join(configHome, ...suffix);
|
|
41
|
-
}
|
|
42
|
-
return path.join(home, "Library", "Application Support", ...suffix);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function resolveKiroCliDbPathInline(env, home) {
|
|
46
|
-
if (env.KIRO_CLI_DB_PATH) return env.KIRO_CLI_DB_PATH;
|
|
47
|
-
const effectiveHome = env.HOME || home;
|
|
48
|
-
if (process.platform === "win32") {
|
|
49
|
-
const localAppData = typeof env.LOCALAPPDATA === "string" && env.LOCALAPPDATA.trim().length > 0
|
|
50
|
-
? env.LOCALAPPDATA.trim()
|
|
51
|
-
: path.join(effectiveHome, "AppData", "Local");
|
|
52
|
-
return path.join(localAppData, "kiro-cli", "data.sqlite3");
|
|
53
|
-
}
|
|
54
|
-
if (process.platform === "linux") {
|
|
55
|
-
const dataHome = typeof env.XDG_DATA_HOME === "string" && env.XDG_DATA_HOME.trim().length > 0
|
|
56
|
-
? env.XDG_DATA_HOME.trim()
|
|
57
|
-
: path.join(effectiveHome, ".local", "share");
|
|
58
|
-
return path.join(dataHome, "kiro-cli", "data.sqlite3");
|
|
59
|
-
}
|
|
60
|
-
return path.join(
|
|
61
|
-
effectiveHome,
|
|
62
|
-
"Library",
|
|
63
|
-
"Application Support",
|
|
64
|
-
"kiro-cli",
|
|
65
|
-
"data.sqlite3",
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
async function collectTrackerDiagnostics({
|
|
70
|
-
home = os.homedir(),
|
|
71
|
-
codexHome = resolveEnvRoot("codex", { env: process.env, home }) || path.join(home, ".codex"),
|
|
72
|
-
codeHome = process.env.CODE_HOME || path.join(home, ".code"),
|
|
73
|
-
} = {}) {
|
|
74
|
-
const { trackerDir, binDir } = await resolveTrackerPaths({ home });
|
|
75
|
-
const configPath = path.join(trackerDir, "config.json");
|
|
76
|
-
const queuePath = path.join(trackerDir, "queue.jsonl");
|
|
77
|
-
const queueStatePath = path.join(trackerDir, "queue.state.json");
|
|
78
|
-
const cursorsPath = path.join(trackerDir, "cursors.json");
|
|
79
|
-
const notifySignalPath = path.join(trackerDir, "notify.signal");
|
|
80
|
-
const openclawSignalPath = path.join(trackerDir, "openclaw.signal");
|
|
81
|
-
const throttlePath = path.join(trackerDir, "sync.throttle");
|
|
82
|
-
const uploadThrottlePath = path.join(trackerDir, "upload.throttle.json");
|
|
83
|
-
const autoRetryPath = path.join(trackerDir, "auto.retry.json");
|
|
84
|
-
const syncSkipPath = path.join(trackerDir, "sync.skip.json");
|
|
85
|
-
const codexConfigPath = path.join(codexHome, "config.toml");
|
|
86
|
-
const codeConfigPath = path.join(codeHome, "config.toml");
|
|
87
|
-
const claudeConfigPath = path.join(home, ".claude", "settings.json");
|
|
88
|
-
const geminiConfigDir = resolveGeminiConfigDir({ home, env: process.env });
|
|
89
|
-
const geminiSettingsPath = resolveGeminiSettingsPath({ configDir: geminiConfigDir });
|
|
90
|
-
const opencodeConfigDir = resolveOpencodeConfigDir({ home, env: process.env });
|
|
91
|
-
const grokHome =
|
|
92
|
-
process.env.TOKENUSAGE_GROK_HOME ||
|
|
93
|
-
process.env.GROK_HOME ||
|
|
94
|
-
path.join(home, ".grok");
|
|
95
|
-
|
|
96
|
-
const config = await readJson(configPath);
|
|
97
|
-
// Extra scan roots (#657), resolved as sync does. Paths are home-redacted
|
|
98
|
-
// like every other entry in `paths`.
|
|
99
|
-
const scanRoots = resolveScanRoots({
|
|
100
|
-
home,
|
|
101
|
-
env: process.env,
|
|
102
|
-
config,
|
|
103
|
-
base: { codex: [codexHome], claude: [path.join(home, ".claude")] },
|
|
104
|
-
});
|
|
105
|
-
const describeScanRoots = (entries) => entries.map((entry) => ({
|
|
106
|
-
path: redactValue(entry.path, home),
|
|
107
|
-
origin: entry.origin,
|
|
108
|
-
exists: entry.exists,
|
|
109
|
-
error: entry.error || null,
|
|
110
|
-
}));
|
|
111
|
-
const cursorSummary = await readCursorStateSummary({ trackerDir, cursorsPath });
|
|
112
|
-
const cursors = cursorSummary.cursors;
|
|
113
|
-
const queueState = (await readJson(queueStatePath)) || { offset: 0 };
|
|
114
|
-
const uploadThrottle = normalizeUploadState(await readJson(uploadThrottlePath));
|
|
115
|
-
const autoRetry = await readJson(autoRetryPath);
|
|
116
|
-
const syncSkip = await readJson(syncSkipPath);
|
|
117
|
-
|
|
118
|
-
const queueSize = await safeStatSize(queuePath);
|
|
119
|
-
const offsetBytes = Number(queueState.offset || 0);
|
|
120
|
-
const pendingBytes = Math.max(0, queueSize - offsetBytes);
|
|
121
|
-
|
|
122
|
-
const lastNotify = (await safeReadText(notifySignalPath))?.trim() || null;
|
|
123
|
-
const lastOpenclawSync = (await safeReadText(openclawSignalPath))?.trim() || null;
|
|
124
|
-
const lastNotifySpawn = parseEpochMsToIso((await safeReadText(throttlePath))?.trim() || null);
|
|
125
|
-
|
|
126
|
-
const codexNotifyRaw = await readCodexNotify(codexConfigPath);
|
|
127
|
-
const notifyConfigured = Array.isArray(codexNotifyRaw) && codexNotifyRaw.length > 0;
|
|
128
|
-
const codexNotify = notifyConfigured ? codexNotifyRaw.map((v) => redactValue(v, home)) : null;
|
|
129
|
-
const everyCodeNotifyRaw = await readEveryCodeNotify(codeConfigPath);
|
|
130
|
-
const everyCodeConfigured = Array.isArray(everyCodeNotifyRaw) && everyCodeNotifyRaw.length > 0;
|
|
131
|
-
const everyCodeNotify = everyCodeConfigured
|
|
132
|
-
? everyCodeNotifyRaw.map((v) => redactValue(v, home))
|
|
133
|
-
: null;
|
|
134
|
-
const claudeHookCommand = buildClaudeHookCommand(path.join(binDir, "notify.cjs"));
|
|
135
|
-
const claudeHookConfigured = await areClaudeUsageHooksConfigured({
|
|
136
|
-
settingsPath: claudeConfigPath,
|
|
137
|
-
hookCommand: claudeHookCommand,
|
|
138
|
-
});
|
|
139
|
-
const geminiHookCommand = buildGeminiHookCommand(path.join(binDir, "notify.cjs"));
|
|
140
|
-
const geminiHookConfigured = await isGeminiHookConfigured({
|
|
141
|
-
settingsPath: geminiSettingsPath,
|
|
142
|
-
hookCommand: geminiHookCommand,
|
|
143
|
-
});
|
|
144
|
-
const opencodePluginConfigured = await isOpencodePluginInstalled({
|
|
145
|
-
configDir: opencodeConfigDir,
|
|
146
|
-
});
|
|
147
|
-
const openclawSessionPluginState = await probeOpenclawSessionPluginState({
|
|
148
|
-
home,
|
|
149
|
-
trackerDir,
|
|
150
|
-
env: process.env,
|
|
151
|
-
});
|
|
152
|
-
const openclawHookState = await probeOpenclawHookState({ home, trackerDir, env: process.env });
|
|
153
|
-
const grokHookState = await probeGrokHookState({ home, trackerDir, env: process.env });
|
|
154
|
-
|
|
155
|
-
// Kiro IDE and Kiro CLI sub-path presence — merged under one "kiro" source
|
|
156
|
-
// at token/cost aggregation level; operators need visibility of both
|
|
157
|
-
// sub-paths here for debugging.
|
|
158
|
-
const kiroIdeDevDataDir = path.join(resolveKiroIdeBaseInline(process.env, home), "dev_data");
|
|
159
|
-
const kiroIdePresent =
|
|
160
|
-
(await safeStatSize(path.join(kiroIdeDevDataDir, "devdata.sqlite"))) > 0 ||
|
|
161
|
-
(await safeStatSize(path.join(kiroIdeDevDataDir, "tokens_generated.jsonl"))) > 0;
|
|
162
|
-
const kiroCliDbPath = resolveKiroCliDbPathInline(process.env, home);
|
|
163
|
-
const kiroCliPresent = require("node:fs").existsSync(kiroCliDbPath);
|
|
164
|
-
|
|
165
|
-
// WSL installs (win32 only) — surfaced so `tracker doctor --json` can
|
|
166
|
-
// confirm dual-install discovery without running a sync.
|
|
167
|
-
let kiroWslInstalls = null;
|
|
168
|
-
let claudeWslProjects = null;
|
|
169
|
-
if (process.platform === "win32" && wsl.shouldProbeWsl(process.env)) {
|
|
170
|
-
const wslClaudeHome = wsl.discoverWslHome(".claude");
|
|
171
|
-
if (wslClaudeHome) claudeWslProjects = redactWslUser(path.join(wslClaudeHome, "projects"));
|
|
172
|
-
const wslIdeBase = wsl.discoverWslHome(".config/Kiro/User/globalStorage/kiro.kiroagent");
|
|
173
|
-
const wslKiroHomeDir = wsl.discoverWslHome(".kiro");
|
|
174
|
-
const wslCliDataDir = wsl.discoverWslHome(".local/share/kiro-cli");
|
|
175
|
-
const wslHomeRoot = wslKiroHomeDir
|
|
176
|
-
? path.dirname(wslKiroHomeDir)
|
|
177
|
-
: (wslCliDataDir ? path.dirname(path.dirname(path.dirname(wslCliDataDir))) : null);
|
|
178
|
-
const wslCliDb = wslHomeRoot
|
|
179
|
-
? path.join(wslHomeRoot, ".local", "share", "kiro-cli", "data.sqlite3")
|
|
180
|
-
: null;
|
|
181
|
-
if (wslIdeBase || wslHomeRoot) {
|
|
182
|
-
kiroWslInstalls = {
|
|
183
|
-
ide_dev_data: wslIdeBase ? redactWslUser(path.join(wslIdeBase, "dev_data")) : null,
|
|
184
|
-
ide_present: Boolean(wslIdeBase) && (
|
|
185
|
-
(await safeStatSize(path.join(wslIdeBase, "dev_data", "devdata.sqlite"))) > 0 ||
|
|
186
|
-
(await safeStatSize(path.join(wslIdeBase, "dev_data", "tokens_generated.jsonl"))) > 0
|
|
187
|
-
),
|
|
188
|
-
cli_db: wslCliDb ? redactWslUser(wslCliDb) : null,
|
|
189
|
-
cli_present: Boolean(wslCliDb) && require("node:fs").existsSync(wslCliDb),
|
|
190
|
-
};
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
const lastSuccessAt = uploadThrottle.lastSuccessMs
|
|
195
|
-
? new Date(uploadThrottle.lastSuccessMs).toISOString()
|
|
196
|
-
: null;
|
|
197
|
-
const autoRetryAt = parseEpochMsToIso(autoRetry?.retryAtMs);
|
|
198
|
-
|
|
199
|
-
return {
|
|
200
|
-
ok: true,
|
|
201
|
-
version: 1,
|
|
202
|
-
generated_at: new Date().toISOString(),
|
|
203
|
-
env: {
|
|
204
|
-
node: process.version,
|
|
205
|
-
platform: process.platform,
|
|
206
|
-
arch: process.arch,
|
|
207
|
-
},
|
|
208
|
-
paths: {
|
|
209
|
-
tracker_dir: redactValue(trackerDir, home),
|
|
210
|
-
codex_home: redactValue(codexHome, home),
|
|
211
|
-
codex_config: redactValue(codexConfigPath, home),
|
|
212
|
-
code_home: redactValue(codeHome, home),
|
|
213
|
-
code_config: redactValue(codeConfigPath, home),
|
|
214
|
-
claude_config: redactValue(claudeConfigPath, home),
|
|
215
|
-
claude_projects: redactValue(path.join(home, ".claude", "projects"), home),
|
|
216
|
-
...(process.platform === "win32" ? { claude_projects_wsl: claudeWslProjects } : {}),
|
|
217
|
-
gemini_config: redactValue(geminiSettingsPath, home),
|
|
218
|
-
opencode_config: redactValue(opencodeConfigDir, home),
|
|
219
|
-
grok_home: redactValue(grokHome, home),
|
|
220
|
-
grok_hooks: redactValue(grokHookState?.grokHooksDir, home),
|
|
221
|
-
grok_handler: redactValue(grokHookState?.handlerPath, home),
|
|
222
|
-
kiro_ide_dev_data: redactValue(kiroIdeDevDataDir, home),
|
|
223
|
-
kiro_cli_db: redactValue(kiroCliDbPath, home),
|
|
224
|
-
},
|
|
225
|
-
kiro: {
|
|
226
|
-
ide_present: kiroIdePresent,
|
|
227
|
-
cli_present: kiroCliPresent,
|
|
228
|
-
...(process.platform === "win32"
|
|
229
|
-
? { wsl_mode: wsl.getWslMode(process.env), wsl_installs: kiroWslInstalls }
|
|
230
|
-
: {}),
|
|
231
|
-
cli_approximation:
|
|
232
|
-
"When Kiro CLI does not report token counts, tokens are estimated at ~4 chars/token from new user messages, tool outputs and assistant text. The estimate does not measure re-sent history, system context or cache usage, and can substantially undercount tool-heavy requests. contextUsage percentages are not converted to tokens because their denominator and request correspondence are not established. Dollar amounts use model rates, not Kiro credit charges; recorded usage_summary credits remain separate. Source rows use model='kiro-cli-agent' when the underlying model is unknown; known Bedrock ARNs canonicalize to their short name (e.g. claude-sonnet-4).",
|
|
233
|
-
merge_policy:
|
|
234
|
-
"Kiro IDE and Kiro CLI both emit source='kiro' in queue.jsonl so token, cost, heatmap, and leaderboard aggregations merge transparently. Use this block to distinguish sub-path contributions.",
|
|
235
|
-
},
|
|
236
|
-
scan_roots: {
|
|
237
|
-
codex: describeScanRoots(scanRoots.codex),
|
|
238
|
-
claude: describeScanRoots(scanRoots.claude),
|
|
239
|
-
},
|
|
240
|
-
config: {
|
|
241
|
-
base_url: typeof config?.baseUrl === "string" ? config.baseUrl : null,
|
|
242
|
-
device_token: resolveDeviceTokenPresence({ trackerDir, config: config || {} }).set
|
|
243
|
-
? "set"
|
|
244
|
-
: "unset",
|
|
245
|
-
device_id: maskId(config?.deviceId),
|
|
246
|
-
installed_at: typeof config?.installedAt === "string" ? config.installedAt : null,
|
|
247
|
-
},
|
|
248
|
-
parse: {
|
|
249
|
-
updated_at: typeof cursors?.updatedAt === "string" ? cursors.updatedAt : null,
|
|
250
|
-
file_count: cursorSummary.fileCount,
|
|
251
|
-
cursor_store: cursorSummary.mode,
|
|
252
|
-
cursor_store_legacy_drift: cursorSummary.legacyDrift === true,
|
|
253
|
-
codex_file_count: cursorSummary.codexFileCount,
|
|
254
|
-
codex_event_count: cursorSummary.codexEventCount,
|
|
255
|
-
},
|
|
256
|
-
queue: {
|
|
257
|
-
size_bytes: queueSize,
|
|
258
|
-
offset_bytes: offsetBytes,
|
|
259
|
-
pending_bytes: pendingBytes,
|
|
260
|
-
updated_at: typeof queueState.updatedAt === "string" ? queueState.updatedAt : null,
|
|
261
|
-
},
|
|
262
|
-
notify: {
|
|
263
|
-
last_notify: lastNotify,
|
|
264
|
-
last_openclaw_triggered_sync: lastOpenclawSync,
|
|
265
|
-
last_notify_triggered_sync: lastNotifySpawn,
|
|
266
|
-
codex_notify_configured: notifyConfigured,
|
|
267
|
-
codex_notify: codexNotify,
|
|
268
|
-
every_code_notify_configured: everyCodeConfigured,
|
|
269
|
-
every_code_notify: everyCodeNotify,
|
|
270
|
-
claude_hook_configured: claudeHookConfigured,
|
|
271
|
-
gemini_hook_configured: geminiHookConfigured,
|
|
272
|
-
opencode_plugin_configured: opencodePluginConfigured,
|
|
273
|
-
openclaw_session_plugin_configured: Boolean(openclawSessionPluginState?.configured),
|
|
274
|
-
openclaw_session_plugin_linked: Boolean(openclawSessionPluginState?.linked),
|
|
275
|
-
openclaw_session_plugin_enabled: Boolean(openclawSessionPluginState?.enabled),
|
|
276
|
-
openclaw_session_plugin_conversation_access: Boolean(
|
|
277
|
-
openclawSessionPluginState?.conversationAccess,
|
|
278
|
-
),
|
|
279
|
-
openclaw_hook_configured: Boolean(openclawHookState?.configured),
|
|
280
|
-
openclaw_hook_linked: Boolean(openclawHookState?.linked),
|
|
281
|
-
openclaw_hook_enabled: Boolean(openclawHookState?.enabled),
|
|
282
|
-
grok_hook_configured: Boolean(grokHookState?.configured),
|
|
283
|
-
grok_hook_exists: Boolean(grokHookState?.hookExists),
|
|
284
|
-
grok_hook_handler_exists: Boolean(grokHookState?.handlerExists),
|
|
285
|
-
grok_sessions_dir: redactValue(grokHookState?.sessionsDir, home),
|
|
286
|
-
},
|
|
287
|
-
upload: {
|
|
288
|
-
last_success_at: lastSuccessAt,
|
|
289
|
-
next_allowed_after: parseEpochMsToIso(uploadThrottle.nextAllowedAtMs || null),
|
|
290
|
-
backoff_until: parseEpochMsToIso(uploadThrottle.backoffUntilMs || null),
|
|
291
|
-
last_error: uploadThrottle.lastError
|
|
292
|
-
? {
|
|
293
|
-
at: uploadThrottle.lastErrorAt || null,
|
|
294
|
-
message: redactError(String(uploadThrottle.lastError), home),
|
|
295
|
-
}
|
|
296
|
-
: null,
|
|
297
|
-
},
|
|
298
|
-
sync_skip: syncSkip?.at
|
|
299
|
-
? {
|
|
300
|
-
at: syncSkip.at,
|
|
301
|
-
reason: typeof syncSkip.reason === "string" ? syncSkip.reason : null,
|
|
302
|
-
detail: typeof syncSkip.detail === "string" ? syncSkip.detail : null,
|
|
303
|
-
lock_path: redactValue(syncSkip.lockPath, home),
|
|
304
|
-
}
|
|
305
|
-
: null,
|
|
306
|
-
auto_retry: autoRetryAt
|
|
307
|
-
? {
|
|
308
|
-
next_retry_at: autoRetryAt,
|
|
309
|
-
reason: typeof autoRetry?.reason === "string" ? autoRetry.reason : null,
|
|
310
|
-
pending_bytes: Number.isFinite(Number(autoRetry?.pendingBytes))
|
|
311
|
-
? Math.max(0, Number(autoRetry.pendingBytes))
|
|
312
|
-
: null,
|
|
313
|
-
scheduled_at: typeof autoRetry?.scheduledAt === "string" ? autoRetry.scheduledAt : null,
|
|
314
|
-
source: typeof autoRetry?.source === "string" ? autoRetry.source : null,
|
|
315
|
-
}
|
|
316
|
-
: null,
|
|
317
|
-
};
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
function maskId(v) {
|
|
321
|
-
if (typeof v !== "string") return null;
|
|
322
|
-
const s = v.trim();
|
|
323
|
-
if (s.length < 12) return null;
|
|
324
|
-
return `${s.slice(0, 8)}…${s.slice(-4)}`;
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
function redactValue(value, home) {
|
|
328
|
-
if (typeof value !== "string") return value;
|
|
329
|
-
if (typeof home !== "string" || home.length === 0) return value;
|
|
330
|
-
const homeNorm = home.endsWith(path.sep) ? home.slice(0, -1) : home;
|
|
331
|
-
return value.startsWith(homeNorm) ? `~${value.slice(homeNorm.length)}` : value;
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
// UNC WSL paths embed the distro name AND the Linux username; doctor reports
|
|
335
|
-
// are shared for support, so mask the user segment the same way redactValue
|
|
336
|
-
// masks $HOME (\\wsl$\Ubuntu\home\alice\... → \\wsl$\Ubuntu\home\~\...).
|
|
337
|
-
function redactWslUser(value) {
|
|
338
|
-
if (typeof value !== "string") return value;
|
|
339
|
-
return value.replace(
|
|
340
|
-
/^([\\/]{2}wsl(?:\$|\.localhost)[\\/][^\\/]+[\\/]home[\\/])[^\\/]+/i,
|
|
341
|
-
"$1~",
|
|
342
|
-
);
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
function redactError(message, home) {
|
|
346
|
-
if (typeof message !== "string") return message;
|
|
347
|
-
if (typeof home !== "string" || home.length === 0) return message;
|
|
348
|
-
const homeNorm = home.endsWith(path.sep) ? home.slice(0, -1) : home;
|
|
349
|
-
return message.split(homeNorm).join("~");
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
async function safeStatSize(p) {
|
|
353
|
-
try {
|
|
354
|
-
const st = await fs.stat(p);
|
|
355
|
-
return st && st.isFile() ? st.size : 0;
|
|
356
|
-
} catch (_e) {
|
|
357
|
-
return 0;
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
async function safeReadText(p) {
|
|
362
|
-
try {
|
|
363
|
-
return await fs.readFile(p, "utf8");
|
|
364
|
-
} catch (_e) {
|
|
365
|
-
return null;
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
function parseEpochMsToIso(v) {
|
|
370
|
-
const ms = Number(v);
|
|
371
|
-
if (!Number.isFinite(ms) || ms <= 0) return null;
|
|
372
|
-
const d = new Date(ms);
|
|
373
|
-
if (Number.isNaN(d.getTime())) return null;
|
|
374
|
-
return d.toISOString();
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
module.exports = {
|
|
378
|
-
collectTrackerDiagnostics,
|
|
379
|
-
// Exported for the parity test that pins these inline copies to the
|
|
380
|
-
// canonical resolvers in rollout.js (see the lockstep note above).
|
|
381
|
-
resolveKiroIdeBaseInline,
|
|
382
|
-
resolveKiroCliDbPathInline,
|
|
383
|
-
};
|
|
1
|
+
const os = require("node:os");
|
|
2
|
+
const path = require("node:path");
|
|
3
|
+
const fs = require("node:fs/promises");
|
|
4
|
+
|
|
5
|
+
const { readJson } = require("./fs");
|
|
6
|
+
const { resolveEnvRoot, resolveScanRoots } = require("./scan-roots");
|
|
7
|
+
const { readCursorStateSummary } = require("./cursor-store");
|
|
8
|
+
const { readCodexNotify, readEveryCodeNotify } = require("./codex-config");
|
|
9
|
+
const { areClaudeUsageHooksConfigured, buildClaudeHookCommand } = require("./claude-config");
|
|
10
|
+
const {
|
|
11
|
+
resolveGeminiConfigDir,
|
|
12
|
+
resolveGeminiSettingsPath,
|
|
13
|
+
buildGeminiHookCommand,
|
|
14
|
+
isGeminiHookConfigured,
|
|
15
|
+
} = require("./gemini-config");
|
|
16
|
+
const { resolveOpencodeConfigDir, isOpencodePluginInstalled } = require("./opencode-config");
|
|
17
|
+
const { normalizeState: normalizeUploadState } = require("./upload-throttle");
|
|
18
|
+
const { probeOpenclawHookState } = require("./openclaw-hook");
|
|
19
|
+
const { probeOpenclawSessionPluginState } = require("./openclaw-session-plugin");
|
|
20
|
+
const { probeGrokHookState } = require("./grok-hook");
|
|
21
|
+
const { resolveTrackerPaths } = require("./tracker-paths");
|
|
22
|
+
const { resolveDeviceTokenPresence } = require("./cloud-device-token");
|
|
23
|
+
const wsl = require("./wsl-probe");
|
|
24
|
+
// TASK-011: Kiro paths inlined here to avoid pulling the ~4000-line
|
|
25
|
+
// rollout module on every `tokenusage status` / `diagnostics` call.
|
|
26
|
+
// rollout.js still exports resolveKiroCliDbPath / resolveKiroBasePath for
|
|
27
|
+
// external callers; keep the platform branches in lockstep.
|
|
28
|
+
function resolveKiroIdeBaseInline(env, home) {
|
|
29
|
+
const suffix = ["Kiro", "User", "globalStorage", "kiro.kiroagent"];
|
|
30
|
+
if (process.platform === "win32") {
|
|
31
|
+
const appData = typeof env.APPDATA === "string" && env.APPDATA.trim().length > 0
|
|
32
|
+
? env.APPDATA.trim()
|
|
33
|
+
: path.join(home, "AppData", "Roaming");
|
|
34
|
+
return path.join(appData, ...suffix);
|
|
35
|
+
}
|
|
36
|
+
if (process.platform === "linux") {
|
|
37
|
+
const configHome = typeof env.XDG_CONFIG_HOME === "string" && env.XDG_CONFIG_HOME.trim().length > 0
|
|
38
|
+
? env.XDG_CONFIG_HOME.trim()
|
|
39
|
+
: path.join(home, ".config");
|
|
40
|
+
return path.join(configHome, ...suffix);
|
|
41
|
+
}
|
|
42
|
+
return path.join(home, "Library", "Application Support", ...suffix);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function resolveKiroCliDbPathInline(env, home) {
|
|
46
|
+
if (env.KIRO_CLI_DB_PATH) return env.KIRO_CLI_DB_PATH;
|
|
47
|
+
const effectiveHome = env.HOME || home;
|
|
48
|
+
if (process.platform === "win32") {
|
|
49
|
+
const localAppData = typeof env.LOCALAPPDATA === "string" && env.LOCALAPPDATA.trim().length > 0
|
|
50
|
+
? env.LOCALAPPDATA.trim()
|
|
51
|
+
: path.join(effectiveHome, "AppData", "Local");
|
|
52
|
+
return path.join(localAppData, "kiro-cli", "data.sqlite3");
|
|
53
|
+
}
|
|
54
|
+
if (process.platform === "linux") {
|
|
55
|
+
const dataHome = typeof env.XDG_DATA_HOME === "string" && env.XDG_DATA_HOME.trim().length > 0
|
|
56
|
+
? env.XDG_DATA_HOME.trim()
|
|
57
|
+
: path.join(effectiveHome, ".local", "share");
|
|
58
|
+
return path.join(dataHome, "kiro-cli", "data.sqlite3");
|
|
59
|
+
}
|
|
60
|
+
return path.join(
|
|
61
|
+
effectiveHome,
|
|
62
|
+
"Library",
|
|
63
|
+
"Application Support",
|
|
64
|
+
"kiro-cli",
|
|
65
|
+
"data.sqlite3",
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async function collectTrackerDiagnostics({
|
|
70
|
+
home = os.homedir(),
|
|
71
|
+
codexHome = resolveEnvRoot("codex", { env: process.env, home }) || path.join(home, ".codex"),
|
|
72
|
+
codeHome = process.env.CODE_HOME || path.join(home, ".code"),
|
|
73
|
+
} = {}) {
|
|
74
|
+
const { trackerDir, binDir } = await resolveTrackerPaths({ home });
|
|
75
|
+
const configPath = path.join(trackerDir, "config.json");
|
|
76
|
+
const queuePath = path.join(trackerDir, "queue.jsonl");
|
|
77
|
+
const queueStatePath = path.join(trackerDir, "queue.state.json");
|
|
78
|
+
const cursorsPath = path.join(trackerDir, "cursors.json");
|
|
79
|
+
const notifySignalPath = path.join(trackerDir, "notify.signal");
|
|
80
|
+
const openclawSignalPath = path.join(trackerDir, "openclaw.signal");
|
|
81
|
+
const throttlePath = path.join(trackerDir, "sync.throttle");
|
|
82
|
+
const uploadThrottlePath = path.join(trackerDir, "upload.throttle.json");
|
|
83
|
+
const autoRetryPath = path.join(trackerDir, "auto.retry.json");
|
|
84
|
+
const syncSkipPath = path.join(trackerDir, "sync.skip.json");
|
|
85
|
+
const codexConfigPath = path.join(codexHome, "config.toml");
|
|
86
|
+
const codeConfigPath = path.join(codeHome, "config.toml");
|
|
87
|
+
const claudeConfigPath = path.join(home, ".claude", "settings.json");
|
|
88
|
+
const geminiConfigDir = resolveGeminiConfigDir({ home, env: process.env });
|
|
89
|
+
const geminiSettingsPath = resolveGeminiSettingsPath({ configDir: geminiConfigDir });
|
|
90
|
+
const opencodeConfigDir = resolveOpencodeConfigDir({ home, env: process.env });
|
|
91
|
+
const grokHome =
|
|
92
|
+
process.env.TOKENUSAGE_GROK_HOME ||
|
|
93
|
+
process.env.GROK_HOME ||
|
|
94
|
+
path.join(home, ".grok");
|
|
95
|
+
|
|
96
|
+
const config = await readJson(configPath);
|
|
97
|
+
// Extra scan roots (#657), resolved as sync does. Paths are home-redacted
|
|
98
|
+
// like every other entry in `paths`.
|
|
99
|
+
const scanRoots = resolveScanRoots({
|
|
100
|
+
home,
|
|
101
|
+
env: process.env,
|
|
102
|
+
config,
|
|
103
|
+
base: { codex: [codexHome], claude: [path.join(home, ".claude")] },
|
|
104
|
+
});
|
|
105
|
+
const describeScanRoots = (entries) => entries.map((entry) => ({
|
|
106
|
+
path: redactValue(entry.path, home),
|
|
107
|
+
origin: entry.origin,
|
|
108
|
+
exists: entry.exists,
|
|
109
|
+
error: entry.error || null,
|
|
110
|
+
}));
|
|
111
|
+
const cursorSummary = await readCursorStateSummary({ trackerDir, cursorsPath });
|
|
112
|
+
const cursors = cursorSummary.cursors;
|
|
113
|
+
const queueState = (await readJson(queueStatePath)) || { offset: 0 };
|
|
114
|
+
const uploadThrottle = normalizeUploadState(await readJson(uploadThrottlePath));
|
|
115
|
+
const autoRetry = await readJson(autoRetryPath);
|
|
116
|
+
const syncSkip = await readJson(syncSkipPath);
|
|
117
|
+
|
|
118
|
+
const queueSize = await safeStatSize(queuePath);
|
|
119
|
+
const offsetBytes = Number(queueState.offset || 0);
|
|
120
|
+
const pendingBytes = Math.max(0, queueSize - offsetBytes);
|
|
121
|
+
|
|
122
|
+
const lastNotify = (await safeReadText(notifySignalPath))?.trim() || null;
|
|
123
|
+
const lastOpenclawSync = (await safeReadText(openclawSignalPath))?.trim() || null;
|
|
124
|
+
const lastNotifySpawn = parseEpochMsToIso((await safeReadText(throttlePath))?.trim() || null);
|
|
125
|
+
|
|
126
|
+
const codexNotifyRaw = await readCodexNotify(codexConfigPath);
|
|
127
|
+
const notifyConfigured = Array.isArray(codexNotifyRaw) && codexNotifyRaw.length > 0;
|
|
128
|
+
const codexNotify = notifyConfigured ? codexNotifyRaw.map((v) => redactValue(v, home)) : null;
|
|
129
|
+
const everyCodeNotifyRaw = await readEveryCodeNotify(codeConfigPath);
|
|
130
|
+
const everyCodeConfigured = Array.isArray(everyCodeNotifyRaw) && everyCodeNotifyRaw.length > 0;
|
|
131
|
+
const everyCodeNotify = everyCodeConfigured
|
|
132
|
+
? everyCodeNotifyRaw.map((v) => redactValue(v, home))
|
|
133
|
+
: null;
|
|
134
|
+
const claudeHookCommand = buildClaudeHookCommand(path.join(binDir, "notify.cjs"));
|
|
135
|
+
const claudeHookConfigured = await areClaudeUsageHooksConfigured({
|
|
136
|
+
settingsPath: claudeConfigPath,
|
|
137
|
+
hookCommand: claudeHookCommand,
|
|
138
|
+
});
|
|
139
|
+
const geminiHookCommand = buildGeminiHookCommand(path.join(binDir, "notify.cjs"));
|
|
140
|
+
const geminiHookConfigured = await isGeminiHookConfigured({
|
|
141
|
+
settingsPath: geminiSettingsPath,
|
|
142
|
+
hookCommand: geminiHookCommand,
|
|
143
|
+
});
|
|
144
|
+
const opencodePluginConfigured = await isOpencodePluginInstalled({
|
|
145
|
+
configDir: opencodeConfigDir,
|
|
146
|
+
});
|
|
147
|
+
const openclawSessionPluginState = await probeOpenclawSessionPluginState({
|
|
148
|
+
home,
|
|
149
|
+
trackerDir,
|
|
150
|
+
env: process.env,
|
|
151
|
+
});
|
|
152
|
+
const openclawHookState = await probeOpenclawHookState({ home, trackerDir, env: process.env });
|
|
153
|
+
const grokHookState = await probeGrokHookState({ home, trackerDir, env: process.env });
|
|
154
|
+
|
|
155
|
+
// Kiro IDE and Kiro CLI sub-path presence — merged under one "kiro" source
|
|
156
|
+
// at token/cost aggregation level; operators need visibility of both
|
|
157
|
+
// sub-paths here for debugging.
|
|
158
|
+
const kiroIdeDevDataDir = path.join(resolveKiroIdeBaseInline(process.env, home), "dev_data");
|
|
159
|
+
const kiroIdePresent =
|
|
160
|
+
(await safeStatSize(path.join(kiroIdeDevDataDir, "devdata.sqlite"))) > 0 ||
|
|
161
|
+
(await safeStatSize(path.join(kiroIdeDevDataDir, "tokens_generated.jsonl"))) > 0;
|
|
162
|
+
const kiroCliDbPath = resolveKiroCliDbPathInline(process.env, home);
|
|
163
|
+
const kiroCliPresent = require("node:fs").existsSync(kiroCliDbPath);
|
|
164
|
+
|
|
165
|
+
// WSL installs (win32 only) — surfaced so `tracker doctor --json` can
|
|
166
|
+
// confirm dual-install discovery without running a sync.
|
|
167
|
+
let kiroWslInstalls = null;
|
|
168
|
+
let claudeWslProjects = null;
|
|
169
|
+
if (process.platform === "win32" && wsl.shouldProbeWsl(process.env)) {
|
|
170
|
+
const wslClaudeHome = wsl.discoverWslHome(".claude");
|
|
171
|
+
if (wslClaudeHome) claudeWslProjects = redactWslUser(path.join(wslClaudeHome, "projects"));
|
|
172
|
+
const wslIdeBase = wsl.discoverWslHome(".config/Kiro/User/globalStorage/kiro.kiroagent");
|
|
173
|
+
const wslKiroHomeDir = wsl.discoverWslHome(".kiro");
|
|
174
|
+
const wslCliDataDir = wsl.discoverWslHome(".local/share/kiro-cli");
|
|
175
|
+
const wslHomeRoot = wslKiroHomeDir
|
|
176
|
+
? path.dirname(wslKiroHomeDir)
|
|
177
|
+
: (wslCliDataDir ? path.dirname(path.dirname(path.dirname(wslCliDataDir))) : null);
|
|
178
|
+
const wslCliDb = wslHomeRoot
|
|
179
|
+
? path.join(wslHomeRoot, ".local", "share", "kiro-cli", "data.sqlite3")
|
|
180
|
+
: null;
|
|
181
|
+
if (wslIdeBase || wslHomeRoot) {
|
|
182
|
+
kiroWslInstalls = {
|
|
183
|
+
ide_dev_data: wslIdeBase ? redactWslUser(path.join(wslIdeBase, "dev_data")) : null,
|
|
184
|
+
ide_present: Boolean(wslIdeBase) && (
|
|
185
|
+
(await safeStatSize(path.join(wslIdeBase, "dev_data", "devdata.sqlite"))) > 0 ||
|
|
186
|
+
(await safeStatSize(path.join(wslIdeBase, "dev_data", "tokens_generated.jsonl"))) > 0
|
|
187
|
+
),
|
|
188
|
+
cli_db: wslCliDb ? redactWslUser(wslCliDb) : null,
|
|
189
|
+
cli_present: Boolean(wslCliDb) && require("node:fs").existsSync(wslCliDb),
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const lastSuccessAt = uploadThrottle.lastSuccessMs
|
|
195
|
+
? new Date(uploadThrottle.lastSuccessMs).toISOString()
|
|
196
|
+
: null;
|
|
197
|
+
const autoRetryAt = parseEpochMsToIso(autoRetry?.retryAtMs);
|
|
198
|
+
|
|
199
|
+
return {
|
|
200
|
+
ok: true,
|
|
201
|
+
version: 1,
|
|
202
|
+
generated_at: new Date().toISOString(),
|
|
203
|
+
env: {
|
|
204
|
+
node: process.version,
|
|
205
|
+
platform: process.platform,
|
|
206
|
+
arch: process.arch,
|
|
207
|
+
},
|
|
208
|
+
paths: {
|
|
209
|
+
tracker_dir: redactValue(trackerDir, home),
|
|
210
|
+
codex_home: redactValue(codexHome, home),
|
|
211
|
+
codex_config: redactValue(codexConfigPath, home),
|
|
212
|
+
code_home: redactValue(codeHome, home),
|
|
213
|
+
code_config: redactValue(codeConfigPath, home),
|
|
214
|
+
claude_config: redactValue(claudeConfigPath, home),
|
|
215
|
+
claude_projects: redactValue(path.join(home, ".claude", "projects"), home),
|
|
216
|
+
...(process.platform === "win32" ? { claude_projects_wsl: claudeWslProjects } : {}),
|
|
217
|
+
gemini_config: redactValue(geminiSettingsPath, home),
|
|
218
|
+
opencode_config: redactValue(opencodeConfigDir, home),
|
|
219
|
+
grok_home: redactValue(grokHome, home),
|
|
220
|
+
grok_hooks: redactValue(grokHookState?.grokHooksDir, home),
|
|
221
|
+
grok_handler: redactValue(grokHookState?.handlerPath, home),
|
|
222
|
+
kiro_ide_dev_data: redactValue(kiroIdeDevDataDir, home),
|
|
223
|
+
kiro_cli_db: redactValue(kiroCliDbPath, home),
|
|
224
|
+
},
|
|
225
|
+
kiro: {
|
|
226
|
+
ide_present: kiroIdePresent,
|
|
227
|
+
cli_present: kiroCliPresent,
|
|
228
|
+
...(process.platform === "win32"
|
|
229
|
+
? { wsl_mode: wsl.getWslMode(process.env), wsl_installs: kiroWslInstalls }
|
|
230
|
+
: {}),
|
|
231
|
+
cli_approximation:
|
|
232
|
+
"When Kiro CLI does not report token counts, tokens are estimated at ~4 chars/token from new user messages, tool outputs and assistant text. The estimate does not measure re-sent history, system context or cache usage, and can substantially undercount tool-heavy requests. contextUsage percentages are not converted to tokens because their denominator and request correspondence are not established. Dollar amounts use model rates, not Kiro credit charges; recorded usage_summary credits remain separate. Source rows use model='kiro-cli-agent' when the underlying model is unknown; known Bedrock ARNs canonicalize to their short name (e.g. claude-sonnet-4).",
|
|
233
|
+
merge_policy:
|
|
234
|
+
"Kiro IDE and Kiro CLI both emit source='kiro' in queue.jsonl so token, cost, heatmap, and leaderboard aggregations merge transparently. Use this block to distinguish sub-path contributions.",
|
|
235
|
+
},
|
|
236
|
+
scan_roots: {
|
|
237
|
+
codex: describeScanRoots(scanRoots.codex),
|
|
238
|
+
claude: describeScanRoots(scanRoots.claude),
|
|
239
|
+
},
|
|
240
|
+
config: {
|
|
241
|
+
base_url: typeof config?.baseUrl === "string" ? config.baseUrl : null,
|
|
242
|
+
device_token: resolveDeviceTokenPresence({ trackerDir, config: config || {} }).set
|
|
243
|
+
? "set"
|
|
244
|
+
: "unset",
|
|
245
|
+
device_id: maskId(config?.deviceId),
|
|
246
|
+
installed_at: typeof config?.installedAt === "string" ? config.installedAt : null,
|
|
247
|
+
},
|
|
248
|
+
parse: {
|
|
249
|
+
updated_at: typeof cursors?.updatedAt === "string" ? cursors.updatedAt : null,
|
|
250
|
+
file_count: cursorSummary.fileCount,
|
|
251
|
+
cursor_store: cursorSummary.mode,
|
|
252
|
+
cursor_store_legacy_drift: cursorSummary.legacyDrift === true,
|
|
253
|
+
codex_file_count: cursorSummary.codexFileCount,
|
|
254
|
+
codex_event_count: cursorSummary.codexEventCount,
|
|
255
|
+
},
|
|
256
|
+
queue: {
|
|
257
|
+
size_bytes: queueSize,
|
|
258
|
+
offset_bytes: offsetBytes,
|
|
259
|
+
pending_bytes: pendingBytes,
|
|
260
|
+
updated_at: typeof queueState.updatedAt === "string" ? queueState.updatedAt : null,
|
|
261
|
+
},
|
|
262
|
+
notify: {
|
|
263
|
+
last_notify: lastNotify,
|
|
264
|
+
last_openclaw_triggered_sync: lastOpenclawSync,
|
|
265
|
+
last_notify_triggered_sync: lastNotifySpawn,
|
|
266
|
+
codex_notify_configured: notifyConfigured,
|
|
267
|
+
codex_notify: codexNotify,
|
|
268
|
+
every_code_notify_configured: everyCodeConfigured,
|
|
269
|
+
every_code_notify: everyCodeNotify,
|
|
270
|
+
claude_hook_configured: claudeHookConfigured,
|
|
271
|
+
gemini_hook_configured: geminiHookConfigured,
|
|
272
|
+
opencode_plugin_configured: opencodePluginConfigured,
|
|
273
|
+
openclaw_session_plugin_configured: Boolean(openclawSessionPluginState?.configured),
|
|
274
|
+
openclaw_session_plugin_linked: Boolean(openclawSessionPluginState?.linked),
|
|
275
|
+
openclaw_session_plugin_enabled: Boolean(openclawSessionPluginState?.enabled),
|
|
276
|
+
openclaw_session_plugin_conversation_access: Boolean(
|
|
277
|
+
openclawSessionPluginState?.conversationAccess,
|
|
278
|
+
),
|
|
279
|
+
openclaw_hook_configured: Boolean(openclawHookState?.configured),
|
|
280
|
+
openclaw_hook_linked: Boolean(openclawHookState?.linked),
|
|
281
|
+
openclaw_hook_enabled: Boolean(openclawHookState?.enabled),
|
|
282
|
+
grok_hook_configured: Boolean(grokHookState?.configured),
|
|
283
|
+
grok_hook_exists: Boolean(grokHookState?.hookExists),
|
|
284
|
+
grok_hook_handler_exists: Boolean(grokHookState?.handlerExists),
|
|
285
|
+
grok_sessions_dir: redactValue(grokHookState?.sessionsDir, home),
|
|
286
|
+
},
|
|
287
|
+
upload: {
|
|
288
|
+
last_success_at: lastSuccessAt,
|
|
289
|
+
next_allowed_after: parseEpochMsToIso(uploadThrottle.nextAllowedAtMs || null),
|
|
290
|
+
backoff_until: parseEpochMsToIso(uploadThrottle.backoffUntilMs || null),
|
|
291
|
+
last_error: uploadThrottle.lastError
|
|
292
|
+
? {
|
|
293
|
+
at: uploadThrottle.lastErrorAt || null,
|
|
294
|
+
message: redactError(String(uploadThrottle.lastError), home),
|
|
295
|
+
}
|
|
296
|
+
: null,
|
|
297
|
+
},
|
|
298
|
+
sync_skip: syncSkip?.at
|
|
299
|
+
? {
|
|
300
|
+
at: syncSkip.at,
|
|
301
|
+
reason: typeof syncSkip.reason === "string" ? syncSkip.reason : null,
|
|
302
|
+
detail: typeof syncSkip.detail === "string" ? syncSkip.detail : null,
|
|
303
|
+
lock_path: redactValue(syncSkip.lockPath, home),
|
|
304
|
+
}
|
|
305
|
+
: null,
|
|
306
|
+
auto_retry: autoRetryAt
|
|
307
|
+
? {
|
|
308
|
+
next_retry_at: autoRetryAt,
|
|
309
|
+
reason: typeof autoRetry?.reason === "string" ? autoRetry.reason : null,
|
|
310
|
+
pending_bytes: Number.isFinite(Number(autoRetry?.pendingBytes))
|
|
311
|
+
? Math.max(0, Number(autoRetry.pendingBytes))
|
|
312
|
+
: null,
|
|
313
|
+
scheduled_at: typeof autoRetry?.scheduledAt === "string" ? autoRetry.scheduledAt : null,
|
|
314
|
+
source: typeof autoRetry?.source === "string" ? autoRetry.source : null,
|
|
315
|
+
}
|
|
316
|
+
: null,
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
function maskId(v) {
|
|
321
|
+
if (typeof v !== "string") return null;
|
|
322
|
+
const s = v.trim();
|
|
323
|
+
if (s.length < 12) return null;
|
|
324
|
+
return `${s.slice(0, 8)}…${s.slice(-4)}`;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
function redactValue(value, home) {
|
|
328
|
+
if (typeof value !== "string") return value;
|
|
329
|
+
if (typeof home !== "string" || home.length === 0) return value;
|
|
330
|
+
const homeNorm = home.endsWith(path.sep) ? home.slice(0, -1) : home;
|
|
331
|
+
return value.startsWith(homeNorm) ? `~${value.slice(homeNorm.length)}` : value;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
// UNC WSL paths embed the distro name AND the Linux username; doctor reports
|
|
335
|
+
// are shared for support, so mask the user segment the same way redactValue
|
|
336
|
+
// masks $HOME (\\wsl$\Ubuntu\home\alice\... → \\wsl$\Ubuntu\home\~\...).
|
|
337
|
+
function redactWslUser(value) {
|
|
338
|
+
if (typeof value !== "string") return value;
|
|
339
|
+
return value.replace(
|
|
340
|
+
/^([\\/]{2}wsl(?:\$|\.localhost)[\\/][^\\/]+[\\/]home[\\/])[^\\/]+/i,
|
|
341
|
+
"$1~",
|
|
342
|
+
);
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
function redactError(message, home) {
|
|
346
|
+
if (typeof message !== "string") return message;
|
|
347
|
+
if (typeof home !== "string" || home.length === 0) return message;
|
|
348
|
+
const homeNorm = home.endsWith(path.sep) ? home.slice(0, -1) : home;
|
|
349
|
+
return message.split(homeNorm).join("~");
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
async function safeStatSize(p) {
|
|
353
|
+
try {
|
|
354
|
+
const st = await fs.stat(p);
|
|
355
|
+
return st && st.isFile() ? st.size : 0;
|
|
356
|
+
} catch (_e) {
|
|
357
|
+
return 0;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
async function safeReadText(p) {
|
|
362
|
+
try {
|
|
363
|
+
return await fs.readFile(p, "utf8");
|
|
364
|
+
} catch (_e) {
|
|
365
|
+
return null;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
function parseEpochMsToIso(v) {
|
|
370
|
+
const ms = Number(v);
|
|
371
|
+
if (!Number.isFinite(ms) || ms <= 0) return null;
|
|
372
|
+
const d = new Date(ms);
|
|
373
|
+
if (Number.isNaN(d.getTime())) return null;
|
|
374
|
+
return d.toISOString();
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
module.exports = {
|
|
378
|
+
collectTrackerDiagnostics,
|
|
379
|
+
// Exported for the parity test that pins these inline copies to the
|
|
380
|
+
// canonical resolvers in rollout.js (see the lockstep note above).
|
|
381
|
+
resolveKiroIdeBaseInline,
|
|
382
|
+
resolveKiroCliDbPathInline,
|
|
383
|
+
};
|