diff --git a/.github/workflows/claude.yml b/.github/workflows/claude.yml index 1ae5efec4..e2fa10c28 100644 --- a/.github/workflows/claude.yml +++ b/.github/workflows/claude.yml @@ -54,20 +54,28 @@ jobs: PR NUMBER: ${{ github.event.pull_request.number }} EVENT: ${{ github.event.action }} - ## STEP 1: Run pre-commit checks and fix issues + ## STEP 1: Run prek and mypy checks, fix issues - First, run `uv run prek run --from-ref origin/main` to check for linting/formatting issues on files changed in this PR. + First, run these checks on files changed in this PR: + 1. `uv run prek run --from-ref origin/main` - linting/formatting issues + 2. `uv run mypy ` - type checking issues - If there are any issues: + If there are prek issues: - For SAFE auto-fixable issues (formatting, import sorting, trailing whitespace, etc.), run `uv run prek run --from-ref origin/main` again to auto-fix them + + If there are mypy issues: + - Fix type annotation issues (missing return types, Optional/None unions, import errors for type hints, incorrect types) + - Do NOT add `type: ignore` comments - always fix the root cause + + After fixing issues: - Stage the fixed files with `git add` - - Commit with message "style: auto-fix linting issues" + - Commit with message "style: auto-fix linting issues" or "fix: resolve mypy type errors" as appropriate - Push the changes with `git push` Do NOT attempt to fix: - - Type errors that require logic changes - - Complex refactoring suggestions - - Anything that could change behavior + - Type errors that require logic changes or refactoring + - Complex generic type issues + - Anything that could change runtime behavior ## STEP 2: Review the PR @@ -85,7 +93,6 @@ jobs: - Only create NEW inline comments for HIGH-PRIORITY issues found in changed files. - Limit to 5-7 NEW comments maximum per review. - Use CLAUDE.md for project-specific guidance. - - Use `gh pr comment` for summary-level feedback. - Use `mcp__github_inline_comment__create_inline_comment` sparingly for critical code issues only. ## STEP 3: Coverage analysis @@ -122,7 +129,34 @@ jobs: - New implementations/files: Must have ≥75% test coverage - Modified code: Changed lines should be exercised by existing or new tests - No coverage regressions: Overall coverage should not decrease - claude_args: '--allowedTools "mcp__github_inline_comment__create_inline_comment,Bash(gh pr comment:*),Bash(gh pr diff:*),Bash(gh pr view:*),Bash(gh pr list:*),Bash(gh issue view:*),Bash(gh issue list:*),Bash(gh api:*),Bash(uv run prek *),Bash(uv run coverage *),Bash(uv run pytest *),Bash(git status*),Bash(git add *),Bash(git commit *),Bash(git push*),Bash(git diff *),Bash(git checkout *),Read,Glob,Grep"' + + ## STEP 4: Post ONE consolidated summary comment + + CRITICAL: You must post exactly ONE summary comment containing ALL results (pre-commit, review, coverage). + DO NOT post multiple separate comments. Use this format: + + ``` + ## PR Review Summary + + ### Prek Checks + [status and any fixes made] + + ### Code Review + [critical issues found, if any] + + ### Test Coverage + [coverage table and analysis] + + --- + *Last updated: * + ``` + + To ensure only ONE comment exists: + 1. Find existing claude[bot] comment: `gh api repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments --jq '.[] | select(.user.login == "claude[bot]") | .id' | head -1` + 2. If found, UPDATE it: `gh api --method PATCH repos/${{ github.repository }}/issues/comments/ -f body=""` + 3. If not found, CREATE: `gh pr comment ${{ github.event.pull_request.number }} --body ""` + 4. Delete any OTHER claude[bot] comments to clean up duplicates: `gh api repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments --jq '.[] | select(.user.login == "claude[bot]") | .id' | tail -n +2 | xargs -I {} gh api --method DELETE repos/${{ github.repository }}/issues/comments/{}` + claude_args: '--allowedTools "mcp__github_inline_comment__create_inline_comment,Bash(gh pr comment:*),Bash(gh pr diff:*),Bash(gh pr view:*),Bash(gh pr list:*),Bash(gh issue view:*),Bash(gh issue list:*),Bash(gh api:*),Bash(uv run prek *),Bash(uv run mypy *),Bash(uv run coverage *),Bash(uv run pytest *),Bash(git status*),Bash(git add *),Bash(git commit *),Bash(git push*),Bash(git diff *),Bash(git checkout *),Read,Glob,Grep,Edit"' additional_permissions: | actions: read env: diff --git a/CLAUDE.md b/CLAUDE.md index 5d4b6cb96..94ca7e6e0 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -24,8 +24,8 @@ uv run mypy codeflash/ # Type check uv run ruff check codeflash/ # Lint uv run ruff format codeflash/ # Format -# Pre-commit (run before committing) -uv run pre-commit run --all-files +# Linting (run before committing) +uv run prek run --from-ref origin/main # Running the CLI uv run codeflash --help @@ -69,7 +69,7 @@ codeflash/ - **Line length**: 120 characters - **Python**: 3.9+ syntax -- **Tooling**: Ruff for linting/formatting, mypy strict mode, pre-commit hooks +- **Tooling**: Ruff for linting/formatting, mypy strict mode, prek for pre-commit checks - **Comments**: Minimal - only explain "why", not "what" - **Docstrings**: Do not add unless explicitly requested - **Naming**: NEVER use leading underscores (`_function_name`) - Python has no true private functions, use public names