# 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**:
```bash
# 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**:
```bash
# 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**:
```bash
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):
```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

- GitHub API docs: https://docs.github.com/en/rest/releases
- nix-prefetch-url: `man nix-prefetch-url`
- SRI format: https://www.w3.org/TR/SRI/
