tokentracker-cli 0.87.8 → 0.87.9
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/dashboard/dist/assets/{AchievementBadge-CpxX02OK.js → AchievementBadge-D3_hERkQ.js} +1 -1
- package/dashboard/dist/assets/{AchievementsPage-CSms8IjI.js → AchievementsPage-DZGjT92g.js} +2 -2
- package/dashboard/dist/assets/{AchievementsSection-Sm43tnkh.js → AchievementsSection-CEzq3U3A.js} +1 -1
- package/dashboard/dist/assets/{BadgeDetailModal-cSNqMLsK.js → BadgeDetailModal-D3_B8E--.js} +1 -1
- package/dashboard/dist/assets/{Card-wNwNRVSb.js → Card-CMXM3-lp.js} +1 -1
- package/dashboard/dist/assets/{ClawdAnimated-S8sIS2Ca.js → ClawdAnimated-lQxUKRzw.js} +1 -1
- package/dashboard/dist/assets/{CommandPalette-DVeiwbPM.js → CommandPalette-BCGdAeFB.js} +1 -1
- package/dashboard/dist/assets/{CommunityStatsModal-g5P4j3um.js → CommunityStatsModal-BwE5h2y5.js} +1 -1
- package/dashboard/dist/assets/{ConfirmModal-2P2D5iIp.js → ConfirmModal-8uhS2ccj.js} +1 -1
- package/dashboard/dist/assets/{Controls-CCaotoQP.js → Controls-CBEQTl2X.js} +1 -1
- package/dashboard/dist/assets/{DashboardPage-DxPGTJpe.js → DashboardPage-UE_3tGVy.js} +1 -1
- package/dashboard/dist/assets/{DevicePage-_nLwNash.js → DevicePage-B06ybHJI.js} +1 -1
- package/dashboard/dist/assets/{DialogClose-D0giFwO3.js → DialogClose-L_t-nrYm.js} +1 -1
- package/dashboard/dist/assets/DialogDescription-B7FFtR7A.js +1 -0
- package/dashboard/dist/assets/{DialogTitle-JS_04eUC.js → DialogTitle-Bsft4VvL.js} +1 -1
- package/dashboard/dist/assets/{FadeIn-tFzTWDkC.js → FadeIn-BNDdLqTu.js} +1 -1
- package/dashboard/dist/assets/{HeaderGithubStar-B2EUJUTH.js → HeaderGithubStar-CvNaKDbl.js} +1 -1
- package/dashboard/dist/assets/{HoverTooltip-BJzHksPT.js → HoverTooltip-D5j5IpNx.js} +1 -1
- package/dashboard/dist/assets/{IpCheckPage-B8mA0mut.js → IpCheckPage-Csf8gMJW.js} +1 -1
- package/dashboard/dist/assets/{LandingPage-DmJZDKr9.js → LandingPage-BVSSwM0D.js} +2 -2
- package/dashboard/dist/assets/{LeaderboardAvatar-CDeRQUCg.js → LeaderboardAvatar-DXxSHqmP.js} +1 -1
- package/dashboard/dist/assets/{LeaderboardPage-Dkgm89kY.js → LeaderboardPage-DXj21BBR.js} +2 -2
- package/dashboard/dist/assets/{LeaderboardProfileModal-B6_kuR1z.js → LeaderboardProfileModal-DbEzZGg4.js} +3 -3
- package/dashboard/dist/assets/{LeaderboardProfilePage-BRs8sJBV.js → LeaderboardProfilePage-DoIm3jB_.js} +1 -1
- package/dashboard/dist/assets/{LimitsPage-DZ1s5NWV.js → LimitsPage-D_tpQrUM.js} +1 -1
- package/dashboard/dist/assets/{LocalOnlyNotice-Cu_hSnux.js → LocalOnlyNotice-DBi5iuPr.js} +1 -1
- package/dashboard/dist/assets/{LoginCard-yDZbGsHR.js → LoginCard-qDIJgUX1.js} +1 -1
- package/dashboard/dist/assets/{LoginModal-DEvzCUfQ.js → LoginModal-D4b5p4u1.js} +1 -1
- package/dashboard/dist/assets/{LoginPage-DBySF9do.js → LoginPage-CsSgItFA.js} +1 -1
- package/dashboard/dist/assets/{PetPage-DnzH9t-r.js → PetPage-B-wElg5q.js} +1 -1
- package/dashboard/dist/assets/{PopoverPopup-DgFsEMax.js → PopoverPopup-9C_VarUQ.js} +1 -1
- package/dashboard/dist/assets/{ProviderIcon-BEixe-xP.js → ProviderIcon-CciEdEeR.js} +1 -1
- package/dashboard/dist/assets/{ResetPasswordPage-excKqsCL.js → ResetPasswordPage-lsI8qlzE.js} +1 -1
- package/dashboard/dist/assets/{SegmentedControl-DDFkH64o.js → SegmentedControl-BGonMV45.js} +1 -1
- package/dashboard/dist/assets/{Select-ChEPIuJf.js → Select-DhRrGrDT.js} +1 -1
- package/dashboard/dist/assets/{SelectItemText--b7ISnJm.js → SelectItemText-ClMYgZsa.js} +1 -1
- package/dashboard/dist/assets/{ServiceStatusPage-DtAY-Qnn.js → ServiceStatusPage-DuzttgL7.js} +1 -1
- package/dashboard/dist/assets/{SessionsPage-CKFglvuj.js → SessionsPage-gZbxx0f_.js} +1 -1
- package/dashboard/dist/assets/{SettingsPage-s0605qWg.js → SettingsPage-NhxTrVNW.js} +1 -1
- package/dashboard/dist/assets/{SkillsPage-DTsbCucq.js → SkillsPage-BeXojJqQ.js} +1 -1
- package/dashboard/dist/assets/{TokenGalaxy-C_M7q8S4.js → TokenGalaxy-DM49zKzo.js} +1 -1
- package/dashboard/dist/assets/{ToolbarRootContext-CXQwpea-.js → ToolbarRootContext-BfvoVNMW.js} +1 -1
- package/dashboard/dist/assets/{TrendMonitor-1Yhlplf0.js → TrendMonitor-Bu-dXcrV.js} +1 -1
- package/dashboard/dist/assets/{WidgetsPage-DC6pmtld.js → WidgetsPage-D2Wo7seE.js} +1 -1
- package/dashboard/dist/assets/{WrappedPage-DixoqR13.js → WrappedPage-BXAwic4D.js} +1 -1
- package/dashboard/dist/assets/{__vite-browser-external-5aLUeBkM.js → __vite-browser-external-BDEQk--l.js} +2 -2
- package/dashboard/dist/assets/{agent-logos-DILTbPLg.js → agent-logos-DMEEHjG7.js} +1 -1
- package/dashboard/dist/assets/{arrow-up-right-DgIDgjVW.js → arrow-up-right-gNviKtY8.js} +1 -1
- package/dashboard/dist/assets/{check-Bz6l09VH.js → check-Cvg5pmYP.js} +1 -1
- package/dashboard/dist/assets/{chevron-right-EvGQXbI3.js → chevron-right-DxdaNTo8.js} +1 -1
- package/dashboard/dist/assets/{copy-DbsB0OVy.js → copy-BNIJL7bf.js} +1 -1
- package/dashboard/dist/assets/{download-R8nUvXYh.js → download-C9McJlPa.js} +1 -1
- package/dashboard/dist/assets/{external-link-x0oNzGeq.js → external-link-C_IU6zDK.js} +1 -1
- package/dashboard/dist/assets/{flame-Bo4IdG6k.js → flame-CII7X8Je.js} +1 -1
- package/dashboard/dist/assets/{format-tokens-BSGC1-Gz.js → format-tokens-DuQbGpPt.js} +1 -1
- package/dashboard/dist/assets/{icons-D0Okncmo.js → icons-B1YTqnxG.js} +1 -1
- package/dashboard/dist/assets/{index-D6F8eNr_.js → index-BRMxraNK.js} +1 -1
- package/dashboard/dist/assets/{index-BbOkC6wf.js → index-Dc9xsIu2.js} +1 -1
- package/dashboard/dist/assets/{index-Bvvmei-I.js → index-QtcYir6O.js} +1 -1
- package/dashboard/dist/assets/{info-DXXKNpLG.js → info-CIgVqJoj.js} +1 -1
- package/dashboard/dist/assets/{limits-providers-DYa4fdsE.js → limits-providers-B31NsGar.js} +1 -1
- package/dashboard/dist/assets/{link-2-C9mxEnT6.js → link-2-DTPXzHuB.js} +1 -1
- package/dashboard/dist/assets/{loader-circle-Y8V8Mq9L.js → loader-circle-CgQSyCz8.js} +1 -1
- package/dashboard/dist/assets/{maximize-2-QuP69Xcg.js → maximize-2-BL5J4aHZ.js} +1 -1
- package/dashboard/dist/assets/{modifiers.esm-B3SleRKs.js → modifiers.esm-s_rzcEf2.js} +1 -1
- package/dashboard/dist/assets/{monitor-smartphone-B2LslYi7.js → monitor-smartphone-C9ei_xde.js} +1 -1
- package/dashboard/dist/assets/{provider-display-DzBwrDZp.js → provider-display-ZgvoJi05.js} +1 -1
- package/dashboard/dist/assets/{react-BooKG84W.js → react-DhfPVGOm.js} +1 -1
- package/dashboard/dist/assets/{search-zdYuHmL-.js → search-Ba_MWO7q.js} +1 -1
- package/dashboard/dist/assets/{skills-api-C2IkKfwE.js → skills-api-BkmJmyg1.js} +1 -1
- package/dashboard/dist/assets/{sortable.esm-BHvl5vG5.js → sortable.esm-Bmd5t12E.js} +1 -1
- package/dashboard/dist/assets/{store-BBP4jx0R.js → store-BxRQs9yc.js} +1 -1
- package/dashboard/dist/assets/{terminal-C0nhFNQ0.js → terminal-BzUwAs4g.js} +1 -1
- package/dashboard/dist/assets/{trash-2-DNVSqbxA.js → trash-2-CCprY7cu.js} +1 -1
- package/dashboard/dist/assets/{use-community-stats-BK070d1s.js → use-community-stats-TCdPJ_ir.js} +1 -1
- package/dashboard/dist/assets/{use-limits-display-prefs-BXOUxblO.js → use-limits-display-prefs-CNF9luO6.js} +1 -1
- package/dashboard/dist/assets/{use-ordered-list-0SVHZHaW.js → use-ordered-list-BlTuSYJy.js} +1 -1
- package/dashboard/dist/assets/use-reduced-motion-CfiR91Eg.js +1 -0
- package/dashboard/dist/assets/{use-session-efficiency-pref-eaUpwuLK.js → use-session-efficiency-pref-iHS0O_Fo.js} +1 -1
- package/dashboard/dist/assets/{use-transform-Bhar2U4w.js → use-transform-CcVfL3mi.js} +1 -1
- package/dashboard/dist/assets/{use-usage-limits-BGGCMVzi.js → use-usage-limits-Xdy-Y_1Z.js} +1 -1
- package/dashboard/dist/assets/{useCurrency-gIJVmq3w.js → useCurrency-IXccXbmx.js} +1 -1
- package/dashboard/dist/assets/{useScrollLock-BhFzeRtR.js → useScrollLock-BEVewfZm.js} +1 -1
- package/dashboard/dist/assets/{useTokenFormat-BZ8WT-A6.js → useTokenFormat-Cihv3Ghl.js} +1 -1
- package/dashboard/dist/assets/{zap-Dvc_Jt1t.js → zap-zG2Fbb5_.js} +1 -1
- package/dashboard/dist/index.html +1 -1
- package/dashboard/dist/ip-check.html +1 -1
- package/dashboard/dist/leaderboard.html +1 -1
- package/dashboard/dist/share.html +1 -1
- package/package.json +1 -1
- package/src/commands/sync.js +245 -1
- package/src/lib/install-resolver.js +22 -6
- package/src/lib/pricing/seed-snapshot.json +1 -1
- package/src/lib/rollout.js +272 -32
- package/dashboard/dist/assets/DialogDescription-8veCvaUb.js +0 -1
- package/dashboard/dist/assets/use-reduced-motion-abZbtoVS.js +0 -1
package/src/commands/sync.js
CHANGED
|
@@ -83,6 +83,7 @@ const {
|
|
|
83
83
|
listAntigravityTranscripts,
|
|
84
84
|
parseAntigravityIncremental,
|
|
85
85
|
resolveCodebuddyProjectFiles,
|
|
86
|
+
codebuddyJsonlHasUsage,
|
|
86
87
|
parseCodebuddyIncremental,
|
|
87
88
|
resolveWorkbuddyProjectFiles,
|
|
88
89
|
parseWorkbuddyIncremental,
|
|
@@ -142,6 +143,7 @@ const CURSOR_UNKNOWN_MIGRATION_KEY = "cursorUnknownPurge_2026_04";
|
|
|
142
143
|
const ROLLOUT_CUMULATIVE_DELTA_MIGRATION_KEY = "rolloutCumulativeDeltaReparse_2026_05";
|
|
143
144
|
const CLAUDE_MEM_OBSERVER_REINCLUDE_KEY = "claudeMemObserverReinclude_2026_05_v3";
|
|
144
145
|
const GROK_APPEND_ONLY_REPAIR_MIGRATION_KEY = "grokAppendOnlyRepair_2026_05_v4";
|
|
146
|
+
const CODEBUDDY_LOG_JSONL_REPAIR_KEY = "codebuddyLogJsonlOverlapRepair_2026_08";
|
|
145
147
|
const CLAUDE_MEM_OBSERVER_PATH_SEGMENT = "--claude-mem-observer-sessions";
|
|
146
148
|
// v1 had a cursor-format bug (wrote plain integer instead of {inode, offset,
|
|
147
149
|
// updatedAt}), which made parseClaudeIncremental reread every jsonl from
|
|
@@ -589,7 +591,16 @@ async function cmdSync(argv, context = {}) {
|
|
|
589
591
|
const wslCodexDir = process.platform === "win32" && wsl.shouldProbeWsl(process.env)
|
|
590
592
|
? wsl.discoverWslHome(".codex")
|
|
591
593
|
: null;
|
|
592
|
-
|
|
594
|
+
// resolveInstallPaths stays the single authority for wsl-first /
|
|
595
|
+
// native-first / wsl-only / native-only / both selection; requireAnyChild
|
|
596
|
+
// makes it validate that a candidate actually holds sessions/ or
|
|
597
|
+
// archived_sessions/ so an empty WSL ~/.codex shell cannot shadow the
|
|
598
|
+
// native install (issue #codex-wsl-shadow).
|
|
599
|
+
const codexPaths = resolveInstallPaths({
|
|
600
|
+
nativeValue: codexNativeValue,
|
|
601
|
+
wslValue: wslCodexDir,
|
|
602
|
+
requireAnyChild: ["sessions", "archived_sessions"],
|
|
603
|
+
});
|
|
593
604
|
if (codexPaths.native) {
|
|
594
605
|
sources.push({ source: "codex", sessionsDir: path.join(codexPaths.native, "sessions"), codexInventoryCache: true });
|
|
595
606
|
if (!isBackgroundLightweightSync || backgroundCodexUsageRepair) {
|
|
@@ -1770,6 +1781,26 @@ async function cmdSync(argv, context = {}) {
|
|
|
1770
1781
|
// Tencent's CodeBuddy CLI is a Claude Code clone; no hook system, so we
|
|
1771
1782
|
// tail the per-session JSONL conversation logs incrementally on each sync.
|
|
1772
1783
|
let codebuddyResult = { recordsProcessed: 0, eventsAggregated: 0, bucketsQueued: 0 };
|
|
1784
|
+
if (isFullSourceScan && sourceAllowed("codebuddy")) {
|
|
1785
|
+
const repairCodebuddyFiles = mergeBothFileSources({
|
|
1786
|
+
resolveFiles: (env) => resolveCodebuddyProjectFiles({
|
|
1787
|
+
...env,
|
|
1788
|
+
TOKENTRACKER_CODEBUDDY_LOG_FALLBACK: "1",
|
|
1789
|
+
}),
|
|
1790
|
+
env: process.env,
|
|
1791
|
+
});
|
|
1792
|
+
try {
|
|
1793
|
+
await repairCodebuddyLogJsonlOverlap({
|
|
1794
|
+
cursors,
|
|
1795
|
+
queuePath,
|
|
1796
|
+
queueStatePath,
|
|
1797
|
+
codebuddyFiles: repairCodebuddyFiles,
|
|
1798
|
+
env: process.env,
|
|
1799
|
+
});
|
|
1800
|
+
} catch (err) {
|
|
1801
|
+
warnProviderParseFailure("CodeBuddy log/JSONL repair", err, opts);
|
|
1802
|
+
}
|
|
1803
|
+
}
|
|
1773
1804
|
const codebuddyFiles = sourceAllowed("codebuddy")
|
|
1774
1805
|
? mergeBothFileSources({ resolveFiles: resolveCodebuddyProjectFiles, env: process.env })
|
|
1775
1806
|
: [];
|
|
@@ -2730,6 +2761,7 @@ module.exports = {
|
|
|
2730
2761
|
acquireSyncLock,
|
|
2731
2762
|
migrateCursorUnknownBuckets,
|
|
2732
2763
|
migrateRolloutCumulativeDeltaBuckets,
|
|
2764
|
+
repairCodebuddyLogJsonlOverlap,
|
|
2733
2765
|
repairCodexRescanInflation,
|
|
2734
2766
|
repairCodexForkReplayInflation,
|
|
2735
2767
|
repairCodexInterleavedUsageInflation,
|
|
@@ -2744,6 +2776,7 @@ module.exports = {
|
|
|
2744
2776
|
recordCodexColdScanAudit,
|
|
2745
2777
|
CURSOR_UNKNOWN_MIGRATION_KEY,
|
|
2746
2778
|
ROLLOUT_CUMULATIVE_DELTA_MIGRATION_KEY,
|
|
2779
|
+
CODEBUDDY_LOG_JSONL_REPAIR_KEY,
|
|
2747
2780
|
CODEX_RESCAN_DEDUP_REPAIR_KEY,
|
|
2748
2781
|
CODEX_FORK_REPLAY_REPAIR_KEY,
|
|
2749
2782
|
CODEX_USAGE_LINEAGE_REPAIR_KEY,
|
|
@@ -3809,6 +3842,217 @@ async function migrateRolloutCumulativeDeltaBuckets({ cursors, queuePath, rollou
|
|
|
3809
3842
|
cursors.migrations[ROLLOUT_CUMULATIVE_DELTA_MIGRATION_KEY] = new Date().toISOString();
|
|
3810
3843
|
}
|
|
3811
3844
|
|
|
3845
|
+
function codebuddyUsageRowKey(row) {
|
|
3846
|
+
if (!row || row.source !== "codebuddy") return null;
|
|
3847
|
+
const model = typeof row.model === "string" && row.model ? row.model : "unknown";
|
|
3848
|
+
const hourStart = typeof row.hour_start === "string" && row.hour_start ? row.hour_start : null;
|
|
3849
|
+
return hourStart ? bucketKey("codebuddy", model, hourStart) : null;
|
|
3850
|
+
}
|
|
3851
|
+
|
|
3852
|
+
function codebuddyZeroUsageRow(model, hourStart) {
|
|
3853
|
+
return {
|
|
3854
|
+
source: "codebuddy",
|
|
3855
|
+
model: model || "unknown",
|
|
3856
|
+
hour_start: hourStart,
|
|
3857
|
+
input_tokens: 0,
|
|
3858
|
+
cached_input_tokens: 0,
|
|
3859
|
+
cache_creation_input_tokens: 0,
|
|
3860
|
+
output_tokens: 0,
|
|
3861
|
+
reasoning_output_tokens: 0,
|
|
3862
|
+
total_tokens: 0,
|
|
3863
|
+
billable_total_tokens: 0,
|
|
3864
|
+
conversation_count: 0,
|
|
3865
|
+
};
|
|
3866
|
+
}
|
|
3867
|
+
|
|
3868
|
+
// Issue #403 historical repair. Before the JSONL usage fix, CodeBuddy could
|
|
3869
|
+
// ingest the same round-trip once from ~/.codebuddy/projects and once from the
|
|
3870
|
+
// IDE extension log. The forward resolver now disables logs whenever any JSONL
|
|
3871
|
+
// has usable rawUsage, but existing queues/hourly state need one guarded,
|
|
3872
|
+
// atomic rebuild so the old double-count is not left visible forever.
|
|
3873
|
+
async function repairCodebuddyLogJsonlOverlap({
|
|
3874
|
+
cursors,
|
|
3875
|
+
queuePath,
|
|
3876
|
+
queueStatePath,
|
|
3877
|
+
codebuddyFiles,
|
|
3878
|
+
env = process.env,
|
|
3879
|
+
} = {}) {
|
|
3880
|
+
if (!cursors || typeof cursors !== "object") return false;
|
|
3881
|
+
const migrations = (cursors.migrations ||= {});
|
|
3882
|
+
const prior = migrations[CODEBUDDY_LOG_JSONL_REPAIR_KEY];
|
|
3883
|
+
if (prior && !(typeof prior === "object" && prior.skipped)) return false;
|
|
3884
|
+
|
|
3885
|
+
const files = Array.isArray(codebuddyFiles) ? codebuddyFiles : [];
|
|
3886
|
+
const jsonlFiles = files.filter((filePath) => typeof filePath === "string" && filePath.endsWith(".jsonl"));
|
|
3887
|
+
const logFiles = files.filter((filePath) => typeof filePath === "string" && filePath.endsWith(".log"));
|
|
3888
|
+
const hasDetailedJsonl = jsonlFiles.some((filePath) => codebuddyJsonlHasUsage(filePath));
|
|
3889
|
+
|
|
3890
|
+
const hourly = cursors.hourly && typeof cursors.hourly === "object" ? cursors.hourly : {};
|
|
3891
|
+
const liveHourlyKeys = new Set(
|
|
3892
|
+
Object.keys(hourly.buckets || {}).filter((key) => key.startsWith("codebuddy|")),
|
|
3893
|
+
);
|
|
3894
|
+
let queueRaw = "";
|
|
3895
|
+
try {
|
|
3896
|
+
queueRaw = await fs.readFile(queuePath, "utf8");
|
|
3897
|
+
} catch (e) {
|
|
3898
|
+
if (e?.code !== "ENOENT") throw e;
|
|
3899
|
+
}
|
|
3900
|
+
const queueCodebuddyKeys = new Set();
|
|
3901
|
+
const keptQueueLines = [];
|
|
3902
|
+
for (const line of queueRaw.split("\n")) {
|
|
3903
|
+
if (!line.trim()) continue;
|
|
3904
|
+
let row;
|
|
3905
|
+
try {
|
|
3906
|
+
row = JSON.parse(line);
|
|
3907
|
+
} catch (_e) {
|
|
3908
|
+
keptQueueLines.push(line);
|
|
3909
|
+
continue;
|
|
3910
|
+
}
|
|
3911
|
+
const key = codebuddyUsageRowKey(row);
|
|
3912
|
+
if (!key) {
|
|
3913
|
+
keptQueueLines.push(line);
|
|
3914
|
+
continue;
|
|
3915
|
+
}
|
|
3916
|
+
queueCodebuddyKeys.add(key);
|
|
3917
|
+
}
|
|
3918
|
+
const liveKeys = new Set([...liveHourlyKeys, ...queueCodebuddyKeys]);
|
|
3919
|
+
if (liveKeys.size === 0) {
|
|
3920
|
+
migrations[CODEBUDDY_LOG_JSONL_REPAIR_KEY] = {
|
|
3921
|
+
status: "noop",
|
|
3922
|
+
appliedAt: new Date().toISOString(),
|
|
3923
|
+
reason: "no-codebuddy-history",
|
|
3924
|
+
};
|
|
3925
|
+
return false;
|
|
3926
|
+
}
|
|
3927
|
+
|
|
3928
|
+
// Keep this condition retryable when old CodeBuddy history exists but the
|
|
3929
|
+
// extension log is temporarily rotated/missing. A permanent no-op here
|
|
3930
|
+
// would close the repair window before a later full scan can rediscover it.
|
|
3931
|
+
if (jsonlFiles.length === 0 || logFiles.length === 0 || !hasDetailedJsonl) {
|
|
3932
|
+
migrations[CODEBUDDY_LOG_JSONL_REPAIR_KEY] = {
|
|
3933
|
+
skipped: true,
|
|
3934
|
+
reason: "no-mixed-detailed-sources",
|
|
3935
|
+
at: new Date().toISOString(),
|
|
3936
|
+
};
|
|
3937
|
+
return false;
|
|
3938
|
+
}
|
|
3939
|
+
|
|
3940
|
+
// A rebuild from the currently discoverable JSONL is safe only if every
|
|
3941
|
+
// file previously tailed by CodeBuddy is still available in this scan. If a
|
|
3942
|
+
// rotated/deleted log is missing, retain the user's history and retry later
|
|
3943
|
+
// rather than silently erasing an unreproducible bucket.
|
|
3944
|
+
const discovered = new Set(files);
|
|
3945
|
+
const priorFiles = cursors.codebuddy?.fileOffsets && typeof cursors.codebuddy.fileOffsets === "object"
|
|
3946
|
+
? Object.keys(cursors.codebuddy.fileOffsets)
|
|
3947
|
+
: [];
|
|
3948
|
+
const missingPriorFile = priorFiles.find((filePath) => !discovered.has(filePath));
|
|
3949
|
+
if (missingPriorFile) {
|
|
3950
|
+
migrations[CODEBUDDY_LOG_JSONL_REPAIR_KEY] = {
|
|
3951
|
+
skipped: true,
|
|
3952
|
+
reason: "codebuddy_file_unreproducible",
|
|
3953
|
+
filePath: missingPriorFile,
|
|
3954
|
+
at: new Date().toISOString(),
|
|
3955
|
+
};
|
|
3956
|
+
return false;
|
|
3957
|
+
}
|
|
3958
|
+
|
|
3959
|
+
const tmpQueue = `${queuePath}.codebuddyrebuild.${process.pid}.${Date.now()}`;
|
|
3960
|
+
const tmpCursors = {
|
|
3961
|
+
version: 1,
|
|
3962
|
+
hourly: { buckets: {}, groupQueued: {} },
|
|
3963
|
+
codebuddy: {},
|
|
3964
|
+
};
|
|
3965
|
+
let rebuiltRows = [];
|
|
3966
|
+
try {
|
|
3967
|
+
await parseCodebuddyIncremental({
|
|
3968
|
+
projectFiles: jsonlFiles,
|
|
3969
|
+
cursors: tmpCursors,
|
|
3970
|
+
queuePath: tmpQueue,
|
|
3971
|
+
env,
|
|
3972
|
+
});
|
|
3973
|
+
let rebuiltRaw = "";
|
|
3974
|
+
try {
|
|
3975
|
+
rebuiltRaw = await fs.readFile(tmpQueue, "utf8");
|
|
3976
|
+
} catch (e) {
|
|
3977
|
+
if (e?.code !== "ENOENT") throw e;
|
|
3978
|
+
}
|
|
3979
|
+
rebuiltRows = rebuiltRaw.split("\n").filter((line) => line.trim());
|
|
3980
|
+
} catch (e) {
|
|
3981
|
+
console.error("[sync] CodeBuddy log/JSONL repair: rebuild failed, leaving history untouched:", e?.message || e);
|
|
3982
|
+
return false;
|
|
3983
|
+
} finally {
|
|
3984
|
+
await fs.rm(tmpQueue, { force: true }).catch(() => {});
|
|
3985
|
+
}
|
|
3986
|
+
|
|
3987
|
+
const rebuiltKeys = new Set();
|
|
3988
|
+
const validRebuiltRows = [];
|
|
3989
|
+
for (const line of rebuiltRows) {
|
|
3990
|
+
let row;
|
|
3991
|
+
try { row = JSON.parse(line); } catch (_e) { continue; }
|
|
3992
|
+
const key = codebuddyUsageRowKey(row);
|
|
3993
|
+
if (!key) continue;
|
|
3994
|
+
rebuiltKeys.add(key);
|
|
3995
|
+
validRebuiltRows.push(line);
|
|
3996
|
+
}
|
|
3997
|
+
if (rebuiltKeys.size === 0) {
|
|
3998
|
+
migrations[CODEBUDDY_LOG_JSONL_REPAIR_KEY] = {
|
|
3999
|
+
skipped: true,
|
|
4000
|
+
reason: "jsonl_rebuild_empty",
|
|
4001
|
+
at: new Date().toISOString(),
|
|
4002
|
+
};
|
|
4003
|
+
return false;
|
|
4004
|
+
}
|
|
4005
|
+
|
|
4006
|
+
const staleRetractions = [];
|
|
4007
|
+
for (const key of liveKeys) {
|
|
4008
|
+
if (rebuiltKeys.has(key)) continue;
|
|
4009
|
+
const [, model, ...hourParts] = key.split("|");
|
|
4010
|
+
staleRetractions.push(JSON.stringify(codebuddyZeroUsageRow(model, hourParts.join("|"))));
|
|
4011
|
+
}
|
|
4012
|
+
|
|
4013
|
+
const nextQueueLines = keptQueueLines.concat(staleRetractions, validRebuiltRows);
|
|
4014
|
+
await ensureDir(path.dirname(queuePath));
|
|
4015
|
+
const queueTmp = `${queuePath}.tmp.${process.pid}.${Date.now()}`;
|
|
4016
|
+
await fs.writeFile(queueTmp, nextQueueLines.length ? `${nextQueueLines.join("\n")}\n` : "", "utf8");
|
|
4017
|
+
await fs.rename(queueTmp, queuePath);
|
|
4018
|
+
|
|
4019
|
+
const nextHourly = (cursors.hourly ||= { buckets: {}, groupQueued: {} });
|
|
4020
|
+
nextHourly.buckets ||= {};
|
|
4021
|
+
nextHourly.groupQueued ||= {};
|
|
4022
|
+
for (const key of Object.keys(nextHourly.buckets)) {
|
|
4023
|
+
if (key.startsWith("codebuddy|")) delete nextHourly.buckets[key];
|
|
4024
|
+
}
|
|
4025
|
+
for (const key of Object.keys(nextHourly.groupQueued)) {
|
|
4026
|
+
if (key.startsWith("codebuddy|")) delete nextHourly.groupQueued[key];
|
|
4027
|
+
}
|
|
4028
|
+
for (const [key, bucket] of Object.entries(tmpCursors.hourly.buckets || {})) {
|
|
4029
|
+
if (key.startsWith("codebuddy|")) nextHourly.buckets[key] = bucket;
|
|
4030
|
+
}
|
|
4031
|
+
for (const [key, value] of Object.entries(tmpCursors.hourly.groupQueued || {})) {
|
|
4032
|
+
if (key.startsWith("codebuddy|")) nextHourly.groupQueued[key] = value;
|
|
4033
|
+
}
|
|
4034
|
+
cursors.codebuddy = tmpCursors.codebuddy || {};
|
|
4035
|
+
|
|
4036
|
+
let uploadState = {};
|
|
4037
|
+
try { uploadState = JSON.parse(await fs.readFile(queueStatePath, "utf8")); } catch (_e) {}
|
|
4038
|
+
uploadState.offset = 0;
|
|
4039
|
+
uploadState.updatedAt = new Date().toISOString();
|
|
4040
|
+
uploadState.note = "reset_after_codebuddy_log_jsonl_repair_2026_08";
|
|
4041
|
+
await ensureDir(path.dirname(queueStatePath));
|
|
4042
|
+
await fs.writeFile(queueStatePath, JSON.stringify(uploadState, null, 2) + "\n", "utf8");
|
|
4043
|
+
|
|
4044
|
+
migrations[CODEBUDDY_LOG_JSONL_REPAIR_KEY] = {
|
|
4045
|
+
status: "applied",
|
|
4046
|
+
appliedAt: new Date().toISOString(),
|
|
4047
|
+
jsonlFiles: jsonlFiles.length,
|
|
4048
|
+
logFiles: logFiles.length,
|
|
4049
|
+
previousBuckets: liveKeys.size,
|
|
4050
|
+
rebuiltBuckets: rebuiltKeys.size,
|
|
4051
|
+
retractedBuckets: staleRetractions.length,
|
|
4052
|
+
};
|
|
4053
|
+
return true;
|
|
4054
|
+
}
|
|
4055
|
+
|
|
3812
4056
|
// One-time repair (#187): rebuild codex hourly buckets that the inode-keyed
|
|
3813
4057
|
// re-scan double-counted before the codexHashes event-dedup landed, and push
|
|
3814
4058
|
// the corrected values to the cloud. Runs BEFORE the codex parse in the same
|
|
@@ -1,18 +1,29 @@
|
|
|
1
1
|
const fssync = require("node:fs");
|
|
2
|
+
const path = require("node:path");
|
|
2
3
|
const wsl = require("./wsl-probe");
|
|
3
4
|
|
|
4
|
-
function resolveInstallPaths({ nativeValue, wslDir, wslValue } = {}, env = process.env, deps = {}) {
|
|
5
|
-
|
|
5
|
+
function resolveInstallPaths({ nativeValue, wslDir, wslValue, requireAnyChild } = {}, env = process.env, deps = {}) {
|
|
6
|
+
const platform = deps.platform || process.platform;
|
|
7
|
+
if (platform !== "win32") {
|
|
6
8
|
return { native: nativeValue ?? null, wsl: null };
|
|
7
9
|
}
|
|
8
10
|
|
|
11
|
+
// requireAnyChild (opt-in): a candidate install must hold at least one of
|
|
12
|
+
// the named children (e.g. "sessions"/"archived_sessions") to qualify — an
|
|
13
|
+
// empty shell dir must not shadow a populated install. For wslDir discovery
|
|
14
|
+
// the check is folded into the existsSync probe so discoverWslHome skips an
|
|
15
|
+
// empty-shell distro and continues to the next one.
|
|
16
|
+
const populated = (p) => !requireAnyChild || hasAnyChild(p, requireAnyChild, deps.existsSync);
|
|
17
|
+
const wslExists = requireAnyChild
|
|
18
|
+
? (p) => Boolean(pathExists(p, deps.existsSync)) && hasAnyChild(p, requireAnyChild, deps.existsSync)
|
|
19
|
+
: deps.existsSync;
|
|
9
20
|
const wslCandidate = wslValue !== undefined
|
|
10
|
-
? (wsl.shouldProbeWsl(env) && pathExists(wslValue, deps.existsSync) ? wslValue : null)
|
|
11
|
-
: (wslDir && wsl.shouldProbeWsl(env) ? wsl.discoverWslHome(wslDir, { ...deps, env }) : null);
|
|
12
|
-
const nativeCandidate = wsl.shouldProbeNative(env) && nativeValue
|
|
21
|
+
? (wsl.shouldProbeWsl(env) && pathExists(wslValue, deps.existsSync) && populated(wslValue) ? wslValue : null)
|
|
22
|
+
: (wslDir && wsl.shouldProbeWsl(env) ? wsl.discoverWslHome(wslDir, { ...deps, env, existsSync: wslExists }) : null);
|
|
23
|
+
const nativeCandidate = wsl.shouldProbeNative(env) && nativeValue && populated(nativeValue)
|
|
13
24
|
? pathExists(nativeValue, deps.existsSync) : null;
|
|
14
25
|
|
|
15
|
-
return wsl.resolveAllWin32Paths({ nativeValue: nativeCandidate, wslValue: wslCandidate, env, platform
|
|
26
|
+
return wsl.resolveAllWin32Paths({ nativeValue: nativeCandidate, wslValue: wslCandidate, env, platform });
|
|
16
27
|
}
|
|
17
28
|
|
|
18
29
|
function pathExists(p, existsSync) {
|
|
@@ -20,6 +31,11 @@ function pathExists(p, existsSync) {
|
|
|
20
31
|
try { return (existsSync || fssync.existsSync)(p) ? p : null; } catch (_e) { return null; }
|
|
21
32
|
}
|
|
22
33
|
|
|
34
|
+
function hasAnyChild(p, children, existsSync) {
|
|
35
|
+
const ex = existsSync || fssync.existsSync;
|
|
36
|
+
return children.some((c) => { try { return ex(path.join(p, c)); } catch (_e) { return false; } });
|
|
37
|
+
}
|
|
38
|
+
|
|
23
39
|
// Migrate a flat (single-install) cursor to { native, wsl } namespaces.
|
|
24
40
|
// `activeKeys` names the namespaces seeded with a copy of the flat state; the
|
|
25
41
|
// others start empty so their install's full history backfills on first parse.
|