@mikulgohil/ai-kit 1.3.2 → 1.4.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikulgohil/ai-kit",
3
- "version": "1.3.2",
3
+ "version": "1.4.0",
4
4
  "description": "AI-assisted development setup kit. Auto-detects your tech stack and generates tailored CLAUDE.md, .cursorrules, hooks, agents, context modes, slash commands, and developer guides.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -0,0 +1,279 @@
1
+ # =============================================================================
2
+ # AI-Powered PR Review — GitHub Actions Workflow Template
3
+ # =============================================================================
4
+ #
5
+ # This workflow uses the Anthropic Claude API to review pull request diffs
6
+ # against your project's coding standards defined in CLAUDE.md.
7
+ #
8
+ # Template variables (replace before use):
9
+ # {{PROJECT_NAME}} — Your project/repo name (e.g., "my-app")
10
+ # {{MODEL}} — Claude model to use (default: claude-sonnet-4-20250514)
11
+ #
12
+ # Setup:
13
+ # 1. Copy this file to your project's .github/workflows/ai-review.yml
14
+ # 2. Replace template variables with your values
15
+ # 3. Add ANTHROPIC_API_KEY to your repository secrets:
16
+ # Settings → Secrets and variables → Actions → New repository secret
17
+ # 4. Ensure CLAUDE.md exists at the repo root with your project rules
18
+ #
19
+ # =============================================================================
20
+
21
+ name: "AI PR Review — {{PROJECT_NAME}}"
22
+
23
+ # Trigger on pull request events: when a PR is opened or new commits are pushed
24
+ on:
25
+ pull_request:
26
+ types: [opened, synchronize]
27
+
28
+ # Restrict permissions to the minimum required
29
+ permissions:
30
+ contents: read # Read repo contents (for CLAUDE.md and diff)
31
+ pull-requests: write # Post review comments on the PR
32
+
33
+ # Cancel in-progress runs for the same PR when new commits are pushed
34
+ concurrency:
35
+ group: ai-review-${{ github.event.pull_request.number }}
36
+ cancel-in-progress: true
37
+
38
+ jobs:
39
+ ai-review:
40
+ name: Claude PR Review
41
+ runs-on: ubuntu-latest
42
+
43
+ # Skip reviews on draft PRs and bot-authored PRs
44
+ if: |
45
+ github.event.pull_request.draft == false &&
46
+ github.actor != 'dependabot[bot]' &&
47
+ github.actor != 'renovate[bot]'
48
+
49
+ steps:
50
+ # -----------------------------------------------------------------------
51
+ # Step 1: Checkout the repository
52
+ # We need the full repo to read CLAUDE.md and generate the diff.
53
+ # fetch-depth: 0 ensures we have the base branch for accurate diff.
54
+ # -----------------------------------------------------------------------
55
+ - name: Checkout repository
56
+ uses: actions/checkout@v4
57
+ with:
58
+ fetch-depth: 0
59
+
60
+ # -----------------------------------------------------------------------
61
+ # Step 2: Fetch the base branch
62
+ # Ensures we can compute an accurate diff between base and head.
63
+ # -----------------------------------------------------------------------
64
+ - name: Fetch base branch
65
+ run: git fetch origin ${{ github.event.pull_request.base.ref }}
66
+
67
+ # -----------------------------------------------------------------------
68
+ # Step 3: Read project rules from CLAUDE.md
69
+ # This file contains your project's coding standards, conventions, and
70
+ # guidelines that the AI reviewer will enforce.
71
+ # Falls back to a sensible default if CLAUDE.md doesn't exist.
72
+ # -----------------------------------------------------------------------
73
+ - name: Read project rules
74
+ id: rules
75
+ run: |
76
+ if [ -f "CLAUDE.md" ]; then
77
+ echo "rules_found=true" >> "$GITHUB_OUTPUT"
78
+ # Store rules content in a file for the review step
79
+ cp CLAUDE.md /tmp/project-rules.md
80
+ echo "Project rules loaded from CLAUDE.md"
81
+ else
82
+ echo "rules_found=false" >> "$GITHUB_OUTPUT"
83
+ echo "No CLAUDE.md found — review will use general best practices"
84
+ echo "No project-specific CLAUDE.md found. Use general best practices." > /tmp/project-rules.md
85
+ fi
86
+
87
+ # -----------------------------------------------------------------------
88
+ # Step 4: Generate the PR diff
89
+ # Produces a unified diff of all changes in this PR relative to the
90
+ # base branch. Limited to 100KB to stay within API token limits.
91
+ # Binary files and lockfiles are excluded to reduce noise.
92
+ # -----------------------------------------------------------------------
93
+ - name: Generate PR diff
94
+ id: diff
95
+ run: |
96
+ DIFF=$(git diff \
97
+ origin/${{ github.event.pull_request.base.ref }}..HEAD \
98
+ -- . \
99
+ ':!package-lock.json' \
100
+ ':!pnpm-lock.yaml' \
101
+ ':!yarn.lock' \
102
+ ':!*.lock' \
103
+ ':!*.png' ':!*.jpg' ':!*.jpeg' ':!*.gif' ':!*.svg' ':!*.ico' \
104
+ ':!*.woff' ':!*.woff2' ':!*.ttf' ':!*.eot' \
105
+ | head -c 100000)
106
+
107
+ if [ -z "$DIFF" ]; then
108
+ echo "No reviewable diff found (only lockfiles, images, or binary changes)"
109
+ echo "empty=true" >> "$GITHUB_OUTPUT"
110
+ else
111
+ echo "empty=false" >> "$GITHUB_OUTPUT"
112
+ # Write diff to file to avoid shell escaping issues
113
+ echo "$DIFF" > /tmp/pr-diff.txt
114
+ fi
115
+
116
+ # -----------------------------------------------------------------------
117
+ # Step 5: Collect PR metadata
118
+ # Gathers PR title, description, changed file list, and author info
119
+ # to give the AI reviewer full context.
120
+ # -----------------------------------------------------------------------
121
+ - name: Collect PR metadata
122
+ if: steps.diff.outputs.empty != 'true'
123
+ id: metadata
124
+ run: |
125
+ # Get the list of changed files with status (Added, Modified, Deleted)
126
+ git diff --name-status \
127
+ origin/${{ github.event.pull_request.base.ref }}..HEAD \
128
+ -- . \
129
+ ':!package-lock.json' ':!pnpm-lock.yaml' ':!yarn.lock' ':!*.lock' \
130
+ > /tmp/changed-files.txt
131
+
132
+ FILE_COUNT=$(wc -l < /tmp/changed-files.txt | tr -d ' ')
133
+ echo "file_count=$FILE_COUNT" >> "$GITHUB_OUTPUT"
134
+ echo "Changed files: $FILE_COUNT"
135
+
136
+ # -----------------------------------------------------------------------
137
+ # Step 6: Call Claude API for review
138
+ # Sends the diff, project rules, and PR context to Claude for analysis.
139
+ # The prompt instructs Claude to act as a code reviewer and output
140
+ # structured markdown feedback.
141
+ # -----------------------------------------------------------------------
142
+ - name: Run AI review
143
+ if: steps.diff.outputs.empty != 'true'
144
+ id: review
145
+ env:
146
+ ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
147
+ run: |
148
+ # Read inputs into variables
149
+ PROJECT_RULES=$(cat /tmp/project-rules.md)
150
+ PR_DIFF=$(cat /tmp/pr-diff.txt)
151
+ CHANGED_FILES=$(cat /tmp/changed-files.txt)
152
+ PR_TITLE="${{ github.event.pull_request.title }}"
153
+ PR_BODY="${{ github.event.pull_request.body }}"
154
+
155
+ # Build the review prompt
156
+ REVIEW_PROMPT=$(cat <<'PROMPT_END'
157
+ You are a senior code reviewer for the {{PROJECT_NAME}} project. Review the following pull request diff against the project rules and coding standards.
158
+
159
+ ## Your Task
160
+ 1. Check for bugs, logic errors, and security vulnerabilities
161
+ 2. Verify the changes follow the project rules and conventions below
162
+ 3. Look for performance issues, missing error handling, and edge cases
163
+ 4. Check for accessibility issues in any UI changes
164
+ 5. Note any missing tests for new functionality
165
+
166
+ ## Output Format
167
+ Structure your review as markdown with these sections:
168
+
169
+ ### Summary
170
+ One paragraph overview of what the PR does and overall quality assessment.
171
+
172
+ ### Issues Found
173
+ List issues by severity. Use this format for each:
174
+ - **[Critical]** / **[Warning]** / **[Suggestion]** `file:line` — Description of the issue and how to fix it.
175
+
176
+ If no issues are found in a severity level, omit that level.
177
+
178
+ ### Positive Highlights
179
+ Brief notes on things done well (max 3 items). This encourages good patterns.
180
+
181
+ ## Rules
182
+ - Be constructive and specific — always suggest a fix, not just point out problems
183
+ - Do not flag style issues that are consistent with the existing codebase
184
+ - Do not suggest changes that would significantly expand the PR scope
185
+ - Focus on substantive issues over nitpicks
186
+ - If the diff is too large to review thoroughly, focus on the highest-risk files
187
+ PROMPT_END
188
+ )
189
+
190
+ # Build the JSON payload using jq to handle escaping safely
191
+ PAYLOAD=$(jq -n \
192
+ --arg model "{{MODEL}}" \
193
+ --arg system "You are a code reviewer. Be concise, constructive, and specific." \
194
+ --arg rules "$PROJECT_RULES" \
195
+ --arg diff "$PR_DIFF" \
196
+ --arg files "$CHANGED_FILES" \
197
+ --arg title "$PR_TITLE" \
198
+ --arg body "$PR_BODY" \
199
+ --arg prompt "$REVIEW_PROMPT" \
200
+ '{
201
+ model: (if $model == "{{MODEL}}" then "claude-sonnet-4-20250514" else $model end),
202
+ max_tokens: 4096,
203
+ messages: [
204
+ {
205
+ role: "user",
206
+ content: ($prompt + "\n\n## Project Rules (from CLAUDE.md)\n\n" + $rules + "\n\n## PR: " + $title + "\n\n" + $body + "\n\n## Changed Files\n\n```\n" + $files + "\n```\n\n## Diff\n\n```diff\n" + $diff + "\n```")
207
+ }
208
+ ]
209
+ }')
210
+
211
+ # Call the Anthropic Messages API
212
+ RESPONSE=$(curl -s -w "\n%{http_code}" \
213
+ https://api.anthropic.com/v1/messages \
214
+ -H "content-type: application/json" \
215
+ -H "x-api-key: $ANTHROPIC_API_KEY" \
216
+ -H "anthropic-version: 2023-06-01" \
217
+ -d "$PAYLOAD")
218
+
219
+ # Separate response body and HTTP status code
220
+ HTTP_CODE=$(echo "$RESPONSE" | tail -1)
221
+ BODY=$(echo "$RESPONSE" | sed '$d')
222
+
223
+ if [ "$HTTP_CODE" != "200" ]; then
224
+ echo "API request failed with status $HTTP_CODE"
225
+ echo "$BODY" | jq '.error' 2>/dev/null || echo "$BODY"
226
+ exit 1
227
+ fi
228
+
229
+ # Extract the review text from the API response
230
+ REVIEW=$(echo "$BODY" | jq -r '.content[0].text')
231
+
232
+ # Write review to file for the comment step
233
+ echo "$REVIEW" > /tmp/review-output.md
234
+
235
+ # -----------------------------------------------------------------------
236
+ # Step 7: Post the review as a PR comment
237
+ # Uses the GitHub API to post the AI review as a comment on the PR.
238
+ # Includes a header identifying it as an automated review.
239
+ # -----------------------------------------------------------------------
240
+ - name: Post review comment
241
+ if: steps.diff.outputs.empty != 'true'
242
+ env:
243
+ GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
244
+ run: |
245
+ REVIEW_BODY=$(cat /tmp/review-output.md)
246
+ FILE_COUNT="${{ steps.metadata.outputs.file_count }}"
247
+
248
+ # Build the comment with a clear header
249
+ COMMENT=$(cat <<EOF
250
+ ## AI Code Review
251
+
252
+ > Automated review by Claude ({{MODEL}}) | $FILE_COUNT files reviewed
253
+ > Rules source: $([ "${{ steps.rules.outputs.rules_found }}" = "true" ] && echo "CLAUDE.md" || echo "general best practices")
254
+
255
+ ---
256
+
257
+ $REVIEW_BODY
258
+
259
+ ---
260
+
261
+ <sub>This review was generated automatically. It supplements but does not replace human review.</sub>
262
+ EOF
263
+ )
264
+
265
+ # Post the comment using GitHub CLI
266
+ gh pr comment ${{ github.event.pull_request.number }} \
267
+ --body "$COMMENT"
268
+
269
+ # -----------------------------------------------------------------------
270
+ # Step 8: Handle empty diff (no reviewable changes)
271
+ # Posts a brief note when the PR only contains lockfiles or binary assets.
272
+ # -----------------------------------------------------------------------
273
+ - name: Skip review (no diff)
274
+ if: steps.diff.outputs.empty == 'true'
275
+ env:
276
+ GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
277
+ run: |
278
+ gh pr comment ${{ github.event.pull_request.number }} \
279
+ --body "## AI Code Review\n\nNo reviewable code changes found in this PR (only lockfiles, images, or binary assets). Skipping automated review."