# Auto-Update Feature ## Overview The dborg CLI includes an automatic update checker that runs on every program start. It checks the git remote for newer tagged versions and prompts the user to update if available. ## How It Works 1. **Version Check**: On startup, the CLI queries the git remote for the latest tag 2. **Comparison**: Compares remote version with current version (embedded at build time) 3. **User Prompt**: If newer version exists, prompts user to update 4. **Installation**: Runs `go install git.db.org.ai/dborg` to fetch latest version 5. **Auto-Restart**: Uses `syscall.Exec()` to restart with the new binary seamlessly ## Implementation Details ### Version Embedding The version is embedded at build time using ldflags: ```bash go build -ldflags "-X git.db.org.ai/dborg/internal/utils.Version=v0.1.0" ``` The Makefile automatically extracts the version from git tags: ```makefile VERSION := $(shell git describe --tags --abbrev=0 2>/dev/null || echo "v0.1.0") LDFLAGS := -X git.db.org.ai/dborg/internal/utils.Version=$(VERSION) ``` ### Version Check Process Located in `internal/utils/version.go`: 1. **CheckForUpdates()**: Main entry point called from root command's PersistentPreRunE 2. **getLatestRemoteTag()**: Queries git remote using `git ls-remote --tags` 3. **isNewerVersion()**: Simple string comparison for version numbers 4. **promptAndUpdate()**: Handles user interaction and update process 5. **restartSelf()**: Restarts the binary using `syscall.Exec()` ### Skip Conditions Auto-update is skipped when: - Running in non-interactive mode (piped output) - Version is "dev" (development builds) - Git remote query fails (silently continues) - No newer version available - User declines update ## User Experience ``` $ dborg npd --firstname John 🔔 A new version of dborg is available: v0.2.0 (current: v0.1.0) Would you like to update now? [Y/n]: y Updating to v0.2.0... ✓ Update successful! Restarting... [Binary automatically restarts and continues with original command] ``` ## Manual Update Users can always update manually: ```bash go install git.db.org.ai/dborg@latest ``` Or check their current version: ```bash dborg version ``` ## Testing Unit tests cover version comparison logic: ```bash go test ./internal/utils -v ``` ## Security Considerations - Only queries official git remote (git.db.org.ai/dborg) - Runs exact command: `go install git.db.org.ai/dborg` - No automatic updates without user confirmation - Fails safely if update errors occur - Preserves original command arguments after restart