Codebase quality improvements: validation, type safety, DRY, and CLI enhancements#5
Open
levifig wants to merge 7 commits intonumman-ali:mainfrom
Open
Codebase quality improvements: validation, type safety, DRY, and CLI enhancements#5levifig wants to merge 7 commits intonumman-ali:mainfrom
levifig wants to merge 7 commits intonumman-ali:mainfrom
Conversation
- Add support for XDG-compliant ~/.config/claude path - Check ~/.config/claude first, fall back to ~/.claude - Add --config-dir/-c CLI option to override config path - Remove unused xdg-basedir dependency
- Check for NaN from invalid input - Enforce range: 2024 to current year - Show helpful error message with valid range
- Add type guard isValidStatsCache() - Validate parsed JSON before returning - Throw descriptive error on invalid format
- Use explicit unknown type for JSON parsing - Add type narrowing for timestamp validation - Cast message and usage objects explicitly - Improves type safety without changing behavior
- Remove duplicate from collector.ts - Remove duplicate from stats.ts - Import from utils/dates.ts (single source of truth)
- Export resolveClaudeDataPath() from collector - Add -V/--verbose CLI option - Show config directory path when verbose - Show sessions/messages/projects summary when verbose - Improve error message formatting
- Add -o/--output CLI option to specify save location - Skip interactive prompt when --output is provided - Improve error message formatting for save failures
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.
Summary
A collection of code quality improvements addressing bugs, type safety, DRY violations, and CLI usability.
Changes
Bug Fixes
--yearparameter to prevent crashes on invalid input (e.g.,--year abc)stats-cache.jsonbefore parsingType Safety
anytypes withRecord<string, unknown>in collectorCode Quality (DRY)
formatDateKey()functions into single source inutils/dates.tsCLI Enhancements
--verbose/-Vflag to show debug info (config path, session/message counts)--output/-oflag to specify image save location (skips interactive prompt)Testing
--helpshows all new options--year invalidshows helpful error--verbosedisplays config path and stats summary--output ~/test.pngsaves directly without prompting