Conversation
- Replace github.com/sirupsen/logrus with log/slog across all packages - Add model/path.go with centralized path helper functions - Fix typo: SocketTopicProccessor -> SocketTopicProcessor - Remove logrus dependency from go.mod 🤖 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 significantly refactors the application's logging infrastructure by migrating from a third-party library to the native Go 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 is a great step forward in modernizing the codebase by replacing logrus with the standard library's slog for structured logging. The changes are applied consistently across the project. The introduction of model/path.go to centralize path management is also a very good initiative. I've provided some feedback to improve the portability of the new path helpers and to refine some of the new logging statements. Overall, this is a solid refactoring effort.
| package model | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "os" | ||
| "path/filepath" | ||
| ) | ||
|
|
||
| // GetBaseStoragePath returns the base storage path for shelltime | ||
| // e.g., /Users/username/.shelltime | ||
| func GetBaseStoragePath() string { | ||
| return os.ExpandEnv("$HOME/" + COMMAND_BASE_STORAGE_FOLDER) | ||
| } | ||
|
|
||
| // GetStoragePath returns the full path for a given subpath within the storage folder | ||
| // e.g., GetStoragePath("config.toml") returns /Users/username/.shelltime/config.toml | ||
| func GetStoragePath(subpath string) string { | ||
| return filepath.Join(GetBaseStoragePath(), subpath) | ||
| } | ||
|
|
||
| // GetConfigFilePath returns the path to the main config file | ||
| func GetConfigFilePath() string { | ||
| return GetStoragePath("config.toml") | ||
| } | ||
|
|
||
| // GetLocalConfigFilePath returns the path to the local config file | ||
| func GetLocalConfigFilePath() string { | ||
| return GetStoragePath("config.local.toml") | ||
| } | ||
|
|
||
| // GetLogFilePath returns the path to the log file | ||
| func GetLogFilePath() string { | ||
| return GetStoragePath("log.log") | ||
| } | ||
|
|
||
| // GetCommandsStoragePath returns the path to the commands storage folder | ||
| func GetCommandsStoragePath() string { | ||
| return os.ExpandEnv("$HOME/" + COMMAND_STORAGE_FOLDER) | ||
| } | ||
|
|
||
| // GetPreCommandFilePath returns the path to the pre-command storage file | ||
| func GetPreCommandFilePath() string { | ||
| return os.ExpandEnv("$HOME/" + COMMAND_PRE_STORAGE_FILE) | ||
| } | ||
|
|
||
| // GetPostCommandFilePath returns the path to the post-command storage file | ||
| func GetPostCommandFilePath() string { | ||
| return os.ExpandEnv("$HOME/" + COMMAND_POST_STORAGE_FILE) | ||
| } | ||
|
|
||
| // GetCursorFilePath returns the path to the cursor storage file | ||
| func GetCursorFilePath() string { | ||
| return os.ExpandEnv("$HOME/" + COMMAND_CURSOR_STORAGE_FILE) | ||
| } | ||
|
|
||
| // GetHeartbeatLogFilePath returns the path to the heartbeat log file | ||
| func GetHeartbeatLogFilePath() string { | ||
| return os.ExpandEnv("$HOME/" + HEARTBEAT_LOG_FILE) | ||
| } | ||
|
|
||
| // GetSyncPendingFilePath returns the path to the sync pending file | ||
| func GetSyncPendingFilePath() string { | ||
| return os.ExpandEnv("$HOME/" + SYNC_PENDING_FILE) | ||
| } | ||
|
|
||
| // GetBinFolderPath returns the path to the bin folder | ||
| func GetBinFolderPath() string { | ||
| return os.ExpandEnv(fmt.Sprintf("$HOME/%s/bin", COMMAND_BASE_STORAGE_FOLDER)) | ||
| } | ||
|
|
||
| // GetHooksFolderPath returns the path to the hooks folder | ||
| func GetHooksFolderPath() string { | ||
| return os.ExpandEnv(fmt.Sprintf("$HOME/%s/hooks", COMMAND_BASE_STORAGE_FOLDER)) | ||
| } |
There was a problem hiding this comment.
The new path helper functions are a great idea for centralizing path logic. However, many of them use os.ExpandEnv with hardcoded / separators (e.g., os.ExpandEnv("$HOME/" + ...)), which is not portable and will cause issues on Windows.
I suggest rewriting this file to use path/filepath.Join for all path constructions. This will make the path helpers robust and platform-independent. The proposed implementation below also makes GetStoragePath variadic for more flexibility.
package model
import (
"os"
"path/filepath"
)
// GetBaseStoragePath returns the base storage path for shelltime
// e.g., /Users/username/.shelltime
func GetBaseStoragePath() string {
home, err := os.UserHomeDir()
if err != nil {
// Fallback for environments where home dir is not available.
return filepath.Join(os.TempDir(), COMMAND_BASE_STORAGE_FOLDER)
}
return filepath.Join(home, COMMAND_BASE_STORAGE_FOLDER)
}
// GetStoragePath returns the full path for a given subpath within the storage folder
// e.g., GetStoragePath("config.toml") returns /Users/username/.shelltime/config.toml
func GetStoragePath(subpaths ...string) string {
return filepath.Join(append([]string{GetBaseStoragePath()}, subpaths...)...)
}
// GetConfigFilePath returns the path to the main config file
func GetConfigFilePath() string {
return GetStoragePath("config.toml")
}
// GetLocalConfigFilePath returns the path to the local config file
func GetLocalConfigFilePath() string {
return GetStoragePath("config.local.toml")
}
// GetLogFilePath returns the path to the log file
func GetLogFilePath() string {
return GetStoragePath("log.log")
}
// GetCommandsStoragePath returns the path to the commands storage folder
func GetCommandsStoragePath() string {
return GetStoragePath("commands")
}
// GetPreCommandFilePath returns the path to the pre-command storage file
func GetPreCommandFilePath() string {
return GetStoragePath("commands", "pre.txt")
}
// GetPostCommandFilePath returns the path to the post-command storage file
func GetPostCommandFilePath() string {
return GetStoragePath("commands", "post.txt")
}
// GetCursorFilePath returns the path to the cursor storage file
func GetCursorFilePath() string {
return GetStoragePath("commands", "cursor.txt")
}
// GetHeartbeatLogFilePath returns the path to the heartbeat log file
func GetHeartbeatLogFilePath() string {
return GetStoragePath("coding-heartbeat.data.log")
}
// GetSyncPendingFilePath returns the path to the sync pending file
func GetSyncPendingFilePath() string {
return GetStoragePath("sync-pending.jsonl")
}
// GetBinFolderPath returns the path to the bin folder
func GetBinFolderPath() string {
return GetStoragePath("bin")
}
// GetHooksFolderPath returns the path to the hooks folder
func GetHooksFolderPath() string {
return GetStoragePath("hooks")
}There was a problem hiding this comment.
You are absolutely right. Please use path.join to compose the path instead of hard-coded /. @claude
There was a problem hiding this comment.
Claude finished @AnnatarHe's task in 2m 54s —— View job
Path portability fix completed
I've updated model/path.go to use filepath.Join for cross-platform compatibility, following the excellent suggestion from @gemini-code-assist.
Changes made:
- ✅ Replaced
os.ExpandEnv("$HOME/...")withos.UserHomeDir()+filepath.Join - ✅ Added fallback to
os.TempDir()when home directory is unavailable - ✅ Made
GetStoragePath()variadic for flexible path construction - ✅ All path helpers now use
filepath.Joinfor Windows compatibility - ✅ Removed hardcoded
/separators throughout the file
The implementation now properly handles paths across all platforms (Linux, macOS, Windows) by using the standard library's platform-aware path joining functions.
Commit: b6e8bf6
|
| err := os.MkdirAll(baseFolder, 0755) | ||
| if err != nil { | ||
| slog.Error("[ShellTime.xyz] failed to create log directory: ", slog.Any("err", err)) | ||
| slog.Error("[ShellTime.xyz] failed to create log directory", slog.Any("err", err)) |
There was a problem hiding this comment.
For structured logging, it's better to move contextual information from the message string into key-value pairs. This makes logs easier to parse, filter, and query. The [ShellTime.xyz] prefix should be a field, for example component. This applies to the other similar error logs in this function as well.
| slog.Error("[ShellTime.xyz] failed to create log directory", slog.Any("err", err)) | |
| slog.Error("failed to create log directory", slog.String("component", "ShellTime.xyz"), slog.Any("err", err)) |
| func SocketTopicProcessor(messages <-chan *message.Message) { | ||
| for msg := range messages { | ||
| ctx := context.Background() | ||
| slog.InfoContext(ctx, "received message: ", slog.String("msg.uuid", msg.UUID)) |
There was a problem hiding this comment.
Replace hardcoded '/' separators and os.ExpandEnv("$HOME/...") with
filepath.Join and os.UserHomeDir() for Windows compatibility.
- Use os.UserHomeDir() instead of $HOME env var
- Add fallback to os.TempDir() when home dir unavailable
- Make GetStoragePath variadic for flexible path construction
- All path helpers now use filepath.Join for portability
Co-authored-by: Le He <AnnatarHe@users.noreply.github.com>
Summary
github.com/sirupsen/logruswith Go stdliblog/slogacross all packagesmodel/path.gowith centralized path helper functions for config/storage pathsSocketTopicProccessor→SocketTopicProcessorTest plan
go build ./...)go test ./daemon/...)go test ./model/...)🤖 Generated with Claude Code