chore(upstream): auto-resolve conflicts with mergiraf + zdiff3 markers - #9624
Merged
Conversation
Invokes `mergiraf solve` (syntax-aware git merge tool) on each conflicted file before the kilocode-specific transform cascade, re-materializing the file with diff3 markers first so mergiraf can reconstruct the base revision. This auto-resolves the common pattern of neighbouring import additions around kilocode_change markers plus most JSON/YAML/TOML and other structural conflicts, leaving the existing transforms to handle only what's genuinely ambiguous. mergiraf is required at startup; if missing the script aborts early with install instructions (brew / cargo / nix) rather than failing mid-merge.
Contributor
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Files Reviewed (2 files)
Reviewed by gpt-5.5-20260423 · 718,407 tokens |
added 4 commits
April 28, 2026 14:11
Previously git add and mergiraf solve could bubble up exit 128 (e.g. on files missing the base version) and abort the entire merge. Wrap every shell call in .nothrow() and skip to the next transform pass on failure.
mergiraf exit 2 means it reduced conflicts but didn't fully close them. Previously we bailed on any non-zero exit, throwing away the useful partial reduction in the working tree. Now we always read the file after mergiraf runs: if no conflict markers remain we stage, if markers remain we keep the reduced content in the working tree for manual review but leave the file unstaged so nothing half-resolved is auto-committed. Also clean up the debug wording and surface a partial-resolution count in the normal log output.
mergiraf defaults to writing a .orig sibling file for every file it touches. Pass --keep-backup=false so the merge script doesn't leave a pile of .orig files across the working tree after running.
Pass merge.conflictStyle=zdiff3 on the git merge invocation so every conflicted file gets base-aware (|||||||) markers from the start, not just the ones runMergiraf happens to touch. Benefits: - Mergiraf always has a base section to work from, so its structural heuristics apply uniformly. - Remaining manual conflicts show both sides relative to the common ancestor, which is dramatically easier to resolve than a 2-way marker. Since the working tree already carries diff3 markers after the merge, drop the per-file `git checkout --conflict=diff3` in runMergiraf.
…, binary) Files in UD/DU/binary/etc. conflict states have no <<<<<<< markers in the working tree. My earlier simplification that removed the `git checkout --conflict=diff3` pre-check caused mergiraf to run on them: it would exit 0 (nothing to solve), after which the unconditional `git add` silently staged our side as resolved, losing the signal that upstream deleted the file (or that we deleted what upstream modified). Guard runMergiraf by inspecting the file before calling mergiraf: if there are no conflict markers, skip the file entirely so it falls through to manual review. Surface a skipped-count line in the normal log output so the operator can see how many non-textual conflicts were left alone.
imanolmzd-svg
approved these changes
Apr 28, 2026
jliounis
pushed a commit
to jliounis/kilocode
that referenced
this pull request
May 18, 2026
chore(upstream): auto-resolve conflicts with mergiraf + zdiff3 markers
t7tran
pushed a commit
to t7tran/kilocode
that referenced
this pull request
Aug 14, 2026
chore(upstream): auto-resolve conflicts with mergiraf + zdiff3 markers
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Automates most of the conflict-resolution grunt work during upstream merges and makes the leftovers dramatically easier to resolve by hand.
mergiraf solveon each conflicted file before the kilocode-specific transform cascade inscript/upstream/merge.ts. Auto-resolves the common pattern of neighbouring import additions aroundkilocode_changemarkers plus most JSON/YAML/TOML structural conflicts, so the existing i18n/branding/etc. transforms only see what's genuinely ambiguous. On a v1.14.28 merge run this resolved 45 of 74 conflicts.merge.conflictStyle=zdiff3togit mergeinutils/git.ts, so every conflicted file carries base (|||||||) markers from the start — not just the ones mergiraf happens to touch. Manual resolution then shows what both sides changed relative to the common ancestor, which is much easier than reverse-engineering that from a 2-way marker.git statusas needing attention.runMergirafuses.nothrow()and logs at debug level on non-zero exit, so a single problem file can't abort the entire merge mid-run.mergirafrequired at startup: if missing the script aborts at step 1 with install instructions (brew/cargo/nix) rather than failing mid-merge..origpile-up: pass--keep-backup=falsetomergiraf solveso the working tree isn't littered with backup files afterwards.Mergiraf is actively maintained (v0.16.3, 2026-01-26) and supports all the file types we hit during upstream merges (TS/TSX, JSON, YAML, TOML, etc.). Docs: https://mergiraf.org/.
Test plan
Run
bun run script/upstream/merge.tsagainst an upstream version known to produce import-shuffle conflicts (e.g. anything recent where upstream moved imports aroundCrossSpawnSpawner/Config/Global). Verify:mergirafinstalled: script exits at step 1 with install instructions.mergirafinstalled:mergiraf auto-resolved N conflict(s)) and a partial-resolution count (mergiraf partially resolved M file(s) — remaining markers left unstaged for manual review);Before:
After: