Skip to content

Commit a27600c

Browse files
AnnatarHeclaude
andcommitted
refactor(config): consolidate daemon config into model package
Move socket path configuration from daemon-specific config to the main ShellTimeConfig. This simplifies the architecture by having a single source of truth for configuration. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 27d518d commit a27600c

6 files changed

Lines changed: 29 additions & 132 deletions

File tree

cmd/daemon/main.go

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ package main
22

33
import (
44
"context"
5+
"fmt"
56
"log/slog"
67
"os"
78
"os/signal"
8-
"path/filepath"
99
"syscall"
1010

1111
"github.com/ThreeDotsLabs/watermill"
@@ -25,36 +25,22 @@ var (
2525
ppToken = ""
2626
)
2727

28-
func getConfigPath() string {
29-
homeDir, err := os.UserHomeDir()
30-
if err != nil {
31-
slog.Error("Failed to get user home directory", slog.Any("err", err))
32-
return ""
33-
}
34-
return filepath.Join(homeDir, ".shelltime", "config.toml")
35-
}
36-
3728
func main() {
3829
l := slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{
3930
AddSource: true,
4031
Level: slog.LevelDebug,
4132
}))
4233
slog.SetDefault(l)
4334

44-
daemonConfigService := daemon.NewConfigService(daemon.DefaultConfigPath)
45-
daemonConfig, err := daemonConfigService.GetConfig()
35+
ctx := context.Background()
36+
configFile := os.ExpandEnv(fmt.Sprintf("%s/%s/%s", "$HOME", model.COMMAND_BASE_STORAGE_FOLDER, "config.toml"))
37+
daemonConfigService := model.NewConfigService(configFile)
38+
cfg, err := daemonConfigService.ReadConfigFile(ctx)
4639
if err != nil {
4740
slog.Error("Failed to get daemon config", slog.Any("err", err))
4841
return
4942
}
5043

51-
cs, err := daemonConfigService.GetUserConfig()
52-
if err != nil {
53-
slog.Error("Failed to get user config", slog.Any("err", err))
54-
return
55-
}
56-
57-
ctx := context.Background()
5844
uptraceOptions := []uptrace.Option{
5945
uptrace.WithDSN(uptraceDsn),
6046
uptrace.WithServiceName("cli-daemon"),
@@ -66,7 +52,6 @@ func main() {
6652
uptraceOptions = append(uptraceOptions, uptrace.WithResourceAttributes(attribute.String("hostname", hs)))
6753
}
6854

69-
cfg, err := cs.ReadConfigFile(ctx)
7055
if err != nil ||
7156
cfg.EnableMetrics == nil ||
7257
*cfg.EnableMetrics == false ||
@@ -82,7 +67,7 @@ func main() {
8267
defer uptrace.Shutdown(ctx)
8368
defer uptrace.ForceFlush(ctx)
8469

85-
daemon.Init(cs, version)
70+
daemon.Init(daemonConfigService, version)
8671
model.InjectVar(version)
8772
cmdService := model.NewCommandService()
8873

@@ -121,7 +106,7 @@ func main() {
121106
}
122107

123108
// Create processor instance
124-
processor := daemon.NewSocketHandler(daemonConfig, pubsub)
109+
processor := daemon.NewSocketHandler(&cfg, pubsub)
125110

126111
// Start processor
127112
if err := processor.Start(); err != nil {

commands/track.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ func DoSyncData(
264264
trackingData []model.TrackingData,
265265
meta model.TrackingMetaData,
266266
) error {
267-
socketPath := daemon.DefaultSocketPath
267+
socketPath := config.SocketPath
268268
isSocketReady := daemon.IsSocketReady(ctx, socketPath)
269269

270270
logrus.Traceln("is socket ready: ", isSocketReady)

daemon/config.go

Lines changed: 0 additions & 104 deletions
This file was deleted.

daemon/socket.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
"github.com/ThreeDotsLabs/watermill"
1010
"github.com/ThreeDotsLabs/watermill/message"
11+
"github.com/malamtime/cli/model"
1112
)
1213

1314
type SocketMessageType string
@@ -23,14 +24,14 @@ type SocketMessage struct {
2324
}
2425

2526
type SocketHandler struct {
26-
config *DaemonConfig
27+
config *model.ShellTimeConfig
2728
listener net.Listener
2829

2930
channel *GoChannel
3031
stopChan chan struct{}
3132
}
3233

33-
func NewSocketHandler(config *DaemonConfig, ch *GoChannel) *SocketHandler {
34+
func NewSocketHandler(config *model.ShellTimeConfig, ch *GoChannel) *SocketHandler {
3435
return &SocketHandler{
3536
config: config,
3637
channel: ch,

model/config.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ func mergeConfig(base, local *ShellTimeConfig) {
6868
if local.CCOtel != nil {
6969
base.CCOtel = local.CCOtel
7070
}
71+
if local.SocketPath != "" {
72+
base.SocketPath = local.SocketPath
73+
}
7174
}
7275

7376
func (cs *configService) ReadConfigFile(ctx context.Context) (config ShellTimeConfig, err error) {
@@ -95,7 +98,6 @@ func (cs *configService) ReadConfigFile(ctx context.Context) (config ShellTimeCo
9598
baseName := strings.TrimSuffix(configFile, ext)
9699
// Construct local config filename: baseName + ".local" + ext
97100
localConfigFile := baseName + ".local" + ext
98-
99101
if localConfig, localErr := os.ReadFile(localConfigFile); localErr == nil {
100102
// Parse local config and merge with base config
101103
var localSettings ShellTimeConfig
@@ -126,15 +128,18 @@ func (cs *configService) ReadConfigFile(ctx context.Context) (config ShellTimeCo
126128
if config.DataMasking == nil {
127129
config.DataMasking = &truthy
128130
}
129-
131+
130132
// Initialize AI config with defaults if not present
131133
if config.AI == nil {
132134
config.AI = DefaultAIConfig
133135
}
134136

135137
// Initialize CCOtel config with default port if enabled but port not set
136138
if config.CCOtel != nil && config.CCOtel.GRPCPort == 0 {
137-
config.CCOtel.GRPCPort = 4317 // default OTEL gRPC port
139+
config.CCOtel.GRPCPort = 54027 // default OTEL gRPC port
140+
}
141+
if config.SocketPath == "" {
142+
config.SocketPath = DefaultSocketPath
138143
}
139144

140145
UserShellTimeConfig = config

model/types.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package model
22

3+
const (
4+
DefaultSocketPath = "/tmp/shelltime.sock"
5+
)
6+
37
type Endpoint struct {
48
APIEndpoint string `toml:"apiEndpoint"`
59
Token string `token:"token"`
@@ -64,6 +68,10 @@ type ShellTimeConfig struct {
6468

6569
// CCOtel configuration for OTEL-based Claude Code tracking (v2 - gRPC passthrough)
6670
CCOtel *CCOtel `toml:"ccotel"`
71+
72+
// SocketPath is the path to the Unix domain socket used for communication
73+
// between the CLI and the daemon.
74+
SocketPath string `toml:"socketPath"`
6775
}
6876

6977
var DefaultAIConfig = &AIConfig{
@@ -90,4 +98,6 @@ var DefaultConfig = ShellTimeConfig{
9098
Exclude: []string{},
9199
CCUsage: nil,
92100
CCOtel: nil,
101+
102+
SocketPath: DefaultSocketPath,
93103
}

0 commit comments

Comments
 (0)