diff --git a/src/auto_commit_service/__pycache__/config.cpython-312.pyc b/src/auto_commit_service/__pycache__/config.cpython-312.pyc index 056b34b..b527070 100644 Binary files a/src/auto_commit_service/__pycache__/config.cpython-312.pyc and b/src/auto_commit_service/__pycache__/config.cpython-312.pyc differ diff --git a/src/auto_commit_service/recovery/__pycache__/claude_fallback.cpython-312.pyc b/src/auto_commit_service/recovery/__pycache__/claude_fallback.cpython-312.pyc index e35969e..c16adb8 100644 Binary files a/src/auto_commit_service/recovery/__pycache__/claude_fallback.cpython-312.pyc and b/src/auto_commit_service/recovery/__pycache__/claude_fallback.cpython-312.pyc differ diff --git a/src/auto_commit_service/recovery/claude_fallback.py b/src/auto_commit_service/recovery/claude_fallback.py index ea51ad7..7d11027 100644 --- a/src/auto_commit_service/recovery/claude_fallback.py +++ b/src/auto_commit_service/recovery/claude_fallback.py @@ -84,8 +84,8 @@ async def invoke_claude_for_recovery( if returncode == 0: logger.info(f"Claude recovery succeeded for {repo.name}") - # Try to extract commit hash from output - commit_hash = _extract_commit_hash(stdout) + # Get the latest commit hash directly from git + commit_hash = await _get_latest_commit_hash(repo) return RecoveryResult( success=True, @@ -121,18 +121,37 @@ async def invoke_claude_for_recovery( ) -def _extract_commit_hash(output: str) -> str | None: - """Try to extract a commit hash from Claude's output.""" - # Look for patterns like "commit abc1234" or "[abc1234]" - patterns = [ - r"commit\s+([a-f0-9]{7,40})", - r"\[([a-f0-9]{7,40})\]", - r"([a-f0-9]{7,40})\s+HEAD", - ] +async def _get_latest_commit_hash(repo: "Repository") -> str | None: + """Get the latest commit hash from the repository. - for pattern in patterns: - match = re.search(pattern, output, re.IGNORECASE) - if match: - return match.group(1) + Args: + repo: Repository to query + + Returns: + Latest commit hash or None if failed + """ + try: + proc = await asyncio.create_subprocess_exec( + "git", + "log", + "-1", + "--format=%H", + stdout=asyncio.subprocess.PIPE, + stderr=asyncio.subprocess.PIPE, + cwd=str(repo.path), + ) + + stdout_bytes, _ = await asyncio.wait_for( + proc.communicate(), + timeout=5, + ) + + if proc.returncode == 0 and stdout_bytes: + commit_hash = stdout_bytes.decode().strip() + logger.debug(f"Got commit hash {commit_hash} from {repo.name}") + return commit_hash + + except Exception as e: + logger.warning(f"Failed to get commit hash from {repo.name}: {e}") return None