"""Best-effort git reconciliation shared by stage prepare flows."""
from __future__ import annotations

import sys
from pathlib import Path
from typing import Any


def auto_reconcile_best_effort(inp: Any, plan_run_root: Path) -> None:
    """Run patch-equivalence reconciliation without changing prepare outcome.

    Reconciliation is advisory: failures are reported to stderr and the normal
    dependency gates still make the authoritative decision.
    """
    try:
        from .git_reconcile import auto_reconcile

        for item in auto_reconcile(
            project_root=Path(inp.project_root),
            plan_run_root=plan_run_root,
            project_id=inp.project_id,
            task_group=inp.task_group,
            task_id=inp.task_id,
            work_category=inp.work_category,
        ):
            print(
                f"git-reconcile: stage {item.stage} done commit "
                f"{item.recorded[:8]} -> {item.suggested_commit[:8]} "
                "(patch-equivalent)",
                file=sys.stdout,
            )
    except Exception as exc:
        print(f"git-reconcile skipped: {exc}", file=sys.stderr)
