π AI-powered code review using Kimi (Moonshot AI)
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β GitHub β
β ββββββββββββββββββββββββββββββββββββββββββ βββββββββββββββββββββββββββββββββ β
β β Pull Request Events β β Issue Events β β
β β βββββββββββ ββββββββββββ βββββββββββββ β β βββββββββββββ βββββββββββββββ β β
β β β PR β βPR Commentβ β Inline β β β β Issue β βIssue Commentβ β β
β β β Events β β /review β β Comment β β β β Events β β /triage β β β
β β ββββββ¬βββββ ββββββ¬ββββββ βββββββ¬ββββββ β β βββββββ¬ββββββ ββββββββ¬βββββββ β β
β ββββββββΌββββββββββββΌββββββββββββββΌββββββββ βββββββββΌβββββββββββββββΌβββββββββ β
ββββββββββΌββββββββββββΌββββββββββββββΌβββββββββββββββββββΌβββββββββββββββΌβββββββββββ
β β β β β
βΌ βΌ βΌ βΌ βΌ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β GitHub Actions Workflow (Docker) β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β main.py (Entry Point) β β
β β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ βββββββββββββββββββ β β
β β βhandle_pr_ β βhandle_commentβ βhandle_review_β βhandle_issue_ β β β
β β βevent() β β_event() β βcomment_event β βevent/comment() β β β
β β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ βββββββββββββββββββ β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β β
β βΌ β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β Tools Layer β β
β β ββββββββββ ββββββββββ ββββββββββ ββββββββββ ββββββββββ ββββββββββββββ β β
β β βReviewerβ βDescribeβ βImprove β β Ask β β Labels β β Triage β β β
β β β /reviewβ β/describeβ β/improveββ /ask β β/labels β β /triage β β β
β β βββββ¬βββββ βββββ¬βββββ βββββ¬βββββ βββββ¬βββββ βββββ¬βββββ ββββββββ¬ββββββ β β
β β ββββββββββββ΄βββββββββββ΄βββββββββββ΄βββββββββββ΄ββββββββββββββ β β
β β β β β
β β βΌ β β
β β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β β
β β β BaseTool β β β
β β β β’ clone_repo() β’ run_agent() β’ format_footer() β β β
β β β β’ get_diff() β’ get_skill() β’ post_inline_comments() β β β
β β β β’ load_context() β’ get_skills_dir() β’ parse_yaml_response() β β β
β β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β β
β ββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββ β
β βΌ βΌ βΌ β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββββββ β
β β SkillManager β β DiffChunker β βSuggestionService β β
β β (SKILL.md) β β (Large PRs) β β(Post-processing) β β
β β β’ Load skillsβ β β’ Prioritize β β β’ Filter/dedupe β β
β β β’ Set skills_β β β’ Chunk diff β β β’ Validate β β
β β dir for SDKβ β β’ Exclude β β β’ Score/sort β β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββββββ β
β β β
β ββββββββββββββββββββββββββββ΄βββββββββββββββββββββββββββ β
β βΌ βΌ β
β ββββββββββββββββββββββββββββββββββββββββββββ ββββββββββββββββ β
β β Kimi Agent SDK β β GitHub API β β
β β (kimi-k2-thinking-turbo) β β (REST) β β
β β β β β β
β β β’ Automatic token management β β β β
β β β’ Automatic script execution β β β β
β β β’ Context window management β β β β
β β β’ Built-in tools (read/write/bash) β β β β
β β β’ Skills directory integration β β β β
β ββββββββββββββββββββββββββββββββββββββββββββ ββββββββββββββββ β
β β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
- π
/review- Intelligent code review for bugs, security issues, and performance problems - π
/describe- Auto-generate PR title and description - β¨
/improve- Code improvement suggestions with concrete fixes - π¬
/ask- Interactive Q&A about the PR - π·οΈ
/labels- Auto-generate and apply PR labels based on content - π―
/triage- Auto-classify issues (bug/feature/question) with priority and labels - π§ Agent Skills - Modular capability extension with custom review rules
- π Multi-language support (English/Chinese)
- βοΈ Configurable review strictness
- π¦ Smart handling of large PRs (auto-chunking + model fallback)
- Visit Moonshot AI Platform
- Register/Login
- Go to "API Key Management"
- Click "Create API Key"
- Copy the generated API Key
- Go to your GitHub repository
- Click
SettingsβSecrets and variablesβActions - Click
New repository secret - Add
KIMI_API_KEYwith the API Key from step 1 - (Optional) Add
KIMI_BASE_URLif using a custom API endpoint (defaults tohttps://api.moonshot.cn/v1)
# .github/workflows/kimi-review.yml
name: Kimi Code Review
on:
pull_request:
types: [opened, synchronize, reopened]
issues:
types: [opened, reopened]
issue_comment:
types: [created]
pull_request_review_comment:
types: [created]
permissions:
contents: read
pull-requests: write
issues: write
jobs:
# Job for PR-related events (review, describe, improve, ask, labels)
pr-review:
runs-on: ubuntu-latest
if: |
github.event_name == 'pull_request' ||
(github.event_name == 'issue_comment' &&
github.event.issue.pull_request &&
startsWith(github.event.comment.body, '/')) ||
(github.event_name == 'pull_request_review_comment' &&
startsWith(github.event.comment.body, '/'))
steps:
- name: Get PR ref (for comments)
id: get-pr
if: github.event_name == 'issue_comment' || github.event_name == 'pull_request_review_comment'
uses: actions/github-script@v7
with:
script: |
const prNumber = context.issue?.number || context.payload.pull_request?.number;
const pr = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber
});
core.setOutput('ref', pr.data.head.ref);
core.setOutput('sha', pr.data.head.sha);
- uses: actions/checkout@v4
with:
ref: ${{ (github.event_name == 'issue_comment' || github.event_name == 'pull_request_review_comment') && steps.get-pr.outputs.ref || github.head_ref }}
- uses: xiaoju111a/kimi-actions@main
with:
kimi_api_key: ${{ secrets.KIMI_API_KEY }}
kimi_base_url: ${{ secrets.KIMI_BASE_URL }} # Optional
github_token: ${{ secrets.GITHUB_TOKEN }}
auto_review: 'false'
# Job for Issue-related events (triage)
issue-triage:
runs-on: ubuntu-latest
if: |
github.event_name == 'issues' ||
(github.event_name == 'issue_comment' &&
!github.event.issue.pull_request &&
startsWith(github.event.comment.body, '/'))
steps:
- uses: actions/checkout@v4
- uses: xiaoju111a/kimi-actions@main
with:
kimi_api_key: ${{ secrets.KIMI_API_KEY }}
kimi_base_url: ${{ secrets.KIMI_BASE_URL }} # Optional
github_token: ${{ secrets.GITHUB_TOKEN }}
auto_triage: 'false'Use these commands in PR comments:
| Command | Description | Usage Location |
|---|---|---|
/review |
Smart code review with inline comments (auto-detects incremental) | PR comment area |
/describe |
Auto-generate PR description | PR comment area |
/describe --comment |
Generate description as comment | PR comment area |
/improve |
Code improvement suggestions | PR comment area |
/ask <question> |
Q&A about the PR or specific code | PR comment area or Files changed tab (inline) |
/labels |
Auto-generate and apply PR labels | PR comment area |
/help |
Show help message | PR comment area |
π§ Smart Incremental Review:
The /review command automatically detects the best review strategy:
- First review: Full review of all changes
- Subsequent reviews: Only reviews new commits since last review (if previous review <7 days old)
- Old reviews: Automatically does full re-review if previous review is >7 days old
- No new commits: Shows "β No new changes since last review" message
No parameters needed - it intelligently adapts to your workflow! π―
π‘ Using /ask for code-specific questions:
- In PR comment area: Ask general questions about the entire PR
- In Files changed tab: Click the + button next to a line of code, then use
/ask <question>to ask about that specific code
Use these commands in Issue comments:
| Command | Description |
|---|---|
/triage |
Auto-classify issue type and apply labels |
/triage --no-apply |
Classify without applying labels |
/help |
Show help message |
- uses: xiaoju111a/kimi-actions@main
with:
# Required
kimi_api_key: ${{ secrets.KIMI_API_KEY }}
github_token: ${{ secrets.GITHUB_TOKEN }}
# Optional
kimi_base_url: ${{ secrets.KIMI_BASE_URL }} # Custom API endpoint (optional, defaults to https://api.moonshot.cn/v1)
language: 'en-US' # Response language: zh-CN, en-US
model: 'kimi-k2-thinking-turbo' # Kimi model (default: kimi-k2-thinking-turbo, or kimi-k2-thinking for more thorough analysis)
review_level: 'normal' # Review strictness: strict, normal, gentle
max_files: '10' # Max files to review
exclude_patterns: '*.lock,*.min.js' # File patterns to exclude
auto_review: 'true' # Auto review on PR open
auto_describe: 'false' # Auto generate description on PR open
auto_improve: 'false' # Auto provide suggestions on PR open
auto_triage: 'false' # Auto triage issues on openCreate .kimi-config.yml in your repo root to customize behavior:
# Category toggles
categories:
bug: true
performance: true
security: true
# Replace built-in skills with custom ones
skill_overrides:
code-review: my-company-review
# Ignore files
ignore_files:
- "*.test.ts"
- "**/__mocks__/**"
# Extra instructions
extra_instructions: |
Focus on security issues.Create .kimi/skills/ directory in your repo, each skill is a folder:
.kimi/skills/
βββ react-review/
β βββ SKILL.md # Required: core instructions
β βββ scripts/ # Optional: executable scripts
β β βββ check_hooks.py
β βββ references/ # Optional: reference documents
β βββ hooks-rules.md
βββ company-rules/
βββ SKILL.md
SKILL.md format:
---
name: react-review
description: React code review expert
triggers:
- react
- jsx
- hooks
---
# React Review Focus
## Hooks Rules
- Hooks can only be called at the top level of function components
- Cannot call Hooks inside conditionals
## Performance
- Check if useMemo/useCallback is neededSkills are automatically triggered based on PR code content.
| Model | Context | Notes |
|---|---|---|
kimi-k2-thinking-turbo |
256K | Default, faster thinking model, good balance |
kimi-k2-thinking |
256K | More thorough reasoning, slower |
kimi-k2-turbo-preview |
256K | Fast, for simple tasks |
All commands use Kimi Agent SDK with kimi-k2-thinking-turbo model by default for best speed/quality balance.
When PR is too large, the action uses intelligent chunking to prioritize important files.
| Category | Description | Examples |
|---|---|---|
| Bug | Code defects | Unhandled exceptions, null pointers, logic errors |
| Security | Security vulnerabilities | SQL injection, XSS, auth flaws |
| Performance | Performance issues | O(nΒ²) algorithms, N+1 queries |
kimi-actions/
βββ action.yml # GitHub Action definition
βββ Dockerfile # Docker container config
βββ requirements.txt # Python dependencies
βββ tests/ # Unit tests (235 tests)
βββ src/
βββ main.py # Entry point, event routing
βββ action_config.py # Action config (env vars)
βββ repo_config.py # Repo config (.kimi-config.yml)
βββ github_client.py # GitHub API client
βββ diff_chunker.py # Intelligent diff chunking for large PRs
βββ diff_processor.py # Diff file filtering (binary, lock files)
βββ skill_loader.py # Skill loading/management
βββ suggestion_service.py # Suggestion post-processing
βββ models.py # Data models
βββ tools/ # Command implementations (Agent SDK)
β βββ base.py # Base class (common functionality)
β βββ reviewer.py # /review - Code review
β βββ describe.py # /describe - PR description
β βββ improve.py # /improve - Code improvements
β βββ ask.py # /ask - Q&A
β βββ labels.py # /labels - Label generation
β βββ triage.py # /triage - Issue classification
βββ skills/ # Built-in Skills
βββ code-review/
β βββ SKILL.md # Review instructions
β βββ scripts/ # Review scripts (called by Agent SDK)
βββ describe/
βββ improve/
βββ ask/
βββ labels/
βββ triage/
βββ scripts/
βββ scan_codebase.py
| Component | Purpose | Notes |
|---|---|---|
| diff_chunker.py | Handle large PRs | Priority-based file selection, token-aware chunking |
| skill_loader.py | Manage skills | Load SKILL.md, set skills_dir for Agent SDK |
| suggestion_service.py | Post-process suggestions | Filter, dedupe, validate, score, sort |
| base.py | Common tool functionality | Diff fetching, repo cloning, Agent SDK execution |
| Agent SDK | LLM execution | Automatic token management, script execution, context handling |
Visit Moonshot AI Platform, register and create an API Key in the management page. New users get free credits.
Yes. Just ensure GITHUB_TOKEN has permission to read repository contents.
The action uses intelligent diff chunking:
- Priority-based selection: Security files and core logic prioritized over tests/docs
- Token-aware chunking: Automatically fits within Agent SDK context limits (256K tokens)
- File filtering: Excludes binary files, lock files, minified files
Agent SDK automatically manages token counting and context windows.
Kimi Agent SDK is an intelligent agent framework that:
- Automatic token management: No need to manually count tokens or manage context
- Dynamic script execution: Automatically calls skill scripts when needed
- Built-in tools: Provides file operations (read/write) and bash execution
- Context optimization: Intelligently manages conversation context
This allows the action to focus on what to review (skills, rules) rather than how to execute (token counting, script running).
Skills define what the agent should do:
- SKILL.md contains instructions for the agent
- scripts/ contains executable tools (Python scripts)
- Agent SDK automatically calls scripts when needed based on instructions
Example flow:
1. Load skill: code-review
2. Pass skills_dir to Agent SDK
3. Agent reads SKILL.md instructions
4. Agent automatically calls scripts/check_security.py when analyzing code
5. Agent generates review based on script output + instructions
Create .kimi-config.yml in your repo root, or add custom Skills in .kimi/skills/ directory. See Configuration section above.
If you're using a proxy or custom Kimi API endpoint, add KIMI_BASE_URL to your repository secrets:
- Go to
SettingsβSecrets and variablesβActions - Click
New repository secret - Add
KIMI_BASE_URLwith your custom endpoint (e.g.,https://your-proxy.example.com/v1)
Then use it in your workflow:
- uses: xiaoju111a/kimi-actions@main
with:
kimi_api_key: ${{ secrets.KIMI_API_KEY }}
kimi_base_url: ${{ secrets.KIMI_BASE_URL }} # Custom endpoint from secrets
github_token: ${{ secrets.GITHUB_TOKEN }}Note: If KIMI_BASE_URL is not set, it defaults to https://api.moonshot.cn/v1.
This is useful for:
- Using a corporate proxy
- Testing with a local development server
- Using alternative API gateways
- Keeping endpoint URLs private
- Moonshot AI - Kimi LLM
- Kimi Agent SDK - Agent framework
- pr-agent - Architecture reference
- kimi-cli - Kimi CLI tool
- kodus-ai - AI code review reference
MIT