fix: recompute infra_stop live on every capability resolve (#285)
Add assess_infra_stop() to scan git state and conflict markers on each reviewer capability check, return the exact conflict path in responses, and clear stale capability-stop terminal state once the worktree is clean. Closes #285 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
This commit is contained in:
+58
-26
@@ -134,22 +134,28 @@ def route_task_session(
|
||||
_record_route(result)
|
||||
return result
|
||||
|
||||
if required_role == "reviewer" and check_mid_merge():
|
||||
result = {
|
||||
"task_type": task_type,
|
||||
"required_role": required_role,
|
||||
"active_role": active_role_kind,
|
||||
"active_profile": active_profile,
|
||||
"route_result": ROUTE_INFRA_STOP,
|
||||
"downstream_allowed": False,
|
||||
"reasons": [
|
||||
"infra_stop: Unresolved merge conflict or mid-merge state detected in MCP runtime source.",
|
||||
"Please resolve all conflicts manually, finish/abort the merge, restart the MCP server, and retry."
|
||||
],
|
||||
"message": "infra_stop: Unresolved merge conflict or mid-merge state detected in MCP runtime source.",
|
||||
}
|
||||
_record_route(result)
|
||||
return result
|
||||
if required_role == "reviewer":
|
||||
infra = assess_infra_stop()
|
||||
if infra["infra_stop"]:
|
||||
detail = "; ".join(infra.get("infra_stop_reasons") or [])
|
||||
message = (
|
||||
"infra_stop: Unresolved merge conflict or mid-merge state detected "
|
||||
f"in MCP runtime source ({detail}). Please resolve all conflicts "
|
||||
"manually, finish/abort the merge, and retry."
|
||||
)
|
||||
result = {
|
||||
"task_type": task_type,
|
||||
"required_role": required_role,
|
||||
"active_role": active_role_kind,
|
||||
"active_profile": active_profile,
|
||||
"route_result": ROUTE_INFRA_STOP,
|
||||
"downstream_allowed": False,
|
||||
"reasons": [message],
|
||||
"message": message,
|
||||
"infra_stop_assessment": infra,
|
||||
}
|
||||
_record_route(result)
|
||||
return result
|
||||
|
||||
if allowed_in_current_session:
|
||||
result = {
|
||||
@@ -317,14 +323,40 @@ def first_conflict_marker_path(project_root: str | None = None) -> str | None:
|
||||
return None
|
||||
|
||||
|
||||
def check_mid_merge() -> bool:
|
||||
"""Return True if the repository is mid-merge, mid-rebase, or has conflict markers."""
|
||||
project_root = os.path.dirname(os.path.abspath(__file__))
|
||||
git_dir = os.path.join(project_root, ".git")
|
||||
if os.path.exists(git_dir):
|
||||
if (os.path.exists(os.path.join(git_dir, "MERGE_HEAD"))
|
||||
or os.path.exists(os.path.join(git_dir, "rebase-merge"))
|
||||
or os.path.exists(os.path.join(git_dir, "rebase-apply"))):
|
||||
return True
|
||||
def _default_project_root() -> str:
|
||||
override = (os.environ.get("GITEA_MCP_PROJECT_ROOT") or "").strip()
|
||||
if override:
|
||||
return os.path.realpath(override)
|
||||
return os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
return first_conflict_marker_path(project_root) is not None
|
||||
|
||||
def assess_infra_stop(project_root: str | None = None) -> dict:
|
||||
"""Recompute infra_stop from live git and source scan state (#285)."""
|
||||
root_dir = os.path.realpath(project_root or _default_project_root())
|
||||
reasons: list[str] = []
|
||||
mid_merge = False
|
||||
git_dir = os.path.join(root_dir, ".git")
|
||||
if os.path.isdir(git_dir):
|
||||
for marker in ("MERGE_HEAD", "rebase-merge", "rebase-apply"):
|
||||
marker_path = os.path.join(git_dir, marker)
|
||||
if os.path.exists(marker_path):
|
||||
mid_merge = True
|
||||
reasons.append(f"git state: {marker} present under {git_dir}")
|
||||
conflict_file = first_conflict_marker_path(root_dir)
|
||||
if conflict_file:
|
||||
reasons.append(
|
||||
f"conflict markers detected in {conflict_file} (project_root={root_dir})"
|
||||
)
|
||||
infra_stop = mid_merge or bool(conflict_file)
|
||||
return {
|
||||
"infra_stop": infra_stop,
|
||||
"project_root": root_dir,
|
||||
"conflict_file": conflict_file,
|
||||
"mid_merge": mid_merge,
|
||||
"infra_stop_reasons": reasons,
|
||||
}
|
||||
|
||||
|
||||
def check_mid_merge(project_root: str | None = None) -> bool:
|
||||
"""Return True if the repository is mid-merge, mid-rebase, or has conflict markers."""
|
||||
return assess_infra_stop(project_root)["infra_stop"]
|
||||
Reference in New Issue
Block a user