create-pr
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCreate Pull Request
创建拉取请求
Comprehensive PR creation with validation. All output goes directly to GitHub PR.
带有验证机制的全面PR创建流程。所有输出直接同步至GitHub PR。
Quick Start
快速开始
bash
/create-prbash
/create-prSTEP 0: Verify User Intent with AskUserQuestion
步骤0:使用AskUserQuestion确认用户意图
BEFORE creating tasks, clarify PR type:
python
AskUserQuestion(
questions=[{
"question": "What type of PR is this?",
"header": "Type",
"options": [
{"label": "Feature (Recommended)", "description": "New functionality with full validation"},
{"label": "Bug fix", "description": "Fix for existing issue"},
{"label": "Refactor", "description": "Code improvement, no behavior change"},
{"label": "Quick", "description": "Skip validation, just create PR"}
],
"multiSelect": false
}]
)Based on answer, adjust workflow:
- Feature: Full validation with all agents
- Bug fix: Focus on test verification
- Refactor: Skip new feature validation
- Quick: Skip all validation, just create PR
在创建任务之前,请明确PR类型:
python
AskUserQuestion(
questions=[{
"question": "What type of PR is this?",
"header": "Type",
"options": [
{"label": "Feature (Recommended)", "description": "New functionality with full validation"},
{"label": "Bug fix", "description": "Fix for existing issue"},
{"label": "Refactor", "description": "Code improvement, no behavior change"},
{"label": "Quick", "description": "Skip validation, just create PR"}
],
"multiSelect": false
}]
)根据回答调整工作流:
- Feature(功能新增):使用所有Agent进行完整验证
- Bug fix(BUG修复):重点进行测试验证
- Refactor(代码重构):跳过新功能验证
- Quick(快速创建):跳过所有验证,直接创建PR
⚠️ CRITICAL: Task Management is MANDATORY (CC 2.1.16)
⚠️ 关键要求:任务管理是强制性的(CC 2.1.16)
BEFORE doing ANYTHING else, create tasks to show progress:
python
undefined在执行任何操作之前,请先创建任务以展示进度:
python
undefined1. Create main PR task IMMEDIATELY
1. 立即创建主PR任务
TaskCreate(
subject="Create PR for {branch}",
description="PR creation with parallel validation agents",
activeForm="Creating pull request"
)
TaskCreate(
subject="Create PR for {branch}",
description="PR creation with parallel validation agents",
activeForm="Creating pull request"
)
2. Create subtasks for phases
2. 为各个阶段创建子任务
TaskCreate(subject="Pre-flight checks", activeForm="Running pre-flight checks")
TaskCreate(subject="Run parallel validation agents", activeForm="Validating with agents")
TaskCreate(subject="Run local tests", activeForm="Running local tests")
TaskCreate(subject="Create PR on GitHub", activeForm="Creating GitHub PR")
TaskCreate(subject="Pre-flight checks", activeForm="Running pre-flight checks")
TaskCreate(subject="Run parallel validation agents", activeForm="Validating with agents")
TaskCreate(subject="Run local tests", activeForm="Running local tests")
TaskCreate(subject="Create PR on GitHub", activeForm="Creating GitHub PR")
3. Update status as you progress
3. 随着进度更新状态
TaskUpdate(taskId="2", status="in_progress") # When starting phase
TaskUpdate(taskId="2", status="completed") # When phase done
---TaskUpdate(taskId="2", status="in_progress") # 开始阶段时
TaskUpdate(taskId="2", status="completed") # 阶段完成时
---Workflow
工作流
Phase 1: Pre-Flight Checks
阶段1:预检检查
bash
undefinedbash
undefinedVerify branch
Verify branch
BRANCH=$(git branch --show-current)
if [[ "$BRANCH" == "dev" || "$BRANCH" == "main" ]]; then
echo "Cannot create PR from dev/main. Create a feature branch first."
exit 1
fi
BRANCH=$(git branch --show-current)
if [[ "$BRANCH" == "dev" || "$BRANCH" == "main" ]]; then
echo "Cannot create PR from dev/main. Create a feature branch first."
exit 1
fi
Check for uncommitted changes
Check for uncommitted changes
if [[ -n $(git status --porcelain) ]]; then
echo "Uncommitted changes detected. Commit or stash first."
exit 1
fi
if [[ -n $(git status --porcelain) ]]; then
echo "Uncommitted changes detected. Commit or stash first."
exit 1
fi
Push branch if needed
Push branch if needed
git fetch origin
if ! git rev-parse --verify origin/$BRANCH &>/dev/null; then
git push -u origin $BRANCH
fi
undefinedgit fetch origin
if ! git rev-parse --verify origin/$BRANCH &>/dev/null; then
git push -u origin $BRANCH
fi
undefinedPhase 2: Parallel Pre-PR Validation (3 Agents)
阶段2:PR创建前的并行验证(3个Agent)
Launch validation agents in ONE message BEFORE creating PR:
python
undefined在创建PR前,通过一条消息启动所有验证Agent:
python
undefinedPARALLEL - All 3 in ONE message
PARALLEL - All 3 in ONE message
Task(
subagent_type="security-auditor",
prompt="""Security audit for PR changes:
- Check for secrets/credentials in diff
- Dependency vulnerabilities (npm audit/pip-audit)
- OWASP Top 10 quick scan Return: {status: PASS/BLOCK, issues: [...]}
Scope: ONLY read files directly relevant to the PR diff. Do NOT explore the entire codebase.
SUMMARY: End with: "RESULT: [PASS|WARN|BLOCK] - [N] issues: [brief list or 'clean']"
""",
run_in_background=True,
max_turns=25
)
Task(
subagent_type="test-generator",
prompt="""Test coverage verification:
- Run test suite with coverage
- Identify untested code in changed files Return: {coverage: N%, passed: N/N, gaps: [...]}
Scope: ONLY read files directly relevant to the PR diff. Do NOT explore the entire codebase.
SUMMARY: End with: "RESULT: [N]% coverage, [passed]/[total] tests - [status]"
""",
run_in_background=True,
max_turns=25
)
Task(
subagent_type="code-quality-reviewer",
prompt="""Code quality check:
- Run linting (ruff/eslint)
- Type checking (mypy/tsc)
- Check for anti-patterns Return: {lint_errors: N, type_errors: N, issues: [...]}
Scope: ONLY read files directly relevant to the PR diff. Do NOT explore the entire codebase.
SUMMARY: End with: "RESULT: [PASS|WARN|FAIL] - [N] lint, [M] type errors"
""",
run_in_background=True,
max_turns=25
)
Wait for agents, then run local validation:
```bashTask(
subagent_type="security-auditor",
prompt="""Security audit for PR changes:
- Check for secrets/credentials in diff
- Dependency vulnerabilities (npm audit/pip-audit)
- OWASP Top 10 quick scan Return: {status: PASS/BLOCK, issues: [...]}
Scope: ONLY read files directly relevant to the PR diff. Do NOT explore the entire codebase.
SUMMARY: End with: "RESULT: [PASS|WARN|BLOCK] - [N] issues: [brief list or 'clean']"
""",
run_in_background=True,
max_turns=25
)
Task(
subagent_type="test-generator",
prompt="""Test coverage verification:
- Run test suite with coverage
- Identify untested code in changed files Return: {coverage: N%, passed: N/N, gaps: [...]}
Scope: ONLY read files directly relevant to the PR diff. Do NOT explore the entire codebase.
SUMMARY: End with: "RESULT: [N]% coverage, [passed]/[total] tests - [status]"
""",
run_in_background=True,
max_turns=25
)
Task(
subagent_type="code-quality-reviewer",
prompt="""Code quality check:
- Run linting (ruff/eslint)
- Type checking (mypy/tsc)
- Check for anti-patterns Return: {lint_errors: N, type_errors: N, issues: [...]}
Scope: ONLY read files directly relevant to the PR diff. Do NOT explore the entire codebase.
SUMMARY: End with: "RESULT: [PASS|WARN|FAIL] - [N] lint, [M] type errors"
""",
run_in_background=True,
max_turns=25
)
等待Agent完成,然后运行本地验证:
```bashBackend
Backend
cd backend
poetry run ruff format --check app/
poetry run ruff check app/
poetry run pytest tests/unit/ -v --tb=short -x
cd backend
poetry run ruff format --check app/
poetry run ruff check app/
poetry run pytest tests/unit/ -v --tb=short -x
Frontend
Frontend
cd ../frontend
npm run lint && npm run typecheck
undefinedcd ../frontend
npm run lint && npm run typecheck
undefinedPhase 3: Gather Context
阶段3:收集上下文信息
bash
BRANCH=$(git branch --show-current)
ISSUE=$(echo $BRANCH | grep -oE '[0-9]+' | head -1)
git log --oneline dev..HEAD
git diff dev...HEAD --statbash
BRANCH=$(git branch --show-current)
ISSUE=$(echo $BRANCH | grep -oE '[0-9]+' | head -1)
git log --oneline dev..HEAD
git diff dev...HEAD --statPhase 4: Create PR
阶段4:创建PR
bash
TYPE="feat" # Determine: feat/fix/refactor/docs/test/chore
gh pr create --base dev \
--title "$TYPE(#$ISSUE): Brief description" \
--body "## Summary
[1-2 sentence description]bash
TYPE="feat" # Determine: feat/fix/refactor/docs/test/chore
gh pr create --base dev \
--title "$TYPE(#$ISSUE): Brief description" \
--body "## Summary
[1-2 sentence description]Changes
Changes
- [Change 1]
- [Change 2]
- [Change 1]
- [Change 2]
Test Plan
Test Plan
Phase 5: Verify
阶段5:验证
bash
PR_URL=$(gh pr view --json url -q .url)
echo "PR created: $PR_URL"
gh pr view --webbash
PR_URL=$(gh pr view --json url -q .url)
echo "PR created: $PR_URL"
gh pr view --webCC 2.1.27+ Enhancements
CC 2.1.27+ 增强功能
Auto PR Linking
自动PR关联
Sessions created via are now automatically linked to the PR. Use to resume sessions linked to a specific PR:
gh pr create--from-pr <number|url>bash
claude --from-pr 123 # Resume session linked to PR #123
claude --from-pr https://github.com/org/repo/pull/123This means PR context (diff, comments, review status) is available when resuming.
通过创建的会话现在会自动关联到对应的PR。使用可以恢复与特定PR关联的会话:
gh pr create--from-pr <number|url>bash
claude --from-pr 123 # Resume session linked to PR #123
claude --from-pr https://github.com/org/repo/pull/123这意味着恢复会话时可以获取到PR的上下文信息(代码差异、评论、评审状态)。
Task Metrics (CC 2.1.30)
任务指标(CC 2.1.30)
Task tool results now include , , and . Report validation efficiency:
token_counttool_usesduration_msmarkdown
undefined任务工具的结果现在包含、和字段。可以报告验证效率:
token_counttool_usesduration_msmarkdown
undefinedPre-PR Validation Metrics
Pre-PR Validation Metrics
| Agent | Tokens | Tools | Duration |
|---|---|---|---|
| security-auditor | 520 | 10 | 15s |
| test-generator | 380 | 6 | 12s |
| code-quality-reviewer | 450 | 8 | 10s |
Total: 1,350 tokens in 37s
undefined| Agent | Tokens | Tools | Duration |
|---|---|---|---|
| security-auditor | 520 | 10 | 15s |
| test-generator | 380 | 6 | 12s |
| code-quality-reviewer | 450 | 8 | 10s |
Total: 1,350 tokens in 37s
undefinedSession Resume Hints (CC 2.1.31)
会话恢复提示(CC 2.1.31)
At session end, Claude shows resume hints. Before ending PR creation sessions:
bash
undefined会话结束时,Claude会显示恢复提示。在结束PR创建会话之前:
bash
undefinedStore PR context for future sessions
Store PR context for future sessions
/ork:remember PR #123 created: [brief description], pending review from [team]
undefined/ork:remember PR #123 created: [brief description], pending review from [team]
undefinedRules
规则
- NO junk files - Don't create files in repo root
- Run validation locally - Don't spawn agents for lint/test
- All content goes to GitHub - PR body via
gh pr create --body - Keep it simple - One command to create PR
- 禁止生成无用文件 - 不要在仓库根目录创建文件
- 本地运行验证 - 不要为lint/测试任务启动Agent
- 所有内容同步至GitHub - 通过提交PR正文
gh pr create --body - 保持简洁 - 使用单一命令创建PR
Agent Usage
Agent使用规范
Only use Task agents for:
- Complex code analysis requiring multiple files
- Security review of sensitive changes
- Architecture review for large refactors
仅在以下场景使用Task Agent:
- 需要分析多个文件的复杂代码分析
- 敏感变更的安全评审
- 大型重构的架构评审
Related Skills
相关技能
- commit: Create commits before PRs
- review-pr: Review PRs after creation
- commit: 创建PR前的代码提交
- review-pr: PR创建后的评审
References
参考资料
- PR Template
- PR模板