From c239a6bb22514308a09df987c61b1cbd8af29de3 Mon Sep 17 00:00:00 2001 From: "kiloconnect[bot]" <240665456+kiloconnect[bot]@users.noreply.github.com> Date: Tue, 5 May 2026 14:49:50 +0000 Subject: [PATCH 1/2] chore(config): enforce zdiff3 conflict style via postinstall Add a new setup script to configure `merge.conflictStyle=zdiff3` locally within the repository. This ensures that the common ancestor is visible during merge conflicts, which is required for structural resolution by `mergiraf` and simplifies manual conflict resolution. The configuration is applied during `bun install` via the `postinstall` hook and remains as a fallback for the upstream merge utilities. --- AGENTS.md | 4 ++++ package.json | 2 +- script/setup-git.ts | 21 +++++++++++++++++++++ script/upstream/utils/git.ts | 10 +++++----- 4 files changed, 31 insertions(+), 6 deletions(-) create mode 100644 script/setup-git.ts diff --git a/AGENTS.md b/AGENTS.md index ecfd388986b..7285909eb25 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -255,6 +255,10 @@ We regularly merge upstream changes from opencode. To minimize merge conflicts a The goal is to keep our diff from upstream as small as possible, making regular merges straightforward and reducing the risk of conflicts. +### Git conflict style + +`bun install` sets `merge.conflictStyle=zdiff3` repo-locally via `script/setup-git.ts` (wired into `postinstall`). Conflicts include the common ancestor between `|||||||` and `=======`, which is what `script/upstream/` and `mergiraf` rely on for structural resolution and what makes manual resolution on shared opencode files tractable. If you've overridden it in your user config, the repo-local setting takes precedence — don't override it back. + ### Kilocode Change Markers To minimize merge conflicts when syncing with upstream, mark Kilo Code-specific changes in shared code with `kilocode_change` comments. diff --git a/package.json b/package.json index fe7327a31fc..a67e5c4a566 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "dev:storybook": "bun --cwd packages/storybook storybook", "lint": "oxlint", "typecheck": "bun turbo typecheck", - "postinstall": "bun run --cwd packages/opencode fix-node-pty", + "postinstall": "bun run --cwd packages/opencode fix-node-pty && bun run script/setup-git.ts", "prepare": "husky", "random": "echo 'Random script'", "hello": "echo 'Hello World!'", diff --git a/script/setup-git.ts b/script/setup-git.ts new file mode 100644 index 00000000000..21bcfd55080 --- /dev/null +++ b/script/setup-git.ts @@ -0,0 +1,21 @@ +#!/usr/bin/env bun + +/** + * Configures repo-local git settings for all contributors. + * + * `merge.conflictStyle=zdiff3` makes conflict markers include the common + * ancestor (|||||||) alongside ours/theirs. That base section is what + * mergiraf's syntax-aware resolution feeds on during upstream opencode + * merges (see script/upstream/merge.ts) and it makes manual resolution + * dramatically easier than the default 2-way `merge` markers. + * + * Runs from `postinstall`. Safe to re-run — `git config` is idempotent. + * Guarded so tarball / docker installs without a `.git` don't fail. + */ + +import { $ } from "bun" + +const inside = await $`git rev-parse --is-inside-work-tree`.nothrow().quiet() +if (inside.exitCode !== 0) process.exit(0) + +await $`git config --local merge.conflictStyle zdiff3`.quiet() diff --git a/script/upstream/utils/git.ts b/script/upstream/utils/git.ts index a781276e983..d54d11bb958 100644 --- a/script/upstream/utils/git.ts +++ b/script/upstream/utils/git.ts @@ -122,11 +122,11 @@ export async function commit(message: string): Promise { } export async function merge(branch: string): Promise<{ success: boolean; conflicts: string[] }> { - // Use zdiff3 markers so conflicts carry the base version (|||||||) alongside - // ours/theirs. This gives mergiraf the base it needs for structural heuristics - // and makes any remaining manual resolution dramatically easier (you can see - // what both sides changed relative to the common ancestor instead of - // reverse-engineering it from a 2-way marker). + // Force zdiff3 markers even if the contributor's local config has drifted: + // conflicts carry the base version (|||||||) alongside ours/theirs so mergiraf + // has the common ancestor for structural heuristics and any remaining manual + // resolution is dramatically easier. `postinstall` (script/setup-git.ts) sets + // this repo-wide as well; the `-c` override here is belt-and-suspenders. const result = await $`git -c merge.conflictStyle=zdiff3 merge ${branch}`.nothrow() if (result.exitCode === 0) { From 05fabd3f1f0dca0022fbbe0c2b1b416298d28ecc Mon Sep 17 00:00:00 2001 From: "kiloconnect[bot]" <240665456+kiloconnect[bot]@users.noreply.github.com> Date: Tue, 5 May 2026 15:11:02 +0000 Subject: [PATCH 2/2] chore: mark script/setup-git.ts with kilocode_change marker --- script/setup-git.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/script/setup-git.ts b/script/setup-git.ts index 21bcfd55080..db9d5e320ba 100644 --- a/script/setup-git.ts +++ b/script/setup-git.ts @@ -1,4 +1,5 @@ #!/usr/bin/env bun +// kilocode_change - new file /** * Configures repo-local git settings for all contributors.