Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 100 additions & 14 deletions .claude/agents/code-inline-reviewer.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,42 @@ You are a **React Native Expert** — an AI trained to evaluate code contributio

Your job is to scan through changed files and create **inline comments** for specific violations based on the below rules.

## Mechanical Checking Process

**CRITICAL**: You are a pattern-matching machine. Do not interpret, do not reason about intent. Follow these exact steps:

### For EVERY file

1. **Read the entire file first** with the Read tool
2. **Create a TodoWrite checklist** with 6 items (one per rule) for this file
3. **For each rule in order**, execute its mechanical check pattern (defined in each rule below)
4. **Mark the todo complete** after checking each rule
5. **Move to next file** only after all 6 rule checks are complete

### What "mechanical checking" means

- ❌ Do NOT ask "is this bad?" or "should this be memoized?"
- ✅ DO ask "Does pattern X exist? If yes, check condition. True? → Flag."
- ❌ Do NOT rationalize "but removing useMemo might be intentional"
- ✅ DO check "Is variable X in a dependency array? Is it not memoized? → Flag."
- ❌ Do NOT skip files because "they look fine"
- ✅ DO search for each rule's patterns in every file, even if you expect zero matches

### Your mental model

You are executing this pseudocode:

```javascript
for each file in changed_files:
content = read(file)
for each rule in rules:
matches = search_patterns(content, rule.patterns)
for each match in matches:
if all_conditions_true(match, rule.conditions):
create_inline_comment(match, rule)
mark_todo_complete(file, rule)
```

## Rules

