claude-git-hooks 2.1.0 → 2.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +240 -0
- package/README.md +280 -78
- package/bin/claude-hooks +295 -119
- package/lib/config.js +164 -0
- package/lib/hooks/pre-commit.js +180 -67
- package/lib/hooks/prepare-commit-msg.js +47 -41
- package/lib/utils/claude-client.js +107 -16
- package/lib/utils/claude-diagnostics.js +266 -0
- package/lib/utils/file-operations.js +1 -65
- package/lib/utils/file-utils.js +65 -0
- package/lib/utils/installation-diagnostics.js +145 -0
- package/lib/utils/package-info.js +75 -0
- package/lib/utils/preset-loader.js +214 -0
- package/lib/utils/prompt-builder.js +83 -67
- package/lib/utils/resolution-prompt.js +12 -2
- package/package.json +49 -50
- package/templates/ANALYZE_DIFF.md +33 -0
- package/templates/COMMIT_MESSAGE.md +24 -0
- package/templates/CUSTOMIZATION_GUIDE.md +656 -0
- package/templates/SUBAGENT_INSTRUCTION.md +1 -0
- package/templates/config.example.json +41 -0
- package/templates/pre-commit +40 -2
- package/templates/prepare-commit-msg +40 -2
- package/templates/presets/ai/ANALYSIS_PROMPT.md +133 -0
- package/templates/presets/ai/PRE_COMMIT_GUIDELINES.md +176 -0
- package/templates/presets/ai/config.json +12 -0
- package/templates/presets/ai/preset.json +42 -0
- package/templates/presets/backend/ANALYSIS_PROMPT.md +85 -0
- package/templates/presets/backend/PRE_COMMIT_GUIDELINES.md +87 -0
- package/templates/presets/backend/config.json +12 -0
- package/templates/presets/backend/preset.json +49 -0
- package/templates/presets/database/ANALYSIS_PROMPT.md +114 -0
- package/templates/presets/database/PRE_COMMIT_GUIDELINES.md +143 -0
- package/templates/presets/database/config.json +12 -0
- package/templates/presets/database/preset.json +38 -0
- package/templates/presets/default/config.json +12 -0
- package/templates/presets/default/preset.json +53 -0
- package/templates/presets/frontend/ANALYSIS_PROMPT.md +99 -0
- package/templates/presets/frontend/PRE_COMMIT_GUIDELINES.md +95 -0
- package/templates/presets/frontend/config.json +12 -0
- package/templates/presets/frontend/preset.json +50 -0
- package/templates/presets/fullstack/ANALYSIS_PROMPT.md +107 -0
- package/templates/presets/fullstack/CONSISTENCY_CHECKS.md +147 -0
- package/templates/presets/fullstack/PRE_COMMIT_GUIDELINES.md +125 -0
- package/templates/presets/fullstack/config.json +12 -0
- package/templates/presets/fullstack/preset.json +55 -0
- package/templates/shared/ANALYSIS_PROMPT.md +103 -0
- package/templates/shared/ANALYZE_DIFF.md +33 -0
- package/templates/shared/COMMIT_MESSAGE.md +24 -0
- package/templates/shared/PRE_COMMIT_GUIDELINES.md +145 -0
- package/templates/shared/RESOLUTION_PROMPT.md +32 -0
- package/templates/check-version.sh +0 -266
package/templates/pre-commit
CHANGED
|
@@ -8,6 +8,7 @@ set -e
|
|
|
8
8
|
|
|
9
9
|
# Colors for output
|
|
10
10
|
RED='\033[0;31m'
|
|
11
|
+
YELLOW='\033[1;33m'
|
|
11
12
|
NC='\033[0m'
|
|
12
13
|
|
|
13
14
|
# Convert Windows path to Git Bash/WSL path
|
|
@@ -64,13 +65,50 @@ find_hook_script() {
|
|
|
64
65
|
return 1
|
|
65
66
|
}
|
|
66
67
|
|
|
68
|
+
# Early validation: Check if .claude directory exists
|
|
69
|
+
# Why: Provides helpful error message if installation incomplete or in wrong directory
|
|
70
|
+
REPO_ROOT=$(git rev-parse --show-toplevel 2>/dev/null || echo "")
|
|
71
|
+
if [ -z "$REPO_ROOT" ]; then
|
|
72
|
+
echo -e "${RED}Error: Not in a git repository${NC}" >&2
|
|
73
|
+
exit 1
|
|
74
|
+
fi
|
|
75
|
+
|
|
76
|
+
if [ ! -d "$REPO_ROOT/.claude" ]; then
|
|
77
|
+
echo -e "${RED}Error: .claude directory not found${NC}" >&2
|
|
78
|
+
echo "" >&2
|
|
79
|
+
echo "Claude Git Hooks installation is incomplete or missing." >&2
|
|
80
|
+
echo "" >&2
|
|
81
|
+
echo "Current directory: $(pwd)" >&2
|
|
82
|
+
echo "Repository root: $REPO_ROOT" >&2
|
|
83
|
+
echo "" >&2
|
|
84
|
+
echo "Common cause: Installation performed from wrong directory" >&2
|
|
85
|
+
echo "" >&2
|
|
86
|
+
echo "Solution:" >&2
|
|
87
|
+
echo " cd $REPO_ROOT" >&2
|
|
88
|
+
echo " claude-hooks install --force" >&2
|
|
89
|
+
exit 1
|
|
90
|
+
fi
|
|
91
|
+
|
|
67
92
|
# Find the Node.js script
|
|
68
93
|
NODE_HOOK=$(find_hook_script)
|
|
69
94
|
|
|
70
95
|
if [ -z "$NODE_HOOK" ]; then
|
|
71
96
|
echo -e "${RED}Error: Could not find pre-commit.js${NC}" >&2
|
|
72
|
-
echo "
|
|
73
|
-
echo "
|
|
97
|
+
echo "" >&2
|
|
98
|
+
echo "Claude Git Hooks installation is incomplete." >&2
|
|
99
|
+
echo "" >&2
|
|
100
|
+
echo "Current directory: $(pwd)" >&2
|
|
101
|
+
echo "Repository root: $REPO_ROOT" >&2
|
|
102
|
+
echo "" >&2
|
|
103
|
+
echo "Common cause: Installation from wrong directory or npm package not properly installed" >&2
|
|
104
|
+
echo "" >&2
|
|
105
|
+
echo "Solution:" >&2
|
|
106
|
+
echo " # Verify you're in repository root" >&2
|
|
107
|
+
echo " cd $REPO_ROOT" >&2
|
|
108
|
+
echo " # Verify npm package is installed globally" >&2
|
|
109
|
+
echo " npm list -g claude-git-hooks" >&2
|
|
110
|
+
echo " # Reinstall hooks" >&2
|
|
111
|
+
echo " claude-hooks install --force" >&2
|
|
74
112
|
exit 1
|
|
75
113
|
fi
|
|
76
114
|
|
|
@@ -8,6 +8,7 @@ set -e
|
|
|
8
8
|
|
|
9
9
|
# Colors for output
|
|
10
10
|
RED='\033[0;31m'
|
|
11
|
+
YELLOW='\033[1;33m'
|
|
11
12
|
NC='\033[0m'
|
|
12
13
|
|
|
13
14
|
# Convert Windows path to Git Bash/WSL path
|
|
@@ -64,13 +65,50 @@ find_hook_script() {
|
|
|
64
65
|
return 1
|
|
65
66
|
}
|
|
66
67
|
|
|
68
|
+
# Early validation: Check if .claude directory exists
|
|
69
|
+
# Why: Provides helpful error message if installation incomplete or in wrong directory
|
|
70
|
+
REPO_ROOT=$(git rev-parse --show-toplevel 2>/dev/null || echo "")
|
|
71
|
+
if [ -z "$REPO_ROOT" ]; then
|
|
72
|
+
echo -e "${RED}Error: Not in a git repository${NC}" >&2
|
|
73
|
+
exit 1
|
|
74
|
+
fi
|
|
75
|
+
|
|
76
|
+
if [ ! -d "$REPO_ROOT/.claude" ]; then
|
|
77
|
+
echo -e "${RED}Error: .claude directory not found${NC}" >&2
|
|
78
|
+
echo "" >&2
|
|
79
|
+
echo "Claude Git Hooks installation is incomplete or missing." >&2
|
|
80
|
+
echo "" >&2
|
|
81
|
+
echo "Current directory: $(pwd)" >&2
|
|
82
|
+
echo "Repository root: $REPO_ROOT" >&2
|
|
83
|
+
echo "" >&2
|
|
84
|
+
echo "Common cause: Installation performed from wrong directory" >&2
|
|
85
|
+
echo "" >&2
|
|
86
|
+
echo "Solution:" >&2
|
|
87
|
+
echo " cd $REPO_ROOT" >&2
|
|
88
|
+
echo " claude-hooks install --force" >&2
|
|
89
|
+
exit 1
|
|
90
|
+
fi
|
|
91
|
+
|
|
67
92
|
# Find the Node.js script
|
|
68
93
|
NODE_HOOK=$(find_hook_script)
|
|
69
94
|
|
|
70
95
|
if [ -z "$NODE_HOOK" ]; then
|
|
71
96
|
echo -e "${RED}Error: Could not find prepare-commit-msg.js${NC}" >&2
|
|
72
|
-
echo "
|
|
73
|
-
echo "
|
|
97
|
+
echo "" >&2
|
|
98
|
+
echo "Claude Git Hooks installation is incomplete." >&2
|
|
99
|
+
echo "" >&2
|
|
100
|
+
echo "Current directory: $(pwd)" >&2
|
|
101
|
+
echo "Repository root: $REPO_ROOT" >&2
|
|
102
|
+
echo "" >&2
|
|
103
|
+
echo "Common cause: Installation from wrong directory or npm package not properly installed" >&2
|
|
104
|
+
echo "" >&2
|
|
105
|
+
echo "Solution:" >&2
|
|
106
|
+
echo " # Verify you're in repository root" >&2
|
|
107
|
+
echo " cd $REPO_ROOT" >&2
|
|
108
|
+
echo " # Verify npm package is installed globally" >&2
|
|
109
|
+
echo " npm list -g claude-git-hooks" >&2
|
|
110
|
+
echo " # Reinstall hooks" >&2
|
|
111
|
+
echo " claude-hooks install --force" >&2
|
|
74
112
|
exit 1
|
|
75
113
|
fi
|
|
76
114
|
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
You are analyzing a **{{PRESET_NAME}}** project with the following technology stack:
|
|
2
|
+
|
|
3
|
+
**Tech Stack:** {{TECH_STACK}}
|
|
4
|
+
|
|
5
|
+
**Analyzing files matching:** {{FILE_EXTENSIONS}}
|
|
6
|
+
|
|
7
|
+
## Your Task
|
|
8
|
+
|
|
9
|
+
Perform a comprehensive code quality analysis focusing on these areas:
|
|
10
|
+
|
|
11
|
+
{{FOCUS_AREAS}}
|
|
12
|
+
|
|
13
|
+
## Analysis Guidelines
|
|
14
|
+
|
|
15
|
+
1. **Claude API Best Practices**:
|
|
16
|
+
- Proper use of Claude API endpoints
|
|
17
|
+
- Correct model selection (haiku/sonnet/opus)
|
|
18
|
+
- Token usage optimization
|
|
19
|
+
- Error handling for API failures
|
|
20
|
+
- Rate limiting considerations
|
|
21
|
+
- Timeout handling
|
|
22
|
+
|
|
23
|
+
2. **Prompt Engineering**:
|
|
24
|
+
- Clear and specific instructions
|
|
25
|
+
- Well-structured prompts
|
|
26
|
+
- Appropriate context inclusion
|
|
27
|
+
- Effective use of examples
|
|
28
|
+
- Proper output format specifications
|
|
29
|
+
- Token-efficient prompting
|
|
30
|
+
|
|
31
|
+
3. **CLI User Experience**:
|
|
32
|
+
- Clear, helpful error messages
|
|
33
|
+
- Appropriate use of colors/formatting
|
|
34
|
+
- Progress indicators for long operations
|
|
35
|
+
- Helpful usage instructions
|
|
36
|
+
- Graceful error recovery
|
|
37
|
+
- Cross-platform compatibility
|
|
38
|
+
|
|
39
|
+
4. **Git Operations**:
|
|
40
|
+
- Safe git command execution
|
|
41
|
+
- Proper error handling
|
|
42
|
+
- Repository state validation
|
|
43
|
+
- Avoiding destructive operations
|
|
44
|
+
- Cross-platform path handling
|
|
45
|
+
|
|
46
|
+
5. **Security**:
|
|
47
|
+
- API key protection (never log/expose)
|
|
48
|
+
- Secure credential storage
|
|
49
|
+
- Input validation
|
|
50
|
+
- Avoiding command injection
|
|
51
|
+
- Sensitive data handling in prompts
|
|
52
|
+
|
|
53
|
+
6. **Code Quality**:
|
|
54
|
+
- Proper error handling
|
|
55
|
+
- Comprehensive logging
|
|
56
|
+
- Modular, reusable functions
|
|
57
|
+
- Clear documentation
|
|
58
|
+
- Maintainable code structure
|
|
59
|
+
|
|
60
|
+
## Specific Checks
|
|
61
|
+
|
|
62
|
+
### Claude API Usage
|
|
63
|
+
✅ Using appropriate model for task (haiku for simple, sonnet for complex)
|
|
64
|
+
✅ Implementing proper error handling (network, API, rate limit)
|
|
65
|
+
✅ Token usage calculated and optimized
|
|
66
|
+
✅ Prompts are well-structured and clear
|
|
67
|
+
✅ Output parsing is robust
|
|
68
|
+
✅ API keys never logged or exposed
|
|
69
|
+
|
|
70
|
+
### Git Operations
|
|
71
|
+
✅ Using proper git commands
|
|
72
|
+
✅ Handling errors gracefully
|
|
73
|
+
✅ Cross-platform path compatibility
|
|
74
|
+
✅ Avoiding destructive operations without confirmation
|
|
75
|
+
✅ Proper handling of special characters in filenames
|
|
76
|
+
|
|
77
|
+
### Template Quality
|
|
78
|
+
✅ Clear instructions for Claude
|
|
79
|
+
✅ Well-defined output format
|
|
80
|
+
✅ Appropriate context provided
|
|
81
|
+
✅ Token-efficient design
|
|
82
|
+
✅ Placeholders used correctly
|
|
83
|
+
|
|
84
|
+
## Output Format
|
|
85
|
+
|
|
86
|
+
Respond with a valid JSON following the SonarQube format:
|
|
87
|
+
|
|
88
|
+
```json
|
|
89
|
+
{
|
|
90
|
+
"QUALITY_GATE": "PASSED|FAILED",
|
|
91
|
+
"approved": true|false,
|
|
92
|
+
"metrics": {
|
|
93
|
+
"reliability": "A|B|C|D|E",
|
|
94
|
+
"security": "A|B|C|D|E",
|
|
95
|
+
"maintainability": "A|B|C|D|E",
|
|
96
|
+
"coverage": 0-100,
|
|
97
|
+
"duplications": 0-100,
|
|
98
|
+
"complexity": "number"
|
|
99
|
+
},
|
|
100
|
+
"issues": {
|
|
101
|
+
"blocker": 0,
|
|
102
|
+
"critical": 0,
|
|
103
|
+
"major": 0,
|
|
104
|
+
"minor": 0,
|
|
105
|
+
"info": 0
|
|
106
|
+
},
|
|
107
|
+
"details": [
|
|
108
|
+
{
|
|
109
|
+
"severity": "BLOCKER|CRITICAL|MAJOR|MINOR|INFO",
|
|
110
|
+
"type": "BUG|VULNERABILITY|CODE_SMELL|PROMPT_QUALITY",
|
|
111
|
+
"file": "path/to/file",
|
|
112
|
+
"line": 123,
|
|
113
|
+
"message": "Clear description of the issue"
|
|
114
|
+
}
|
|
115
|
+
],
|
|
116
|
+
"securityHotspots": 0,
|
|
117
|
+
"blockingIssues": ["List of critical issues that must be fixed"]
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## Analysis Rules
|
|
122
|
+
|
|
123
|
+
- **Block commit** if:
|
|
124
|
+
- Exposed API keys or secrets
|
|
125
|
+
- Security vulnerabilities
|
|
126
|
+
- Critical bugs in git operations
|
|
127
|
+
- Destructive operations without safeguards
|
|
128
|
+
|
|
129
|
+
- **Pass** if: Only minor issues, suggestions, or no issues
|
|
130
|
+
|
|
131
|
+
- Be constructive about prompt quality - suggest improvements
|
|
132
|
+
- Focus on safety and user experience
|
|
133
|
+
- Provide actionable, specific feedback with line numbers
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
# AI/CLI Code Quality Guidelines
|
|
2
|
+
|
|
3
|
+
## Claude API Best Practices
|
|
4
|
+
|
|
5
|
+
### Model Selection
|
|
6
|
+
✅ **Haiku**: Simple tasks, fast responses, cost-effective
|
|
7
|
+
✅ **Sonnet**: Balanced performance, most use cases
|
|
8
|
+
✅ **Opus**: Complex reasoning, highest quality
|
|
9
|
+
❌ Don't use Opus when Haiku would suffice
|
|
10
|
+
|
|
11
|
+
### API Usage
|
|
12
|
+
✅ Implement proper timeout handling
|
|
13
|
+
✅ Handle rate limiting gracefully
|
|
14
|
+
✅ Retry with exponential backoff on failures
|
|
15
|
+
✅ Validate API responses before use
|
|
16
|
+
✅ Log API errors (but never log API keys!)
|
|
17
|
+
✅ Calculate and monitor token usage
|
|
18
|
+
|
|
19
|
+
### Error Handling
|
|
20
|
+
```javascript
|
|
21
|
+
// ✅ Good
|
|
22
|
+
try {
|
|
23
|
+
const response = await callClaudeAPI(prompt);
|
|
24
|
+
if (!response || !response.content) {
|
|
25
|
+
throw new Error('Invalid API response');
|
|
26
|
+
}
|
|
27
|
+
return parseResponse(response);
|
|
28
|
+
} catch (error) {
|
|
29
|
+
if (error.status === 429) {
|
|
30
|
+
// Handle rate limiting
|
|
31
|
+
} else if (error.status === 500) {
|
|
32
|
+
// Handle server error
|
|
33
|
+
}
|
|
34
|
+
logger.error('API call failed', error);
|
|
35
|
+
throw new UserFriendlyError('Failed to analyze code');
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Prompt Engineering
|
|
40
|
+
|
|
41
|
+
### Structure
|
|
42
|
+
✅ Clear role/context at the beginning
|
|
43
|
+
✅ Specific task instructions
|
|
44
|
+
✅ Well-defined output format (usually JSON)
|
|
45
|
+
✅ Relevant examples when helpful
|
|
46
|
+
✅ Appropriate length (token-efficient)
|
|
47
|
+
|
|
48
|
+
### Quality Checklist
|
|
49
|
+
✅ Instructions are unambiguous
|
|
50
|
+
✅ Output format is machine-parseable
|
|
51
|
+
✅ Context is sufficient but not excessive
|
|
52
|
+
✅ Examples match expected usage
|
|
53
|
+
✅ Placeholders are replaced correctly
|
|
54
|
+
|
|
55
|
+
### Common Prompt Issues
|
|
56
|
+
❌ Vague instructions
|
|
57
|
+
❌ No output format specification
|
|
58
|
+
❌ Too much unnecessary context
|
|
59
|
+
❌ Ambiguous requirements
|
|
60
|
+
❌ Missing examples for complex tasks
|
|
61
|
+
|
|
62
|
+
## CLI User Experience
|
|
63
|
+
|
|
64
|
+
### Error Messages
|
|
65
|
+
✅ Clear, actionable error messages
|
|
66
|
+
✅ Suggest solutions when possible
|
|
67
|
+
✅ Use appropriate log levels
|
|
68
|
+
✅ Color-code for readability (error=red, success=green)
|
|
69
|
+
✅ Include context (what was being attempted)
|
|
70
|
+
|
|
71
|
+
### User Feedback
|
|
72
|
+
✅ Show progress for long operations
|
|
73
|
+
✅ Confirm destructive operations
|
|
74
|
+
✅ Provide helpful usage information
|
|
75
|
+
✅ Display meaningful results
|
|
76
|
+
✅ Log debug info only when debug mode enabled
|
|
77
|
+
|
|
78
|
+
## Git Operations Safety
|
|
79
|
+
|
|
80
|
+
### Safe Practices
|
|
81
|
+
✅ Validate repository state before operations
|
|
82
|
+
✅ Use `--cached` for staged changes
|
|
83
|
+
✅ Handle special characters in filenames
|
|
84
|
+
✅ Cross-platform path handling
|
|
85
|
+
✅ Graceful handling of git errors
|
|
86
|
+
|
|
87
|
+
### Dangerous Operations
|
|
88
|
+
❌ Never run git commands that modify history without explicit user confirmation
|
|
89
|
+
❌ Avoid hard resets
|
|
90
|
+
❌ Be careful with force pushes
|
|
91
|
+
❌ Validate before bulk operations
|
|
92
|
+
|
|
93
|
+
## Security
|
|
94
|
+
|
|
95
|
+
### API Keys
|
|
96
|
+
✅ Load from environment variables
|
|
97
|
+
✅ Never log or display API keys
|
|
98
|
+
✅ Never commit API keys to repository
|
|
99
|
+
✅ Use secure storage methods
|
|
100
|
+
✅ Clear keys from memory when done
|
|
101
|
+
|
|
102
|
+
### Command Injection
|
|
103
|
+
✅ Validate all user input
|
|
104
|
+
✅ Use parameterized commands when possible
|
|
105
|
+
✅ Escape special characters
|
|
106
|
+
✅ Avoid `eval()` and similar
|
|
107
|
+
✅ Sanitize file paths
|
|
108
|
+
|
|
109
|
+
### Sensitive Data
|
|
110
|
+
✅ Don't send secrets to Claude API
|
|
111
|
+
✅ Filter sensitive data from diffs
|
|
112
|
+
✅ Be careful with error messages (don't expose internals)
|
|
113
|
+
✅ Implement SKIP_ANALYSIS for sensitive code
|
|
114
|
+
|
|
115
|
+
## Code Organization
|
|
116
|
+
|
|
117
|
+
### File Structure
|
|
118
|
+
```
|
|
119
|
+
lib/
|
|
120
|
+
hooks/ # Git hook implementations
|
|
121
|
+
utils/ # Utility functions
|
|
122
|
+
claude-client.js
|
|
123
|
+
git-operations.js
|
|
124
|
+
file-operations.js
|
|
125
|
+
logger.js
|
|
126
|
+
config.js # Configuration management
|
|
127
|
+
templates/ # Prompt templates
|
|
128
|
+
bin/ # CLI entry points
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Module Design
|
|
132
|
+
✅ Single responsibility principle
|
|
133
|
+
✅ Clear, descriptive function names
|
|
134
|
+
✅ Comprehensive error handling
|
|
135
|
+
✅ Proper logging at decision points
|
|
136
|
+
✅ Export reusable functions
|
|
137
|
+
|
|
138
|
+
## Common Issues to Avoid
|
|
139
|
+
|
|
140
|
+
### Critical Issues
|
|
141
|
+
❌ Exposed API keys or secrets
|
|
142
|
+
❌ Command injection vulnerabilities
|
|
143
|
+
❌ Destructive git operations without confirmation
|
|
144
|
+
❌ Unhandled promise rejections
|
|
145
|
+
|
|
146
|
+
### Major Issues
|
|
147
|
+
❌ Missing error handling
|
|
148
|
+
❌ Poor user experience (unclear errors)
|
|
149
|
+
❌ Cross-platform incompatibility
|
|
150
|
+
❌ Memory leaks (large file handling)
|
|
151
|
+
❌ Missing input validation
|
|
152
|
+
|
|
153
|
+
### Minor Issues
|
|
154
|
+
❌ Insufficient logging
|
|
155
|
+
❌ Unclear variable names
|
|
156
|
+
❌ Missing documentation
|
|
157
|
+
❌ Inefficient token usage
|
|
158
|
+
❌ Poor code organization
|
|
159
|
+
|
|
160
|
+
## Testing
|
|
161
|
+
|
|
162
|
+
✅ Test with various input sizes
|
|
163
|
+
✅ Test error scenarios (API failures, git errors)
|
|
164
|
+
✅ Test cross-platform compatibility
|
|
165
|
+
✅ Mock external dependencies (Claude API, git)
|
|
166
|
+
✅ Test with edge cases (special characters, large files)
|
|
167
|
+
✅ Verify token usage calculations
|
|
168
|
+
|
|
169
|
+
## Documentation
|
|
170
|
+
|
|
171
|
+
✅ Document API usage patterns
|
|
172
|
+
✅ Explain prompt design decisions
|
|
173
|
+
✅ Document configuration options
|
|
174
|
+
✅ Provide usage examples
|
|
175
|
+
✅ Keep README up to date
|
|
176
|
+
✅ Document breaking changes
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "ai",
|
|
3
|
+
"displayName": "AI/CLI (Node.js + Claude)",
|
|
4
|
+
"description": "Node.js CLI tools with Claude API integration",
|
|
5
|
+
"version": "1.0.0",
|
|
6
|
+
|
|
7
|
+
"techStack": [
|
|
8
|
+
"Node.js",
|
|
9
|
+
"ES Modules",
|
|
10
|
+
"Claude API",
|
|
11
|
+
"CLI tools",
|
|
12
|
+
"Git hooks",
|
|
13
|
+
"Bash scripting",
|
|
14
|
+
"Markdown templates"
|
|
15
|
+
],
|
|
16
|
+
|
|
17
|
+
"fileExtensions": [
|
|
18
|
+
".js",
|
|
19
|
+
".json",
|
|
20
|
+
".md",
|
|
21
|
+
".sh"
|
|
22
|
+
],
|
|
23
|
+
|
|
24
|
+
"focusAreas": [
|
|
25
|
+
"Claude API usage and best practices",
|
|
26
|
+
"Prompt engineering quality",
|
|
27
|
+
"CLI user experience",
|
|
28
|
+
"Error handling and logging",
|
|
29
|
+
"Git operations safety",
|
|
30
|
+
"Cross-platform compatibility",
|
|
31
|
+
"Token usage optimization",
|
|
32
|
+
"Security (API keys, secrets)"
|
|
33
|
+
],
|
|
34
|
+
|
|
35
|
+
"templates": {
|
|
36
|
+
"analysis": "ANALYSIS_PROMPT.md",
|
|
37
|
+
"guidelines": "PRE_COMMIT_GUIDELINES.md",
|
|
38
|
+
"commitMessage": "../shared/COMMIT_MESSAGE.md",
|
|
39
|
+
"analyzeDiff": "../shared/ANALYZE_DIFF.md",
|
|
40
|
+
"resolution": "../shared/RESOLUTION_PROMPT.md"
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
You are analyzing a **{{PRESET_NAME}}** project with the following technology stack:
|
|
2
|
+
|
|
3
|
+
**Tech Stack:** {{TECH_STACK}}
|
|
4
|
+
|
|
5
|
+
**Analyzing files matching:** {{FILE_EXTENSIONS}}
|
|
6
|
+
|
|
7
|
+
## Your Task
|
|
8
|
+
|
|
9
|
+
Perform a comprehensive code quality analysis focusing on these areas:
|
|
10
|
+
|
|
11
|
+
{{FOCUS_AREAS}}
|
|
12
|
+
|
|
13
|
+
## Analysis Guidelines
|
|
14
|
+
|
|
15
|
+
1. **Security First**: Check for OWASP Top 10 vulnerabilities, especially:
|
|
16
|
+
- SQL injection risks
|
|
17
|
+
- Authentication/authorization flaws
|
|
18
|
+
- Sensitive data exposure
|
|
19
|
+
- XML external entities (XXE)
|
|
20
|
+
- Insecure deserialization
|
|
21
|
+
|
|
22
|
+
2. **Spring Boot Best Practices**:
|
|
23
|
+
- Proper use of `@Transactional`
|
|
24
|
+
- Correct exception handling
|
|
25
|
+
- Appropriate use of DTOs vs Entities
|
|
26
|
+
- Proper dependency injection
|
|
27
|
+
- Configuration management
|
|
28
|
+
|
|
29
|
+
3. **JPA/Hibernate**:
|
|
30
|
+
- N+1 query problems
|
|
31
|
+
- Lazy loading issues
|
|
32
|
+
- Proper use of relationships
|
|
33
|
+
- Query optimization
|
|
34
|
+
- Transaction boundaries
|
|
35
|
+
|
|
36
|
+
4. **Code Quality**:
|
|
37
|
+
- SOLID principles
|
|
38
|
+
- DRY violations
|
|
39
|
+
- Proper error handling
|
|
40
|
+
- Logging best practices
|
|
41
|
+
- Test coverage
|
|
42
|
+
|
|
43
|
+
## Output Format
|
|
44
|
+
|
|
45
|
+
Respond with a valid JSON following the SonarQube format:
|
|
46
|
+
|
|
47
|
+
```json
|
|
48
|
+
{
|
|
49
|
+
"QUALITY_GATE": "PASSED|FAILED",
|
|
50
|
+
"approved": true|false,
|
|
51
|
+
"metrics": {
|
|
52
|
+
"reliability": "A|B|C|D|E",
|
|
53
|
+
"security": "A|B|C|D|E",
|
|
54
|
+
"maintainability": "A|B|C|D|E",
|
|
55
|
+
"coverage": 0-100,
|
|
56
|
+
"duplications": 0-100,
|
|
57
|
+
"complexity": "number"
|
|
58
|
+
},
|
|
59
|
+
"issues": {
|
|
60
|
+
"blocker": 0,
|
|
61
|
+
"critical": 0,
|
|
62
|
+
"major": 0,
|
|
63
|
+
"minor": 0,
|
|
64
|
+
"info": 0
|
|
65
|
+
},
|
|
66
|
+
"details": [
|
|
67
|
+
{
|
|
68
|
+
"severity": "BLOCKER|CRITICAL|MAJOR|MINOR|INFO",
|
|
69
|
+
"type": "BUG|VULNERABILITY|CODE_SMELL",
|
|
70
|
+
"file": "path/to/file.java",
|
|
71
|
+
"line": 123,
|
|
72
|
+
"message": "Clear description of the issue"
|
|
73
|
+
}
|
|
74
|
+
],
|
|
75
|
+
"securityHotspots": 0,
|
|
76
|
+
"blockingIssues": ["List of critical issues that must be fixed"]
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Analysis Rules
|
|
81
|
+
|
|
82
|
+
- **Block commit** if: Security vulnerabilities, critical bugs, or blocker issues found
|
|
83
|
+
- **Pass** if: Only minor issues, info messages, or no issues
|
|
84
|
+
- Be strict but fair - focus on real problems, not style preferences
|
|
85
|
+
- Provide actionable, specific feedback with line numbers
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# Backend Code Quality Guidelines
|
|
2
|
+
|
|
3
|
+
## Spring Boot Standards
|
|
4
|
+
|
|
5
|
+
### Controllers
|
|
6
|
+
- Use proper HTTP methods and status codes
|
|
7
|
+
- Validate input with `@Valid`
|
|
8
|
+
- Handle exceptions with `@ExceptionHandler`
|
|
9
|
+
- Keep controllers thin - business logic in services
|
|
10
|
+
- Use DTOs for API contracts
|
|
11
|
+
|
|
12
|
+
### Services
|
|
13
|
+
- Use `@Transactional` appropriately
|
|
14
|
+
- Handle exceptions properly
|
|
15
|
+
- Keep methods focused and small
|
|
16
|
+
- Avoid business logic in controllers or repositories
|
|
17
|
+
|
|
18
|
+
### Repositories
|
|
19
|
+
- Extend appropriate Spring Data interfaces
|
|
20
|
+
- Use method naming conventions for queries
|
|
21
|
+
- Optimize queries with `@Query` when needed
|
|
22
|
+
- Avoid N+1 problems with `@EntityGraph`
|
|
23
|
+
|
|
24
|
+
### Entities
|
|
25
|
+
- Use Lombok annotations appropriately
|
|
26
|
+
- Define proper relationships (`@OneToMany`, `@ManyToOne`, etc.)
|
|
27
|
+
- Use `@Version` for optimistic locking
|
|
28
|
+
- Never expose entities in API - use DTOs
|
|
29
|
+
|
|
30
|
+
## Security Requirements
|
|
31
|
+
|
|
32
|
+
### Authentication & Authorization
|
|
33
|
+
- Never hardcode credentials
|
|
34
|
+
- Use Spring Security properly
|
|
35
|
+
- Validate JWT tokens correctly
|
|
36
|
+
- Check permissions before operations
|
|
37
|
+
|
|
38
|
+
### Data Validation
|
|
39
|
+
- Validate all user input
|
|
40
|
+
- Use parameterized queries (JPA does this by default)
|
|
41
|
+
- Sanitize data before logging
|
|
42
|
+
- Never trust client-side validation alone
|
|
43
|
+
|
|
44
|
+
### SQL Injection Prevention
|
|
45
|
+
- Always use JPA/JPQL or prepared statements
|
|
46
|
+
- Never concatenate SQL strings
|
|
47
|
+
- Be careful with native queries
|
|
48
|
+
- Use `@Query` with proper parameter binding
|
|
49
|
+
|
|
50
|
+
## Performance
|
|
51
|
+
|
|
52
|
+
### Database
|
|
53
|
+
- Use pagination for large result sets
|
|
54
|
+
- Optimize queries with proper indexes
|
|
55
|
+
- Avoid loading unnecessary data
|
|
56
|
+
- Use projections when you don't need full entities
|
|
57
|
+
|
|
58
|
+
### Threading
|
|
59
|
+
- Be careful with `@Async` methods
|
|
60
|
+
- Use proper thread pool configuration
|
|
61
|
+
- Avoid blocking operations in async methods
|
|
62
|
+
- Handle exceptions in async methods
|
|
63
|
+
|
|
64
|
+
### Caching
|
|
65
|
+
- Use `@Cacheable` appropriately
|
|
66
|
+
- Clear caches when data changes
|
|
67
|
+
- Don't cache sensitive data without encryption
|
|
68
|
+
|
|
69
|
+
## Testing
|
|
70
|
+
|
|
71
|
+
- Write unit tests for business logic
|
|
72
|
+
- Use `@DataJpaTest` for repository tests
|
|
73
|
+
- Use `@WebMvcTest` for controller tests
|
|
74
|
+
- Mock external dependencies
|
|
75
|
+
- Aim for 80%+ coverage on new code
|
|
76
|
+
|
|
77
|
+
## Common Issues to Avoid
|
|
78
|
+
|
|
79
|
+
❌ Returning entities from controllers
|
|
80
|
+
❌ Missing `@Transactional` on write operations
|
|
81
|
+
❌ N+1 query problems
|
|
82
|
+
❌ Hardcoded secrets or credentials
|
|
83
|
+
❌ Catching and ignoring exceptions
|
|
84
|
+
❌ Missing input validation
|
|
85
|
+
❌ Exposing sensitive data in logs
|
|
86
|
+
❌ Using `SELECT *` in queries
|
|
87
|
+
❌ Not handling null values properly
|