feat(daemon): add version command with config debug info#165
Conversation
…able 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add -v/--version flags to shelltime-daemon that display version info and current config state without starting any services. This helps diagnose configuration issues by showing: - Version, commit, build date - Go version and OS/Arch - Socket path and API endpoint - CCOtel, CCUsage, LogCleanup, CodeTracking config states Also add debug log when writing CCOtel debug files. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Summary of ChangesHello @AnnatarHe, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
Codecov Report❌ Patch coverage is
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Code Review
This pull request adds a useful -v/--version flag to the shelltime-daemon for displaying version and configuration information, which is great for debugging. The implementation is straightforward. I've made a couple of suggestions: one to improve platform compatibility by adhering to repository guidelines for path construction, and another to refactor some repetitive code to enhance maintainability. Overall, a good addition.
| configFile := os.ExpandEnv(fmt.Sprintf("%s/%s/%s", "$HOME", model.COMMAND_BASE_STORAGE_FOLDER, "config.toml")) | ||
| configService := model.NewConfigService(configFile) | ||
| cfg, err := configService.ReadConfigFile(ctx) | ||
| if err != nil { | ||
| fmt.Printf("\nConfig: error reading config: %v\n", err) | ||
| return | ||
| } |
There was a problem hiding this comment.
For platform-independent paths, it's better to use os.UserHomeDir() and filepath.Join as per the repository's general rules. This avoids hardcoding path separators and reliance on environment variables like $HOME, making the code more robust across different operating systems. Note that this change requires importing the path/filepath package.
| configFile := os.ExpandEnv(fmt.Sprintf("%s/%s/%s", "$HOME", model.COMMAND_BASE_STORAGE_FOLDER, "config.toml")) | |
| configService := model.NewConfigService(configFile) | |
| cfg, err := configService.ReadConfigFile(ctx) | |
| if err != nil { | |
| fmt.Printf("\nConfig: error reading config: %v\n", err) | |
| return | |
| } | |
| homeDir, err := os.UserHomeDir() | |
| if err != nil { | |
| fmt.Printf("\nConfig: error getting user home directory: %v\n", err) | |
| return | |
| } | |
| configFile := filepath.Join(homeDir, model.COMMAND_BASE_STORAGE_FOLDER, "config.toml") | |
| configService := model.NewConfigService(configFile) | |
| cfg, err := configService.ReadConfigFile(ctx) | |
| if err != nil { | |
| fmt.Printf("\nConfig: error reading config: %v\n", err) | |
| return | |
| } |
References
- For platform-independent paths, use
filepath.Jointo combine segments andos.UserHomeDir()to get the home directory, rather than hardcoding path separators or environment variables like$HOME.
| // CCOtel config | ||
| if cfg.CCOtel != nil { | ||
| fmt.Println("\nCCOtel:") | ||
| if cfg.CCOtel.Enabled != nil { | ||
| fmt.Printf(" Enabled: %v\n", *cfg.CCOtel.Enabled) | ||
| } else { | ||
| fmt.Printf(" Enabled: <nil>\n") | ||
| } | ||
| fmt.Printf(" gRPC Port: %d\n", cfg.CCOtel.GRPCPort) | ||
| if cfg.CCOtel.Debug != nil { | ||
| fmt.Printf(" Debug: %v\n", *cfg.CCOtel.Debug) | ||
| } else { | ||
| fmt.Printf(" Debug: <nil>\n") | ||
| } | ||
| } else { | ||
| fmt.Println("\nCCOtel: <not configured>") | ||
| } | ||
|
|
||
| // CCUsage config | ||
| if cfg.CCUsage != nil { | ||
| fmt.Println("\nCCUsage:") | ||
| if cfg.CCUsage.Enabled != nil { | ||
| fmt.Printf(" Enabled: %v\n", *cfg.CCUsage.Enabled) | ||
| } else { | ||
| fmt.Printf(" Enabled: <nil>\n") | ||
| } | ||
| } | ||
|
|
||
| // LogCleanup config | ||
| if cfg.LogCleanup != nil { | ||
| fmt.Println("\nLogCleanup:") | ||
| if cfg.LogCleanup.Enabled != nil { | ||
| fmt.Printf(" Enabled: %v\n", *cfg.LogCleanup.Enabled) | ||
| } else { | ||
| fmt.Printf(" Enabled: <nil>\n") | ||
| } | ||
| fmt.Printf(" ThresholdMB: %d\n", cfg.LogCleanup.ThresholdMB) | ||
| } | ||
|
|
||
| // CodeTracking config | ||
| if cfg.CodeTracking != nil { | ||
| fmt.Println("\nCodeTracking:") | ||
| if cfg.CodeTracking.Enabled != nil { | ||
| fmt.Printf(" Enabled: %v\n", *cfg.CodeTracking.Enabled) | ||
| } else { | ||
| fmt.Printf(" Enabled: <nil>\n") | ||
| } | ||
| } |
There was a problem hiding this comment.
The logic for printing each configuration section is very similar across CCOtel, CCUsage, LogCleanup, and CodeTracking. To improve maintainability and reduce code duplication, consider abstracting this logic into a helper function. For instance, a helper could accept a section name and a pointer to its Enabled field, and handle the nil check and formatted printing. This would make the printVersionInfo function more concise and easier to modify in the future.
Enhance `shelltime daemon status` command to query the running daemon via socket for real-time status including: - Version and build info - Uptime (tracked from daemon start) - Go version and platform The daemon now tracks its start time in daemon.Init() and responds to status requests via the Unix socket, providing accurate runtime info. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Summary
-v/--versionflags toshelltime-daemonbinaryThis helps diagnose configuration issues by quickly showing what config values the daemon would use.
Test plan
shelltime-daemon -vand verify output shows version and configshelltime-daemon --versionand verify same outputgo build ./cmd/daemon/main.go🤖 Generated with Claude Code