Skip to content

feat(cli): add self-update command for automatic binary updates #91

@gcmartinezg

Description

@gcmartinezg

📋 Pre-flight Checks

  • I have searched existing issues and this is not a duplicate
  • I understand this issue needs status:approved before a PR can be opened

🔍 Problem Description

I recently encountered a critical issue where my local engram installation was running an old version (pre-v1.10) with the 2000-character truncation limit, while the current codebase has a 50,000-character limit (fixed in commit 4235fa6).

This resulted in:

  • Data loss: Most my observations were permanently truncated at exactly 2000 characters
  • Silent degradation: The version checker notified me of updates, but I had to manually rebuild from source
  • Inconsistent behavior: Different installations could have vastly different limits without users realizing

The current update workflow requires users to either:

  1. Run go install github.com/Gentleman-Programming/engram/cmd/engram@latest (requires Go toolchain)
  2. Manually download from GitHub releases (requires finding the correct asset for their platform)
  3. Use Homebrew (macOS/Linux only, not everyone uses it)

This creates friction and increases the risk of running outdated versions with bugs or missing features.

💡 Proposed Solution

Add a self-update command that automatically downloads and installs the latest engram binary:

engram update

Expected behavior:

  1. Fetch latest release from GitHub API (already implemented in internal/version/check.go)
  2. Download the appropriate binary for the current platform (Windows/macOS/Linux, amd64/arm64)
  3. Replace the running binary with the new version
  4. Verify the update succeeded
  5. Display the new version and changelog

Example output:

Checking for updates...
Found new version: v1.10.1 (current: v1.9.5)

Downloading engram_1.10.1_windows_amd64.zip...
[████████████████████████████████████] 100%

Installing to C:\Users\user\bin\engram.exe...
✓ Update successful!

engram v1.10.1
Release notes: https://github.com/Gentleman-Programming/engram/releases/tag/v1.10.1

Optional flags:

  • --check: Only check for updates, don't install
  • --force: Force update even if already on latest version
  • --version <tag>: Install a specific version

Technical approach:

  • Use GitHub Releases API to find latest version
  • Download the appropriate asset based on runtime.GOOS and runtime.GOARCH
  • Use a library like go-selfupdate or equinox.io for safe binary replacement
  • Implement atomic replacement to avoid corrupting the binary on failure

📦 Affected Area

CLI (commands, flags)

🔄 Alternatives Considered

Alternative 1: Keep manual update only

  • ❌ Requires users to remember to update
  • ❌ Risk of running outdated versions with critical bugs
  • ❌ Friction for non-technical users

Alternative 2: Auto-update on every run

  • ❌ Too aggressive, could surprise users
  • ❌ Might fail in restricted environments
  • ✅ Current version checker is a good middle ground (notify but don't install)

Alternative 3: Package manager only (Homebrew, apt, etc.)

  • ❌ Not all users use package managers
  • ❌ Windows users have limited options
  • ❌ Doesn't help users who installed via go install

📎 Additional Context

Real-world impact:

  • My observations on a few of the projects I have been working on were truncated at 2000 chars and cannot be recovered
  • The version checker alerted me to updates, but I still had to figure out how to update manually
  • A simple engram update command would have prevented this data loss

Reference implementations:

  • Goreleaser has built-in self-update
  • gh CLI has gh upgrade
  • hugo has similar functionality via plugins

Code locations:

  • Version checking already exists: internal/version/check.go
  • Just needs download + install logic added

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions