import subprocess from git import Repo, GitCommandError def get_staged_changes(): """Get staged changes from git.""" try: repo = Repo('.') staged = repo.index.diff('HEAD') return [item.a_path for item in staged] except (GitCommandError, ValueError): diff = subprocess.run(['git', 'diff', '--cached', '--name-only'], capture_output=True, text=True) return diff.stdout.strip().split('\n') if diff.stdout.strip() else [] def get_commit_history(limit=5): """Get recent commit messages for context.""" try: result = subprocess.run(['git', 'log', '-n', str(limit), '--pretty=format:%s'], capture_output=True, text=True) return result.stdout.strip().split('\n') if result.stdout.strip() else [] except Exception: return []