| 142 | } |
| 143 | |
| 144 | async function fix(pr: PR, files: string[], prs: PR[], applied: number[], idx: number) { |
| 145 | console.log(` Trying to auto-resolve ${files.length} conflict(s) with opencode...`) |
| 146 | |
| 147 | const done = lines(prs.filter((x) => applied.includes(x.number))) |
| 148 | const next = lines(prs.slice(idx + 1)) |
| 149 | |
| 150 | const prompt = [ |
| 151 | `Resolve the current git merge conflicts while merging PR #${pr.number} into the beta branch.`, |
| 152 | `PR #${pr.number}: ${pr.title}`, |
| 153 | `Start with these conflicted files: ${files.join(", ")}.`, |
| 154 | `Merged PRs on HEAD:\n${done}`, |
| 155 | `Pending PRs after this one (context only):\n${next}`, |
| 156 | "IMPORTANT: The conflict resolution must be consistent with already-merged PRs.", |
| 157 | "Pending PRs are context only; do not introduce their changes unless they are already present on HEAD.", |
| 158 | "Prefer already-merged PRs over the base branch when resolving stacked conflicts.", |
| 159 | "If bun.lock is conflicted, do not hand-merge it. Delete bun.lock and run bun install after the code conflicts are resolved.", |
| 160 | "If a PR already deleted a file/directory, do not re-add it, instead apply changes in the new semantic location.", |
| 161 | "If a PR already changed an import, keep that change.", |
| 162 | "After resolving the conflicts, run `bun typecheck` at the repo root.", |
| 163 | "If typecheck fails, you may also update any files reported by typecheck.", |
| 164 | "Keep any non-conflict edits narrowly scoped to restoring a valid merged state for the current PR batch.", |
| 165 | "Fix any merge-caused typecheck errors before finishing.", |
| 166 | "Keep the merge in progress, do not abort the merge, and do not create a commit.", |
| 167 | "When done, leave the working tree with no unmerged files and a passing typecheck.", |
| 168 | ].join("\n") |
| 169 | |
| 170 | try { |
| 171 | await $`opencode run -m ${model} ${prompt}` |
| 172 | } catch (err) { |
| 173 | console.log(` opencode failed: ${err}`) |
| 174 | return false |
| 175 | } |
| 176 | |
| 177 | const left = await conflicts() |
| 178 | if (left.length > 0) { |
| 179 | console.log(` Conflicts remain: ${left.join(", ")}`) |
| 180 | return false |
| 181 | } |
| 182 | |
| 183 | if (files.includes("bun.lock") && !(await install())) return false |
| 184 | |
| 185 | if (!(await typecheck())) return false |
| 186 | |
| 187 | console.log(" Conflicts resolved with opencode") |
| 188 | return true |
| 189 | } |
| 190 | |
| 191 | async function smoke(prs: PR[], applied: number[]) { |
| 192 | console.log("\nRunning final smoke check...") |