|
| 1 | +# Syncing SkyCode OpenCode Fork with Upstream |
| 2 | + |
| 3 | +This document explains how to keep the `skycode-opencode` fork synchronized with the upstream OpenCode repository. |
| 4 | + |
| 5 | +## Strategy Overview |
| 6 | + |
| 7 | +**Key Principle: Keep Fork Minimal for Easy Syncing** |
| 8 | + |
| 9 | +- **Plugins Location**: SkyCode plugins are **NOT** in this fork |
| 10 | +- **Plugins Location**: Plugins live in `skycode/packages/opencode-plugin/` (main repo) |
| 11 | +- **Fork Purpose**: Version control, major incompatible changes, and OpenCode customization |
| 12 | +- **Minimal Changes**: Keep fork as close to upstream as possible |
| 13 | + |
| 14 | +## Why This Approach? |
| 15 | + |
| 16 | +1. **Easy Upstream Syncs**: Minimal changes in fork = fewer conflicts |
| 17 | +2. **Plugin Maintenance**: Plugins evolve separately from OpenCode |
| 18 | +3. **Version Control**: Fork controls OpenCode version bundled with SkyCode |
| 19 | +4. **Clean Separation**: Core OpenCode changes vs. SkyCode extensions |
| 20 | + |
| 21 | +## Quick Start |
| 22 | + |
| 23 | +```bash |
| 24 | +cd skycode-opencode |
| 25 | +./sync-upstream.sh |
| 26 | +``` |
| 27 | + |
| 28 | +## Manual Sync Process |
| 29 | + |
| 30 | +### 1. Add Upstream Remote (First Time Only) |
| 31 | + |
| 32 | +```bash |
| 33 | +cd skycode-opencode |
| 34 | +git remote add upstream https://github.com/sst/opencode.git |
| 35 | +git remote -v # Verify remotes |
| 36 | +``` |
| 37 | + |
| 38 | +### 2. Fetch Upstream Changes |
| 39 | + |
| 40 | +```bash |
| 41 | +git fetch upstream |
| 42 | +``` |
| 43 | + |
| 44 | +### 3. Merge Upstream into Your Branch |
| 45 | + |
| 46 | +```bash |
| 47 | +# Switch to your working branch (e.g., main or dev) |
| 48 | +git checkout dev # or your branch name |
| 49 | + |
| 50 | +# Merge upstream changes |
| 51 | +git merge upstream/main |
| 52 | +``` |
| 53 | + |
| 54 | +### 4. Resolve Conflicts (If Any) |
| 55 | + |
| 56 | +If there are conflicts: |
| 57 | +```bash |
| 58 | +# Resolve conflicts in files |
| 59 | +git status # See conflicted files |
| 60 | +# Edit files to resolve conflicts |
| 61 | + |
| 62 | +# After resolving: |
| 63 | +git add . |
| 64 | +git commit -m "Merge upstream: resolve conflicts" |
| 65 | +``` |
| 66 | + |
| 67 | +### 5. Push Changes |
| 68 | + |
| 69 | +```bash |
| 70 | +git push origin dev |
| 71 | +``` |
| 72 | + |
| 73 | +## Automated Sync Script |
| 74 | + |
| 75 | +The `sync-upstream.sh` script automates the sync process: |
| 76 | + |
| 77 | +```bash |
| 78 | +cd skycode-opencode |
| 79 | +./sync-upstream.sh |
| 80 | +``` |
| 81 | + |
| 82 | +**What it does:** |
| 83 | +- Checks for upstream remote (adds if missing) |
| 84 | +- Fetches upstream changes |
| 85 | +- Stashes local uncommitted changes (if any) |
| 86 | +- Merges upstream/main into current branch |
| 87 | +- Restores stashed changes |
| 88 | +- Shows summary |
| 89 | + |
| 90 | +## Sync Strategy |
| 91 | + |
| 92 | +### Recommended Frequency |
| 93 | +- **Monthly**: Regular syncs to get upstream bug fixes and features |
| 94 | +- **As Needed**: When upstream releases important features or fixes |
| 95 | + |
| 96 | +### Branch Strategy |
| 97 | +- **dev**: SkyCode's development branch (sync with upstream/main) |
| 98 | +- **main**: Stable branch (sync before releases) |
| 99 | +- **feature/***: Feature branches (sync before merging) |
| 100 | + |
| 101 | +### What to Keep in Fork vs. Main Repo |
| 102 | + |
| 103 | +**In Fork (skycode-opencode):** |
| 104 | +- ✅ Version pinning/compatibility changes |
| 105 | +- ✅ Major incompatible behavior changes (rare) |
| 106 | +- ✅ OpenCode core modifications needed for SkyCode |
| 107 | +- ✅ Build configuration for bundling |
| 108 | + |
| 109 | +**In Main Repo (skycode):** |
| 110 | +- ✅ **All SkyCode plugins** (`packages/opencode-plugin/`) |
| 111 | +- ✅ Plugin loading/integration logic |
| 112 | +- ✅ SkyCode-specific configurations |
| 113 | +- ✅ Settings import logic |
| 114 | + |
| 115 | +### Conflict Resolution |
| 116 | + |
| 117 | +When conflicts occur: |
| 118 | + |
| 119 | +1. **Keep Minimal Changes in Fork**: |
| 120 | + - Only essential OpenCode core changes |
| 121 | + - Version compatibility fixes |
| 122 | + - Bundling-related modifications |
| 123 | + |
| 124 | +2. **Move to Main Repo When Possible**: |
| 125 | + - Plugin-related changes → Main repo |
| 126 | + - Configuration changes → Main repo |
| 127 | + - Integration logic → Main repo |
| 128 | + |
| 129 | +3. **Merge Both** (when applicable): |
| 130 | + - Documentation updates |
| 131 | + - Bug fixes that don't conflict |
| 132 | + |
| 133 | +## Plugin Loading Strategy |
| 134 | + |
| 135 | +Since plugins are in the main repo, they're loaded via: |
| 136 | + |
| 137 | +1. **Build Time**: Bundle plugin with SkyCode |
| 138 | +2. **Runtime**: OpenCode loads plugin from bundled location |
| 139 | +3. **Configuration**: Point OpenCode to SkyCode plugin location |
| 140 | + |
| 141 | +**Plugin Path**: `skycode/packages/opencode-plugin/` |
| 142 | + |
| 143 | +## Verifying Sync |
| 144 | + |
| 145 | +```bash |
| 146 | +# Check commits ahead/behind upstream |
| 147 | +git log upstream/main..HEAD # Our commits not in upstream |
| 148 | +git log HEAD..upstream/main # Upstream commits we don't have |
| 149 | + |
| 150 | +# Check diff summary |
| 151 | +git diff --stat upstream/main..HEAD |
| 152 | + |
| 153 | +# Should show minimal differences (only essential changes) |
| 154 | +``` |
| 155 | + |
| 156 | +## Troubleshooting |
| 157 | + |
| 158 | +### Upstream Remote Not Found |
| 159 | +```bash |
| 160 | +git remote add upstream https://github.com/sst/opencode.git |
| 161 | +``` |
| 162 | + |
| 163 | +### Merge Conflicts |
| 164 | +```bash |
| 165 | +# See conflicted files |
| 166 | +git status |
| 167 | + |
| 168 | +# Use merge tool |
| 169 | +git mergetool |
| 170 | + |
| 171 | +# After resolving, complete merge |
| 172 | +git add . |
| 173 | +git commit |
| 174 | +``` |
| 175 | + |
| 176 | +### Too Many Conflicts (Fork Drifted Too Far) |
| 177 | + |
| 178 | +If fork has drifted significantly: |
| 179 | + |
| 180 | +1. **Create backup branch**: |
| 181 | + ```bash |
| 182 | + git branch backup-before-reset |
| 183 | + ``` |
| 184 | + |
| 185 | +2. **Reset to upstream** (if changes are in main repo): |
| 186 | + ```bash |
| 187 | + git fetch upstream |
| 188 | + git reset --hard upstream/main |
| 189 | + ``` |
| 190 | + |
| 191 | +3. **Re-apply only essential changes**: |
| 192 | + - Re-add version pinning |
| 193 | + - Re-add bundling changes |
| 194 | + - Verify everything still works |
| 195 | + |
| 196 | +### Stale Remote |
| 197 | +```bash |
| 198 | +# Update remote URL if needed |
| 199 | +git remote set-url upstream https://github.com/sst/opencode.git |
| 200 | + |
| 201 | +# Verify |
| 202 | +git remote -v |
| 203 | +``` |
| 204 | + |
| 205 | +## Best Practices |
| 206 | + |
| 207 | +1. **Sync Regularly**: Don't let fork get too far behind |
| 208 | +2. **Keep Changes Minimal**: Only essential changes in fork |
| 209 | +3. **Move to Main Repo**: When possible, keep changes in main repo |
| 210 | +4. **Test After Sync**: Run tests to ensure nothing broke |
| 211 | +5. **Document Fork Changes**: Keep track of what's different and why |
| 212 | +6. **Small Incremental Syncs**: Sync monthly rather than yearly |
| 213 | + |
| 214 | +## CI/CD Integration (Future) |
| 215 | + |
| 216 | +Consider adding automated sync checks: |
| 217 | +- Weekly check for upstream updates |
| 218 | +- Notification when upstream has changes |
| 219 | +- Automated test runs after sync |
| 220 | +- Automated conflict detection |
| 221 | + |
| 222 | +## Related Documentation |
| 223 | + |
| 224 | +- Architecture: `skycode/docs/architecture/opencode-integration-architecture.md` |
| 225 | +- Plugin Implementation: `skycode/docs/plans/opencode-bundled-implementation.md` |
| 226 | +- Plugin Code: `skycode/packages/opencode-plugin/` |
0 commit comments