Skip to content

Add merge gate and AI-assisted merge pick to fork merge-pick#27

Open
plebioda wants to merge 2 commits into
masterfrom
ai-merge-pick
Open

Add merge gate and AI-assisted merge pick to fork merge-pick#27
plebioda wants to merge 2 commits into
masterfrom
ai-merge-pick

Conversation

@plebioda

Copy link
Copy Markdown
Collaborator

A deterministic gate decides when to merge; the pick (deterministic or AI) decides which upstream commit to merge to.

  • Config: MergeGateConfig (min_commits/max_age_days/max_commits/ force_strategies) and AiPickConfig (enabled/agent/rules_file/fallback) on ForkConfig.
  • ForkStatus.unmerged_oldest_age_days: age of the oldest unmerged commit (distinct from days_behind), surfaced in to_dict().
  • Gate: pure evaluate_merge_gate() + GateDecision over fork status and prioritized commits, no AI tokens.
  • merge-pick --plan: token-free JSON decision (wait / merge + mode + sha), deterministic sha capped to the candidate window.
  • merge-pick --ai [--next] [--force] [--json]: gate re-check, agent pick within the window, sha validation, deterministic/error fallback. Styled human output plus --json for downstream processing.
  • System prompt + project rules file support, gate surfaced in fork status.
  • Tests for the gate, window capping, deterministic resolution, config parsing, and the AI pick output/validation/fallback.

Comment thread tests/test_merge_pick_ai.py Fixed
Comment thread tests/test_merge_pick_ai.py Fixed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a deterministic “merge gate” (decides when to merge) and an optional AI-assisted “merge pick” flow (decides which upstream commit boundary to merge to) to the mergai fork merge-pick command set, and surfaces the gate decision in fork status.

Changes:

  • Add fork.merge_gate and fork.ai_pick config sections and implement a pure evaluate_merge_gate() + GateDecision.
  • Extend fork merge-pick with --plan (token-free JSON decision) and --ai (agent pick within a capped candidate window, with validation and fallback).
  • Add prompts and tests covering the gate logic, window capping, deterministic resolution, and AI-pick validation/fallback behavior.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
tests/test_merge_pick_ai.py Command-level tests for merge-pick --plan and --ai flows (including JSON output and fallback cases).
tests/test_merge_gate.py Unit tests for gate evaluation, window capping, deterministic/window sha resolution, and config parsing.
src/mergai/utils/git_utils.py Adds ForkStatus.unmerged_oldest_age_days and surfaces it in JSON divergence output.
src/mergai/prompts/system_prompt_merge_pick.md New system prompt instructing the agent how to choose a merge boundary and output JSON.
src/mergai/prompts/init.py Adds loader for the merge-pick system prompt.
src/mergai/prompt_builder.py Adds build_merge_pick_prompt() to assemble system prompt + optional project rules + candidates JSON.
src/mergai/merge_pick_strategies/gate.py Implements the pure deterministic merge gate and GateDecision.
src/mergai/config.py Adds MergeGateConfig and AiPickConfig and wires them into ForkConfig.
src/mergai/commands/fork.py Implements candidate-window capping, gate computation, merge-pick --plan, and merge-pick --ai (with validation/fallback), and surfaces gate decision in fork status.
README.md Documents new config sections and CLI flags (--plan, --ai).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/mergai/config.py
Comment thread src/mergai/commands/fork.py Outdated
Comment thread src/mergai/commands/fork.py Outdated
Comment thread src/mergai/commands/fork.py
Comment thread src/mergai/commands/fork.py
Comment thread src/mergai/commands/fork.py
Comment thread src/mergai/prompts/system_prompt_merge_pick.md Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.

Comment thread src/mergai/commands/fork.py Outdated
@plebioda plebioda force-pushed the ai-merge-pick branch 2 times, most recently from 9147620 to 414c9b1 Compare June 22, 2026 06:34
@plebioda plebioda requested a review from Copilot June 22, 2026 07:29

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.

Comment thread src/mergai/commands/fork.py Outdated
Comment thread src/mergai/commands/fork.py

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.

Comment thread src/mergai/commands/fork.py

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.

Comment thread src/mergai/config.py
Comment thread src/mergai/config.py

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.

Comment thread src/mergai/commands/fork.py Outdated
Comment thread README.md

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.

Comment thread src/mergai/utils/git_utils.py
Comment thread src/mergai/commands/fork.py

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.

Comment thread src/mergai/config.py
Comment thread tests/test_merge_pick_ai.py Outdated
@plebioda plebioda requested a review from Copilot June 22, 2026 10:58

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@plebioda plebioda requested a review from Copilot June 22, 2026 11:51

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.

Comment thread src/mergai/commands/fork.py
Comment thread src/mergai/config.py
plebioda added 2 commits June 22, 2026 16:35
A deterministic gate (count + age + force-strategy override, capped by a max
batch size) decides whether to merge now; the deterministic pick chooses where
to cut within the candidate window. No AI tokens, safe for an unprivileged
periodic phase.

- config: `MergeGateConfig` (min_commits / max_age_days / max_commits /
  force_strategies, with string-or-list and enum validation) and `AiPickConfig`
  (consumed here by `--plan` to report the mode) on `ForkConfig`.
- `ForkStatus.unmerged_oldest_age_days`, surfaced in `to_dict()`.
- gate: pure `evaluate_merge_gate()` + `GateDecision`.
- fork.py: candidate-window restriction, `compute_gate`, the banded
  `resolve_deterministic_sha` (forced-below-min, else first in-band match, else
  window tip), `merge-pick --plan` (token-free JSON decision) and
  `merge-pick --gate` (gate-respecting deterministic pick), and the gate
  decision surfaced in `fork status`.
- docs + tests for the gate, window capping, deterministic resolution, and
  config parsing.
Builds on the deterministic gate/pick: when fork.ai_pick is enabled, an AI
agent chooses the merge boundary within the candidate window instead of the
deterministic resolver.

- config: `AiPickConfig.fallback` is validated against {deterministic, error}.
- prompts: `system_prompt_merge_pick.md` + loader + `build_merge_pick_prompt`
  (system prompt + optional project rules + candidate JSON).
- fork.py: `merge-pick --ai [--next] [--force] [--json]` (agent pick within
  the window, sha + reasoning validation, deterministic/error fallback, clean
  stdout in capture modes), the candidate-window input builder, and the
  agent-sha resolver.
- docs + tests for the AI pick output, validation, and fallback.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants