Skip to content

Add PR merge optimizer tool (batch conflict-free merge planner)#514

Draft
tsainez wants to merge 1 commit into
mainfrom
claude/ai-pr-merge-optimizer-kdzjmc
Draft

Add PR merge optimizer tool (batch conflict-free merge planner)#514
tsainez wants to merge 1 commit into
mainfrom
claude/ai-pr-merge-optimizer-kdzjmc

Conversation

@tsainez

@tsainez tsainez commented Jul 18, 2026

Copy link
Copy Markdown
Owner

Description

Implements the AI-Powered Batch Pull Request Merger design as a standalone maintenance tool under scripts/pr_merge_optimizer/.

The tool analyzes a set of open pull requests, builds a pairwise conflict graph, and computes the largest set of PRs that can be merged together without conflicts by solving the Maximum Independent Set (MIS) on that graph. The remaining PRs are flagged for manual / agentic conflict resolution.

Pipeline (per the design doc):

  1. Fetch open PRs + changed files (from a JSON file or the GitHub REST API).
  2. File-overlap pre-filter — PRs touching no common files can't textually conflict, so no edge.
  3. Precise check for overlapping PRs — a side-effect-free git merge-tree simulation, or a conservative default.
  4. Solve the MIS to get the conflict-free batch; everything else is deferred.

Module layout (scripts/pr_merge_optimizer/):

  • models.pyPullRequest / MergePlan data models and file classification.
  • mis.py — exact branch-and-bound MIS solver (isolated-vertex + max-degree reductions, upper-bound cutoff).
  • conflict_graph.py — file-overlap pre-filter + pluggable precise conflict check.
  • git_simulator.pygit merge-tree pairwise conflict tester (no working-tree side effects).
  • github_client.py — stdlib-only GitHub REST fetch, with offline-testable payload parsing.
  • optimizer.py / cli.py / __main__.py — orchestration and a python -m scripts.pr_merge_optimizer CLI.

Game / RTS adaptation: overlaps on binary assets (.png, .fbx, .wav, …), Git LFS tracked files, and engine scene/prefab formats (.unity, .prefab, .tscn, .uasset, …) are treated as hard, unmergeable conflicts, since the default git text driver corrupts them (the engine-scene rule is toggleable for repos with a smart merge driver configured).

The tool lives under scripts/ (not the command_line_conflict/ game package) because it operates on git/GitHub metadata rather than the engine.

Example:

$ python -m scripts.pr_merge_optimizer --input plan.json
Pull requests analyzed : 3
Conflict-free batch    : 2 (#1, #3)
Deferred for AI resolve: 1 (#2)
Conflict edges         : 1

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Verification

All project gates pass locally (./scripts/pre_commit.sh): Black, isort, Flake8, Pylint (9.83/10), Mypy, and pytest — 305 passed, 80.87% coverage. mkdocs build --strict succeeds. The MIS solver is validated in tests against a brute-force oracle over 60 random graphs. Uses the Python standard library only — no new dependencies.

🤖 Generated with Claude Code

https://claude.ai/code/session_01NJKckD5An9CHFUu8GHHTDT


Generated by Claude Code

Implements the "AI-Powered Batch Pull Request Merger" design as a
standalone maintenance tool under scripts/pr_merge_optimizer/.

The tool models a set of open pull requests as a conflict graph and
computes the largest conflict-free batch via Maximum Independent Set
(MIS); the remaining PRs are flagged for manual/agentic resolution.

- models.py: PullRequest / MergePlan data models and file classification
  (binary assets, Git LFS, engine scene/prefab formats as hard conflicts).
- mis.py: exact branch-and-bound Maximum Independent Set solver with
  isolated-vertex and max-degree reductions plus an upper-bound cutoff.
- conflict_graph.py: file-overlap pre-filter + pluggable precise check.
- git_simulator.py: side-effect-free `git merge-tree` pairwise check.
- github_client.py: stdlib GitHub REST fetch with offline-testable parsing.
- optimizer.py / cli.py: orchestration and a `python -m` command line.

Tests (tests/test_pr_merge_optimizer.py) validate the MIS solver against a
brute-force oracle over random graphs, conflict-graph construction, the
game/RTS asset handling, and the CLI. Docs added and wired into mkdocs nav.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NJKckD5An9CHFUu8GHHTDT
@github-actions github-actions Bot added documentation Improvements or additions to documentation test labels Jul 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants