import { readFileSync } from 'fs' import { resolve as resolvePath, sep } from 'path' import { SimpleGit } from 'simple-git' import { writeFileAtomic } from '../lib/utils/atomicFileWrite' import { BranchActionResult } from './branchActions' /** * Conflict-region extraction + write-back for AI conflict resolution * (#1369). * * A conflicted file contains one or more marker regions: * * <<<<<<< * ...our side... * ||||||| (only with merge.conflictStyle=diff3) * ...merged base... * ======= * ...their side... * >>>>>>> * * `parseConflictRegions` lifts each region into a structured record; * `applyConflictResolution` replaces ONE region's whole marker block * with accepted resolution text and rewrites the file atomically * (tmp+rename). Regions are re-parsed and matched BY CONTENT at apply * time — earlier accepts shift line numbers, so positional identity * would target the wrong block. */ export type ConflictRegion = { /** 0-based ordinal among the file's regions at parse time. */ index: number /** 1-based line number of the `<<<<<<<` marker. */ startLine: number /** 1-based line number of the `>>>>>>>` marker. */ endLine: number /** Ref label after `<<<<<<<` (usually HEAD / a branch). */ oursLabel: string /** Ref label after `>>>>>>>` (the incoming ref). */ theirsLabel: string ours: string[] /** diff3-style base section (`|||||||`), when present. */ base?: string[] theirs: string[] } // Git's markers are EXACTLY seven marker characters: `<<<<<<<