Each rule includes:
Expand Down Expand Up @@ -220,25 +256,69 @@ const {amountColumnSize, dateColumnSize, taxAmountColumnSize} = useMemo(() => {

## Instructions

1. **Read each changed file carefully** using the Read tool
2. **For each violation found, immediately create an inline comment** using the available GitHub inline comment tool
3. **Required parameters for each inline comment:**
### Phase 1: Systematic Analysis (REQUIRED)

**CRITICAL**: You MUST use the TodoWrite tool to create a systematic checklist before analyzing ANY code. This is not optional.

1. **Create a todo list with TodoWrite containing one task per file to check against all rules**

Example: If there are 3 files, you should create 3 tasks.

2. **Read each changed file completely** using the Read tool - never skip files or assume they're clean

3. **For EACH file, systematically check against ALL rules**

4. **Mark each task as completed** using TodoWrite as you finish checking each file against all rules

5. **DO NOT proceed to Phase 2** until you have checked ALL files against ALL rules

6. **If you believe something MIGHT be a Rule violation but are uncertain, err on the side of flagging it rather than skipping it.**

7. **DO NOT invent new rules, stylistic preferences, or commentary outside the listed rules.**

### Phase 2: Creating Comments

1. **For each violation found, immediately create an inline comment** using the available GitHub inline comment tool

2. **Required parameters for each inline comment:**
- `path`: Full file path (e.g., "src/components/ReportActionsList.tsx")
- `line`: Line number where the issue occurs
- `body`: Concise and actionable description of the violation and fix, following the below Comment Format
4. **Each comment must reference exactly one Rule ID.**
5. **Output must consist exclusively of calls to mcp__github_inline_comment__create_inline_comment in the required format.** No other text, Markdown, or prose is allowed.
6. **If no violations are found, output exactly** (with no quotes, markdown, or additional text):
- `body`: Concise and actionable description of the violation and fix, following the Comment Format below

3. **Each comment must reference exactly one Rule ID.**

4. **Output must consist exclusively of calls to mcp__github_inline_comment__create_inline_comment in the required format or a LGTM comment using gh pr comment tool** No other text, Markdown, or prose is allowed.

5. **If no violations are found, create a comment using gh pr comment tool** (with no quotes, markdown, or additional text):
LGTM :feelsgood:. Thank you for your hard work!
7. **Output LGTM if and only if**:

6. **Output LGTM if and only if**:
- You created and completed ALL tasks in your TodoWrite checklist
- You examined EVERY line of EVERY changed file
- You checked EVERY changed file against ALL rules
- You found ZERO violations matching the exact rule criteria
- You checked EVERY changed file against ALL 6 rules systematically
- You found ZERO violations matching the rule criteria
- You verified no false negatives by checking each rule systematically
If you found even ONE violation or have ANY uncertainty do NOT output LGTM - create inline comments instead.
8. **DO NOT invent new rules, stylistic preferences, or commentary outside the listed rules.**
9. **DO NOT describe what you are doing, output any summaries, explanations, extra content, comments on rules that are NOT violated or ANYTHING ELSE except from rules violations or LGTM message.**
EXCEPTION: If you believe something MIGHT be a Rule violation but are uncertain, err on the side of creating an inline comment with your concern rather than skipping it.

If you found even ONE violation or have ANY uncertainty do NOT create LGTM comment - create inline comments instead.

7. **DO NOT describe what you are doing, create comments with any summaries, explanations, extra content, comments on rules that are NOT violated or ANYTHING ELSE.**
Only inline comments regarding rules violations or general comments with LGTM message are allowed.

### Patterns to follow

✅ **DO** create a comprehensive TodoWrite checklist first
✅ **DO** check every file against every rule methodically
✅ **DO** use search patterns (grep mentally) for each rule's keywords
✅ **DO** mark tasks complete as you go
✅ **DO** if in doubt err on the side of flagging potential violations

### Anti-Patterns to avoid

❌ **DO NOT** scan files quickly and assume there are no violations
❌ **DO NOT** skip creating the TodoWrite checklist
❌ **DO NOT** check only some rules or some files
❌ **DO NOT** rely on intuition - use systematic search patterns
❌ **DO NOT** output LGTM without completing your entire checklist

## Tool Usage Example

Expand All @@ -251,6 +331,12 @@ mcp__github_inline_comment__create_inline_comment:
body: "<Body of the comment according to the Comment Format>"
```

If no violations are found, use the Bash tool to create a top-level PR comment:

```bash
gh pr comment --body "LGTM :feelsgood:. Thank you for your hard work!"
```

## Comment Format

```
Expand Down
243 changes: 243 additions & 0 deletions .claude/utils/test-review-prompt.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,243 @@
#!/bin/bash
# Local Claude Code Review Testing Script
#
# REQUIREMENTS:
# - macOS
# - Git repository
# - Claude CLI installed (https://docs.claude.com/en/docs/claude-code)
# - pbcopy (included with macOS)
#
# USAGE:
# ./test-review.sh <branch-name> [prompt-file] [--manual]
#
# EXAMPLES:
# ./test-review.sh main # Auto CLI mode, compare against main
# ./test-review.sh develop --manual # Manual mode, compare against develop
# ./test-review.sh main custom.md # Custom prompt file
# ./test-review.sh main custom.md --manual # Custom prompt, manual mode
#
# DEFAULT BEHAVIOR: Automatically pipes to 'claude' command (CLI mode)
# Use --manual flag to get instructions for manual copy/paste instead. Useful if you would like to paste it into a browser.

set -e

# Colors for output
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m' # No Color

# Configuration
PROMPT_DIR="./prompts"
REVIEW_OUTPUT_DIR="./review-output"
DEFAULT_PROMPT="../agents/code-inline-reviewer.md"

# Parse arguments
TARGET_BRANCH=""
PROMPT_FILE=""
MANUAL_MODE=false

for arg in "$@"; do
if [ "$arg" = "--manual" ]; then
MANUAL_MODE=true
elif [ -z "$TARGET_BRANCH" ]; then
TARGET_BRANCH="$arg"
elif [ -z "$PROMPT_FILE" ]; then
PROMPT_FILE="$arg"
fi
done

# Set defaults if not provided
TARGET_BRANCH=${TARGET_BRANCH:-main}
PROMPT_FILE=${PROMPT_FILE:-$DEFAULT_PROMPT}

if [ "$MANUAL_MODE" = true ]; then
echo -e "${BLUE}=== Claude Code Review (Manual Mode) ===${NC}"
else
echo -e "${BLUE}=== Claude Code Review (CLI Mode) ===${NC}"
fi
echo -e "${BLUE}Target branch: ${TARGET_BRANCH}${NC}"
echo -e "${BLUE}Prompt file: ${PROMPT_FILE}${NC}\n"

# Check if claude CLI is available (only in CLI mode)
if [ "$MANUAL_MODE" = false ]; then
if ! command -v claude &> /dev/null; then
echo -e "${RED}Error: 'claude' command not found${NC}"
echo -e "${YELLOW}Please install Claude CLI: https://docs.claude.com/en/docs/claude-code${NC}"
echo -e "${YELLOW}Or use --manual flag for manual copy/paste mode${NC}"
exit 1
fi
fi

# Create necessary directories
mkdir -p "$PROMPT_DIR"
mkdir -p "$REVIEW_OUTPUT_DIR"

# Check if prompt file exists
if [ ! -f "$PROMPT_FILE" ]; then
echo -e "${RED}Error: Prompt file not found: ${PROMPT_FILE}${NC}"
echo -e "${YELLOW}Please ensure the prompt file exists at the specified path.${NC}"
exit 1
fi

# Get current branch
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
echo -e "${BLUE}Current branch: ${CURRENT_BRANCH}${NC}\n"

# Get the diff
echo -e "${YELLOW}Generating diff against ${TARGET_BRANCH}...${NC}"
TIMESTAMP=$(date +%Y%m%d-%H%M%S)
DIFF_FILE="$REVIEW_OUTPUT_DIR/diff-${TIMESTAMP}.txt"
git diff "$TARGET_BRANCH"...HEAD > "$DIFF_FILE"

# Check if there are changes
if [ ! -s "$DIFF_FILE" ]; then
echo -e "${RED}No changes found between ${CURRENT_BRANCH} and ${TARGET_BRANCH}${NC}"
rm "$DIFF_FILE"
exit 1
fi

echo -e "${GREEN}Diff saved to: ${DIFF_FILE}${NC}"
echo -e "${BLUE}Diff stats:${NC}"
git diff --stat "$TARGET_BRANCH"...HEAD
echo ""

# Get list of changed files
echo -e "${YELLOW}Changed files:${NC}"
git diff --name-only "$TARGET_BRANCH"...HEAD
echo ""

# Create review request file
REVIEW_REQUEST="$REVIEW_OUTPUT_DIR/review-request-${TIMESTAMP}.txt"

{
echo "Below you will see output for automated code review. For the purpose of this prompt: Instead of calling github actions output all comments to the console here, in the same format as if they were comments in GH. Otherwise follow the rules mentioned below in the PROMPT section."
echo ""
echo "IMPORTANT CONTEXT:"
echo "- All changed file contents are provided in full below"
echo "- You have complete access to review all code"
echo "- Do NOT attempt to use file reading tools or request permissions"
echo "- Analyze the provided diff and file contents directly"
echo "- The files are ready for your review - proceed with the analysis"
echo ""
echo "PROMPT"
cat "$PROMPT_FILE"
echo ""
echo "---"
echo ""
echo "Branch: $CURRENT_BRANCH -> $TARGET_BRANCH"
echo "Date: $(date '+%Y-%m-%d %H:%M:%S')"
echo ""
echo "Code Changes:"
echo ""
cat "$DIFF_FILE"
echo ""
echo "---"
echo ""
echo "## Full File Contents"
echo ""

# Add full content of changed files
git diff --name-only "$TARGET_BRANCH"...HEAD | while read -r file; do
if [ -f "$file" ]; then
echo "### File: $file"
echo '```'
cat "$file"
echo '```'
echo ""
fi
done
} > "$REVIEW_REQUEST"

echo -e "${GREEN}Review request prepared: ${REVIEW_REQUEST}${NC}\n"

# Manual Mode: Provide instructions for copy/paste
if [ "$MANUAL_MODE" = true ]; then
echo -e "${BLUE}╔═══════════════════════════════════════════════════════════╗${NC}"
echo -e "${BLUE}║ ${YELLOW}Review request is ready!${BLUE} ║${NC}"
echo -e "${BLUE}╚═══════════════════════════════════════════════════════════╝${NC}"
echo ""
echo -e "${YELLOW}Option 1: Copy content to clipboard and paste to Claude CLI${NC}"
echo -e " cat \"${REVIEW_REQUEST}\" | pbcopy"
echo -e " claude"
echo -e " ${GREEN}# Then paste (Cmd+V) into Claude${NC}"
echo ""
echo -e "${YELLOW}Option 2: Use automatic CLI mode (recommended)${NC}"
echo -e " ./test-review.sh ${TARGET_BRANCH}${PROMPT_FILE:+ $PROMPT_FILE}"
echo ""
echo -e "${YELLOW}Option 3: View the file and manually copy${NC}"
echo -e " cat \"${REVIEW_REQUEST}\""
echo ""
echo -e "${YELLOW}Option 4: Open in your editor${NC}"
echo -e " \$EDITOR \"${REVIEW_REQUEST}\""
echo ""
echo -e "${BLUE}════════════════════════════════════════════════════════════${NC}"
echo ""

# Ask if user wants to copy to clipboard
echo -e "${YELLOW}Would you like to copy to clipboard now? (y/n)${NC}"
read -r RESPONSE

if [[ "$RESPONSE" =~ ^[Yy]$ ]]; then
if command -v pbcopy &> /dev/null; then
pbcopy < "$REVIEW_REQUEST"
echo -e "${GREEN}✓ Copied to clipboard!${NC}"
echo -e "${YELLOW}Now run 'claude' and paste (Cmd+V)${NC}"
else
echo -e "${RED}Clipboard tool not found.${NC}"
echo -e "${YELLOW}Please manually copy from: ${REVIEW_REQUEST}${NC}"
fi
fi

echo ""
echo -e "${BLUE}After getting Claude's review, save it to:${NC}"
REVIEW_OUTPUT="$REVIEW_OUTPUT_DIR/review-result-${TIMESTAMP}.md"
echo -e "${GREEN}${REVIEW_OUTPUT}${NC}"
echo ""

# Summary
echo -e "${BLUE}=== Files Generated ===${NC}"
echo -e "Diff file: ${DIFF_FILE}"
echo -e "Review request: ${REVIEW_REQUEST}"
echo -e "Save review to: ${REVIEW_OUTPUT}"
echo -e "\n${GREEN}Preparation complete!${NC}"

exit 0
fi

# CLI Mode: Automatically copy to clipboard and pipe to claude
echo -e "${BLUE}╔═══════════════════════════════════════════════════════════╗${NC}"
echo -e "${BLUE}║ ${YELLOW}Automatically running Claude CLI${BLUE} ║${NC}"
echo -e "${BLUE}╚═══════════════════════════════════════════════════════════╝${NC}"
echo ""

# Copy to clipboard
if command -v pbcopy &> /dev/null; then
pbcopy < "$REVIEW_REQUEST"
echo -e "${GREEN}✓ Copied to clipboard${NC}"
else
echo -e "${YELLOW}⚠ pbcopy not found, skipping clipboard copy${NC}"
fi

# Pipe to claude
echo -e "${YELLOW}Running: claude -p < \"${REVIEW_REQUEST}\" ${NC}"
echo ""
echo -e "${BLUE}════════════════════════════════════════════════════════════${NC}"
echo ""

claude -p < "$REVIEW_REQUEST"

echo ""
echo -e "${BLUE}════════════════════════════════════════════════════════════${NC}"
echo ""

# Summary
REVIEW_OUTPUT="$REVIEW_OUTPUT_DIR/review-result-${TIMESTAMP}.md"
echo -e "${BLUE}=== Files Generated ===${NC}"
echo -e "Diff file: ${DIFF_FILE}"
echo -e "Review request: ${REVIEW_REQUEST}"
echo -e "Save review to: ${REVIEW_OUTPUT}"
echo ""
echo -e "${GREEN}✓ Review complete!${NC}"
echo -e "${YELLOW}Tip: Save the output above to ${REVIEW_OUTPUT}${NC}"
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,7 @@ modules/*/lib/

# Claude local settings
.claude/settings.local.json

# Claude prompt testing output
.claude/utils/review-output

Loading
Loading