analyze
Analyze PR changes to detect languages, frameworks, test setup, impact areas, and risk classes. Use when starting a PR review and you need to understand what changed before deeper analysis.
- License 许可
- MIT
- 最近更新
- 2026-11-14
- Stars
- ★ 1
- Forks
- 0
01 前言 Front Matter
- name
- analyze
- description
- Analyze PR changes to detect languages, frameworks, test setup, impact areas, and risk classes. Use when starting a PR review and you need to understand what changed before deeper analysis.
- allowed-tools
- Bash Read Grep Glob
03 SKILL.md 正文
Analyze PR Changes
Analyze a pull request: what changed, which languages/frameworks involved, how to test it, what impact areas need review, which risk classes should gate deeper passes.
Foundation for other review skills — produces structured analysis driving test recommendations, security scanning, documentation validation, and quality-review pass routing (shared/risk-class-routing.md).
Inputs
- PR URL: Full GitHub/Enterprise PR URL (e.g.,
https://github.com/org/repo/pull/123) - OUTPUT_DIR (optional): Output dir. Defaults to private
mktemp -d.
Outputs
Writes analysis to <OUTPUT_DIR>/pr-analysis-<PR_NUMBER>.json:
{
"pr": {
"number": 123,
"title": "Add user authentication",
"url": "https://github.com/org/repo/pull/123",
"base_branch": "main",
"head_branch": "feature/auth",
"author": "username",
"state": "open"
},
"changes": {
"files_changed": 15,
"additions": 450,
"deletions": 120,
"files": ["src/auth.py", "tests/test_auth.py", "README.md"]
},
"languages": {
"primary": "python",
"detected": ["python", "javascript", "shell"],
"confidence": {
"python": 0.85,
"javascript": 0.10,
"shell": 0.05
}
},
"frameworks": {
"detected": ["django", "pytest", "npm"],
"confidence": "high"
},
"test_setup": {
"framework": "pytest",
"test_command": "pytest",
"test_files": ["tests/test_auth.py"],
"config_files": ["pytest.ini", "setup.py"],
"can_run_safely": true,
"safety_notes": "Uses pytest with standard config"
},
"build_system": {
"type": "python",
"files": ["setup.py", "requirements.txt", "pyproject.toml"],
"commands": {
"install": "pip install -r requirements.txt",
"test": "pytest",
"lint": "flake8"
}
},
"change_categories": {
"code": ["src/auth.py", "src/api.py"],
"tests": ["tests/test_auth.py"],
"docs": ["README.md", "docs/auth.md"],
"config": ["setup.py"],
"infra": []
},
"impact_analysis": {
"high_impact": ["authentication", "security"],
"medium_impact": ["API endpoints"],
"low_impact": ["documentation"],
"breaking_changes": false
},
"security_sensitive": true,
"needs_security_review": true,
"uses_mac_ui": false,
"mac_ui_ref_repo": "owner/mac-ui",
"risk_class": ["domain", "auth", "api"]
}
risk_class is an array of zero or more of: domain, auth, data, api, concurrency, ops.
The orchestrator uses it to gate QR passes (see shared/risk-class-routing.md).
uses_mac_ui (see Step 4) tells security-scan and docs-drift
to fetch mac-ui's live authority docs. mac_ui_ref_repo is the repo they fetch
from, taken from $MAC_UI_REF_REPO. Downstream skills read both from this JSON.
Step 0: Parse Arguments
Extract PR URL and output dir from arguments:
PR_URL="$1"
# Default to a private per-run temp dir when run standalone (no OUTPUT_DIR passed)
OUTPUT_DIR="${2:-$(mktemp -d -t pr-review-XXXXXX)}"
# Create output dir if missing
mkdir -p "$OUTPUT_DIR"
# Extract PR number for filename
PR_NUMBER=$(echo "$PR_URL" | grep -oE 'pull/[0-9]+' | grep -oE '[0-9]+')
echo "Output directory: $OUTPUT_DIR" >&2
echo "PR number: $PR_NUMBER" >&2
Step 1: Fetch PR Metadata
/review:review captures the PR once into $OUTPUT_DIR before this skill
runs. Read $OUTPUT_DIR/pr-view.json and $OUTPUT_DIR/pr.files; fetch only
when they are absent (standalone run):
if [ ! -s "$OUTPUT_DIR/pr.files" ]; then
gh pr view "$PR_URL" --json number,title,url,baseRefName,headRefName,author,state,additions,deletions,body \
> "$OUTPUT_DIR/pr-view.json"
gh pr diff "$PR_URL" --name-only > "$OUTPUT_DIR/pr.files"
fi
Store in variables for later use.
Step 2: Get Changed Files
cat "$OUTPUT_DIR/pr.files"
Count files and categorize by type:
- Code:
.py,.js,.go,.java,.rb,.php,.ts,.tsx,.jsx - Tests:
test_*.py,*.test.js,*_test.go,Test*.java - Docs:
*.md,*.rst,*.txt,docs/,README* - Config:
*.json,*.yaml,*.yml,*.toml,*.ini,Makefile,Dockerfile - Infra:
.github/,terraform/,k8s/,.circleci/,.gitlab-ci.yml
Step 3: Detect Languages
Analyze file extensions and count:
sed 's/.*\.//' "$OUTPUT_DIR/pr.files" | sort | uniq -c | sort -rn
Primary language: extension with most files Secondary languages: extensions with >10% of files
Language mapping:
.py→ Python.js,.jsx,.ts,.tsx→ JavaScript/TypeScript.go→ Go.java→ Java.rb→ Ruby.rs→ Rust.php→ PHP.c,.cpp,.cc→ C/C++
Step 4: Detect Frameworks
Look for framework indicators in changed files or project root.
Python:
- Django:
djangoin requirements.txt,manage.pyexists - Flask:
flaskin requirements.txt,app.pypattern - FastAPI:
fastapiin requirements.txt - Pytest:
pytestin requirements.txt orpytest.iniexists
JavaScript:
- React:
package.jsoncontains"react" - Vue:
package.jsoncontains"vue" - Angular:
package.jsoncontains"@angular" - Express:
package.jsoncontains"express" - Jest:
package.jsoncontains"jest" - Mocha:
package.jsoncontains"mocha"
Go:
go.modexists → Go modules- Standard library (no frameworks typically)
Java:
- Spring:
pom.xmlorbuild.gradlecontainsspring - JUnit:
pom.xmlcontainsjunit
Rust:
- Cargo:
Cargo.tomlexists (a[workspace]root marks a multi-crate workspace). - Test runner:
cargo-nextestif.config/nextest.tomlexists or ajustfilerecipe runsnextest; else plaincargo test. - Coverage:
cargo-llvm-covif ajust coverage/llvm-covrecipe orcargo-llvm-covin CI. Note any--fail-under-linesthreshold (a hard gate). - Supply-chain:
cargo-audit,cargo-deny(deny.toml),cargo-machete. - Command source: prefer a
justfile— itsfmt/clippy/test/coverage/cirecipes are what CI runs; record exact recipes, don't guess.
mac-ui / Web Components ($MAC_UI_PACKAGE):
- Only when both
$MAC_UI_PACKAGE(npm name, e.g.@scope/mac-ui) and$MAC_UI_REF_REPO(owner/repo) are set; otherwise leaveuses_mac_ui: false. - Set
uses_mac_ui: truewhen any of:package.json(root or a workspace package) depends on$MAC_UI_PACKAGEor its-react/-utilssiblings; a changed file registers or consumes amac-*custom element (customElements.define, a<mac-…>tag, or an import from$MAC_UI_PACKAGE). - Monorepo:
lerna.json+packages/→ lerna workspace;biome.json→ Biome lint/format;vite.config.ts/web-dev-server-config.js→ Vite/WTR. - Test runner: per-package
package.jsontestscript is authoritative (web-test-runner / vitest / jsdom); don't assume.
Step 5: Analyze Test Setup
5.1 Find Test Framework
Look for:
- Python:
pytest.ini,tox.ini,setup.pywith test_suite - JavaScript:
jest.config.js,package.json"test" script - Go:
*_test.gofiles (standard testing) - Java:
pom.xmlwith surefire plugin, JUnit
5.2 Determine Test Command
Infer from config: Python → pytest / python setup.py test / make test; JS → npm test; Go → go test ./...; Rust → just recipes or cargo nextest / cargo test. Prefer the command CI actually runs.
5.3 Safety Assessment
can_run_safely when: standard framework, no external deps, no destructive ops, reasonable runtime (<5min).
Mark unsafe for integration/e2e, DB/docker requirements, or tests that hit live network. Rust: unsafe when gated on PGURL / Kafka / compose; unit-only nextest filter is usually safe. mac-ui: default unsafe unless package test is jsdom/vitest-only (needs Chromium otherwise).
Step 6: Detect Build System
Look for build config files.
Python:
setup.py→ setuptoolspyproject.toml→ modern Python (poetry, flit, hatch)requirements.txt→ pipPipfile→ pipenvMakefile→ make
JavaScript:
package.json→ npm/yarnyarn.lock→ yarnpackage-lock.json→ npm
Go:
go.mod→ Go modulesMakefile→ make
Java:
pom.xml→ Mavenbuild.gradle→ Gradle
Rust:
Cargo.toml→ cargo (workspace if[workspace])justfile→ task runner; its recipes are the source of truth forinstall/test/lint/build(mirror them into the commands map below)
JS monorepo:
lerna.json/pnpm-workspace.yaml/package.jsonworkspaces→ monorepo; commands run per-package (npm -w <pkg> test)
Record install / test / lint / build commands in the build_system JSON (prefer justfile / package scripts over guesses).
Step 7: Impact Analysis
7.1 Detect High-Impact Areas
Look for changes in sensitive files/patterns.
Authentication/Security:
- Files matching:
*auth*,*security*,*login*,*password*,*token* - Keywords in diff: "auth", "login", "password", "secret", "key"
Database:
- Files matching:
*migration*,*schema*,*model*,*db* - Keywords: "ALTER TABLE", "DROP", "CREATE TABLE"
API:
- Files matching:
*api*,*endpoint*,*route*,*handler* - Keywords: "GET", "POST", "PUT", "DELETE" in route definitions
Configuration:
- Files:
config/*,.env*,*.yaml,*.json(in root or config dirs)
Infrastructure:
- Files:
Dockerfile,docker-compose.yml,k8s/*,terraform/*
7.2 Detect Breaking Changes
Indicators:
- Major version bump in package file
- Removed or renamed functions/classes
- Changed function signatures
- Deleted files
- Database schema changes (DROP, ALTER)
Keywords in commits/PR title:
- "BREAKING", "breaking change", "incompatible", "removed", "deprecated"
Step 8: Security Sensitivity Assessment
Determine if PR needs extra security scrutiny.
High security sensitivity:
- Changes authentication/authorization code
- Modifies database schemas
- Changes API endpoints
- Touches encryption/crypto code
- Modifies access control
- Updates dependencies with known vulnerabilities
Markers:
security_sensitive = (
affects_auth OR
affects_database OR
affects_api OR
affects_crypto OR
updates_security_deps
)
Step 8b: Emit risk_class array
Set RISK_CLASS_JSON to a JSON array of applicable classes ([] is valid). Include a class when the diff/title/body/paths strongly suggest it — prefer false-positive inclusion over missing a QR pass.
| Class | Include when |
|---|---|
domain |
Domain model, aggregates, bounded-context, ownership/CODEOWNERS cross-boundary, layering/hex/ports changes |
auth |
Authn/z, sessions, tokens, IDOR-prone ID lookups, permission/role changes |
data |
Migrations, schema, serializers, caches as SoT, dual-write, retention/delete |
api |
Public/internal HTTP/RPC/event/webhook contracts, OpenAPI/Protobuf/Avro, versioning |
concurrency |
Locks, atomics, shared mutable state, async cancel, queues/consumers, idempotent handlers |
ops |
Timeouts, retries, circuit breakers, metrics/traces on new paths, pools, pagination limits, hot-path perf |
Map from impact_analysis + path heuristics. Example: auth+API endpoint change → ["auth","api"] (and often domain if model touched).
Step 9: Generate Analysis JSON
Combine all findings into structured JSON, write to $OUTPUT_DIR/pr-analysis-<PR_NUMBER>.json.
Build JSON with jq -n so every PR-derived value is safely escaped — pass strings with --arg, numbers/booleans/arrays/objects with --argjson. Never interpolate untrusted text into a heredoc.
jq -n \
--argjson pr "$PR_JSON" \
--argjson changes "$CHANGES_JSON" \
--argjson languages "$LANGUAGES_JSON" \
--argjson frameworks "$FRAMEWORKS_JSON" \
--argjson test_setup "$TEST_SETUP_JSON" \
--argjson build_system "$BUILD_SYSTEM_JSON" \
--argjson change_categories "$CHANGE_CATEGORIES_JSON" \
--argjson impact_analysis "$IMPACT_ANALYSIS_JSON" \
--argjson security_sensitive "$SECURITY_SENSITIVE" \
--argjson needs_security_review "$NEEDS_SECURITY_REVIEW" \
--argjson uses_mac_ui "${USES_MAC_UI:-false}" \
--arg mac_ui_ref_repo "${MAC_UI_REF_REPO:-}" \
--argjson risk_class "${RISK_CLASS_JSON:-[]}" \
'{
pr: $pr,
changes: $changes,
languages: $languages,
frameworks: $frameworks,
test_setup: $test_setup,
build_system: $build_system,
change_categories: $change_categories,
impact_analysis: $impact_analysis,
security_sensitive: $security_sensitive,
needs_security_review: $needs_security_review,
uses_mac_ui: $uses_mac_ui,
mac_ui_ref_repo: $mac_ui_ref_repo,
risk_class: $risk_class
}' > "$OUTPUT_DIR/pr-analysis-${PR_NUMBER}.json"
Step 10: Provide Summary to User
Display human-readable summary.
✅ PR Analysis Complete
PR: #123 - Add user authentication
Files changed: 15 (+450, -120)
Languages:
- Python (85%)
- JavaScript (10%)
- Shell (5%)
Frameworks:
- Django
- Pytest
Test Setup:
- Framework: pytest
- Command: pytest
- Can run safely: ✅
- Test files: 1
Impact Areas:
- 🔴 High: authentication, security
- 🟡 Medium: API endpoints
- 🟢 Low: documentation
Risk classes: domain, auth, api
Security: ⚠️ Requires security review
Analysis saved to: $OUTPUT_DIR/pr-analysis-123.json
Error Handling
If gh CLI fails:
Error: Could not fetch PR. Check:
- gh is installed and authenticated
- PR URL is valid and accessible
- You have permissions to view this PR
If analysis is incomplete:
- Still generate JSON with available data
- Mark missing fields as
null - Prefer
risk_class: []over omitting the key - Note in summary which analysis steps failed
Notes
- Does NOT modify code or run tests - only analyzes
- All analysis read-only (safe to run on any PR)
- Output JSON designed to be consumed by other skills
- Can be run standalone or as part of review
- Routing consumers: orchestrator +
shared/risk-class-routing.md
04 同仓库更多 Skills
writing-design-docs
Use when the user wants to write a problem-statement design doc, says "let's plan a feature properly" / "write a design doc" / "I'm thinking about how to do X" for a non-trivial X, or before committing to a non-obvious technical direction
write-doc
Use when the user asks to write or draft a README, ADR, runbook, tutorial, how-to, explanation, or reference doc, or a caller passes "type ADR" or "type README". Picks the type, fills a template, adds diagrams. RFCs and design docs belong to writing-design-docs.
review-doc
Use when the user asks to review, critique, score, grade, or "how good is this doc" for a Markdown doc or pasted text. Read-only. Scores it on the 20 Practical Prose dimensions and emits a findings table. Does not edit; fix-doc applies the findings next.
fix-doc
Use when the user asks to fix, edit for prose quality, polish, tighten, humanize, or de-slop a Markdown doc or pasted text, or says "make this read less AI". Applies review-doc findings, generates flagged diagrams, lists substantive issues for the author, then runs the AI-tell pass last. Modifies the target.
create-slides
Use when the user asks for a slide deck, presentation, talk, or slides from a document, report, PR, notes, or topic. Builds one self-contained Machinify-branded HTML deck in a minimalist style, with headline-plus-visual slides, speaker notes, and every diagram drawn by architecture-design:create-diagram.
start-session
Open a Claude Code working session in a fresh, isolated git worktree, so the user can start a task with a single /start-session <name>. Use at the START of a session when the user says "start session", "start a worktree", "spin up a worktree for ABC-123", "begin work on <ticket>", or passes a name/ticket to work under. Creates and ENTERS a worktree via the EnterWorktree tool (never `git worktree add`) under .claude/worktrees/, named exactly after the argument, on a local branch `worktree-<argument>`. Reports what the worktree inherited (`.worktreeinclude` copies, symlinked node_modules) and whether its `.env` still points at the main checkout's stack. If the argument is a JIRA key (e.g. ABC-123, PROJ-1505), also loads that story with the Atlassian CLI (`acli`) when available and summarizes the implementation ask. Also renames the session to the argument (the same effect as `/rename <NAME>`) so it's easy to find in `/resume`. Then stops and waits — it sets up the workspace and context, it does not implement.