关于 generate-custom-instructions-from-codebase
此技能比较代码库的两个状态,并将迁移或重构模式整理为适用于 GitHub Copilot 的定制指令,帮助团队在后续代码修改中延续项目特定的变更方式。
主要功能
- 01比较源代码与目标代码状态
- 02识别结构和配置变更
- 03生成针对代码库的迁移指令
- 04为 Copilot 记录转换模式
适用场景
- 01记录框架版本迁移
- 02规划技术替换时的模式映射
- 03记录架构重构决策
- 04指导采用更新后的设计模式
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ github/ awesome-copilot --skill generate-custom-instructions-from-codebase安装后在 Claude Code 中输入/generate-custom-instructions-from-codebase确认已加载。
详细介绍
迁移与代码演进指令生成器
配置变量
${MIGRATION_TYPE="Framework Version|Architecture Refactoring|Technology Migration|Dependencies Update|Pattern Changes"}
${SOURCE_REFERENCE="branch|commit|tag"}
${TARGET_REFERENCE="branch|commit|tag"}
${ANALYSIS_SCOPE="Entire project|Specific folder|Modified files only"}
${CHANGE_FOCUS="Breaking Changes|New Conventions|Obsolete Patterns|API Changes|Configuration"}
${AUTOMATION_LEVEL="Conservative|Balanced|Aggressive"}
${GENERATE_EXAMPLES="true|false"}
${VALIDATION_REQUIRED="true|false"}
生成的提示词
"Analyze code evolution between two project states to generate precise migration instructions for GitHub Copilot. These instructions will guide Copilot to automatically apply the same transformation patterns during future modifications. Follow this methodology:
### Phase 1: Comparative State Analysis
#### Structural Changes Detection
- Compare folder structure between ${SOURCE_REFERENCE} and ${TARGET_REFERENCE}
- Identify moved, renamed, or deleted files
- Analyze changes in configuration files
- Document new dependencies and removed ones
#### Code Transformation Analysis
${MIGRATION_TYPE == "Framework Version" ?
"- Identify API changes between framework versions
- Analyze new features being used
- Document obsolete methods/properties
- Note syntax or convention changes" : ""}
${MIGRATION_TYPE == "Architecture Refactoring" ?
"- Analyze architectural pattern changes
- Identify new abstractions introduced
- Document responsibility reorganization
- Note changes in data flows" : ""}
${MIGRATION_TYPE == "Technology Migration" ?
"- Analyze replacement of one technology with another
- Identify functional equivalences
- Document API and syntax changes
- Note new dependencies and configurations" : ""}
#### Transformation Pattern Extraction
- Identify repetitive transformations applied
- Analyze conversion rules from old to new format
- Document exceptions and special cases
- Create before/after correspondence matrix
### Phase 2: Migration Instructions Generation
Create a `.github/copilot-migration-instructions.md` file with this structure:
\`\`\`markdown
# GitHub Copilot Migration Instructions
## Migration Context
- **Type**: ${MIGRATION_TYPE}
- **From**: ${SOURCE_REFERENCE}
- **To**: ${TARGET_REFERENCE}
- **Date**: [GENERATION_DATE]
- **Scope**: ${ANALYSIS_SCOPE}
## Automatic Transformation Rules
### 1. Mandatory Transformations
${AUTOMATION_LEVEL != "Conservative" ?
"[AUTOMATIC_TRANSFORMATION_RULES]
- **Old Pattern**: [OLD_CODE]
- **New Pattern**: [NEW_CODE]
- **Trigger**: When to detect this pattern
- **Action**: Transformation to apply automatically" : ""}
### 2. Transformations with Validation
${VALIDATION_REQUIRED == "true" ?
"[TRANSFORMATIONS_WITH_VALIDATION]
- **Detected Pattern**: [DESCRIPTION]
- **Suggested Transformation**: [NEW_APPROACH]
- **Required Validation**: [VALIDATION_CRITERIA]
- **Alternatives**: [ALTERNATIVE_OPTIONS]" : ""}
### 3. API Correspondences
${CHANGE_FOCUS == "API Changes" || MIGRATION_TYPE == "Framework Version" ?
"[API_CORRESPONDENCE_TABLE]
| Old API | New API | Notes | Example |
| --------- | --------- | --------- | -------------- |
| [OLD_API] | [NEW_API] | [CHANGES] | [CODE_EXAMPLE] | " : ""} |
### 4. New Patterns to Adopt
[DETECTED_EMERGING_PATTERNS]
- **Pattern**: [PATTERN_NAME]
- **Usage**: [WHEN_TO_USE]
- **Implementation**: [HOW_TO_IMPLEMENT]
- **Benefits**: [ADVANTAGES]
### 5. Obsolete Patterns to Avoid
[DETECTED_OBSOLETE_PATTERNS]
- **Obsolete Pattern**: [OLD_PATTERN]
- **Why Avoid**: [REASONS]
- **Alternative**: [NEW_PATTERN]
- **Migration**: [CONVERSION_STEPS]
## File Type Specific Instructions
${GENERATE_EXAMPLES == "true" ?
"### Configuration Files
[CONFIG_TRANSFORMATION_EXAMPLES]
### Main Source Files
[SOURCE_TRANSFORMATION_EXAMPLES]
### Test Files
[TEST_TRANSFORMATION_EXAMPLES]" : ""}
## Validation and Security
### Automatic Control Points
- Verifications to perform after each transformation
- Tests to run to validate changes
- Performance metrics to monitor
- Compatibility checks to perform
### Manual Escalation
Situations requiring human intervention:
- [COMPLEX_CASES_LIST]
- [ARCHITECTURAL_DECISIONS]
- [BUSINESS_IMPACTS]
## Migration Monitoring
### Tracking Metrics
- Percentage of code automatically migrated
- Number of manual validations required
- Error rate of automatic transformations
- Average migration time per file
### Error Reporting
How to report incorrect transformations to Copilot:
- Feedback patterns to improve rules
- Exceptions to document
- Adjustments to make to instructions
\`\`\`
### Phase 3: Contextual Examples Generation
${GENERATE_EXAMPLES == "true" ?
"#### Transformation Examples
For each identified pattern, generate:
\`\`\`
// BEFORE (${SOURCE_REFERENCE})
[OLD_CODE_EXAMPLE]
// AFTER (${TARGET_REFERENCE})
[NEW_CODE_EXAMPLE]
// COPILOT INSTRUCTIONS
When you see this pattern [TRIGGER], transform it to [NEW_PATTERN] following these steps: [STEPS]
\`\`\`" : ""}
### Phase 4: Validation and Optimization
#### Instructions Testing
- Apply instructions on test code
- Verify transformation consistency
- Adjust rules based on results
- Document exceptions and edge cases
#### Iterative Optimization
${AUTOMATION_LEVEL == "Aggressive" ?
"- Refine rules to maximize automation
- Reduce false positives in detection
- Improve transformation accuracy
- Document lessons learned" : ""}
### Final Result
Migration instructions that enable GitHub Copilot to:
1. **Automatically apply** the same transformations during future modifications
2. **Maintain consistency** with newly adopted conventions
3. **Avoid obsolete patterns** by automatically proposing alternatives
4. **Accelerate future migrations** by capitalizing on acquired experience
5. **Reduce errors** by automating repetitive transformations
These instructions transform Copilot into an intelligent migration assistant, capable of reproducing your technology evolution decisions consistently and reliably.
"
典型使用场景
框架版本迁移
非常适合记录从 Angular 14 到 Angular 17、从 React 类组件到 Hooks,或从 .NET Framework 到 .NET Core 的过渡。自动识别破坏性变更并生成相应的转换规则。
技术栈演进
在彻底替换某项技术时必不可少:从 jQuery 到 React、从 REST 到 GraphQL、从 SQL 到 NoSQL。创建包含模式映射的全面迁移指南。
架构重构
非常适合大型重构,例如从单体到微服务、从 MVC 到整洁架构,或从组件到组合式架构。为未来类似的转换保留架构知识。
设计模式现代化
适用于采用新模式:仓储模式、依赖注入、从观察者到响应式编程。记录其理由和实现差异。
独特优势
🧠 人工智能增强
与传统迁移文档不同,这些指令会“训练” GitHub Copilot,使其在未来修改代码时自动重现你的技术演进决策。
🔄 知识资本化
将特定项目经验转化为可复用规则,避免迁移专业知识流失,并加速未来类似的转换。
🎯 上下文感知的精准性
不是提供通用建议,而是生成针对你特定代码库量身定制的指令,并包含来自你项目演进过程的真实前后示例。
⚡ 自动化一致性
确保新增代码自动遵循新约定,防止架构回退并保持代码演进的一致性。
评论
支持 Markdown