vibe-heal

CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

Project Overview

vibe-heal is an AI-powered SonarQube issue remediation tool that automatically fixes code quality problems. The project is initialized from the cookiecutter-uv template and uses modern Python tooling.

Development Environment

This project uses uv as the package manager (not pip or poetry). All Python commands should be run via uv run.

Initial Setup

make install  # Sets up environment and pre-commit hooks

This command:

Common Commands

Testing

# Run all tests with coverage
make test

# Run tests manually
uv run python -m pytest --cov --cov-config=pyproject.toml --cov-report=xml

# Run tests across multiple Python versions (requires multiple Python installations)
tox

Test files are located in tests/ directory. When writing tests, remember that tests/* files have S101 (assert usage) ignored in ruff configuration.

Code Quality

# Run all quality checks (recommended before committing)
make check

# Run pre-commit hooks manually
uv run pre-commit run -a

# Type checking with mypy
uv run mypy

# Check for obsolete dependencies
uv run deptry src

Linting & Formatting

The project uses ruff for linting and formatting (not black or flake8). Configuration is in pyproject.toml:

Pre-commit hooks will automatically run ruff-check and ruff-format on commits.

Documentation

# Build and serve docs locally
make docs

# Test documentation build
make docs-test

Documentation uses MkDocs with Material theme. Configuration is in mkdocs.yml.

Building

# Build wheel file
make build

# Clean build artifacts
make clean-build

Build uses hatchling as the backend. Package source is in src/vibe_heal/.

Project Structure

Type Checking

mypy is configured with strict settings:

All functions should have type annotations.

Testing Philosophy

Dependencies

Development dependencies are defined in [dependency-groups] in pyproject.toml. To add dependencies:

# Add a runtime dependency
uv add <package>

# Add a dev dependency
uv add --dev <package>

CI/CD

The project has GitHub Actions workflows for:

Workflows use uv and are configured in .github/workflows/.

Python Version Support

Supports Python 3.11 through 3.13. The tox.ini configuration tests against all these versions.


vibe-heal Specific Architecture

What is vibe-heal?

vibe-heal is an AI-powered SonarQube issue remediation tool that automatically fixes code quality problems using AI coding assistants (Claude Code or Aider).

Core Workflow:

  1. Fetch SonarQube issues for a file
  2. Sort issues in reverse line order (high to low - prevents line number shifts)
  3. For each issue: invoke AI tool → if successful, create git commit
  4. Display summary report

High-Level Architecture

CLI Layer (cli.py)
    ↓
Orchestrator (orchestrator.py) - coordinates entire workflow
    ↓
├─ Config (config/) - loads .env.vibeheal
├─ SonarQubeClient (sonarqube/) - fetches issues via API
├─ IssueProcessor (processor/) - sorts/filters issues
├─ AITool (ai_tools/) - fixes issues (ClaudeCodeTool implemented)
└─ GitManager (git/) - creates commits

Module Responsibilities

config/: Pydantic-based configuration from .env.vibeheal or .env

sonarqube/: Async HTTP client for SonarQube Web API

processor/: Business logic for issue handling

ai_tools/: Abstract interface + implementations

git/: Git operations via GitPython

orchestrator.py: Main workflow coordination

cleanup/: Branch cleanup workflow

deduplication/: Code duplication removal module

cli.py: Command-line interface with typer

Critical Implementation Details

Reverse Line Order: Issues and duplications are fixed from highest line number to lowest. This prevents line number shifts from earlier fixes affecting later fixes.

Component Path Construction: SonarQube API queries use components=projectkey:filepath (lowercase project key). The old approach of querying with componentKeys and filtering client-side was incorrect.

Issue Status Filtering: Use issueStatuses=OPEN,CONFIRMED instead of resolved=false for more precise filtering.

Git Safety: Only checks that the specific file being fixed has no uncommitted changes. Other files can have changes (requirement was relaxed from “clean working directory”).

Async/Await: SonarQube client and AI tool operations use async/await pattern. CLI wraps with asyncio.run().

AI Tool Integration: Claude Code is invoked with permission mode acceptEdits and tool restriction to Edit,Read only for security. Uses --print and --output-format json flags.

Deduplication Specifics:

Configuration (.env.vibeheal)

By default, configuration is loaded from .env.vibeheal or .env in the current directory.

SONARQUBE_URL=https://sonar.example.com
SONARQUBE_TOKEN=your_token  # Preferred
# OR: SONARQUBE_USERNAME + SONARQUBE_PASSWORD
SONARQUBE_PROJECT_KEY=your_project
# AI_TOOL=claude-code  # Optional, auto-detects if not set

# Context enrichment (optional, enhances AI fix quality)
# CODE_CONTEXT_LINES=5  # Lines before/after issue to show AI (default: 5)
# INCLUDE_RULE_DESCRIPTION=true  # Include full rule docs in prompts (default: true)

Custom environment files: All CLI commands support --env-file to specify a custom configuration file:

vibe-heal fix src/file.py --env-file .env.production
vibe-heal cleanup --env-file ~/configs/project-a.env
vibe-heal config --env-file .env.staging

Development Workflow

Running vibe-heal locally:

# Install in development mode
uv pip install -e .

# Test with actual SonarQube (requires .env.vibeheal)
vibe-heal config  # Verify configuration
vibe-heal fix src/file.py --dry-run  # Preview issue fixes
vibe-heal fix src/file.py --max-issues 1  # Fix one issue
vibe-heal dedupe src/file.py --dry-run  # Preview deduplication
vibe-heal dedupe src/file.py --max-duplications 1  # Fix one duplication

Testing specific modules:

# Run specific test file
uv run pytest tests/sonarqube/test_client.py -v

# Run with one test function
uv run pytest tests/sonarqube/test_client.py::TestSonarQubeClient::test_get_issues_for_file -v

# Run tests for one module with coverage
uv run pytest tests/processor/ -v --cov=src/vibe_heal/processor

Common Development Patterns

Adding a new AI tool:

  1. Create src/vibe_heal/ai_tools/new_tool.py implementing AITool ABC
  2. Add to AIToolType enum in base.py
  3. Update AIToolFactory._tool_map
  4. Add tests in tests/ai_tools/test_new_tool.py

Modifying SonarQube API queries:

Changing commit message format:

Subprocess conventions:

Mocking stdlib symbols in tests:

Retry loops and mypy: