skills/specs/002-update-opencode/research.md
dan 99187460b1 feat(update-opencode): add skill for automating OpenCode version updates in Nix
Implement complete workflow for checking and applying OpenCode updates:
- check-version.sh: Compare current vs latest GitHub release
- fetch-sha256.sh: Fetch SHA256 hash using nix-prefetch-url
- update-nix-file.sh: Update Nix package definition with dry-run support
- verify-update.sh: Verify installed version matches expectation

Includes comprehensive documentation (SKILL.md for agents, README.md for users)
and full spec in specs/002-update-opencode/ with user stories and acceptance criteria.

Eliminates manual Nix file editing and hash lookups for OpenCode updates.
2025-11-15 13:35:58 -08:00

2 KiB

Implementation Decisions: Update OpenCode Skill

Date: 2025-11-11
Feature: 002-update-opencode


Key Technical Decisions

1. Nix File Parsing

Decision: Use sed with regex patterns
Rationale: Simple, preserves formatting, no complex parsing needed
Commands:

# Read: grep -oP 'version\s*=\s*"\K[^"]+' file
# Update: sed -i 's/version = "[^"]*"/version = "X.Y.Z"/' file

2. GitHub API

Decision: Use /repos/sst/opencode/releases/latest endpoint
Rationale: Automatically excludes pre-releases, single query
Rate Limits: 60/hour unauthenticated, 5000/hour authenticated

3. SHA256 Hash Format

Decision: Use SRI format (sha256-...), not Nix base-32
Rationale: OpenCode package uses fetchzip which expects SRI format
Implementation:

# Fetch: nix-prefetch-url --type sha256 <URL>
# Convert: nix hash to-sri --type sha256 <nix-hash>
# Output: sha256-ABC123...

Critical: Binary releases (~50MB zips), NOT source tarballs

4. Version Comparison

Decision: Use sort -V (version sort)
Rationale: Handles semantic versioning correctly, standard tool

5. System Rebuild

Decision: Detect nixos-rebuild vs home-manager
Commands:

if command -v nixos-rebuild >/dev/null 2>&1; then
  sudo nixos-rebuild switch --flake ~/proj/dotfiles#delpad
elif command -v home-manager >/dev/null 2>&1; then
  home-manager switch --flake ~/proj/dotfiles
fi

Important Details

Binary Release URL Pattern:

https://github.com/sst/opencode/releases/download/v${VERSION}/opencode-linux-x64.zip

Current Package Format (from ~/proj/dotfiles/pkgs/opencode/default.nix):

{
  version = "1.0.44";
  sha256 = "sha256-q3K5w1lhzd7GhBesKbaD3jDo2B/twUDLmi8wrkWzWh4=";
  # Uses fetchzip for binary releases
}

Error Handling: Fail fast with clear messages, no sophisticated retry logic


References