feat(daemon): add auto_pull config parameter for periodic remote sync
Add --auto-pull flag to control whether the daemon periodically pulls from remote to check for updates from other clones. Configuration precedence: 1. --auto-pull CLI flag (highest) 2. BEADS_AUTO_PULL environment variable 3. daemon.auto_pull in database config 4. Default: true when sync.branch is configured When auto_pull is enabled, the daemon creates a remoteSyncTicker that periodically calls doAutoImport() to pull remote changes. When disabled, users must manually run 'git pull' to sync remote changes. Changes: - cmd/bd/daemon.go: Add --auto-pull flag and config reading logic - cmd/bd/daemon_event_loop.go: Gate remoteSyncTicker on autoPull parameter - cmd/bd/daemon_lifecycle.go: Add auto-pull to status output and spawn args - internal/rpc/protocol.go: Add AutoPull field to StatusResponse - internal/rpc/server_core.go: Add autoPull to Server struct and SetConfig - internal/rpc/server_routing_validation_diagnostics.go: Include in status - Tests updated to pass autoPull parameter Closes #TBD
This commit is contained in:
@@ -36,6 +36,7 @@ func runEventDrivenLoop(
|
||||
jsonlPath string,
|
||||
doExport func(),
|
||||
doAutoImport func(),
|
||||
autoPull bool,
|
||||
parentPID int,
|
||||
log daemonLogger,
|
||||
) {
|
||||
@@ -100,9 +101,20 @@ func runEventDrivenLoop(
|
||||
// This is essential for multi-clone workflows where the file watcher only
|
||||
// sees local changes but remote may have updates from other clones.
|
||||
// Default is 30 seconds; configurable via BEADS_REMOTE_SYNC_INTERVAL.
|
||||
remoteSyncInterval := getRemoteSyncInterval(log)
|
||||
remoteSyncTicker := time.NewTicker(remoteSyncInterval)
|
||||
defer remoteSyncTicker.Stop()
|
||||
// Only enabled when autoPull is true (default when sync.branch is configured).
|
||||
var remoteSyncTicker *time.Ticker
|
||||
if autoPull {
|
||||
remoteSyncInterval := getRemoteSyncInterval(log)
|
||||
if remoteSyncInterval > 0 {
|
||||
remoteSyncTicker = time.NewTicker(remoteSyncInterval)
|
||||
defer remoteSyncTicker.Stop()
|
||||
log.log("Auto-pull enabled: checking remote every %v", remoteSyncInterval)
|
||||
} else {
|
||||
log.log("Auto-pull disabled: remote-sync-interval is 0")
|
||||
}
|
||||
} else {
|
||||
log.log("Auto-pull disabled: use 'git pull' manually to sync remote changes")
|
||||
}
|
||||
|
||||
// Parent process check (every 10 seconds)
|
||||
parentCheckTicker := time.NewTicker(10 * time.Second)
|
||||
@@ -126,7 +138,13 @@ func runEventDrivenLoop(
|
||||
// Periodic health validation (not sync)
|
||||
checkDaemonHealth(ctx, store, log)
|
||||
|
||||
case <-remoteSyncTicker.C:
|
||||
case <-func() <-chan time.Time {
|
||||
if remoteSyncTicker != nil {
|
||||
return remoteSyncTicker.C
|
||||
}
|
||||
// Never fire if auto-pull is disabled
|
||||
return make(chan time.Time)
|
||||
}():
|
||||
// Periodic remote sync to pull updates from other clones
|
||||
// This ensures the daemon sees changes pushed by other clones
|
||||
// even when the local file watcher doesn't trigger
|
||||
|
||||
Reference in New Issue
Block a user