Expand lock-file skip list and extract checkoutTheirs into git module

Covers all common ecosystem lock files (npm, yarn, pnpm, Go, Ruby,
PHP, Poetry) so merge conflicts in any of them are auto-resolved
with --theirs rather than sent to Claude.
This commit is contained in:
Chris Wanstrath 2026-04-10 08:17:55 -07:00
parent cc61e09384
commit 85cf9cc02f
2 changed files with 21 additions and 6 deletions

View File

@ -82,7 +82,17 @@ export async function teardownSession(root: string, branch: string, worktree: st
} }
/** Lock files to skip AI resolution — accept theirs and move on (basename match so `packages/foo/bun.lock` is also covered). */ /** Lock files to skip AI resolution — accept theirs and move on (basename match so `packages/foo/bun.lock` is also covered). */
const SKIP_RESOLVE = new Set(["bun.lock", "Cargo.lock"]) const SKIP_RESOLVE = new Set([
"bun.lock",
"Cargo.lock",
"package-lock.json",
"yarn.lock",
"pnpm-lock.yaml",
"go.sum",
"Gemfile.lock",
"composer.lock",
"poetry.lock",
])
/** Resolve conflict markers in files using Claude, then stage them. */ /** Resolve conflict markers in files using Claude, then stage them. */
export async function resolveConflicts( export async function resolveConflicts(
@ -95,10 +105,7 @@ export async function resolveConflicts(
onFile(file, i + 1, files.length) onFile(file, i + 1, files.length)
if (SKIP_RESOLVE.has(basename(file))) { if (SKIP_RESOLVE.has(basename(file))) {
const result = await $`git checkout --theirs -- ${file}`.cwd(cwd).nothrow().quiet() await git.checkoutTheirs(file, cwd)
if (result.exitCode !== 0) {
throw new Error(`Failed to resolve lock file ${file}: ${result.stderr.toString().trim()}`)
}
await git.stageFile(file, cwd) await git.stageFile(file, cwd)
continue continue
} }
@ -111,7 +118,7 @@ export async function resolveConflicts(
) )
if (resolved.exitCode !== 0) { if (resolved.exitCode !== 0) {
throw new Error(`Claude failed to resolve ${file}: ${resolved.stderr}`) throw new Error(`Claude failed to resolve ${file}: ${resolved.stderr.toString().trim()}`)
} }
await Bun.write(join(cwd, file), resolved.stdout.trimEnd() + "\n") await Bun.write(join(cwd, file), resolved.stdout.trimEnd() + "\n")

View File

@ -133,6 +133,14 @@ export async function commit(message: string, cwd: string): Promise<void> {
} }
} }
/** Accept "theirs" version of a conflicted file. */
export async function checkoutTheirs(file: string, cwd: string): Promise<void> {
const result = await $`git checkout --theirs -- ${file}`.cwd(cwd).nothrow().quiet()
if (result.exitCode !== 0) {
throw new Error(`Failed to checkout theirs for ${file}: ${result.stderr.toString().trim()}`)
}
}
/** Stage a file. */ /** Stage a file. */
export async function stageFile(file: string, cwd: string): Promise<void> { export async function stageFile(file: string, cwd: string): Promise<void> {
const result = await $`git add ${file}`.cwd(cwd).nothrow().quiet() const result = await $`git add ${file}`.cwd(cwd).nothrow().quiet()