feat: show daemon config in 'bd daemon --status' output
Add auto-commit, auto-push, local mode, sync interval, and daemon mode to the status output when querying a running daemon. This helps users understand the current daemon configuration without having to check logs or remember what flags were used at startup. Changes: - Add config fields to StatusResponse in protocol.go - Add SetConfig() method to Server for daemon to set its config - Update handleStatus() to include config in response - Update showDaemonStatus() to query and display config via RPC - Add comprehensive test coverage for new functionality Co-authored-by: Christian Catalan <crcatala@gmail.com>
This commit is contained in:
@@ -454,6 +454,15 @@ func runDaemonLoop(interval time.Duration, autoCommit, autoPush, localMode bool,
|
||||
return
|
||||
}
|
||||
|
||||
// Choose event loop based on BEADS_DAEMON_MODE (need to determine early for SetConfig)
|
||||
daemonMode := os.Getenv("BEADS_DAEMON_MODE")
|
||||
if daemonMode == "" {
|
||||
daemonMode = "events" // Default to event-driven mode (production-ready as of v0.21.0)
|
||||
}
|
||||
|
||||
// Set daemon configuration for status reporting
|
||||
server.SetConfig(autoCommit, autoPush, localMode, interval.String(), daemonMode)
|
||||
|
||||
// Register daemon in global registry
|
||||
registry, err := daemon.NewRegistry()
|
||||
if err != nil {
|
||||
@@ -496,12 +505,7 @@ func runDaemonLoop(interval time.Duration, autoCommit, autoPush, localMode bool,
|
||||
parentPID := computeDaemonParentPID()
|
||||
log.log("Monitoring parent process (PID %d)", parentPID)
|
||||
|
||||
// Choose event loop based on BEADS_DAEMON_MODE
|
||||
daemonMode := os.Getenv("BEADS_DAEMON_MODE")
|
||||
if daemonMode == "" {
|
||||
daemonMode = "events" // Default to event-driven mode (production-ready as of v0.21.0)
|
||||
}
|
||||
|
||||
// daemonMode already determined above for SetConfig
|
||||
switch daemonMode {
|
||||
case "events":
|
||||
log.log("Using event-driven mode")
|
||||
|
||||
@@ -54,6 +54,17 @@ func showDaemonStatus(pidFile string) {
|
||||
}
|
||||
}
|
||||
|
||||
// Try to get detailed status from daemon via RPC
|
||||
var rpcStatus *rpc.StatusResponse
|
||||
beadsDir := filepath.Dir(pidFile)
|
||||
socketPath := filepath.Join(beadsDir, "bd.sock")
|
||||
if client, err := rpc.TryConnectWithTimeout(socketPath, 1*time.Second); err == nil && client != nil {
|
||||
if status, err := client.Status(); err == nil {
|
||||
rpcStatus = status
|
||||
}
|
||||
_ = client.Close()
|
||||
}
|
||||
|
||||
if jsonOutput {
|
||||
status := map[string]interface{}{
|
||||
"running": true,
|
||||
@@ -65,6 +76,14 @@ func showDaemonStatus(pidFile string) {
|
||||
if logPath != "" {
|
||||
status["log_path"] = logPath
|
||||
}
|
||||
// Add config from RPC status if available
|
||||
if rpcStatus != nil {
|
||||
status["auto_commit"] = rpcStatus.AutoCommit
|
||||
status["auto_push"] = rpcStatus.AutoPush
|
||||
status["local_mode"] = rpcStatus.LocalMode
|
||||
status["sync_interval"] = rpcStatus.SyncInterval
|
||||
status["daemon_mode"] = rpcStatus.DaemonMode
|
||||
}
|
||||
outputJSON(status)
|
||||
return
|
||||
}
|
||||
@@ -76,6 +95,16 @@ func showDaemonStatus(pidFile string) {
|
||||
if logPath != "" {
|
||||
fmt.Printf(" Log: %s\n", logPath)
|
||||
}
|
||||
// Display config from RPC status if available
|
||||
if rpcStatus != nil {
|
||||
fmt.Printf(" Mode: %s\n", rpcStatus.DaemonMode)
|
||||
fmt.Printf(" Sync Interval: %s\n", rpcStatus.SyncInterval)
|
||||
fmt.Printf(" Auto-Commit: %v\n", rpcStatus.AutoCommit)
|
||||
fmt.Printf(" Auto-Push: %v\n", rpcStatus.AutoPush)
|
||||
if rpcStatus.LocalMode {
|
||||
fmt.Printf(" Local Mode: %v (no git sync)\n", rpcStatus.LocalMode)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if jsonOutput {
|
||||
outputJSON(map[string]interface{}{"running": false})
|
||||
|
||||
Reference in New Issue
Block a user