fix(stats): source heatmap from session_cache instead of stats-cache.json - #7
Merged
Merged
Conversation
…json Claude's /stats command only counts parent JSONL files and rotates them off disk, making the heatmap blind to subagent sessions and older months. Switch to an in-DB aggregate (getDailyActivity) that covers everything Switchboard has indexed — parents and subagents alike. - db.js: add getDailyActivity() — GROUP BY date over session_cache - main.js: add get-stats-from-db IPC handler; rewrite refresh-stats to drop the /stats PTY spawn (now redundant); remove dead runClaude helper - preload.js: expose getStatsFromDb to renderer - public/stats-view.js: consume DB stats; update data-source notice text - test/db-daily-activity.test.js: 6 tests covering aggregation logic and stats-object shape (better-sqlite3 ABI incompatibility with plain node means the SQL path is covered via a pure-JS mirror of the query)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The stats heatmap had a large hole between March and April 2026 and was mostly empty before February. Root cause:
claude /statsonly counts parent JSONL files, silently ignoring all subagent sessionsSolution
Source the heatmap directly from
session_cache(Switchboard's own SQLite DB), which already indexes every parent and subagent session and persists them independently of Claude's file rotation.DB counts by month:
All months are now fully visible in the heatmap.
Changes
db.js: addgetDailyActivity()—GROUP BY substr(modified,1,10)oversession_cachemain.js: addget-stats-from-dbIPC handler; rewriterefresh-statsto drop the slow/statsPTY spawn; remove deadrunClaudehelper (~90 lines)preload.js: exposegetStatsFromDbto rendererpublic/stats-view.js: consume DB stats; update data-source notice texttest/db-daily-activity.test.js: 6 tests covering aggregation logic and stats-object shapeTest plan
fetchAndTransformUsage, unchanged)npm testpasses (38/38)