| name | upstream-sync |
| description | Sync upstream OpenCode releases into the DevEco Code fork. Use when the user asks to sync, merge, or update from the OpenCode upstream (e.g. "sync upstream", "merge OpenCode v1.14.xx", "update from upstream"). Covers git graft repair, merge analysis, conflict resolution with brand preservation (DEVECO_*), squash commit workflow, and post-sync verification. |
Upstream Sync
Sync upstream OpenCode release tags into the DevEco Code fork on the develop branch.
Remote
| Name | URL | Purpose |
|---|
upstream | git@github.com:anomalyco/opencode.git (SSH) / https://github.com/anomalyco/opencode.git (HTTPS) | OpenCode upstream source |
Sync Strategy
- Always sync from upstream release tags (e.g.
v1.14.33), never from branches
- Preserve upstream commit history: use
git merge --no-ff
- Convert to single-parent squash commit after resolving conflicts
Workflow
Step 1: Prepare
git remote -v | grep upstream
git branch --show-current
git status
git fetch upstream --tags
git log --oneline <old-tag>..<new-tag>
Verify target tag exists — upstream may skip versions (e.g. no v1.14.36).
Step 2: Repair Graft
Historical sync commits are single-parent (squash), so git doesn't recognize upstream tags as ancestors. Without graft, the merge range explodes to thousands of commits because git thinks it needs to merge the entire history.
git merge-base --is-ancestor <old-tag> develop && echo "OK: graft exists"
git log --oneline develop | grep "sync:"
git replace --graft <sync-commit> <actual-parent> <old-tag-hash>
git merge-base --is-ancestor <old-tag> develop && echo "OK"
Step 3: Pre-merge Analysis (present report, wait for user confirmation)
git diff <old-tag>..<new-tag> --stat — changed files
git merge --no-commit --no-ff <new-tag> — simulated merge
git diff --name-only --diff-filter=U — conflicted files
- For each conflicted file: classify (version bump / brand / feature logic / new config) and check if it involves DevEco Code custom features
- Check
git diff --stat for rename lines — upstream renames (e.g. module migration to packages/core) won't produce conflict markers but all import paths need updating
- Check
.agents/upstream-sync/LESSONS.md for version-specific historical pitfalls
git merge --abort
- Output: change summary / conflict list with recommendations / high-risk items / overall assessment
Skip-version assessment: if all changes are in modules we don't use (e.g. upstream-only CI configs, unrelated platform fixes), recommend skipping to the user.
Wait for user confirmation before continuing.
Step 4: Execute Merge
Before resolving conflicts, read references/brand-mapping.md for brand identifier rules and references/pitfalls.md for known traps.
git merge --no-ff <new-tag> --no-edit
Resolve conflicts by category (batch where possible):
| Category | Resolution | Notes |
|---|
| package.json version bumps | git checkout --theirs -- <file> (batch) | All **/package.json version fields |
| bun.lock | git checkout --theirs bun.lock | |
| packages/opencode/package.json | Accept version, keep name: "deveco", bin: "deveco", and all @deveco-codegenie/* custom dependencies | Custom deps and bin field are overwritten on every sync; see Known Pitfalls |
| packages/web/package.json | Accept version, ensure "deveco": "workspace:*" in devDependencies | Reverts to opencode on every sync |
| packages/extensions/zed/extension.toml | Accept upstream version + download URL | |
| Feature logic files | Analyze individually: accept upstream architecture, keep DEVECO_* branding | |
Test files (*.test.ts) | Accept upstream, replace OPENCODE_ env vars → DEVECO_ only | Do NOT rename providerID, external API headers, or functional identifiers — same rule applies to all files |
Documentation (*.md) | Accept upstream | Upstream AGENTS.md → overwrite local OPENCODE-AGENTS.md |
| Config (tsconfig, turbo.json) | Local as base, merge upstream additions | |
When merging import blocks: deduplicate — simple concatenation produces duplicate identifiers (TS2300).
Rollback (if merge goes wrong):
git merge --abort
git reset --hard HEAD~1
Step 5: Squash Commit
The two-step commit + reset creates a single-parent commit that preserves the merge result but keeps history clean.
SKIP_SPECS_CHECK=1 git commit --no-edit
git reset --soft HEAD~1
git status
SKIP_SPECS_CHECK=1 git commit -m "sync: OpenCode <old-tag> -> <new-tag>
Upstream commits:
- <commit 1>
- ...
Conflicts resolved: <N> files
- <file/module>: <resolution>
Brand identifiers preserved throughout, HarmonyOS tools and plugins retained
Baseline updated in BASELINE.md
Signed-off-by: GIT_USER <GIT_EMAIL>"
All sync-related git commits must use SKIP_SPECS_CHECK=1 prefix.
Step 6: Clean Graft (only if Step 2 created one)
git replace -d <sync-commit>
Step 7: Verify
Read references/pitfalls.md and references/custom-features-checklist.md for comprehensive verification.
bun install — no errors
bun run typecheck — critical: auto-merged files may have hidden type errors from upstream API changes (signatures, imports, renames, module migrations)
bun turbo build --filter=deveco — build passes
grep -r "OPENCODE_" packages/ infra/ sdks/ --include="*.ts" --include="*.tsx" — verify no stale upstream env var prefixes in packages/ (check both existing AND new files). Hits in infra/ and sdks/vscode/ are expected — these are functional identifiers that must NOT be renamed
- Verify brand identifier mapping completeness (see references/brand-mapping.md)
- Fix issues and amend:
SKIP_SPECS_CHECK=1 git commit --amend --no-edit
Step 8: Update Baseline and Lessons
MANDATORY — DO NOT SKIP: Update .agents/upstream-sync/BASELINE.md with the new tag (e.g. v1.14.50). This file is the single source of truth for the current upstream baseline. Skipping this will cause the next sync's graft repair to fail.
If new issues or traps encountered, add to .agents/upstream-sync/LESSONS.md.
Step 9: Post-Sync Assessment
Launch the upstream-sync subagent to perform a comprehensive post-sync quality assessment. The subagent audits the sync results against all known pitfalls and brand mapping rules, then generates a structured assessment report.
- Launch the subagent via the
Agent tool with subagent_type="general-purpose". The subagent prompt is located at .agents/skills/upstream-sync/upstream-sync-reviewer.md.
- The subagent will produce a report covering: brand identifier audit, custom dependency verification, workspace dependency check, agent permission audit, import path integrity, TUI branding check, and known pitfalls cross-check.
- After receiving the report, the main Agent must:
- Review all issues in the report
- Apply fixes for each issue, prioritizing Critical → Branding → Config → Recommendations
- Re-run verification (Step 7) to confirm all fixes are effective
- Amend the sync commit if fixes were applied:
SKIP_SPECS_CHECK=1 git commit --amend --no-edit
Conflict Resolution Priority (highest to lowest)
- DevEco Code custom features (branding
DEVECO_*/DevEco Code, HarmonyOS, custom flags) — always keep local
- Upstream feature changes (bug fixes, enhancements, dependency upgrades, refactors) — accept upstream
- Config and build scripts — local as base, merge upstream additions; if conflicts with #1, follow #1
Reference Files
| File | When to Read |
|---|
| references/brand-mapping.md | Step 4 (conflict resolution) and Step 7 (verification) — brand identifier rules, exceptions, TUI tips |
| references/pitfalls.md | Step 3 (analysis), Step 4 (conflict resolution), Step 7 (verification) — known traps by severity |
| references/custom-features-checklist.md | Step 7 and Step 9 (post-sync) — structured checklist for all DevEco Code custom features |
.agents/upstream-sync/BASELINE.md | Step 1 — current upstream version baseline |
.agents/upstream-sync/LESSONS.md | Step 3 — version-specific historical pitfalls not yet generalized |