tokenusage-cli 0.1.0
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 +19 -0
- package/LICENSE +22 -0
- package/README.md +94 -0
- package/THIRD_PARTY_NOTICES.md +140 -0
- package/bin/tokenusage.js +69 -0
- package/package.json +59 -0
- package/src/cli.js +134 -0
- package/src/commands/device-login.js +205 -0
- package/src/commands/diagnostics.js +38 -0
- package/src/commands/doctor.js +110 -0
- package/src/commands/init.js +2436 -0
- package/src/commands/sessions.js +29 -0
- package/src/commands/status.js +1747 -0
- package/src/commands/sync.js +7934 -0
- package/src/commands/uninstall.js +312 -0
- package/src/lib/account-usage-dedup.js +267 -0
- package/src/lib/antigravity-paths.js +48 -0
- package/src/lib/ark-agent-plan-limits.js +438 -0
- package/src/lib/ark-coding-plan-limits.js +537 -0
- package/src/lib/async-queue-reader.js +138 -0
- package/src/lib/atomic-json.js +27 -0
- package/src/lib/bearer-token.js +11 -0
- package/src/lib/categorizer-utils.js +232 -0
- package/src/lib/claude-categorizer.js +1343 -0
- package/src/lib/claude-config.js +279 -0
- package/src/lib/claude-user-identity.js +56 -0
- package/src/lib/cli-ui.js +179 -0
- package/src/lib/cloud-account.js +541 -0
- package/src/lib/cloud-device-token.js +141 -0
- package/src/lib/cloud-sync-prefs.js +14 -0
- package/src/lib/cloud-usage-reset.js +115 -0
- package/src/lib/codex-config.js +595 -0
- package/src/lib/codex-context-breakdown.js +806 -0
- package/src/lib/codex-model-attribution.js +128 -0
- package/src/lib/codex-rollout-parser.js +1471 -0
- package/src/lib/codex-service-tier.js +49 -0
- package/src/lib/codex-token-refresh.js +140 -0
- package/src/lib/codex-token-usage.js +195 -0
- package/src/lib/codex-usage-record.js +195 -0
- package/src/lib/command-runner.js +313 -0
- package/src/lib/commandcode-limits.js +317 -0
- package/src/lib/context-health.js +124 -0
- package/src/lib/cursor-config.js +605 -0
- package/src/lib/cursor-store.js +1918 -0
- package/src/lib/debug-flags.js +7 -0
- package/src/lib/devin-limits.js +249 -0
- package/src/lib/devin-usage.js +212 -0
- package/src/lib/diagnostics.js +383 -0
- package/src/lib/doctor.js +385 -0
- package/src/lib/dumate.js +95 -0
- package/src/lib/fs.js +455 -0
- package/src/lib/function-url.js +14 -0
- package/src/lib/gemini-config.js +291 -0
- package/src/lib/git-outcomes.js +243 -0
- package/src/lib/grok-context-breakdown.js +890 -0
- package/src/lib/grok-hook.js +360 -0
- package/src/lib/grok-limits.js +865 -0
- package/src/lib/grok-usage.js +98 -0
- package/src/lib/heatmap-compact.js +114 -0
- package/src/lib/ingest-sanitize.js +41 -0
- package/src/lib/init-flow.js +42 -0
- package/src/lib/install-resolver.js +170 -0
- package/src/lib/jsonl-lines.js +134 -0
- package/src/lib/kimi-model-repair.js +173 -0
- package/src/lib/kimi-profile.js +61 -0
- package/src/lib/kimi-session.js +216 -0
- package/src/lib/local-api.js +3588 -0
- package/src/lib/machine-id.js +238 -0
- package/src/lib/multi-install-parser.js +113 -0
- package/src/lib/notify-command.js +38 -0
- package/src/lib/omp-hook.js +589 -0
- package/src/lib/openclaw-cli.js +104 -0
- package/src/lib/openclaw-hook.js +375 -0
- package/src/lib/openclaw-session-plugin.js +560 -0
- package/src/lib/opencode-config.js +121 -0
- package/src/lib/opencode-go-limits.js +807 -0
- package/src/lib/outcomes-engine.js +253 -0
- package/src/lib/passive-mode.js +219 -0
- package/src/lib/pet-packages.js +722 -0
- package/src/lib/pricing/curated-overrides.json +822 -0
- package/src/lib/pricing/index.js +379 -0
- package/src/lib/pricing/litellm-fetcher.js +172 -0
- package/src/lib/pricing/matcher.js +456 -0
- package/src/lib/pricing/seed-snapshot.json +1 -0
- package/src/lib/progress.js +76 -0
- package/src/lib/project-usage-purge.js +117 -0
- package/src/lib/prompt.js +24 -0
- package/src/lib/provider-status.js +104 -0
- package/src/lib/proxy-env.js +489 -0
- package/src/lib/proxy-settings.js +163 -0
- package/src/lib/qoder-cn-cli-limits.js +119 -0
- package/src/lib/qoder-limits.js +880 -0
- package/src/lib/quiet-warnings.js +26 -0
- package/src/lib/rollout.js +25966 -0
- package/src/lib/runtime-config.js +259 -0
- package/src/lib/scan-roots.js +277 -0
- package/src/lib/sentry.js +231 -0
- package/src/lib/session-analytics.js +2972 -0
- package/src/lib/session-performance.js +237 -0
- package/src/lib/session-upload.js +379 -0
- package/src/lib/skill-usage.js +267 -0
- package/src/lib/skills-manager.js +1591 -0
- package/src/lib/source-metadata.js +48 -0
- package/src/lib/sqlite-reader.js +215 -0
- package/src/lib/star-cta.js +73 -0
- package/src/lib/subscription-manager.js +293 -0
- package/src/lib/subscriptions.js +508 -0
- package/src/lib/telemetry.js +193 -0
- package/src/lib/tracker-paths.js +16 -0
- package/src/lib/trae-cn-config.js +548 -0
- package/src/lib/trae-db.js +127 -0
- package/src/lib/trae-snapshot.js +230 -0
- package/src/lib/trae-sqlite.js +143 -0
- package/src/lib/trae-usage.js +121 -0
- package/src/lib/upload-queue.js +134 -0
- package/src/lib/upload-throttle.js +171 -0
- package/src/lib/usage-limits.js +4552 -0
- package/src/lib/wrapped-aggregator.js +236 -0
- package/src/lib/wsl-probe.js +281 -0
- package/src/lib/zcode-limits.js +1172 -0
- package/src/lib/zcode-reset-credits.js +66 -0
- package/test/cli-smoke.test.js +53 -0
- package/test/ingest-sanitize.test.js +162 -0
- package/test/quiet-warnings.test.js +53 -0
- package/test/session-upload.test.js +427 -0
|
@@ -0,0 +1,1747 @@
|
|
|
1
|
+
const os = require("node:os");
|
|
2
|
+
const path = require("node:path");
|
|
3
|
+
const fs = require("node:fs/promises");
|
|
4
|
+
const fssync = require("node:fs");
|
|
5
|
+
const pkg = require("../../package.json");
|
|
6
|
+
const { resolveDumateDbPaths } = require("../lib/dumate");
|
|
7
|
+
|
|
8
|
+
const { readJson } = require("../lib/fs");
|
|
9
|
+
const { readCursorStateSummary } = require("../lib/cursor-store");
|
|
10
|
+
const {
|
|
11
|
+
readCodexNotify,
|
|
12
|
+
readAcodeNotify,
|
|
13
|
+
readEveryCodeNotify,
|
|
14
|
+
buildCodexNotifyCmd,
|
|
15
|
+
buildAcodeNotifyCmd,
|
|
16
|
+
isManagedNotifyCmd,
|
|
17
|
+
} = require("../lib/codex-config");
|
|
18
|
+
const { countRecordOnlyFiles, formatRecordOnlyWarning } = require("../lib/codex-usage-record");
|
|
19
|
+
const {
|
|
20
|
+
isClaudeHookConfigured,
|
|
21
|
+
areClaudeUsageHooksConfigured,
|
|
22
|
+
buildClaudeHookCommand,
|
|
23
|
+
buildHookCommand,
|
|
24
|
+
} = require("../lib/claude-config");
|
|
25
|
+
const {
|
|
26
|
+
resolveGeminiConfigDir,
|
|
27
|
+
resolveGeminiSettingsPath,
|
|
28
|
+
isGeminiHookConfigured,
|
|
29
|
+
buildGeminiHookCommand,
|
|
30
|
+
} = require("../lib/gemini-config");
|
|
31
|
+
const {
|
|
32
|
+
resolveOpencodeConfigDir,
|
|
33
|
+
isOpencodePluginInstalled,
|
|
34
|
+
} = require("../lib/opencode-config");
|
|
35
|
+
const { collectLocalSubscriptions } = require("../lib/subscriptions");
|
|
36
|
+
const {
|
|
37
|
+
describeCopilotOtelStatus,
|
|
38
|
+
readCopilotOauthToken,
|
|
39
|
+
} = require("../lib/usage-limits");
|
|
40
|
+
const {
|
|
41
|
+
normalizeState: normalizeUploadState,
|
|
42
|
+
} = require("../lib/upload-throttle");
|
|
43
|
+
const { collectTrackerDiagnostics } = require("../lib/diagnostics");
|
|
44
|
+
const { detectPassiveProviders, isPassiveModeActive } = require("../lib/passive-mode");
|
|
45
|
+
const { probeOpenclawHookState } = require("../lib/openclaw-hook");
|
|
46
|
+
const {
|
|
47
|
+
probeOpenclawSessionPluginState,
|
|
48
|
+
} = require("../lib/openclaw-session-plugin");
|
|
49
|
+
const { resolveTrackerPaths } = require("../lib/tracker-paths");
|
|
50
|
+
const { resolveDeviceTokenPresence } = require("../lib/cloud-device-token");
|
|
51
|
+
const {
|
|
52
|
+
resolveKimiWireFiles,
|
|
53
|
+
resolveKimiCodeWireFiles,
|
|
54
|
+
resolveKiroCliDbPath,
|
|
55
|
+
resolveKiroCliSessionFiles,
|
|
56
|
+
resolveKiroBasePath,
|
|
57
|
+
resolveKiroDbPath,
|
|
58
|
+
resolveKiroJsonlPath,
|
|
59
|
+
resolveCodebuddyHome,
|
|
60
|
+
resolveCodebuddyProjectFiles,
|
|
61
|
+
resolveWorkbuddyHome,
|
|
62
|
+
resolveWorkbuddyProjectFiles,
|
|
63
|
+
resolveOmpSessionFiles,
|
|
64
|
+
resolveOmpAgentDir,
|
|
65
|
+
resolveOmoSessionFiles,
|
|
66
|
+
resolveOmoAgentDir,
|
|
67
|
+
resolveMinimaxCodeSessionFiles,
|
|
68
|
+
resolveMinimaxCodeSessionsDir,
|
|
69
|
+
resolvePiSessionFiles,
|
|
70
|
+
resolvePiAgentDir,
|
|
71
|
+
piAgentDirCollidesWithOmp,
|
|
72
|
+
resolvePrimeAgentSessionFiles,
|
|
73
|
+
resolvePrimeAgentDir,
|
|
74
|
+
resolveCraftSessionFiles,
|
|
75
|
+
resolveCraftConfigDir,
|
|
76
|
+
resolveReasonixHome,
|
|
77
|
+
resolveReasonixTelemetryFiles,
|
|
78
|
+
resolveMuseHome,
|
|
79
|
+
resolveMuseSessionFiles,
|
|
80
|
+
resolveKilocodeTaskFiles,
|
|
81
|
+
resolveRoocodeTaskFiles,
|
|
82
|
+
resolveClineSessionFilesWithStatus,
|
|
83
|
+
resolveZedDbPath,
|
|
84
|
+
resolveLmstudioHome,
|
|
85
|
+
resolveLmstudioLogFiles,
|
|
86
|
+
resolveUnslothDbPath,
|
|
87
|
+
resolveQoderDbPaths,
|
|
88
|
+
resolveQoderCnDbPaths,
|
|
89
|
+
resolveQoderProjectsDir,
|
|
90
|
+
resolveQoderCnProjectsDir,
|
|
91
|
+
listQoderNewSessionFiles,
|
|
92
|
+
resolveClaudeScienceDbPaths,
|
|
93
|
+
resolveAnythingllmDbPath,
|
|
94
|
+
resolveDevinDbPath,
|
|
95
|
+
resolveGooseDbPath,
|
|
96
|
+
listDroidSettingsFiles,
|
|
97
|
+
resolveDroidSessionsDir,
|
|
98
|
+
resolveDshHomes,
|
|
99
|
+
resolveDshSessionFiles,
|
|
100
|
+
resolveCommandCodeHomes,
|
|
101
|
+
resolveCommandCodeSessionFiles,
|
|
102
|
+
resolveTraeStoragePath,
|
|
103
|
+
readTraeEntitlementFromStorage,
|
|
104
|
+
resolveGrokBuildSessions,
|
|
105
|
+
resolveHermesPath,
|
|
106
|
+
resolveHermesDbPath,
|
|
107
|
+
resolveCopilotSessionStorePaths,
|
|
108
|
+
describeCopilotSessionStoreDb,
|
|
109
|
+
resolveCopilotAppDbPath,
|
|
110
|
+
resolveCopilotAppDbPaths,
|
|
111
|
+
probeWslDistros,
|
|
112
|
+
resolveZcodeInstallPaths,
|
|
113
|
+
} = require("../lib/rollout");
|
|
114
|
+
const {
|
|
115
|
+
TRAE_CN_USAGE_ENV,
|
|
116
|
+
isTraeCnUsageEnabled,
|
|
117
|
+
resolveTraeCnStoragePath,
|
|
118
|
+
readTraeCnAuthFromStorage,
|
|
119
|
+
extractTraeCnToken,
|
|
120
|
+
} = require("../lib/trae-cn-config");
|
|
121
|
+
const wsl = require("../lib/wsl-probe");
|
|
122
|
+
const { getWslMode, isInvalidWslMode, shouldProbeWsl, discoverWslHome } = wsl;
|
|
123
|
+
const { resolveInstallPaths, resolveZcodeNativeDbPath, resolveMimoNativeDbPath } = require("../lib/install-resolver");
|
|
124
|
+
const {
|
|
125
|
+
describeScanRootOrigin,
|
|
126
|
+
describeScanRootState,
|
|
127
|
+
hasAnyScanChild,
|
|
128
|
+
resolveEnvRoot,
|
|
129
|
+
resolveScanRoots,
|
|
130
|
+
} = require("../lib/scan-roots");
|
|
131
|
+
const { probeGrokHookState, resolveGrokHome } = require("../lib/grok-hook");
|
|
132
|
+
const { probeOmpHookState } = require("../lib/omp-hook");
|
|
133
|
+
|
|
134
|
+
// `filename` may be a list, in which case the first child that exists wins. A
|
|
135
|
+
// resolver using requireAnyChild accepts a root that holds ANY of several
|
|
136
|
+
// children, so probing only the first one here would report "not detected" for
|
|
137
|
+
// an install sync happily counts (e.g. Codex with archived_sessions/ but no
|
|
138
|
+
// live sessions/).
|
|
139
|
+
function formatResolvedPaths(paths, filename) {
|
|
140
|
+
const candidates = filename == null ? [] : (Array.isArray(filename) ? filename : [filename]);
|
|
141
|
+
const resolveFile = (root) => {
|
|
142
|
+
if (candidates.length === 0) return root;
|
|
143
|
+
for (const candidate of candidates) {
|
|
144
|
+
const file = path.join(root, candidate);
|
|
145
|
+
try { if (fssync.existsSync(file)) return file; } catch (_e) {}
|
|
146
|
+
}
|
|
147
|
+
return null;
|
|
148
|
+
};
|
|
149
|
+
const active = [];
|
|
150
|
+
for (const [label, root] of [["native", paths.native], ["WSL", paths.wsl]]) {
|
|
151
|
+
if (!root) continue;
|
|
152
|
+
const file = resolveFile(root);
|
|
153
|
+
if (!file) continue;
|
|
154
|
+
try { if (fssync.existsSync(file)) active.push(`${label}: ${file}`); } catch (_e) {}
|
|
155
|
+
}
|
|
156
|
+
return active;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// Combine a legacy DB path with its new-JSONL projects-dir path for the
|
|
160
|
+
// machine-readable summary. Either side may be "" (absent); both absent
|
|
161
|
+
// yields "" so callers can fall back to "not found".
|
|
162
|
+
function summarizeQoderDetail(dbPath, newPath) {
|
|
163
|
+
return [dbPath, newPath].filter(Boolean).join(" + ") || "";
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// The Trae SOLO entitlement snapshot is read directly from the Trae Local
|
|
167
|
+
// State storage.json via the shared parser (readTraeEntitlementFromStorage).
|
|
168
|
+
// The queue.jsonl contract is token-count-only (CLAUDE.md privacy rule), so
|
|
169
|
+
// plan/limits metadata is never persisted into queue rows — this is the read
|
|
170
|
+
// side of that contract so users can actually see the advertised plan data.
|
|
171
|
+
function formatTraeEntitlementLine(ent) {
|
|
172
|
+
const parts = [];
|
|
173
|
+
if (ent.identity) parts.push(`plan ${ent.identity}`);
|
|
174
|
+
if (ent.pro_period) parts.push(`${ent.pro_period} period`);
|
|
175
|
+
if (typeof ent.is_dollar_billing === "boolean") {
|
|
176
|
+
parts.push(ent.is_dollar_billing ? "dollar billing" : "package billing");
|
|
177
|
+
}
|
|
178
|
+
if (typeof ent.enable_solo_builder === "boolean") {
|
|
179
|
+
parts.push(`solo builder: ${ent.enable_solo_builder ? "yes" : "no"}`);
|
|
180
|
+
}
|
|
181
|
+
if (typeof ent.enable_solo_coder === "boolean") {
|
|
182
|
+
parts.push(`solo coder: ${ent.enable_solo_coder ? "yes" : "no"}`);
|
|
183
|
+
}
|
|
184
|
+
if (typeof ent.fast_request_per === "number") {
|
|
185
|
+
parts.push(`${ent.fast_request_per} fast requests/hr`);
|
|
186
|
+
}
|
|
187
|
+
if (ent.in_waitlist === true) parts.push("in waitlist");
|
|
188
|
+
if (ent.captured_at) parts.push(`snapshot ${ent.captured_at}`);
|
|
189
|
+
return parts.length ? parts.join(", ") : "unknown";
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
async function cmdStatus(argv = []) {
|
|
193
|
+
const opts = parseArgs(argv);
|
|
194
|
+
if (opts.diagnostics) {
|
|
195
|
+
const diagnostics = await collectTrackerDiagnostics();
|
|
196
|
+
process.stdout.write(JSON.stringify(diagnostics, null, 2) + "\n");
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const home = os.homedir();
|
|
201
|
+
const { trackerDir, binDir } = await resolveTrackerPaths({ home });
|
|
202
|
+
const configPath = path.join(trackerDir, "config.json");
|
|
203
|
+
const queuePath = path.join(trackerDir, "queue.jsonl");
|
|
204
|
+
const queueStatePath = path.join(trackerDir, "queue.state.json");
|
|
205
|
+
const cursorsPath = path.join(trackerDir, "cursors.json");
|
|
206
|
+
const notifySignalPath = path.join(trackerDir, "notify.signal");
|
|
207
|
+
const openclawSignalPath = path.join(trackerDir, "openclaw.signal");
|
|
208
|
+
const throttlePath = path.join(trackerDir, "sync.throttle");
|
|
209
|
+
const uploadThrottlePath = path.join(trackerDir, "upload.throttle.json");
|
|
210
|
+
const autoRetryPath = path.join(trackerDir, "auto.retry.json");
|
|
211
|
+
const syncSkipPath = path.join(trackerDir, "sync.skip.json");
|
|
212
|
+
// Normalized like sync (a relative CODEX_HOME is anchored to home, not cwd)
|
|
213
|
+
// so status lists exactly the root sync walks.
|
|
214
|
+
const codexHome = resolveEnvRoot("codex", { env: process.env, home }) || path.join(home, ".codex");
|
|
215
|
+
const codexConfigPath = path.join(codexHome, "config.toml");
|
|
216
|
+
const acodeHome = process.env.TOKENUSAGE_ACODE_HOME || path.join(home, ".acode");
|
|
217
|
+
const acodeConfigPath = path.join(acodeHome, "config.toml");
|
|
218
|
+
const codeHome = process.env.CODE_HOME || path.join(home, ".code");
|
|
219
|
+
const codeConfigPath = path.join(codeHome, "config.toml");
|
|
220
|
+
const claudeSettingsPath = path.join(home, ".claude", "settings.json");
|
|
221
|
+
const codebuddySettingsPath = path.join(
|
|
222
|
+
resolveCodebuddyHome(process.env) || path.join(home, ".codebuddy"),
|
|
223
|
+
"settings.json",
|
|
224
|
+
);
|
|
225
|
+
const workbuddySettingsPath = path.join(
|
|
226
|
+
resolveWorkbuddyHome(process.env) || path.join(home, ".workbuddy"),
|
|
227
|
+
"settings.json",
|
|
228
|
+
);
|
|
229
|
+
// WorkBuddy AI — international build, sibling home (~/.workbuddy-ai).
|
|
230
|
+
const workbuddyAiSettingsPath = path.join(
|
|
231
|
+
resolveWorkbuddyHome(process.env, "workbuddy-ai") || path.join(home, ".workbuddy-ai"),
|
|
232
|
+
"settings.json",
|
|
233
|
+
);
|
|
234
|
+
const geminiConfigDir = resolveGeminiConfigDir({ home, env: process.env });
|
|
235
|
+
const geminiSettingsPath = resolveGeminiSettingsPath({
|
|
236
|
+
configDir: geminiConfigDir,
|
|
237
|
+
});
|
|
238
|
+
const opencodeConfigDir = resolveOpencodeConfigDir({
|
|
239
|
+
home,
|
|
240
|
+
env: process.env,
|
|
241
|
+
});
|
|
242
|
+
const notifyPath = path.join(binDir, "notify.cjs");
|
|
243
|
+
const codexNotifyCmd = buildCodexNotifyCmd(notifyPath);
|
|
244
|
+
const acodeNotifyCmd = buildAcodeNotifyCmd(notifyPath);
|
|
245
|
+
const claudeHookCommand = buildClaudeHookCommand(notifyPath);
|
|
246
|
+
const codebuddyHookCommand = buildHookCommand(notifyPath, "codebuddy");
|
|
247
|
+
const workbuddyHookCommand = buildHookCommand(notifyPath, "workbuddy");
|
|
248
|
+
const workbuddyAiHookCommand = buildHookCommand(notifyPath, "workbuddy-ai");
|
|
249
|
+
const geminiHookCommand = buildGeminiHookCommand(notifyPath);
|
|
250
|
+
|
|
251
|
+
const config = await readJson(configPath);
|
|
252
|
+
// Extra scan roots (#657): CODEX_HOME / CLAUDE_CONFIG_DIR of this process
|
|
253
|
+
// plus config.scanRoots, resolved exactly as sync does, so status lists every
|
|
254
|
+
// root sync walks — this is the output users paste when usage looks wrong.
|
|
255
|
+
const scanRoots = resolveScanRoots({
|
|
256
|
+
home,
|
|
257
|
+
env: process.env,
|
|
258
|
+
config,
|
|
259
|
+
base: { codex: [codexHome], claude: [path.join(home, ".claude")] },
|
|
260
|
+
});
|
|
261
|
+
const extraScanRoots = [];
|
|
262
|
+
for (const provider of ["codex", "claude"]) {
|
|
263
|
+
for (const entry of scanRoots[provider]) {
|
|
264
|
+
if (entry.origin === "native") continue;
|
|
265
|
+
extraScanRoots.push({
|
|
266
|
+
provider,
|
|
267
|
+
origin: describeScanRootOrigin(entry, provider),
|
|
268
|
+
path: entry.path,
|
|
269
|
+
exists: entry.exists,
|
|
270
|
+
error: entry.error || null,
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
const describeExtraScanRoot = (root) =>
|
|
275
|
+
`${root.provider} ${root.origin}: ${root.path}${describeScanRootState(root)}`;
|
|
276
|
+
const scanRootsLine = extraScanRoots.length > 0
|
|
277
|
+
? `- Extra scan roots: ${extraScanRoots.map(describeExtraScanRoot).join(" | ")}`
|
|
278
|
+
: null;
|
|
279
|
+
const { cursors } = await readCursorStateSummary({ trackerDir, cursorsPath });
|
|
280
|
+
const codexRecordOnlyWarning = formatRecordOnlyWarning(countRecordOnlyFiles(cursors));
|
|
281
|
+
const queueState = (await readJson(queueStatePath)) || { offset: 0 };
|
|
282
|
+
const uploadThrottle = normalizeUploadState(
|
|
283
|
+
await readJson(uploadThrottlePath),
|
|
284
|
+
);
|
|
285
|
+
const autoRetry = await readJson(autoRetryPath);
|
|
286
|
+
// Written by sync whenever it had to skip a run. Present here so a stalled
|
|
287
|
+
// parse has a visible cause instead of only a frozen "Last parse".
|
|
288
|
+
const syncSkip = await readJson(syncSkipPath);
|
|
289
|
+
|
|
290
|
+
const queueSize = await safeStatSize(queuePath);
|
|
291
|
+
const pendingBytes = Math.max(0, queueSize - (queueState.offset || 0));
|
|
292
|
+
|
|
293
|
+
const lastNotify = (await safeReadText(notifySignalPath))?.trim() || null;
|
|
294
|
+
const lastOpenclawSync =
|
|
295
|
+
(await safeReadText(openclawSignalPath))?.trim() || null;
|
|
296
|
+
const lastNotifySpawn = parseEpochMsToIso(
|
|
297
|
+
(await safeReadText(throttlePath))?.trim() || null,
|
|
298
|
+
);
|
|
299
|
+
|
|
300
|
+
const codexNotify = await readCodexNotify(codexConfigPath);
|
|
301
|
+
// Not arraysEqual: argv[0] and binDir differ between the desktop app and a
|
|
302
|
+
// terminal `tokenusage` run, so a correctly-installed integration would
|
|
303
|
+
// otherwise report as not configured. See isManagedNotifyCmd.
|
|
304
|
+
const notifyConfigured = isManagedNotifyCmd(codexNotify, codexNotifyCmd);
|
|
305
|
+
const acodeNotify = await readAcodeNotify(acodeConfigPath);
|
|
306
|
+
const acodeConfigured = isManagedNotifyCmd(acodeNotify, acodeNotifyCmd);
|
|
307
|
+
const everyCodeNotify = await readEveryCodeNotify(codeConfigPath);
|
|
308
|
+
const everyCodeConfigured =
|
|
309
|
+
Array.isArray(everyCodeNotify) && everyCodeNotify.length > 0;
|
|
310
|
+
const claudeHookConfigured = await areClaudeUsageHooksConfigured({
|
|
311
|
+
settingsPath: claudeSettingsPath,
|
|
312
|
+
hookCommand: claudeHookCommand,
|
|
313
|
+
});
|
|
314
|
+
const codebuddyHookConfigured = await isClaudeHookConfigured({
|
|
315
|
+
settingsPath: codebuddySettingsPath,
|
|
316
|
+
hookCommand: codebuddyHookCommand,
|
|
317
|
+
});
|
|
318
|
+
const workbuddyHookConfigured = await isClaudeHookConfigured({
|
|
319
|
+
settingsPath: workbuddySettingsPath,
|
|
320
|
+
hookCommand: workbuddyHookCommand,
|
|
321
|
+
});
|
|
322
|
+
const workbuddyAiHookConfigured = await isClaudeHookConfigured({
|
|
323
|
+
settingsPath: workbuddyAiSettingsPath,
|
|
324
|
+
hookCommand: workbuddyAiHookCommand,
|
|
325
|
+
});
|
|
326
|
+
const geminiHookConfigured = await isGeminiHookConfigured({
|
|
327
|
+
settingsPath: geminiSettingsPath,
|
|
328
|
+
hookCommand: geminiHookCommand,
|
|
329
|
+
});
|
|
330
|
+
const opencodePluginConfigured = await isOpencodePluginInstalled({
|
|
331
|
+
configDir: opencodeConfigDir,
|
|
332
|
+
});
|
|
333
|
+
const openclawSessionPluginState = await probeOpenclawSessionPluginState({
|
|
334
|
+
home,
|
|
335
|
+
trackerDir,
|
|
336
|
+
env: process.env,
|
|
337
|
+
});
|
|
338
|
+
const openclawHookState = await probeOpenclawHookState({
|
|
339
|
+
home,
|
|
340
|
+
trackerDir,
|
|
341
|
+
env: process.env,
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
const lastUpload = uploadThrottle.lastSuccessMs
|
|
345
|
+
? parseEpochMsToIso(uploadThrottle.lastSuccessMs)
|
|
346
|
+
: typeof queueState.updatedAt === "string"
|
|
347
|
+
? queueState.updatedAt
|
|
348
|
+
: null;
|
|
349
|
+
const nextUpload = parseEpochMsToIso(uploadThrottle.nextAllowedAtMs || null);
|
|
350
|
+
const backoffUntil = parseEpochMsToIso(uploadThrottle.backoffUntilMs || null);
|
|
351
|
+
const lastUploadError = uploadThrottle.lastError
|
|
352
|
+
? `${uploadThrottle.lastErrorAt || "unknown"} ${uploadThrottle.lastError}`
|
|
353
|
+
: null;
|
|
354
|
+
const syncSkipLine = syncSkip?.at
|
|
355
|
+
? `- Last sync skipped: ${syncSkip.at} (${syncSkip.reason || "unknown"}${
|
|
356
|
+
syncSkip.detail ? `, ${syncSkip.detail}` : ""
|
|
357
|
+
})`
|
|
358
|
+
: null;
|
|
359
|
+
const autoRetryAt = parseEpochMsToIso(autoRetry?.retryAtMs || null);
|
|
360
|
+
const autoRetryLine = autoRetryAt
|
|
361
|
+
? `- Auto retry after: ${autoRetryAt} (${autoRetry?.reason || "scheduled"}, pending ${Number(
|
|
362
|
+
autoRetry?.pendingBytes || 0,
|
|
363
|
+
)} bytes)`
|
|
364
|
+
: null;
|
|
365
|
+
|
|
366
|
+
const subscriptions = await collectLocalSubscriptions({
|
|
367
|
+
home,
|
|
368
|
+
env: process.env,
|
|
369
|
+
probeKeychain: opts.probeKeychain,
|
|
370
|
+
probeKeychainDetails: opts.probeKeychainDetails,
|
|
371
|
+
});
|
|
372
|
+
const subscriptionLines =
|
|
373
|
+
subscriptions.length > 0 ? subscriptions.map(formatSubscriptionLine) : [];
|
|
374
|
+
|
|
375
|
+
const kimiWireFiles = resolveKimiWireFiles(process.env);
|
|
376
|
+
const kimiHome = process.env.KIMI_HOME || path.join(home, ".kimi");
|
|
377
|
+
const kimiInstalled = fssync.existsSync(path.join(kimiHome, "sessions"));
|
|
378
|
+
|
|
379
|
+
const kimiCodeWireFiles = resolveKimiCodeWireFiles(process.env);
|
|
380
|
+
const kimiCodeHome = process.env.KIMI_CODE_HOME || path.join(home, ".kimi-code");
|
|
381
|
+
const kimiCodeInstalled = fssync.existsSync(path.join(kimiCodeHome, "sessions"));
|
|
382
|
+
|
|
383
|
+
// Kiro CLI — reads the legacy SQLite/session files and Kiro CLI 2.13+
|
|
384
|
+
// event sessions. End-user dashboards show them merged under "Kiro"; this
|
|
385
|
+
// status line surfaces which passive sources are actually present.
|
|
386
|
+
const kiroCliDbPath = resolveKiroCliDbPath(process.env);
|
|
387
|
+
const kiroCliSessionFiles = resolveKiroCliSessionFiles(process.env);
|
|
388
|
+
const kiroCliNativePresent =
|
|
389
|
+
fssync.existsSync(kiroCliDbPath) || kiroCliSessionFiles.length > 0;
|
|
390
|
+
// WSL install discovery mirrors sync: overrides pin a single install.
|
|
391
|
+
let kiroCliWsl = null; // { db, sessionFiles }
|
|
392
|
+
if (
|
|
393
|
+
process.platform === "win32" &&
|
|
394
|
+
!process.env.KIRO_CLI_DB_PATH && !process.env.KIRO_HOME &&
|
|
395
|
+
wsl.shouldProbeWsl(process.env)
|
|
396
|
+
) {
|
|
397
|
+
const wslKiroHomeDir = wsl.discoverWslHome(".kiro");
|
|
398
|
+
const wslCliDataDir = wsl.discoverWslHome(".local/share/kiro-cli");
|
|
399
|
+
const wslHomeRoot = wslKiroHomeDir
|
|
400
|
+
? path.dirname(wslKiroHomeDir)
|
|
401
|
+
: (wslCliDataDir ? path.dirname(path.dirname(path.dirname(wslCliDataDir))) : null);
|
|
402
|
+
if (wslHomeRoot) {
|
|
403
|
+
const wslDb = path.join(wslHomeRoot, ".local", "share", "kiro-cli", "data.sqlite3");
|
|
404
|
+
const wslFiles = resolveKiroCliSessionFiles({
|
|
405
|
+
...process.env,
|
|
406
|
+
KIRO_CLI_DB_PATH: wslDb,
|
|
407
|
+
KIRO_HOME: path.join(wslHomeRoot, ".kiro"),
|
|
408
|
+
});
|
|
409
|
+
if (fssync.existsSync(wslDb) || wslFiles.length > 0) {
|
|
410
|
+
kiroCliWsl = { db: wslDb, sessionFiles: wslFiles };
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
const kiroCliPaths = process.platform === "win32"
|
|
415
|
+
? wsl.resolveAllWin32Paths({
|
|
416
|
+
nativeValue: kiroCliNativePresent ? kiroCliDbPath : null,
|
|
417
|
+
wslValue: kiroCliWsl ? kiroCliWsl.db : null,
|
|
418
|
+
env: process.env,
|
|
419
|
+
platform: "win32",
|
|
420
|
+
})
|
|
421
|
+
: { native: kiroCliNativePresent ? kiroCliDbPath : null, wsl: null };
|
|
422
|
+
// Non-both modes park the picked value in the native slot — label by
|
|
423
|
+
// marker identity, not slot name. A session-files-only install has no DB
|
|
424
|
+
// on disk; show the sessions dir instead of a nonexistent DB path.
|
|
425
|
+
const kiroCliMarkers = [kiroCliPaths.native, kiroCliPaths.wsl].filter(Boolean);
|
|
426
|
+
const kiroCliActive = kiroCliMarkers.map((m) => {
|
|
427
|
+
if (kiroCliWsl && m === kiroCliWsl.db) {
|
|
428
|
+
const shown = fssync.existsSync(m) || kiroCliWsl.sessionFiles.length === 0
|
|
429
|
+
? m
|
|
430
|
+
: path.dirname(kiroCliWsl.sessionFiles[0]);
|
|
431
|
+
return `WSL: ${shown}`;
|
|
432
|
+
}
|
|
433
|
+
const shown = fssync.existsSync(m) || kiroCliSessionFiles.length === 0
|
|
434
|
+
? m
|
|
435
|
+
: path.dirname(kiroCliSessionFiles[0]);
|
|
436
|
+
return `native: ${shown}`;
|
|
437
|
+
});
|
|
438
|
+
const kiroCliFileCount =
|
|
439
|
+
(kiroCliMarkers.includes(kiroCliDbPath) ? kiroCliSessionFiles.length : 0) +
|
|
440
|
+
(kiroCliWsl && kiroCliMarkers.includes(kiroCliWsl.db) ? kiroCliWsl.sessionFiles.length : 0);
|
|
441
|
+
const kiroCliDbFound = kiroCliMarkers.some((m) => {
|
|
442
|
+
try { return fssync.existsSync(m); } catch (_e) { return false; }
|
|
443
|
+
});
|
|
444
|
+
const kiroCliInstalled = kiroCliMarkers.length > 0;
|
|
445
|
+
|
|
446
|
+
// Kiro IDE — passive scan of globalStorage dev_data (SQLite or JSONL).
|
|
447
|
+
const kiroIdeNativeBase = resolveKiroBasePath(process.env);
|
|
448
|
+
const wslKiroIdeBase = process.platform === "win32" && wsl.shouldProbeWsl(process.env)
|
|
449
|
+
? wsl.discoverWslHome(".config/Kiro/User/globalStorage/kiro.kiroagent")
|
|
450
|
+
: null;
|
|
451
|
+
const kiroIdePaths = resolveInstallPaths({ nativeValue: kiroIdeNativeBase, wslValue: wslKiroIdeBase });
|
|
452
|
+
const kiroIdeHasData = (base) => Boolean(base)
|
|
453
|
+
&& (fssync.existsSync(resolveKiroDbPath(base)) || fssync.existsSync(resolveKiroJsonlPath(base)));
|
|
454
|
+
const kiroIdeActive = [kiroIdePaths.native, kiroIdePaths.wsl]
|
|
455
|
+
.filter((base) => kiroIdeHasData(base))
|
|
456
|
+
.map((base) => (wslKiroIdeBase && base === wslKiroIdeBase ? `WSL: ${base}` : `native: ${base}`));
|
|
457
|
+
const kiroIdeInstalled = kiroIdeActive.length > 0;
|
|
458
|
+
|
|
459
|
+
// Claude Code — dual-install aware projects scan (#307). Mirrors sync:
|
|
460
|
+
// installs are UNIONED (not single-picked by mode) so a WSL ~/.claude
|
|
461
|
+
// never hides the native one from view, and labels come from install
|
|
462
|
+
// identity rather than resolveAllWin32Paths' slot names.
|
|
463
|
+
const claudeCodeActive = [];
|
|
464
|
+
{
|
|
465
|
+
const claudeHomesStatus = [];
|
|
466
|
+
if (process.platform !== "win32" || wsl.shouldProbeNative(process.env)) {
|
|
467
|
+
claudeHomesStatus.push({ dir: path.join(home, ".claude"), label: "native" });
|
|
468
|
+
}
|
|
469
|
+
const wslClaudeHomeStatus = process.platform === "win32" && wsl.shouldProbeWsl(process.env)
|
|
470
|
+
? wsl.discoverWslHome(".claude")
|
|
471
|
+
: null;
|
|
472
|
+
if (wslClaudeHomeStatus) claudeHomesStatus.push({ dir: wslClaudeHomeStatus, label: "WSL" });
|
|
473
|
+
for (const entry of scanRoots.claude) {
|
|
474
|
+
if (entry.origin === "native" || !entry.exists) continue;
|
|
475
|
+
claudeHomesStatus.push({ dir: entry.path, label: describeScanRootOrigin(entry, "claude") });
|
|
476
|
+
}
|
|
477
|
+
for (const { dir, label } of claudeHomesStatus) {
|
|
478
|
+
const projects = path.join(dir, "projects");
|
|
479
|
+
try {
|
|
480
|
+
if (fssync.existsSync(projects)) claudeCodeActive.push(`${label}: ${projects}`);
|
|
481
|
+
} catch (_e) {}
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
const claudeCodeInstalled = claudeCodeActive.length > 0;
|
|
485
|
+
|
|
486
|
+
// AnythingLLM Desktop — per-message token metrics in workspace_chats.
|
|
487
|
+
const anythingllmDbPath = resolveAnythingllmDbPath(process.env);
|
|
488
|
+
const anythingllmInstalled = Boolean(
|
|
489
|
+
anythingllmDbPath && fssync.existsSync(anythingllmDbPath),
|
|
490
|
+
);
|
|
491
|
+
|
|
492
|
+
// CodeBuddy — passive scan only (no hooks). Surface the file count so
|
|
493
|
+
// operators can confirm JSONL sessions and extension logs are discovered.
|
|
494
|
+
const codebuddyHome = resolveCodebuddyHome(process.env);
|
|
495
|
+
const codebuddyInstalled = Boolean(codebuddyHome && fssync.existsSync(codebuddyHome));
|
|
496
|
+
const codebuddyFiles = codebuddyInstalled
|
|
497
|
+
? resolveCodebuddyProjectFiles(process.env)
|
|
498
|
+
: [];
|
|
499
|
+
|
|
500
|
+
// WorkBuddy — passive scan (sibling Claude-Code fork). Surface both the
|
|
501
|
+
// recursive JSONL count and SQLite fallback so operators can confirm coverage.
|
|
502
|
+
const workbuddyHome = resolveWorkbuddyHome(process.env);
|
|
503
|
+
const workbuddyInstalled = Boolean(workbuddyHome && fssync.existsSync(workbuddyHome));
|
|
504
|
+
const workbuddyFiles = workbuddyInstalled
|
|
505
|
+
? resolveWorkbuddyProjectFiles(process.env)
|
|
506
|
+
: [];
|
|
507
|
+
const workbuddyDbExists = workbuddyInstalled
|
|
508
|
+
? fssync.existsSync(path.join(workbuddyHome, "workbuddy.db"))
|
|
509
|
+
: false;
|
|
510
|
+
|
|
511
|
+
const workbuddyAiHome = resolveWorkbuddyHome(process.env, "workbuddy-ai");
|
|
512
|
+
const workbuddyAiInstalled = Boolean(workbuddyAiHome && fssync.existsSync(workbuddyAiHome));
|
|
513
|
+
const workbuddyAiFiles = workbuddyAiInstalled
|
|
514
|
+
? resolveWorkbuddyProjectFiles(process.env, "workbuddy-ai")
|
|
515
|
+
: [];
|
|
516
|
+
const workbuddyAiDbExists = workbuddyAiInstalled
|
|
517
|
+
? fssync.existsSync(path.join(workbuddyAiHome, "workbuddy.db"))
|
|
518
|
+
: false;
|
|
519
|
+
|
|
520
|
+
// oh-my-pi — passive scan + optional notify extension.
|
|
521
|
+
const ompAgentDir = resolveOmpAgentDir(process.env);
|
|
522
|
+
const ompInstalled = Boolean(ompAgentDir) && fssync.existsSync(path.join(ompAgentDir, "sessions"));
|
|
523
|
+
const ompFiles = ompInstalled ? resolveOmpSessionFiles(process.env) : [];
|
|
524
|
+
const ompHookState = await probeOmpHookState({ home, trackerDir, env: process.env });
|
|
525
|
+
|
|
526
|
+
// OmO — passive scan only (no hooks).
|
|
527
|
+
const omoAgentDir = resolveOmoAgentDir(process.env);
|
|
528
|
+
const omoInstalled = Boolean(omoAgentDir) && fssync.existsSync(path.join(omoAgentDir, "sessions"));
|
|
529
|
+
const omoFiles = omoInstalled ? resolveOmoSessionFiles(process.env) : [];
|
|
530
|
+
|
|
531
|
+
// MiniMax Code — passive scan only (no hooks).
|
|
532
|
+
const minimaxCodeSessionsDir = resolveMinimaxCodeSessionsDir(process.env);
|
|
533
|
+
const minimaxCodeInstalled = Boolean(minimaxCodeSessionsDir) && fssync.existsSync(minimaxCodeSessionsDir);
|
|
534
|
+
const minimaxCodeFiles = minimaxCodeInstalled ? resolveMinimaxCodeSessionFiles(process.env) : [];
|
|
535
|
+
|
|
536
|
+
// pi (@mariozechner/pi-coding-agent) — passive scan only (no hooks).
|
|
537
|
+
// Skip when its agent dir collides with omp's; sync would dedupe anyway.
|
|
538
|
+
const piCollides = piAgentDirCollidesWithOmp(process.env);
|
|
539
|
+
const piAgentDir = resolvePiAgentDir(process.env);
|
|
540
|
+
const piInstalled = !piCollides && Boolean(piAgentDir) && fssync.existsSync(path.join(piAgentDir, "sessions"));
|
|
541
|
+
const piFiles = piInstalled ? resolvePiSessionFiles(process.env) : [];
|
|
542
|
+
|
|
543
|
+
// Prime Agent — passive scan only (no hooks).
|
|
544
|
+
const primeAgentDir = resolvePrimeAgentDir(process.env);
|
|
545
|
+
const primeAgentInstalled = Boolean(primeAgentDir) && fssync.existsSync(path.join(primeAgentDir, "sessions"));
|
|
546
|
+
const primeAgentFiles = primeAgentInstalled ? resolvePrimeAgentSessionFiles(process.env) : [];
|
|
547
|
+
|
|
548
|
+
// Craft Agents — passive scan only (no hooks).
|
|
549
|
+
const craftConfigDir = resolveCraftConfigDir(process.env);
|
|
550
|
+
const craftInstalled = Boolean(craftConfigDir && fssync.existsSync(craftConfigDir));
|
|
551
|
+
const craftFiles = craftInstalled ? resolveCraftSessionFiles(process.env) : [];
|
|
552
|
+
|
|
553
|
+
// Reasonix — passive scan of content-free cumulative telemetry sidecars.
|
|
554
|
+
const reasonixHome = resolveReasonixHome(process.env);
|
|
555
|
+
const reasonixInstalled = Boolean(reasonixHome && fssync.existsSync(reasonixHome));
|
|
556
|
+
const reasonixFiles = reasonixInstalled ? resolveReasonixTelemetryFiles(process.env) : [];
|
|
557
|
+
|
|
558
|
+
// Muse Code (Meta) — passive scan of per-session session.jsonl logs.
|
|
559
|
+
const museInstalled = fssync.existsSync(path.join(resolveMuseHome(process.env), "sessions"));
|
|
560
|
+
const museFiles = museInstalled ? resolveMuseSessionFiles(process.env) : [];
|
|
561
|
+
|
|
562
|
+
// Kilo CLI (kilo.ai @kilocode/plugin) — passive scan of kilo.db.
|
|
563
|
+
const xdgDataHome = process.env.XDG_DATA_HOME || path.join(home, ".local", "share");
|
|
564
|
+
const kiloHome = process.env.KILO_HOME || path.join(xdgDataHome, "kilo");
|
|
565
|
+
const kiloNativeValue = process.platform === "win32" && typeof process.env.APPDATA === "string"
|
|
566
|
+
? path.join(process.env.APPDATA.trim(), "kilo", "kilo.db")
|
|
567
|
+
: path.join(kiloHome, "kilo.db");
|
|
568
|
+
const wslKiloDir = process.platform === "win32" && wsl.shouldProbeWsl(process.env)
|
|
569
|
+
? wsl.discoverWslHome(".local/share/kilo")
|
|
570
|
+
: null;
|
|
571
|
+
const kiloPaths = resolveInstallPaths({ nativeValue: kiloNativeValue, wslValue: wslKiloDir ? path.join(wslKiloDir, "kilo.db") : null });
|
|
572
|
+
const kiloActive = formatResolvedPaths(kiloPaths);
|
|
573
|
+
const kiloInstalled = kiloActive.length > 0;
|
|
574
|
+
const kiloDbPath = kiloActive.join(" | ");
|
|
575
|
+
|
|
576
|
+
const dumateDbPaths = resolveDumateDbPaths({ home });
|
|
577
|
+
const dumateInstalled = dumateDbPaths.length > 0;
|
|
578
|
+
const dumateDbPath = dumateDbPaths.join(" | ");
|
|
579
|
+
|
|
580
|
+
// Mimo (mimocode — OpenCode-fork SQLite) — passive scan of mimocode.db.
|
|
581
|
+
const mimoNativeValue = resolveMimoNativeDbPath({ home });
|
|
582
|
+
const wslMimoDir = process.platform === "win32" && wsl.shouldProbeWsl(process.env)
|
|
583
|
+
? wsl.discoverWslHome(".local/share/mimocode")
|
|
584
|
+
: null;
|
|
585
|
+
const mimoPaths = resolveInstallPaths({ nativeValue: mimoNativeValue, wslValue: wslMimoDir ? path.join(wslMimoDir, "mimocode.db") : null });
|
|
586
|
+
const mimoActive = formatResolvedPaths(mimoPaths);
|
|
587
|
+
const mimoInstalled = mimoActive.length > 0;
|
|
588
|
+
const mimoDbPath = mimoActive.join(" | ");
|
|
589
|
+
|
|
590
|
+
// ZCode (Z.ai's coding agent — OpenCode-fork SQLite) — passive scan of db.sqlite.
|
|
591
|
+
const zcodeNativeValue = resolveZcodeNativeDbPath({ home });
|
|
592
|
+
const wslZcodeDir = process.platform === "win32" && wsl.shouldProbeWsl(process.env)
|
|
593
|
+
? wsl.discoverWslHome(".zcode")
|
|
594
|
+
: null;
|
|
595
|
+
const zcodePaths = resolveZcodeInstallPaths(
|
|
596
|
+
{ nativeValue: zcodeNativeValue, wslValue: wslZcodeDir ? path.join(wslZcodeDir, "cli", "db", "db.sqlite") : null },
|
|
597
|
+
process.env, { cursors },
|
|
598
|
+
);
|
|
599
|
+
const zcodeActive = formatResolvedPaths(zcodePaths);
|
|
600
|
+
const zcodeInstalled = zcodeActive.length > 0;
|
|
601
|
+
const zcodeDbPath = zcodeActive.join(" | ");
|
|
602
|
+
|
|
603
|
+
// Qoder Desktop 1.18+ — token usage lives in SharedClientCache/local.db (legacy)
|
|
604
|
+
// and since 2026-08 (app 0.1.2+) also in ~/.qoder/projects JSONL (credit-based).
|
|
605
|
+
const qoderPaths = resolveQoderDbPaths({
|
|
606
|
+
home,
|
|
607
|
+
env: process.env,
|
|
608
|
+
platform: process.platform,
|
|
609
|
+
});
|
|
610
|
+
const qoderActive = formatResolvedPaths(qoderPaths);
|
|
611
|
+
// New JSONL location (com.qoder.app.stable + ~/.qoder/projects)
|
|
612
|
+
const qoderProjectsDirResolved = resolveQoderProjectsDir({ home, env: process.env });
|
|
613
|
+
let qoderNewFiles = [];
|
|
614
|
+
try {
|
|
615
|
+
qoderNewFiles = await listQoderNewSessionFiles(qoderProjectsDirResolved);
|
|
616
|
+
} catch (_e) {
|
|
617
|
+
qoderNewFiles = [];
|
|
618
|
+
}
|
|
619
|
+
const qoderNewInstalled = qoderNewFiles.length > 0;
|
|
620
|
+
const qoderInstalled = qoderActive.length > 0 || qoderNewInstalled;
|
|
621
|
+
const qoderDbPath = qoderActive.join(" | ");
|
|
622
|
+
const qoderNewPath = qoderNewFiles.length > 0
|
|
623
|
+
? `${qoderProjectsDirResolved} (${qoderNewFiles.length} sessions)`
|
|
624
|
+
: "";
|
|
625
|
+
|
|
626
|
+
// Qoder CN (国内版) — same schema, separate Application Support/QoderCN dir.
|
|
627
|
+
const qoderCnPaths = resolveQoderCnDbPaths({
|
|
628
|
+
home,
|
|
629
|
+
env: process.env,
|
|
630
|
+
platform: process.platform,
|
|
631
|
+
});
|
|
632
|
+
const qoderCnActive = formatResolvedPaths(qoderCnPaths);
|
|
633
|
+
// CN new-JSONL mirrors sync.js: the new CN app writes ~/.qoder-cn/projects,
|
|
634
|
+
// but sync only parses the CN dir when it diverges from the international
|
|
635
|
+
// one (same files must not count under two sources). Only report CN JSONL
|
|
636
|
+
// when the dirs diverge.
|
|
637
|
+
const qoderCnProjectsDirResolved = resolveQoderCnProjectsDir({ home, env: process.env });
|
|
638
|
+
const qoderCnSharesIntlDir = path.normalize(qoderCnProjectsDirResolved) === path.normalize(qoderProjectsDirResolved)
|
|
639
|
+
|| (process.platform === "win32"
|
|
640
|
+
&& path.normalize(qoderCnProjectsDirResolved).toLowerCase() === path.normalize(qoderProjectsDirResolved).toLowerCase());
|
|
641
|
+
let qoderCnNewFiles = [];
|
|
642
|
+
if (!qoderCnSharesIntlDir) {
|
|
643
|
+
try {
|
|
644
|
+
qoderCnNewFiles = await listQoderNewSessionFiles(qoderCnProjectsDirResolved);
|
|
645
|
+
} catch (_e) {
|
|
646
|
+
qoderCnNewFiles = [];
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
const qoderCnNewInstalled = qoderCnNewFiles.length > 0;
|
|
650
|
+
const qoderCnInstalled = qoderCnActive.length > 0 || qoderCnNewInstalled;
|
|
651
|
+
const qoderCnDbPath = qoderCnActive.join(" | ");
|
|
652
|
+
const qoderCnNewPath = qoderCnNewFiles.length > 0
|
|
653
|
+
? `${qoderCnProjectsDirResolved} (${qoderCnNewFiles.length} sessions)`
|
|
654
|
+
: "";
|
|
655
|
+
|
|
656
|
+
// Claude Science — token usage lives on the `frames` table of operon-cli.db.
|
|
657
|
+
// Unlike the native/WSL pair other providers resolve to, this is an open-ended
|
|
658
|
+
// list: multi-org installs keep one DB per org (and on Windows they all sit
|
|
659
|
+
// inside WSL), so the resolver already returns only paths that exist.
|
|
660
|
+
const claudeScienceActive = resolveClaudeScienceDbPaths({ home, env: process.env });
|
|
661
|
+
const claudeScienceInstalled = claudeScienceActive.length > 0;
|
|
662
|
+
const claudeScienceDbPath = claudeScienceActive.join(" | ");
|
|
663
|
+
|
|
664
|
+
// OpenCode (JSON files + SQLite DB) — passive scan of storage/message/ and opencode.db.
|
|
665
|
+
const opencodeStorageNativeValue = process.env.OPENCODE_HOME || path.join(xdgDataHome, "opencode");
|
|
666
|
+
const wslOpencodeStorageDir = process.platform === "win32" && shouldProbeWsl(process.env)
|
|
667
|
+
? discoverWslHome(".local/share/opencode")
|
|
668
|
+
: null;
|
|
669
|
+
const opencodeStoragePaths = resolveInstallPaths({
|
|
670
|
+
nativeValue: opencodeStorageNativeValue,
|
|
671
|
+
wslValue: wslOpencodeStorageDir,
|
|
672
|
+
});
|
|
673
|
+
const opencodeStorageActive = formatResolvedPaths(opencodeStoragePaths);
|
|
674
|
+
|
|
675
|
+
const opencodeDbNativeValue = process.env.OPENCODE_HOME || path.join(xdgDataHome, "opencode");
|
|
676
|
+
const wslOpencodeDbDir = process.platform === "win32" && shouldProbeWsl(process.env)
|
|
677
|
+
? discoverWslHome(".local/share/opencode")
|
|
678
|
+
: null;
|
|
679
|
+
const opencodeDbPaths = resolveInstallPaths({
|
|
680
|
+
nativeValue: opencodeDbNativeValue,
|
|
681
|
+
wslValue: wslOpencodeDbDir,
|
|
682
|
+
});
|
|
683
|
+
const opencodeDbActive = formatResolvedPaths(opencodeDbPaths, "opencode.db");
|
|
684
|
+
const opencodeInstalled = opencodeStorageActive.length > 0 || opencodeDbActive.length > 0;
|
|
685
|
+
|
|
686
|
+
// Every Code (passive sessions scan)
|
|
687
|
+
const codePaths = resolveInstallPaths({
|
|
688
|
+
nativeValue: process.env.CODE_HOME || path.join(home, ".code"),
|
|
689
|
+
wslDir: ".code",
|
|
690
|
+
});
|
|
691
|
+
const codeActive = formatResolvedPaths(codePaths, "sessions");
|
|
692
|
+
const codeInstalled = codeActive.length > 0;
|
|
693
|
+
|
|
694
|
+
// Gemini CLI & Antigravity (shared home)
|
|
695
|
+
const geminiPaths = resolveInstallPaths({
|
|
696
|
+
nativeValue: process.env.GEMINI_HOME || path.join(home, ".gemini"),
|
|
697
|
+
wslDir: ".gemini",
|
|
698
|
+
});
|
|
699
|
+
const geminiActive = formatResolvedPaths(geminiPaths);
|
|
700
|
+
const geminiInstalledStatus = geminiActive.length > 0;
|
|
701
|
+
|
|
702
|
+
// Gemini CLI (passive sessions scan)
|
|
703
|
+
const geminiCliActive = formatResolvedPaths(geminiPaths, "tmp");
|
|
704
|
+
const geminiCliInstalled = geminiCliActive.length > 0;
|
|
705
|
+
|
|
706
|
+
// Antigravity (passive brains scan)
|
|
707
|
+
const antigravityActive = [];
|
|
708
|
+
if (geminiPaths.native) {
|
|
709
|
+
const dirs = [
|
|
710
|
+
path.join(geminiPaths.native, "antigravity", "brain"),
|
|
711
|
+
path.join(geminiPaths.native, "antigravity-ide", "brain"),
|
|
712
|
+
path.join(geminiPaths.native, "antigravity-cli", "brain"),
|
|
713
|
+
];
|
|
714
|
+
if (dirs.some(d => { try { return fssync.existsSync(d); } catch (_) { return false; } })) {
|
|
715
|
+
antigravityActive.push(`native: ${geminiPaths.native}`);
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
if (geminiPaths.wsl) {
|
|
719
|
+
const dirs = [
|
|
720
|
+
path.join(geminiPaths.wsl, "antigravity", "brain"),
|
|
721
|
+
path.join(geminiPaths.wsl, "antigravity-ide", "brain"),
|
|
722
|
+
path.join(geminiPaths.wsl, "antigravity-cli", "brain"),
|
|
723
|
+
];
|
|
724
|
+
if (dirs.some(d => { try { return fssync.existsSync(d); } catch (_) { return false; } })) {
|
|
725
|
+
antigravityActive.push(`WSL: ${geminiPaths.wsl}`);
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
const antigravityInstalled = antigravityActive.length > 0;
|
|
729
|
+
|
|
730
|
+
// Codex CLI (passive sessions scan). Mirrors the sync resolution exactly
|
|
731
|
+
// (union + requireAnyChild, see src/commands/sync.js): status is the tool
|
|
732
|
+
// users are asked to paste when Codex usage looks wrong, so it must list
|
|
733
|
+
// every root sync actually walks — and no empty shell sync would skip.
|
|
734
|
+
const codexPaths = resolveInstallPaths({
|
|
735
|
+
nativeValue: codexHome,
|
|
736
|
+
wslDir: ".codex",
|
|
737
|
+
requireAnyChild: ["sessions", "archived_sessions"],
|
|
738
|
+
union: true,
|
|
739
|
+
});
|
|
740
|
+
// Both children, matching requireAnyChild above: an install holding only
|
|
741
|
+
// archived_sessions/ is counted by sync and must not read as "not detected".
|
|
742
|
+
const codexActive = formatResolvedPaths(codexPaths, ["sessions", "archived_sessions"]);
|
|
743
|
+
for (const entry of scanRoots.codex) {
|
|
744
|
+
if (entry.origin === "native" || !entry.exists) continue;
|
|
745
|
+
if (!hasAnyScanChild(entry.path, ["sessions", "archived_sessions"])) continue;
|
|
746
|
+
codexActive.push(`${describeScanRootOrigin(entry, "codex")}: ${entry.path}`);
|
|
747
|
+
}
|
|
748
|
+
const codexInstalledStatus = codexActive.length > 0;
|
|
749
|
+
|
|
750
|
+
const acodePaths = resolveInstallPaths({
|
|
751
|
+
nativeValue: acodeHome,
|
|
752
|
+
wslDir: ".acode",
|
|
753
|
+
requireAnyChild: ["sessions", "archived_sessions"],
|
|
754
|
+
union: true,
|
|
755
|
+
});
|
|
756
|
+
const acodeActive = formatResolvedPaths(acodePaths, ["sessions", "archived_sessions"]);
|
|
757
|
+
const acodeInstalled = acodeActive.length > 0;
|
|
758
|
+
|
|
759
|
+
// Kimi (passive sessions scan)
|
|
760
|
+
const kimiPaths = resolveInstallPaths({
|
|
761
|
+
nativeValue: path.join(home, ".kimi"),
|
|
762
|
+
wslDir: ".kimi",
|
|
763
|
+
});
|
|
764
|
+
const kimiActive = formatResolvedPaths(kimiPaths, "sessions");
|
|
765
|
+
|
|
766
|
+
// Kilo Code VS Code extension — passive scan of all VS Code-family
|
|
767
|
+
// globalStorage/kilocode.kilo-code/tasks/ ui_messages.json files.
|
|
768
|
+
const kilocodeTaskFiles = resolveKilocodeTaskFiles(process.env);
|
|
769
|
+
const kilocodeInstalled = kilocodeTaskFiles.length > 0;
|
|
770
|
+
|
|
771
|
+
// Roo Code VS Code extension — same Cline-derived ui_messages.json format,
|
|
772
|
+
// different globalStorage subdir (rooveterinaryinc.roo-cline).
|
|
773
|
+
const roocodeTaskFiles = resolveRoocodeTaskFiles(process.env);
|
|
774
|
+
const roocodeInstalled = roocodeTaskFiles.length > 0;
|
|
775
|
+
|
|
776
|
+
// Cline CLI v3 / desktop app — passive scan of
|
|
777
|
+
// <home>/data/sessions/*/<session>.messages.json (Cline's own data dir, not
|
|
778
|
+
// the VS Code globalStorage the Roo/Kilo forks still use).
|
|
779
|
+
const clineScan = resolveClineSessionFilesWithStatus(process.env);
|
|
780
|
+
const clineSessionFiles = clineScan.files;
|
|
781
|
+
const clineInstalled = clineSessionFiles.length > 0;
|
|
782
|
+
const clineSessionsDirCount = new Set(
|
|
783
|
+
clineSessionFiles.map((file) => path.dirname(path.dirname(file.filePath))),
|
|
784
|
+
).size;
|
|
785
|
+
const clineDiscoveryError = clineScan.errors.length > 0
|
|
786
|
+
? clineScan.errors
|
|
787
|
+
.map(({ root, error }) => `${root}: ${error.code ? `${error.code}: ` : ""}${error.message}`)
|
|
788
|
+
.join("; ")
|
|
789
|
+
: null;
|
|
790
|
+
|
|
791
|
+
// Zed Agent — passive read of threads.db across all model providers
|
|
792
|
+
// (hosted "zed.dev" and bring-your-own alike). threadTotals tracks one entry
|
|
793
|
+
// per thread we've surfaced usage for, so its size distinguishes "DB present
|
|
794
|
+
// with usage" from "DB present but nothing counted yet" (fresh/undecodable).
|
|
795
|
+
const zedDbPath = resolveZedDbPath(process.env);
|
|
796
|
+
const zedInstalled = Boolean(zedDbPath && fssync.existsSync(zedDbPath));
|
|
797
|
+
const zedThreadsCounted =
|
|
798
|
+
cursors?.zed?.threadTotals && typeof cursors.zed.threadTotals === "object"
|
|
799
|
+
? Object.keys(cursors.zed.threadTotals).length
|
|
800
|
+
: 0;
|
|
801
|
+
|
|
802
|
+
// Goose (Block) — passive cumulative-delta read of sessions.db.
|
|
803
|
+
const gooseDbPath = resolveGooseDbPath(process.env);
|
|
804
|
+
const gooseInstalled = Boolean(gooseDbPath && fssync.existsSync(gooseDbPath));
|
|
805
|
+
|
|
806
|
+
// Droid (Factory CLI) — passive cumulative-delta read of *.settings.json.
|
|
807
|
+
const droidSessionsDir = resolveDroidSessionsDir(process.env);
|
|
808
|
+
const droidSettingsFiles = listDroidSettingsFiles(process.env);
|
|
809
|
+
const droidInstalled = droidSettingsFiles.length > 0;
|
|
810
|
+
const dshHomes = resolveDshHomes(process.env);
|
|
811
|
+
const dshSessionsDir = dshHomes.map((homeDir) => path.join(homeDir, "sessions")).join(", ");
|
|
812
|
+
const dshSessionFiles = await resolveDshSessionFiles(process.env);
|
|
813
|
+
const dshInstalled = dshSessionFiles.length > 0;
|
|
814
|
+
let commandCodeProjectsDir = "";
|
|
815
|
+
let commandCodeSessionFiles = [];
|
|
816
|
+
let commandCodeDiscoveryError = null;
|
|
817
|
+
try {
|
|
818
|
+
commandCodeProjectsDir = resolveCommandCodeHomes(process.env)
|
|
819
|
+
.map((homeDir) => path.join(homeDir, "projects"))
|
|
820
|
+
.join(", ");
|
|
821
|
+
commandCodeSessionFiles = await resolveCommandCodeSessionFiles(process.env);
|
|
822
|
+
} catch (error) {
|
|
823
|
+
// Discovery stays strict for sync, but a provider read error must not
|
|
824
|
+
// suppress the rest of the status diagnostics.
|
|
825
|
+
commandCodeDiscoveryError = `${error?.code ? `${error.code}: ` : ""}${error?.message || String(error)}`;
|
|
826
|
+
}
|
|
827
|
+
const commandCodeInstalled = commandCodeSessionFiles.length > 0;
|
|
828
|
+
const lmstudioHome = resolveLmstudioHome(process.env);
|
|
829
|
+
const lmstudioLogFiles = await resolveLmstudioLogFiles(process.env);
|
|
830
|
+
const lmstudioInstalled = lmstudioLogFiles.length > 0;
|
|
831
|
+
const unslothDbPath = resolveUnslothDbPath(process.env);
|
|
832
|
+
const unslothInstalled = Boolean(unslothDbPath && fssync.existsSync(unslothDbPath));
|
|
833
|
+
|
|
834
|
+
// Devin CLI (Cognition) — passive reader of message_nodes usage metrics.
|
|
835
|
+
const devinDbPath = resolveDevinDbPath(process.env);
|
|
836
|
+
const devinInstalled = Boolean(devinDbPath && fssync.existsSync(devinDbPath));
|
|
837
|
+
|
|
838
|
+
const { resolveTraeDbPaths } = require("../lib/trae-db");
|
|
839
|
+
const traeDbPaths = resolveTraeDbPaths(process.env);
|
|
840
|
+
const traeStoragePath = resolveTraeStoragePath(process.env);
|
|
841
|
+
const traeInstalled = Boolean(traeStoragePath || traeDbPaths.length);
|
|
842
|
+
// Render path for the entitlement snapshot: read it straight from the
|
|
843
|
+
// Trae Local State storage.json via the shared parser. The queue stays
|
|
844
|
+
// token-count-only, so the status read path never depends on queue rows
|
|
845
|
+
// carrying plan/limits metadata.
|
|
846
|
+
const traeEntitlement = traeInstalled
|
|
847
|
+
? readTraeEntitlementFromStorage(traeStoragePath)
|
|
848
|
+
: null;
|
|
849
|
+
|
|
850
|
+
// Trae SOLO CN — opt-in usage-API reader. Unlike the passive entitlement
|
|
851
|
+
// reader above, this source sends the locally stored sign-in JWT to TRAE's
|
|
852
|
+
// official API, so status surfaces the opt-in flag, the resolved storage
|
|
853
|
+
// path, and whether the auth blob decrypts — the three inputs a "why is my
|
|
854
|
+
// TRAE CN data missing" diagnosis needs.
|
|
855
|
+
// A resolvable default path does NOT mean the app is installed - the
|
|
856
|
+
// macOS/Windows resolver always derives one. Match the sync path semantics
|
|
857
|
+
// exactly: installed iff the storage file actually exists on disk.
|
|
858
|
+
const traeCnStoragePath = resolveTraeCnStoragePath({ env: process.env, home });
|
|
859
|
+
const traeCnInstalled = Boolean(
|
|
860
|
+
traeCnStoragePath && fssync.existsSync(traeCnStoragePath),
|
|
861
|
+
);
|
|
862
|
+
let traeCnAuthState = "not-signed-in";
|
|
863
|
+
if (traeCnInstalled) {
|
|
864
|
+
try {
|
|
865
|
+
const traeCnAuth = readTraeCnAuthFromStorage({ env: process.env, home, platform: process.platform });
|
|
866
|
+
if (traeCnAuth) {
|
|
867
|
+
extractTraeCnToken(traeCnAuth);
|
|
868
|
+
traeCnAuthState = "readable";
|
|
869
|
+
}
|
|
870
|
+
} catch (error) {
|
|
871
|
+
// Distinguish a real IO failure (unreadable) from present-but-bad
|
|
872
|
+
// data (malformed); neither ever carries storage contents.
|
|
873
|
+
traeCnAuthState = error?.code === "TRAE_CN_STORAGE_UNREADABLE" ? "unreadable" : "malformed";
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
const traeCnUsageOptIn = isTraeCnUsageEnabled(process.env);
|
|
877
|
+
|
|
878
|
+
// Grok Build (xAI TUI)
|
|
879
|
+
const grokHookState = await probeGrokHookState({ home, trackerDir, env: process.env });
|
|
880
|
+
const grokSessions = grokHookState.hasGrokInstall || grokHookState.sessionsDir
|
|
881
|
+
? resolveGrokBuildSessions(process.env)
|
|
882
|
+
: [];
|
|
883
|
+
const grokInstalled = grokHookState.hasGrokInstall || grokSessions.length > 0;
|
|
884
|
+
|
|
885
|
+
// Hermes Agent — SQLite state.db, resolved via override / native Windows
|
|
886
|
+
// install / WSL auto-discovery. Surface the resolved path (UNC included) and,
|
|
887
|
+
// on Windows, the discovered distros so WSL users can debug "why no sync"
|
|
888
|
+
// without guessing the right UNC alias (#87).
|
|
889
|
+
const hermesPaths = resolveInstallPaths({
|
|
890
|
+
nativeValue: process.env.TOKENUSAGE_HERMES_HOME || (process.platform === "win32" && typeof process.env.LOCALAPPDATA === "string"
|
|
891
|
+
? path.join(process.env.LOCALAPPDATA.trim(), "hermes")
|
|
892
|
+
: path.join(home, ".hermes")),
|
|
893
|
+
wslDir: ".hermes",
|
|
894
|
+
});
|
|
895
|
+
const hermesActive = formatResolvedPaths(hermesPaths, "state.db");
|
|
896
|
+
const hermesInstalled = hermesActive.length > 0;
|
|
897
|
+
const hermesPath = hermesActive.join(" | ");
|
|
898
|
+
const wslDistros = process.platform === "win32" && shouldProbeWsl(process.env) ? probeWslDistros() : [];
|
|
899
|
+
|
|
900
|
+
const copilotToken = readCopilotOauthToken({ home });
|
|
901
|
+
const copilotOtel = describeCopilotOtelStatus({ home, env: process.env });
|
|
902
|
+
const copilotAppDbPaths = resolveCopilotAppDbPaths(process.env);
|
|
903
|
+
const copilotAppExistingPaths = copilotAppDbPaths.filter((p) => {
|
|
904
|
+
try { return fssync.existsSync(p); } catch (_e) { return false; }
|
|
905
|
+
});
|
|
906
|
+
const copilotStorePaths = Array.from(
|
|
907
|
+
new Set([
|
|
908
|
+
...resolveCopilotSessionStorePaths(process.env),
|
|
909
|
+
...Object.keys(cursors?.copilotStore?.dbs || {}),
|
|
910
|
+
]),
|
|
911
|
+
);
|
|
912
|
+
const copilotStoreExistingPaths = copilotStorePaths.filter((p) => {
|
|
913
|
+
try { return fssync.existsSync(p); } catch (_e) { return false; }
|
|
914
|
+
});
|
|
915
|
+
const copilotStoreDetails = [];
|
|
916
|
+
const copilotStoreInspectionErrors = [];
|
|
917
|
+
for (const storePath of copilotStoreExistingPaths) {
|
|
918
|
+
try {
|
|
919
|
+
copilotStoreDetails.push(describeCopilotSessionStoreDb(storePath));
|
|
920
|
+
} catch (err) {
|
|
921
|
+
copilotStoreInspectionErrors.push(
|
|
922
|
+
`${storePath}: ${err && err.message ? err.message : String(err)}`,
|
|
923
|
+
);
|
|
924
|
+
}
|
|
925
|
+
}
|
|
926
|
+
const copilotStoreCursor =
|
|
927
|
+
cursors?.copilotStore && typeof cursors.copilotStore === "object"
|
|
928
|
+
? cursors.copilotStore
|
|
929
|
+
: {};
|
|
930
|
+
const copilotStoreDbStates =
|
|
931
|
+
copilotStoreCursor.dbs && typeof copilotStoreCursor.dbs === "object"
|
|
932
|
+
? copilotStoreCursor.dbs
|
|
933
|
+
: {};
|
|
934
|
+
const copilotStatusPathKey = (dbPath) => {
|
|
935
|
+
const normalized = path.normalize(dbPath);
|
|
936
|
+
return process.platform === "win32" ? normalized.toLowerCase() : normalized;
|
|
937
|
+
};
|
|
938
|
+
const existingCopilotStoreKeys = new Set(
|
|
939
|
+
copilotStoreExistingPaths.map(copilotStatusPathKey),
|
|
940
|
+
);
|
|
941
|
+
const adoptedCopilotStores = Object.entries(copilotStoreDbStates).filter(
|
|
942
|
+
([, state]) => state?.adoptedAt,
|
|
943
|
+
);
|
|
944
|
+
const missingAdoptedCopilotStores = adoptedCopilotStores
|
|
945
|
+
.map(([dbPath]) => dbPath)
|
|
946
|
+
.filter((dbPath) => !existingCopilotStoreKeys.has(copilotStatusPathKey(dbPath)));
|
|
947
|
+
const copilotStoreDegradedReasons = [
|
|
948
|
+
...missingAdoptedCopilotStores.map(
|
|
949
|
+
(dbPath) => `canonical store unavailable: ${dbPath}`,
|
|
950
|
+
),
|
|
951
|
+
...copilotStoreInspectionErrors.map(
|
|
952
|
+
(message) => `store inspection failed: ${message}`,
|
|
953
|
+
),
|
|
954
|
+
...Object.entries(copilotStoreDbStates)
|
|
955
|
+
.filter(([, state]) => state?.lastError)
|
|
956
|
+
.map(([dbPath, state]) => `${dbPath}: ${state.lastError}`),
|
|
957
|
+
];
|
|
958
|
+
const malformedCopilotEvents = Object.values(copilotStoreDbStates).reduce(
|
|
959
|
+
(sum, state) => sum + Math.max(0, Number(state?.malformedEventCount) || 0),
|
|
960
|
+
0,
|
|
961
|
+
);
|
|
962
|
+
if (malformedCopilotEvents > 0) {
|
|
963
|
+
copilotStoreDegradedReasons.push(
|
|
964
|
+
`${malformedCopilotEvents} event${malformedCopilotEvents === 1 ? "" : "s"} lack a valid timestamp`,
|
|
965
|
+
);
|
|
966
|
+
}
|
|
967
|
+
const copilotResetGapEvents = Object.values(copilotStoreDbStates).reduce(
|
|
968
|
+
(sum, state) => sum + Math.max(0, Number(state?.resetGapEventCount) || 0),
|
|
969
|
+
0,
|
|
970
|
+
);
|
|
971
|
+
if (copilotResetGapEvents > 0) {
|
|
972
|
+
copilotStoreDegradedReasons.push(
|
|
973
|
+
`${copilotResetGapEvents} event${copilotResetGapEvents === 1 ? "" : "s"} were baselined during a legacy cursor/reset race`,
|
|
974
|
+
);
|
|
975
|
+
}
|
|
976
|
+
const copilotStoreCanonical =
|
|
977
|
+
copilotStoreCursor.active === true && adoptedCopilotStores.length > 0;
|
|
978
|
+
const copilotStoreDegraded = copilotStoreDegradedReasons.length > 0;
|
|
979
|
+
const copilotStoreStatus = {
|
|
980
|
+
store_paths: copilotStoreExistingPaths,
|
|
981
|
+
store_path: copilotStorePaths[0] || null,
|
|
982
|
+
store_has_file: copilotStoreExistingPaths.length > 0,
|
|
983
|
+
store_details: copilotStoreDetails.map((detail) => ({
|
|
984
|
+
path: detail.path,
|
|
985
|
+
schema_version: detail.schemaVersion,
|
|
986
|
+
event_count: detail.eventCount,
|
|
987
|
+
last_event_id: detail.lastEventId,
|
|
988
|
+
last_event_at: detail.lastEventAt,
|
|
989
|
+
})),
|
|
990
|
+
canonical: copilotStoreCanonical,
|
|
991
|
+
source_mode: copilotStoreCanonical
|
|
992
|
+
? copilotStoreDegraded
|
|
993
|
+
? "canonical-degraded"
|
|
994
|
+
: "canonical"
|
|
995
|
+
: copilotStoreExistingPaths.length > 0
|
|
996
|
+
? "awaiting-adoption"
|
|
997
|
+
: "legacy",
|
|
998
|
+
precision: copilotStoreCanonical
|
|
999
|
+
? "exact-post-adoption; aggregate-pre-adoption"
|
|
1000
|
+
: "aggregate",
|
|
1001
|
+
coverage: copilotStoreCanonical
|
|
1002
|
+
? "per-request-post-adoption; legacy-aggregate-pre-adoption"
|
|
1003
|
+
: "legacy-aggregate",
|
|
1004
|
+
malformed_event_count: malformedCopilotEvents,
|
|
1005
|
+
reset_gap_event_count: copilotResetGapEvents,
|
|
1006
|
+
degraded: copilotStoreDegraded,
|
|
1007
|
+
degraded_reasons: copilotStoreDegradedReasons,
|
|
1008
|
+
recommended_action: copilotStoreDegraded
|
|
1009
|
+
? "Restore or repair the Copilot session store, then run `tokenusage sync`."
|
|
1010
|
+
: null,
|
|
1011
|
+
};
|
|
1012
|
+
const copilotAppStatus = {
|
|
1013
|
+
app_db_path: resolveCopilotAppDbPath(process.env),
|
|
1014
|
+
app_db_paths: copilotAppExistingPaths,
|
|
1015
|
+
app_db_has_file: copilotAppExistingPaths.length > 0,
|
|
1016
|
+
app_db_mode: copilotStoreCanonical ? "observe-only" : "legacy-writer",
|
|
1017
|
+
};
|
|
1018
|
+
const copilotLines = formatCopilotLines({
|
|
1019
|
+
token: copilotToken,
|
|
1020
|
+
otel: copilotOtel,
|
|
1021
|
+
sessionStore: copilotStoreStatus,
|
|
1022
|
+
appDb: copilotAppStatus,
|
|
1023
|
+
});
|
|
1024
|
+
|
|
1025
|
+
// Detect passive-mode providers exactly once — both the JSON/light path
|
|
1026
|
+
// and the human-readable path consume this, and each call hits 5 readdir
|
|
1027
|
+
// syscalls (~5–10ms cold). Memoize.
|
|
1028
|
+
const passiveProviders = detectPassiveProviders({
|
|
1029
|
+
home,
|
|
1030
|
+
env: process.env,
|
|
1031
|
+
hookStatus: {
|
|
1032
|
+
codex_notify: notifyConfigured,
|
|
1033
|
+
acode_notify: acodeConfigured,
|
|
1034
|
+
every_code_notify: everyCodeConfigured,
|
|
1035
|
+
claude: claudeHookConfigured,
|
|
1036
|
+
gemini: geminiHookConfigured,
|
|
1037
|
+
opencode_plugin: opencodePluginConfigured,
|
|
1038
|
+
openclaw_session_plugin: Boolean(openclawSessionPluginState?.configured),
|
|
1039
|
+
codebuddy: Boolean(codebuddyHookConfigured),
|
|
1040
|
+
workbuddy: Boolean(workbuddyHookConfigured),
|
|
1041
|
+
"workbuddy-ai": Boolean(workbuddyAiHookConfigured),
|
|
1042
|
+
grok: Boolean(grokHookState?.configured),
|
|
1043
|
+
},
|
|
1044
|
+
});
|
|
1045
|
+
|
|
1046
|
+
const deviceTokenPresence = resolveDeviceTokenPresence({
|
|
1047
|
+
trackerDir,
|
|
1048
|
+
config: config || {},
|
|
1049
|
+
});
|
|
1050
|
+
|
|
1051
|
+
if (opts.json || opts.light) {
|
|
1052
|
+
const summary = {
|
|
1053
|
+
version: pkg.version,
|
|
1054
|
+
generated_at: new Date().toISOString(),
|
|
1055
|
+
base_url: config?.baseUrl || null,
|
|
1056
|
+
device_token_set: deviceTokenPresence.set,
|
|
1057
|
+
queue: {
|
|
1058
|
+
pending_bytes: pendingBytes,
|
|
1059
|
+
size_bytes: queueSize,
|
|
1060
|
+
offset: queueState.offset || 0,
|
|
1061
|
+
},
|
|
1062
|
+
last_parse: cursors?.updatedAt || null,
|
|
1063
|
+
last_notify: lastNotify || null,
|
|
1064
|
+
last_openclaw_sync: lastOpenclawSync || null,
|
|
1065
|
+
last_notify_spawn: lastNotifySpawn || null,
|
|
1066
|
+
last_upload: lastUpload || null,
|
|
1067
|
+
next_upload_after: nextUpload || null,
|
|
1068
|
+
backoff_until: backoffUntil || null,
|
|
1069
|
+
last_upload_error: lastUploadError || null,
|
|
1070
|
+
last_sync_skipped: syncSkip?.at ? syncSkip : null,
|
|
1071
|
+
auto_retry: autoRetry || null,
|
|
1072
|
+
// Extra scan roots (#657): CODEX_HOME / CLAUDE_CONFIG_DIR of this process
|
|
1073
|
+
// plus config.scanRoots; `exists` false + `error` null means absent,
|
|
1074
|
+
// `error` set means present but unreadable.
|
|
1075
|
+
extra_scan_roots: extraScanRoots,
|
|
1076
|
+
hooks: {
|
|
1077
|
+
codex_notify: notifyConfigured,
|
|
1078
|
+
acode_notify: acodeConfigured,
|
|
1079
|
+
every_code_notify: everyCodeConfigured,
|
|
1080
|
+
claude: claudeHookConfigured,
|
|
1081
|
+
gemini: geminiHookConfigured,
|
|
1082
|
+
opencode_plugin: opencodePluginConfigured,
|
|
1083
|
+
openclaw_session_plugin: Boolean(openclawSessionPluginState?.configured),
|
|
1084
|
+
openclaw_session_plugin_conversation_access: Boolean(
|
|
1085
|
+
openclawSessionPluginState?.conversationAccess,
|
|
1086
|
+
),
|
|
1087
|
+
openclaw_legacy: Boolean(openclawHookState?.configured),
|
|
1088
|
+
codebuddy: codebuddyInstalled ? Boolean(codebuddyHookConfigured) : null,
|
|
1089
|
+
workbuddy: workbuddyInstalled ? Boolean(workbuddyHookConfigured) : null,
|
|
1090
|
+
"workbuddy-ai": workbuddyAiInstalled ? Boolean(workbuddyAiHookConfigured) : null,
|
|
1091
|
+
grok: grokInstalled ? Boolean(grokHookState?.configured) : null,
|
|
1092
|
+
},
|
|
1093
|
+
providers: {
|
|
1094
|
+
acode: acodeInstalled
|
|
1095
|
+
? { installed: true, detail: acodeActive.join(" | ") }
|
|
1096
|
+
: { installed: false },
|
|
1097
|
+
kimi_code: kimiInstalled || kimiCodeInstalled
|
|
1098
|
+
? { installed: true, files: kimiWireFiles.length + kimiCodeWireFiles.length }
|
|
1099
|
+
: { installed: false },
|
|
1100
|
+
kiro_cli: kiroCliInstalled
|
|
1101
|
+
? {
|
|
1102
|
+
installed: true,
|
|
1103
|
+
detail: kiroCliActive.join(" | "),
|
|
1104
|
+
database: kiroCliMarkers.find((m) => {
|
|
1105
|
+
try { return fssync.existsSync(m); } catch (_e) { return false; }
|
|
1106
|
+
}) || null,
|
|
1107
|
+
files: kiroCliFileCount,
|
|
1108
|
+
}
|
|
1109
|
+
: { installed: false },
|
|
1110
|
+
kiro_ide: kiroIdeInstalled
|
|
1111
|
+
? { installed: true, detail: kiroIdeActive.join(" | ") }
|
|
1112
|
+
: { installed: false },
|
|
1113
|
+
claude_code: claudeCodeInstalled
|
|
1114
|
+
? { installed: true, detail: claudeCodeActive.join(" | ") }
|
|
1115
|
+
: { installed: false },
|
|
1116
|
+
codebuddy: codebuddyInstalled
|
|
1117
|
+
? { installed: true, files: codebuddyFiles.length }
|
|
1118
|
+
: { installed: false },
|
|
1119
|
+
workbuddy: workbuddyInstalled
|
|
1120
|
+
? { installed: true, files: workbuddyFiles.length }
|
|
1121
|
+
: { installed: false },
|
|
1122
|
+
workbuddy_ai: workbuddyAiInstalled
|
|
1123
|
+
? { installed: true, files: workbuddyAiFiles.length }
|
|
1124
|
+
: { installed: false },
|
|
1125
|
+
omp: ompInstalled || ompHookState.ompPresent
|
|
1126
|
+
? {
|
|
1127
|
+
installed: true,
|
|
1128
|
+
files: ompFiles.length,
|
|
1129
|
+
notify_extension: Boolean(ompHookState.configured),
|
|
1130
|
+
notify_extension_path: ompHookState.extensionPath || null,
|
|
1131
|
+
}
|
|
1132
|
+
: { installed: false },
|
|
1133
|
+
omo: omoInstalled
|
|
1134
|
+
? { installed: true, files: omoFiles.length }
|
|
1135
|
+
: { installed: false },
|
|
1136
|
+
minimax_code: minimaxCodeInstalled
|
|
1137
|
+
? { installed: true, files: minimaxCodeFiles.length }
|
|
1138
|
+
: { installed: false },
|
|
1139
|
+
pi: piInstalled
|
|
1140
|
+
? { installed: true, files: piFiles.length }
|
|
1141
|
+
: { installed: false },
|
|
1142
|
+
prime_agent: primeAgentInstalled
|
|
1143
|
+
? { installed: true, files: primeAgentFiles.length }
|
|
1144
|
+
: { installed: false },
|
|
1145
|
+
craft: craftInstalled
|
|
1146
|
+
? { installed: true, files: craftFiles.length }
|
|
1147
|
+
: { installed: false },
|
|
1148
|
+
reasonix: reasonixInstalled
|
|
1149
|
+
? { installed: true, files: reasonixFiles.length }
|
|
1150
|
+
: { installed: false },
|
|
1151
|
+
muse: museInstalled
|
|
1152
|
+
? { installed: true, files: museFiles.length }
|
|
1153
|
+
: { installed: false },
|
|
1154
|
+
anythingllm: anythingllmInstalled
|
|
1155
|
+
? { installed: true, detail: anythingllmDbPath }
|
|
1156
|
+
: { installed: false },
|
|
1157
|
+
kilo_cli: kiloInstalled
|
|
1158
|
+
? { installed: true, detail: kiloDbPath }
|
|
1159
|
+
: { installed: false },
|
|
1160
|
+
dumate: dumateInstalled
|
|
1161
|
+
? { installed: true, detail: dumateDbPath }
|
|
1162
|
+
: { installed: false },
|
|
1163
|
+
mimo: mimoInstalled
|
|
1164
|
+
? { installed: true, detail: mimoDbPath }
|
|
1165
|
+
: { installed: false },
|
|
1166
|
+
zcode: zcodeInstalled
|
|
1167
|
+
? { installed: true, detail: zcodeDbPath }
|
|
1168
|
+
: { installed: false },
|
|
1169
|
+
qoder: qoderInstalled
|
|
1170
|
+
? { installed: true, detail: summarizeQoderDetail(qoderDbPath, qoderNewPath) }
|
|
1171
|
+
: { installed: false },
|
|
1172
|
+
"qoder-cn": qoderCnInstalled
|
|
1173
|
+
? { installed: true, detail: summarizeQoderDetail(qoderCnDbPath, qoderCnNewPath) }
|
|
1174
|
+
: { installed: false },
|
|
1175
|
+
"claude-science": claudeScienceInstalled
|
|
1176
|
+
? { installed: true, detail: claudeScienceDbPath }
|
|
1177
|
+
: { installed: false },
|
|
1178
|
+
kilocode: kilocodeInstalled
|
|
1179
|
+
? { installed: true, files: kilocodeTaskFiles.length }
|
|
1180
|
+
: { installed: false },
|
|
1181
|
+
roocode: roocodeInstalled
|
|
1182
|
+
? { installed: true, files: roocodeTaskFiles.length }
|
|
1183
|
+
: { installed: false },
|
|
1184
|
+
cline: clineInstalled
|
|
1185
|
+
? {
|
|
1186
|
+
installed: true,
|
|
1187
|
+
files: clineSessionFiles.length,
|
|
1188
|
+
...(clineDiscoveryError ? { error: clineDiscoveryError } : {}),
|
|
1189
|
+
}
|
|
1190
|
+
: clineDiscoveryError
|
|
1191
|
+
? { installed: false, error: clineDiscoveryError }
|
|
1192
|
+
: { installed: false },
|
|
1193
|
+
zed: zedInstalled ? { installed: true, detail: zedDbPath } : { installed: false },
|
|
1194
|
+
goose: gooseInstalled
|
|
1195
|
+
? { installed: true, detail: gooseDbPath }
|
|
1196
|
+
: { installed: false },
|
|
1197
|
+
droid: droidInstalled
|
|
1198
|
+
? { installed: true, files: droidSettingsFiles.length, detail: droidSessionsDir }
|
|
1199
|
+
: { installed: false },
|
|
1200
|
+
dsh: dshInstalled
|
|
1201
|
+
? { installed: true, files: dshSessionFiles.length, detail: dshSessionsDir }
|
|
1202
|
+
: { installed: false },
|
|
1203
|
+
"command-code": commandCodeInstalled
|
|
1204
|
+
? {
|
|
1205
|
+
installed: true,
|
|
1206
|
+
files: commandCodeSessionFiles.length,
|
|
1207
|
+
detail: commandCodeProjectsDir,
|
|
1208
|
+
}
|
|
1209
|
+
: commandCodeDiscoveryError
|
|
1210
|
+
? { installed: false, error: commandCodeDiscoveryError }
|
|
1211
|
+
: { installed: false },
|
|
1212
|
+
lmstudio: lmstudioInstalled
|
|
1213
|
+
? {
|
|
1214
|
+
installed: true,
|
|
1215
|
+
files: lmstudioLogFiles.length,
|
|
1216
|
+
detail: path.join(lmstudioHome, "server-logs"),
|
|
1217
|
+
}
|
|
1218
|
+
: { installed: false },
|
|
1219
|
+
unsloth: unslothInstalled
|
|
1220
|
+
? { installed: true, detail: unslothDbPath }
|
|
1221
|
+
: { installed: false },
|
|
1222
|
+
devin: devinInstalled
|
|
1223
|
+
? { installed: true, detail: devinDbPath }
|
|
1224
|
+
: { installed: false },
|
|
1225
|
+
trae: traeInstalled
|
|
1226
|
+
? {
|
|
1227
|
+
installed: true,
|
|
1228
|
+
detail: traeDbPaths[0] || traeStoragePath,
|
|
1229
|
+
usage_databases: traeDbPaths.length,
|
|
1230
|
+
usage_key_source: process.env.TOKENUSAGE_TRAE_SQLCIPHER_KEY?.trim() ? "environment" : "application",
|
|
1231
|
+
...(traeEntitlement ? { entitlement: traeEntitlement } : {}),
|
|
1232
|
+
}
|
|
1233
|
+
: { installed: false },
|
|
1234
|
+
"trae-cn": traeCnInstalled
|
|
1235
|
+
? {
|
|
1236
|
+
installed: true,
|
|
1237
|
+
detail: traeCnStoragePath,
|
|
1238
|
+
auth: traeCnAuthState,
|
|
1239
|
+
usage_opt_in: traeCnUsageOptIn,
|
|
1240
|
+
}
|
|
1241
|
+
: { installed: false },
|
|
1242
|
+
grok_build: grokInstalled
|
|
1243
|
+
? {
|
|
1244
|
+
installed: true,
|
|
1245
|
+
files: grokSessions.length,
|
|
1246
|
+
detail: grokHookState.configured ? "hook installed" : "detected",
|
|
1247
|
+
}
|
|
1248
|
+
: { installed: false },
|
|
1249
|
+
hermes: {
|
|
1250
|
+
installed: hermesInstalled,
|
|
1251
|
+
detail: hermesPath,
|
|
1252
|
+
},
|
|
1253
|
+
},
|
|
1254
|
+
copilot: {
|
|
1255
|
+
token_set: Boolean(copilotToken),
|
|
1256
|
+
otel_has_files: Boolean(copilotOtel.otel_has_files),
|
|
1257
|
+
otel_path: copilotOtel.otel_path || null,
|
|
1258
|
+
otel_enabled: Boolean(copilotOtel.otel_enabled),
|
|
1259
|
+
...copilotStoreStatus,
|
|
1260
|
+
...copilotAppStatus,
|
|
1261
|
+
},
|
|
1262
|
+
passive_mode: {
|
|
1263
|
+
active: isPassiveModeActive(passiveProviders),
|
|
1264
|
+
providers: passiveProviders,
|
|
1265
|
+
},
|
|
1266
|
+
...(process.platform === "win32"
|
|
1267
|
+
? {
|
|
1268
|
+
wsl_mode: getWslMode(),
|
|
1269
|
+
wsl_mode_invalid: isInvalidWslMode(),
|
|
1270
|
+
wsl_distros: wslDistros.map((d) => ({ name: d.name, version: d.version })),
|
|
1271
|
+
}
|
|
1272
|
+
: {}),
|
|
1273
|
+
subscriptions,
|
|
1274
|
+
};
|
|
1275
|
+
|
|
1276
|
+
if (opts.json) {
|
|
1277
|
+
process.stdout.write(JSON.stringify(summary, null, 2) + "\n");
|
|
1278
|
+
return;
|
|
1279
|
+
}
|
|
1280
|
+
process.stdout.write(renderLightTable(summary) + "\n");
|
|
1281
|
+
return;
|
|
1282
|
+
}
|
|
1283
|
+
|
|
1284
|
+
process.stdout.write(
|
|
1285
|
+
[
|
|
1286
|
+
`tokenusage v${pkg.version}`,
|
|
1287
|
+
"Status:",
|
|
1288
|
+
`- Base URL: ${config?.baseUrl || "unset"}`,
|
|
1289
|
+
`- Device token: ${deviceTokenPresence.set ? "set" : "unset"}`,
|
|
1290
|
+
`- Queue: ${pendingBytes} bytes pending`,
|
|
1291
|
+
`- Last parse: ${cursors?.updatedAt || "never"}`,
|
|
1292
|
+
`- Last notify: ${lastNotify || "never"}`,
|
|
1293
|
+
`- Last OpenClaw-triggered sync: ${lastOpenclawSync || "never"}`,
|
|
1294
|
+
`- Last notify-triggered sync: ${lastNotifySpawn || "never"}`,
|
|
1295
|
+
`- Last upload: ${lastUpload || "never"}`,
|
|
1296
|
+
`- Next upload after: ${nextUpload || "never"}`,
|
|
1297
|
+
`- Backoff until: ${backoffUntil || "never"}`,
|
|
1298
|
+
lastUploadError ? `- Last upload error: ${lastUploadError}` : null,
|
|
1299
|
+
syncSkipLine,
|
|
1300
|
+
autoRetryLine,
|
|
1301
|
+
scanRootsLine,
|
|
1302
|
+
`- Codex notify: ${notifyConfigured ? JSON.stringify(codexNotify) : "unset"}`,
|
|
1303
|
+
`- AStudio notify: ${acodeConfigured ? JSON.stringify(acodeNotify) : "unset"}`,
|
|
1304
|
+
`- Every Code notify: ${everyCodeConfigured ? JSON.stringify(everyCodeNotify) : "unset"}`,
|
|
1305
|
+
`- Claude hooks: ${claudeHookConfigured ? "set" : "unset"}`,
|
|
1306
|
+
claudeCodeInstalled
|
|
1307
|
+
? `- Claude Code: projects found (${claudeCodeActive.join(" | ")})`
|
|
1308
|
+
: null,
|
|
1309
|
+
`- Gemini hooks: ${geminiHookConfigured ? "set" : "unset"}`,
|
|
1310
|
+
`- Opencode plugin: ${opencodePluginConfigured ? "set" : "unset"}`,
|
|
1311
|
+
`- OpenClaw session plugin: ${openclawSessionPluginState?.configured ? "set" : "unset"}`,
|
|
1312
|
+
`- OpenClaw session plugin conversation access: ${openclawSessionPluginState?.conversationAccess ? "set" : "unset"}`,
|
|
1313
|
+
`- OpenClaw hook (legacy): ${openclawHookState?.configured ? "set" : "unset"}`,
|
|
1314
|
+
kimiInstalled || kimiCodeInstalled
|
|
1315
|
+
? `- Kimi Code: passive reader (${kimiWireFiles.length + kimiCodeWireFiles.length} wire.jsonl file${(kimiWireFiles.length + kimiCodeWireFiles.length) !== 1 ? "s" : ""} found, directories: ${kimiActive.join(" | ") || "none"})`
|
|
1316
|
+
: null,
|
|
1317
|
+
kiroCliInstalled
|
|
1318
|
+
? `- Kiro CLI: passive reader (${kiroCliFileCount} session file${kiroCliFileCount !== 1 ? "s" : ""} found, SQLite ${kiroCliDbFound ? "found" : "not found"}, installs: ${kiroCliActive.join(" | ")}; missing token counts use new-text estimates at ~4 chars/token, excluding re-sent history, system context and cache usage; model-rate costs are separate from Kiro credit charges; merged under 'kiro')`
|
|
1319
|
+
: null,
|
|
1320
|
+
kiroIdeInstalled
|
|
1321
|
+
? `- Kiro IDE: passive reader (${kiroIdeActive.join(" | ")})`
|
|
1322
|
+
: null,
|
|
1323
|
+
codebuddyInstalled
|
|
1324
|
+
? `- CodeBuddy hooks: ${codebuddyHookConfigured ? "set" : "unset"} (${codebuddyFiles.length} usage file${codebuddyFiles.length !== 1 ? "s" : ""} found)`
|
|
1325
|
+
: null,
|
|
1326
|
+
workbuddyInstalled
|
|
1327
|
+
? `- WorkBuddy hooks: ${workbuddyHookConfigured ? "set" : "unset"} (${workbuddyFiles.length} session jsonl file${workbuddyFiles.length !== 1 ? "s" : ""} found, SQLite DB ${workbuddyDbExists ? "found" : "not found"})`
|
|
1328
|
+
: null,
|
|
1329
|
+
workbuddyAiInstalled
|
|
1330
|
+
? `- WorkBuddy AI hooks: ${workbuddyAiHookConfigured ? "set" : "unset"} (${workbuddyAiFiles.length} session jsonl file${workbuddyAiFiles.length !== 1 ? "s" : ""} found, SQLite DB ${workbuddyAiDbExists ? "found" : "not found"})`
|
|
1331
|
+
: null,
|
|
1332
|
+
ompInstalled || ompHookState.ompPresent
|
|
1333
|
+
? `- oh-my-pi: passive reader (${ompFiles.length} session jsonl file${ompFiles.length !== 1 ? "s" : ""} found${ompHookState.configured ? ", notify extension: yes" : ", notify extension: no"})`
|
|
1334
|
+
: null,
|
|
1335
|
+
omoInstalled
|
|
1336
|
+
? `- OmO: passive reader (${omoFiles.length} session jsonl file${omoFiles.length !== 1 ? "s" : ""} found)`
|
|
1337
|
+
: null,
|
|
1338
|
+
minimaxCodeInstalled
|
|
1339
|
+
? `- MiniMax Code: passive reader (${minimaxCodeFiles.length} session jsonl file${minimaxCodeFiles.length !== 1 ? "s" : ""} found)`
|
|
1340
|
+
: null,
|
|
1341
|
+
piInstalled
|
|
1342
|
+
? `- pi: passive reader (${piFiles.length} session jsonl file${piFiles.length !== 1 ? "s" : ""} found)`
|
|
1343
|
+
: null,
|
|
1344
|
+
primeAgentInstalled
|
|
1345
|
+
? `- Prime Agent: passive reader (${primeAgentFiles.length} session jsonl file${primeAgentFiles.length !== 1 ? "s" : ""} found)`
|
|
1346
|
+
: null,
|
|
1347
|
+
craftInstalled
|
|
1348
|
+
? `- Craft Agents: passive reader (${craftFiles.length} session jsonl file${craftFiles.length !== 1 ? "s" : ""} found)`
|
|
1349
|
+
: null,
|
|
1350
|
+
reasonixInstalled
|
|
1351
|
+
? `- Reasonix: passive reader (${reasonixFiles.length} telemetry file${reasonixFiles.length !== 1 ? "s" : ""} found)`
|
|
1352
|
+
: null,
|
|
1353
|
+
museInstalled
|
|
1354
|
+
? `- Muse Code: passive reader (${museFiles.length} session jsonl file${museFiles.length !== 1 ? "s" : ""} found)`
|
|
1355
|
+
: null,
|
|
1356
|
+
anythingllmInstalled
|
|
1357
|
+
? `- AnythingLLM Desktop: passive reader (${anythingllmDbPath})`
|
|
1358
|
+
: null,
|
|
1359
|
+
kiloInstalled
|
|
1360
|
+
? `- Kilo CLI: passive reader (${kiloDbPath})`
|
|
1361
|
+
: null,
|
|
1362
|
+
dumateInstalled
|
|
1363
|
+
? `- DuMate: passive reader (${dumateDbPath})`
|
|
1364
|
+
: null,
|
|
1365
|
+
mimoInstalled
|
|
1366
|
+
? `- Mimo: passive reader (${mimoDbPath})`
|
|
1367
|
+
: null,
|
|
1368
|
+
zcodeInstalled
|
|
1369
|
+
? `- ZCode: passive reader (${zcodeDbPath})`
|
|
1370
|
+
: null,
|
|
1371
|
+
qoderInstalled
|
|
1372
|
+
? `- Qoder: passive reader (${[qoderDbPath, qoderNewPath].filter(Boolean).join(" + ") || "not found"}${qoderNewInstalled && qoderActive.length > 0 ? " [legacy DB + new JSONL (both tracked)]" : ""}${qoderNewInstalled && qoderActive.length === 0 ? " [new JSONL only]" : ""})`
|
|
1373
|
+
: null,
|
|
1374
|
+
qoderCnInstalled
|
|
1375
|
+
? `- Qoder CN: passive reader (${summarizeQoderDetail(qoderCnDbPath, qoderCnNewPath) || "not found"}${qoderCnNewInstalled && qoderCnActive.length > 0 ? " [legacy DB + new JSONL (both tracked)]" : ""}${qoderCnNewInstalled && qoderCnActive.length === 0 ? " [new JSONL only]" : ""})`
|
|
1376
|
+
: null,
|
|
1377
|
+
claudeScienceInstalled
|
|
1378
|
+
? `- Claude Science: passive reader (${claudeScienceDbPath})`
|
|
1379
|
+
: null,
|
|
1380
|
+
opencodeInstalled
|
|
1381
|
+
? `- OpenCode: passive reader (storage: ${opencodeStorageActive.join(" | ") || "not found"}, DB: ${opencodeDbActive.join(" | ") || "not found"})`
|
|
1382
|
+
: null,
|
|
1383
|
+
codeInstalled
|
|
1384
|
+
? `- Every Code: sessions found (${codeActive.join(" | ")})`
|
|
1385
|
+
: null,
|
|
1386
|
+
geminiCliInstalled
|
|
1387
|
+
? `- Gemini CLI: sessions found (${geminiCliActive.join(" | ")})`
|
|
1388
|
+
: null,
|
|
1389
|
+
antigravityInstalled
|
|
1390
|
+
? `- Antigravity: brain found (${antigravityActive.join(" | ")})`
|
|
1391
|
+
: null,
|
|
1392
|
+
(!geminiCliInstalled && !antigravityInstalled && geminiInstalledStatus)
|
|
1393
|
+
? `- Gemini CLI / Antigravity: home found (${geminiActive.join(" | ")})`
|
|
1394
|
+
: null,
|
|
1395
|
+
codexInstalledStatus
|
|
1396
|
+
? `- Codex CLI: sessions found (${codexActive.join(" | ")})`
|
|
1397
|
+
: null,
|
|
1398
|
+
codexRecordOnlyWarning ? `- ⚠ ${codexRecordOnlyWarning}` : null,
|
|
1399
|
+
acodeInstalled
|
|
1400
|
+
? `- AStudio: sessions found (${acodeActive.join(" | ")})`
|
|
1401
|
+
: null,
|
|
1402
|
+
kilocodeInstalled
|
|
1403
|
+
? `- Kilo Code (VS Code extension): passive reader (${kilocodeTaskFiles.length} task${kilocodeTaskFiles.length !== 1 ? "s" : ""} across ${new Set(kilocodeTaskFiles.map((t) => t.ide)).size} IDE${new Set(kilocodeTaskFiles.map((t) => t.ide)).size !== 1 ? "s" : ""})`
|
|
1404
|
+
: null,
|
|
1405
|
+
roocodeInstalled
|
|
1406
|
+
? `- Roo Code (VS Code extension): passive reader (${roocodeTaskFiles.length} task${roocodeTaskFiles.length !== 1 ? "s" : ""} across ${new Set(roocodeTaskFiles.map((t) => t.ide)).size} IDE${new Set(roocodeTaskFiles.map((t) => t.ide)).size !== 1 ? "s" : ""})`
|
|
1407
|
+
: null,
|
|
1408
|
+
clineInstalled
|
|
1409
|
+
? `- Cline: passive reader (${clineSessionFiles.length} transcript${clineSessionFiles.length !== 1 ? "s" : ""} in ${clineSessionsDirCount} sessions dir${clineSessionsDirCount !== 1 ? "s" : ""})${clineDiscoveryError ? `; discovery failed (${clineDiscoveryError})` : ""}`
|
|
1410
|
+
: clineDiscoveryError
|
|
1411
|
+
? `- Cline: discovery failed (${clineDiscoveryError})`
|
|
1412
|
+
: null,
|
|
1413
|
+
zedInstalled
|
|
1414
|
+
? `- Zed Agent: passive reader (threads.db, all providers${
|
|
1415
|
+
zedThreadsCounted > 0
|
|
1416
|
+
? `, ${zedThreadsCounted} thread${zedThreadsCounted !== 1 ? "s" : ""} counted`
|
|
1417
|
+
: ", no usage counted yet"
|
|
1418
|
+
})`
|
|
1419
|
+
: null,
|
|
1420
|
+
gooseInstalled
|
|
1421
|
+
? `- Goose (Block): passive reader (sessions.db, cumulative-delta)`
|
|
1422
|
+
: null,
|
|
1423
|
+
droidInstalled
|
|
1424
|
+
? `- Droid (Factory): passive reader (${droidSettingsFiles.length} session${droidSettingsFiles.length !== 1 ? "s" : ""} in ${droidSessionsDir}, cumulative-delta)`
|
|
1425
|
+
: null,
|
|
1426
|
+
dshInstalled
|
|
1427
|
+
? `- DeepSeek Harness: passive reader (${dshSessionFiles.length} session${dshSessionFiles.length !== 1 ? "s" : ""} in ${dshSessionsDir})`
|
|
1428
|
+
: null,
|
|
1429
|
+
commandCodeInstalled
|
|
1430
|
+
? `- Command Code: passive reader (${commandCodeSessionFiles.length} session${commandCodeSessionFiles.length !== 1 ? "s" : ""} in ${commandCodeProjectsDir})`
|
|
1431
|
+
: commandCodeDiscoveryError
|
|
1432
|
+
? `- Command Code: discovery failed (${commandCodeDiscoveryError})`
|
|
1433
|
+
: null,
|
|
1434
|
+
lmstudioInstalled
|
|
1435
|
+
? `- LM Studio: passive reader (${lmstudioLogFiles.length} log${lmstudioLogFiles.length !== 1 ? "s" : ""} in ${path.join(lmstudioHome, "server-logs")})`
|
|
1436
|
+
: null,
|
|
1437
|
+
unslothInstalled
|
|
1438
|
+
? `- Unsloth Studio: passive reader (${unslothDbPath})`
|
|
1439
|
+
: null,
|
|
1440
|
+
devinInstalled
|
|
1441
|
+
? `- Devin CLI: passive reader (${devinDbPath})`
|
|
1442
|
+
: null,
|
|
1443
|
+
traeInstalled
|
|
1444
|
+
? traeDbPaths.length
|
|
1445
|
+
? `- TRAE: local usage reader, ${traeDbPaths.length} database(s) (shared application key; optional key override)`
|
|
1446
|
+
: `- TRAE: plan info only, no local usage database found (${traeStoragePath})`
|
|
1447
|
+
: null,
|
|
1448
|
+
traeEntitlement
|
|
1449
|
+
? `- Trae SOLO plan: ${formatTraeEntitlementLine(traeEntitlement)}`
|
|
1450
|
+
: null,
|
|
1451
|
+
traeCnInstalled
|
|
1452
|
+
// Installed, signed in, and one env var away from usage data is the
|
|
1453
|
+
// one actionable state on this line — mark it so it does not read
|
|
1454
|
+
// like the ~30 neutral install lines around it (#492). Every other
|
|
1455
|
+
// combination (opted in, or no readable auth to send) is neutral.
|
|
1456
|
+
? `- ${traeCnAuthState === "readable" && !traeCnUsageOptIn ? "⚠ " : ""}Trae SOLO CN: usage sync ${traeCnUsageOptIn ? "opted in" : `off (set ${TRAE_CN_USAGE_ENV}=1 to enable)`}, auth ${traeCnAuthState} (${traeCnStoragePath})`
|
|
1457
|
+
: null,
|
|
1458
|
+
...(() => {
|
|
1459
|
+
if (!hermesInstalled) return [];
|
|
1460
|
+
return [`- Hermes Agent: state.db found (${hermesPath})`];
|
|
1461
|
+
})(),
|
|
1462
|
+
...(() => {
|
|
1463
|
+
const passive = passiveProviders.filter((p) => p.passive);
|
|
1464
|
+
if (passive.length === 0) return [];
|
|
1465
|
+
return [
|
|
1466
|
+
`- Passive mode: ${passive.length} provider${passive.length !== 1 ? "s" : ""} reading logs without hooks (${passive.map((p) => `${p.name}: ${p.hook_failure_reason || "hook unset"}`).join("; ")})`,
|
|
1467
|
+
];
|
|
1468
|
+
})(),
|
|
1469
|
+
grokInstalled
|
|
1470
|
+
? `- Grok Build (xAI): ${grokHookState.configured ? "hook installed" : "detected"} (${grokSessions.length} session${grokSessions.length !== 1 ? "s" : ""} found, hook: ${grokHookState.configured ? "yes" : "no"})`
|
|
1471
|
+
: null,
|
|
1472
|
+
...copilotLines,
|
|
1473
|
+
...(process.platform === "win32" ? (() => {
|
|
1474
|
+
const wslMode = getWslMode();
|
|
1475
|
+
const modeInvalid = isInvalidWslMode();
|
|
1476
|
+
const modeSuffix = modeInvalid ? ` (invalid TOKENUSAGE_WSL_MODE ignored)` : "";
|
|
1477
|
+
const lines = [
|
|
1478
|
+
`- WSL mode: ${wslMode}${modeSuffix}`,
|
|
1479
|
+
];
|
|
1480
|
+
if (wslDistros.length > 0) {
|
|
1481
|
+
lines.push(` distros: ${wslDistros.map((d) => `${d.name} (v${d.version ?? "?"})`).join(", ")}`);
|
|
1482
|
+
}
|
|
1483
|
+
return lines;
|
|
1484
|
+
})() : []),
|
|
1485
|
+
...subscriptionLines,
|
|
1486
|
+
"",
|
|
1487
|
+
]
|
|
1488
|
+
.filter(Boolean)
|
|
1489
|
+
.join("\n"),
|
|
1490
|
+
);
|
|
1491
|
+
}
|
|
1492
|
+
|
|
1493
|
+
function formatCopilotStoreDetail(detail) {
|
|
1494
|
+
return `${detail.path} (schema ${detail.schema_version ?? "?"}, ${detail.event_count ?? 0} events, last id ${detail.last_event_id ?? 0}${detail.last_event_at ? ` at ${detail.last_event_at}` : ""})`;
|
|
1495
|
+
}
|
|
1496
|
+
|
|
1497
|
+
function formatCopilotLines({ token, otel, sessionStore, appDb }) {
|
|
1498
|
+
if (
|
|
1499
|
+
!token &&
|
|
1500
|
+
!otel.otel_has_files &&
|
|
1501
|
+
!sessionStore?.store_has_file &&
|
|
1502
|
+
!appDb?.app_db_has_file
|
|
1503
|
+
) {
|
|
1504
|
+
return [];
|
|
1505
|
+
}
|
|
1506
|
+
const limitsState = token
|
|
1507
|
+
? "set (via GitHub OAuth)"
|
|
1508
|
+
: "unset (no Copilot OAuth token found)";
|
|
1509
|
+
const storeDetail = (sessionStore?.store_details || [])
|
|
1510
|
+
.map(formatCopilotStoreDetail)
|
|
1511
|
+
.join(", ");
|
|
1512
|
+
const storeState = sessionStore?.store_has_file
|
|
1513
|
+
? `${sessionStore.source_mode || "set"} (${storeDetail || (sessionStore.store_paths || []).join(", ")}; precision ${sessionStore.precision || "unknown"}; coverage ${sessionStore.coverage || "unknown"})`
|
|
1514
|
+
: `not found (${sessionStore?.store_path || "unknown"})`;
|
|
1515
|
+
const appDbState = appDb?.app_db_has_file
|
|
1516
|
+
? `${appDb.app_db_mode || "set"} (${(appDb.app_db_paths || []).join(", ")})`
|
|
1517
|
+
: `not found (${appDb?.app_db_path || "unknown"})`;
|
|
1518
|
+
const otelLocation =
|
|
1519
|
+
otel.otel_path || otel.otel_detected_paths?.[0] || otel.otel_default_dir;
|
|
1520
|
+
const usageState = otel.otel_has_files
|
|
1521
|
+
? `set (${otelLocation})`
|
|
1522
|
+
: otel.otel_enabled
|
|
1523
|
+
? "enabled but no files yet"
|
|
1524
|
+
: "unset (OTEL export not enabled)";
|
|
1525
|
+
const lines = [
|
|
1526
|
+
`- GitHub Copilot limits: ${limitsState}`,
|
|
1527
|
+
`- GitHub Copilot usage (App/CLI store): ${storeState}`,
|
|
1528
|
+
`- GitHub Copilot usage (App DB legacy baseline): ${appDbState}`,
|
|
1529
|
+
`- GitHub Copilot usage (OTEL Chat/legacy CLI): ${usageState}`,
|
|
1530
|
+
];
|
|
1531
|
+
for (const reason of sessionStore?.degraded_reasons || []) {
|
|
1532
|
+
lines.push(` Degraded: ${reason}`);
|
|
1533
|
+
}
|
|
1534
|
+
if (sessionStore?.recommended_action) {
|
|
1535
|
+
lines.push(` Action: ${sessionStore.recommended_action}`);
|
|
1536
|
+
}
|
|
1537
|
+
if (!sessionStore?.store_has_file && !otel.otel_has_files) {
|
|
1538
|
+
lines.push(
|
|
1539
|
+
" To track older Copilot CLI / Chat extension token usage, add to your shell profile:",
|
|
1540
|
+
" export COPILOT_OTEL_ENABLED=true",
|
|
1541
|
+
" export COPILOT_OTEL_EXPORTER_TYPE=file",
|
|
1542
|
+
` export COPILOT_OTEL_FILE_EXPORTER_PATH="${otel.otel_default_dir}/copilot-otel-$(date +%Y%m%d).jsonl"`,
|
|
1543
|
+
);
|
|
1544
|
+
}
|
|
1545
|
+
return lines;
|
|
1546
|
+
}
|
|
1547
|
+
|
|
1548
|
+
function formatSubscriptionLine(entry = {}) {
|
|
1549
|
+
const tool = String(entry.tool || "");
|
|
1550
|
+
const provider = String(entry.provider || "");
|
|
1551
|
+
const product = String(entry.product || "");
|
|
1552
|
+
const planType = String(entry.planType || "");
|
|
1553
|
+
const rateLimitTier = String(entry.rateLimitTier || "");
|
|
1554
|
+
const toolLabel =
|
|
1555
|
+
tool === "codex"
|
|
1556
|
+
? "Codex"
|
|
1557
|
+
: tool === "opencode"
|
|
1558
|
+
? "OpenCode"
|
|
1559
|
+
: tool === "claude"
|
|
1560
|
+
? "Claude Code"
|
|
1561
|
+
: tool;
|
|
1562
|
+
|
|
1563
|
+
if (!planType) return null;
|
|
1564
|
+
|
|
1565
|
+
if (
|
|
1566
|
+
tool === "claude" &&
|
|
1567
|
+
provider === "anthropic" &&
|
|
1568
|
+
product === "subscription"
|
|
1569
|
+
) {
|
|
1570
|
+
const suffix = rateLimitTier ? ` (rate limit tier: ${rateLimitTier})` : "";
|
|
1571
|
+
return `- ${toolLabel} subscription: ${planType}${suffix}`;
|
|
1572
|
+
}
|
|
1573
|
+
|
|
1574
|
+
if (provider === "openai" && product === "chatgpt") {
|
|
1575
|
+
return `- ${toolLabel} ChatGPT plan: ${planType}`;
|
|
1576
|
+
}
|
|
1577
|
+
|
|
1578
|
+
const productLabel = product ? product.replace(/_/g, " ") : "subscription";
|
|
1579
|
+
return `- ${toolLabel} ${productLabel}: ${planType}`;
|
|
1580
|
+
}
|
|
1581
|
+
|
|
1582
|
+
function parseArgs(argv) {
|
|
1583
|
+
const out = {
|
|
1584
|
+
diagnostics: false,
|
|
1585
|
+
json: false,
|
|
1586
|
+
light: false,
|
|
1587
|
+
noSpinner: false,
|
|
1588
|
+
probeKeychain: false,
|
|
1589
|
+
probeKeychainDetails: false,
|
|
1590
|
+
};
|
|
1591
|
+
|
|
1592
|
+
for (let i = 0; i < argv.length; i++) {
|
|
1593
|
+
const a = argv[i];
|
|
1594
|
+
if (a === "--diagnostics") out.diagnostics = true;
|
|
1595
|
+
else if (a === "--json") out.json = true;
|
|
1596
|
+
else if (a === "--light") out.light = true;
|
|
1597
|
+
else if (a === "--no-spinner") out.noSpinner = true;
|
|
1598
|
+
else if (a === "--probe-keychain") out.probeKeychain = true;
|
|
1599
|
+
else if (a === "--probe-keychain-details") {
|
|
1600
|
+
out.probeKeychainDetails = true;
|
|
1601
|
+
out.probeKeychain = true;
|
|
1602
|
+
} else throw new Error(`Unknown option: ${a}`);
|
|
1603
|
+
}
|
|
1604
|
+
|
|
1605
|
+
return out;
|
|
1606
|
+
}
|
|
1607
|
+
|
|
1608
|
+
// Pure renderer: turn the structured summary into a fixed-width ASCII table.
|
|
1609
|
+
// "light" output is for AI agents and CI: deterministic columns, no emoji or
|
|
1610
|
+
// spinner side effects, easy to grep. Returns a string (caller adds trailing
|
|
1611
|
+
// newline).
|
|
1612
|
+
function renderLightTable(summary) {
|
|
1613
|
+
const rows = [];
|
|
1614
|
+
const push = (k, v) => rows.push([k, v == null || v === "" ? "—" : String(v)]);
|
|
1615
|
+
|
|
1616
|
+
push("Version", summary.version);
|
|
1617
|
+
push("Base URL", summary.base_url);
|
|
1618
|
+
push("Device token", summary.device_token_set ? "set" : "unset");
|
|
1619
|
+
push("Queue pending (bytes)", summary.queue.pending_bytes);
|
|
1620
|
+
push("Queue size (bytes)", summary.queue.size_bytes);
|
|
1621
|
+
push("Last parse", summary.last_parse);
|
|
1622
|
+
push("Last notify", summary.last_notify);
|
|
1623
|
+
push("Last upload", summary.last_upload);
|
|
1624
|
+
push("Next upload after", summary.next_upload_after);
|
|
1625
|
+
push("Backoff until", summary.backoff_until);
|
|
1626
|
+
if (summary.last_upload_error) push("Last upload error", summary.last_upload_error);
|
|
1627
|
+
if (summary.last_sync_skipped) {
|
|
1628
|
+
push(
|
|
1629
|
+
"Last sync skipped",
|
|
1630
|
+
`${summary.last_sync_skipped.at} (${summary.last_sync_skipped.reason || "unknown"})`,
|
|
1631
|
+
);
|
|
1632
|
+
}
|
|
1633
|
+
|
|
1634
|
+
for (const [name, state] of Object.entries(summary.hooks || {})) {
|
|
1635
|
+
push(`Hook · ${name}`, state ? "set" : "unset");
|
|
1636
|
+
}
|
|
1637
|
+
|
|
1638
|
+
for (const root of summary.extra_scan_roots || []) {
|
|
1639
|
+
const state = root.exists ? "" : (root.error ? ` (unreadable: ${root.error})` : " (missing)");
|
|
1640
|
+
push(`Scan root · ${root.provider}`, `${root.origin}: ${root.path}${state}`);
|
|
1641
|
+
}
|
|
1642
|
+
|
|
1643
|
+
for (const [name, info] of Object.entries(summary.providers || {})) {
|
|
1644
|
+
const detail = [];
|
|
1645
|
+
if (typeof info.installed === "boolean") detail.push(info.installed ? "installed" : "not installed");
|
|
1646
|
+
if (typeof info.files === "number") detail.push(`${info.files} file${info.files !== 1 ? "s" : ""}`);
|
|
1647
|
+
if (info.detail) detail.push(info.detail);
|
|
1648
|
+
if (info.error) detail.push(info.error);
|
|
1649
|
+
if (Array.isArray(info.wsl_distros) && info.wsl_distros.length) {
|
|
1650
|
+
detail.push(`WSL: ${info.wsl_distros.map((d) => `${d.name} (v${d.version ?? "?"})`).join(", ")}`);
|
|
1651
|
+
}
|
|
1652
|
+
push(`Provider · ${name}`, detail.length ? detail.join(", ") : "—");
|
|
1653
|
+
}
|
|
1654
|
+
|
|
1655
|
+
// Mirror formatCopilotLines(): stay silent for machines with no Copilot
|
|
1656
|
+
// signal at all instead of printing "not found" rows for everyone.
|
|
1657
|
+
const copilotDetected =
|
|
1658
|
+
summary.copilot &&
|
|
1659
|
+
(summary.copilot.token_set ||
|
|
1660
|
+
summary.copilot.otel_enabled ||
|
|
1661
|
+
summary.copilot.otel_has_files ||
|
|
1662
|
+
summary.copilot.store_has_file ||
|
|
1663
|
+
summary.copilot.app_db_has_file);
|
|
1664
|
+
if (copilotDetected) {
|
|
1665
|
+
push(
|
|
1666
|
+
"Copilot App/CLI store",
|
|
1667
|
+
summary.copilot.store_has_file
|
|
1668
|
+
? `${summary.copilot.source_mode || "set"}: ${
|
|
1669
|
+
(summary.copilot.store_details || [])
|
|
1670
|
+
.map(formatCopilotStoreDetail)
|
|
1671
|
+
.join(", ") ||
|
|
1672
|
+
(summary.copilot.store_paths || [summary.copilot.store_path])
|
|
1673
|
+
.filter(Boolean)
|
|
1674
|
+
.join(", ")
|
|
1675
|
+
}`
|
|
1676
|
+
: `not found (${summary.copilot.store_path || "unknown"})`,
|
|
1677
|
+
);
|
|
1678
|
+
push(
|
|
1679
|
+
"Copilot App DB legacy baseline",
|
|
1680
|
+
summary.copilot.app_db_has_file
|
|
1681
|
+
? `${summary.copilot.app_db_mode || "set"}: ${(summary.copilot.app_db_paths || [summary.copilot.app_db_path]).filter(Boolean).join(", ")}`
|
|
1682
|
+
: `not found (${summary.copilot.app_db_path || "unknown"})`,
|
|
1683
|
+
);
|
|
1684
|
+
push(
|
|
1685
|
+
"Copilot OTEL Chat/legacy CLI",
|
|
1686
|
+
summary.copilot.otel_has_files
|
|
1687
|
+
? summary.copilot.otel_path || "files found"
|
|
1688
|
+
: summary.copilot.otel_enabled
|
|
1689
|
+
? "enabled, no files"
|
|
1690
|
+
: "not enabled",
|
|
1691
|
+
);
|
|
1692
|
+
push("Copilot precision", summary.copilot.precision);
|
|
1693
|
+
push("Copilot coverage", summary.copilot.coverage);
|
|
1694
|
+
for (const reason of summary.copilot.degraded_reasons || []) {
|
|
1695
|
+
push("Copilot degraded", reason);
|
|
1696
|
+
}
|
|
1697
|
+
if (summary.copilot.recommended_action) {
|
|
1698
|
+
push("Copilot action", summary.copilot.recommended_action);
|
|
1699
|
+
}
|
|
1700
|
+
}
|
|
1701
|
+
|
|
1702
|
+
if (summary.passive_mode) {
|
|
1703
|
+
push("Passive mode active", summary.passive_mode.active ? "yes" : "no");
|
|
1704
|
+
for (const p of summary.passive_mode.providers || []) {
|
|
1705
|
+
if (p.passive) {
|
|
1706
|
+
push(`Passive · ${p.name}`, `hook ${p.hook_failure_reason || "missing"}, logs present`);
|
|
1707
|
+
}
|
|
1708
|
+
}
|
|
1709
|
+
}
|
|
1710
|
+
|
|
1711
|
+
const keyWidth = Math.max(...rows.map(([k]) => k.length), 8);
|
|
1712
|
+
const valWidth = Math.max(...rows.map(([, v]) => v.length), 8);
|
|
1713
|
+
const sep = `+${"-".repeat(keyWidth + 2)}+${"-".repeat(valWidth + 2)}+`;
|
|
1714
|
+
const lines = [sep, `| ${"Key".padEnd(keyWidth)} | ${"Value".padEnd(valWidth)} |`, sep];
|
|
1715
|
+
for (const [k, v] of rows) {
|
|
1716
|
+
lines.push(`| ${k.padEnd(keyWidth)} | ${v.padEnd(valWidth)} |`);
|
|
1717
|
+
}
|
|
1718
|
+
lines.push(sep);
|
|
1719
|
+
return lines.join("\n");
|
|
1720
|
+
}
|
|
1721
|
+
|
|
1722
|
+
async function safeStatSize(p) {
|
|
1723
|
+
try {
|
|
1724
|
+
const st = await fs.stat(p);
|
|
1725
|
+
return st.size || 0;
|
|
1726
|
+
} catch (_e) {
|
|
1727
|
+
return 0;
|
|
1728
|
+
}
|
|
1729
|
+
}
|
|
1730
|
+
|
|
1731
|
+
async function safeReadText(p) {
|
|
1732
|
+
try {
|
|
1733
|
+
return await fs.readFile(p, "utf8");
|
|
1734
|
+
} catch (_e) {
|
|
1735
|
+
return null;
|
|
1736
|
+
}
|
|
1737
|
+
}
|
|
1738
|
+
|
|
1739
|
+
function parseEpochMsToIso(v) {
|
|
1740
|
+
const ms = Number(v);
|
|
1741
|
+
if (!Number.isFinite(ms) || ms <= 0) return null;
|
|
1742
|
+
const d = new Date(ms);
|
|
1743
|
+
if (Number.isNaN(d.getTime())) return null;
|
|
1744
|
+
return d.toISOString();
|
|
1745
|
+
}
|
|
1746
|
+
|
|
1747
|
+
module.exports = { cmdStatus, summarizeQoderDetail };
|