generate-custom-instructions-from-codebase
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseMigration and Code Evolution Instructions Generator
迁移与代码演进指令生成器
Configuration Variables
配置变量
${MIGRATION_TYPE="Framework Version|Architecture Refactoring|Technology Migration|Dependencies Update|Pattern Changes"}
<!-- Type of migration or evolution -->
${SOURCE_REFERENCE="branch|commit|tag"}
<!-- Source reference point (before state) -->
${TARGET_REFERENCE="branch|commit|tag"}
<!-- Target reference point (after state) -->
${ANALYSIS_SCOPE="Entire project|Specific folder|Modified files only"}
<!-- Scope of analysis -->
${CHANGE_FOCUS="Breaking Changes|New Conventions|Obsolete Patterns|API Changes|Configuration"}
<!-- Main aspect of changes -->
${AUTOMATION_LEVEL="Conservative|Balanced|Aggressive"}
<!-- Level of automation for Copilot suggestions -->
${GENERATE_EXAMPLES="true|false"}
<!-- Include transformation examples -->
${VALIDATION_REQUIRED="true|false"}
<!-- Require validation before application -->${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"}
<!-- Copilot建议的自动化程度 -->
${GENERATE_EXAMPLES="true|false"}
<!-- 是否包含转换示例 -->
${VALIDATION_REQUIRED="true|false"}
<!-- 是否需要在应用前进行验证 -->Generated Prompt
生成的提示词
"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:"分析项目两个状态之间的代码演进,为GitHub Copilot生成精准的迁移指令。这些指令将指导Copilot在未来的代码修改中自动应用相同的转换模式。请遵循以下方法:Phase 1: Comparative State Analysis
阶段1:对比状态分析
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
- 对比${SOURCE_REFERENCE}与${TARGET_REFERENCE}的目录结构
- 识别被移动、重命名或删除的文件
- 分析配置文件的变更
- 记录新增和移除的依赖
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" : ""}
${MIGRATION_TYPE == "Framework Version" ?
"- 识别框架版本间的API变更
- 分析正在使用的新特性
- 记录已废弃的方法/属性
- 标注语法或约定的变更" : ""}
${MIGRATION_TYPE == "Architecture Refactoring" ?
"- 分析架构模式的变更
- 识别引入的新抽象层
- 记录职责划分的调整
- 标注数据流的变更" : ""}
${MIGRATION_TYPE == "Technology Migration" ?
"- 分析技术栈的替换情况
- 识别功能等价点
- 记录API和语法的变更
- 标注新增的依赖和配置" : ""}
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
阶段2:迁移指令生成
Create a file with this structure:
.github/copilot-migration-instructions.md```markdown
创建一个文件,结构如下:
.github/copilot-migration-instructions.md```markdown
GitHub Copilot Migration Instructions
GitHub Copilot 迁移指令
Migration Context
迁移背景
- Type: ${MIGRATION_TYPE}
- From: ${SOURCE_REFERENCE}
- To: ${TARGET_REFERENCE}
- Date: [GENERATION_DATE]
- Scope: ${ANALYSIS_SCOPE}
- 类型:${MIGRATION_TYPE}
- 从:${SOURCE_REFERENCE}
- 到:${TARGET_REFERENCE}
- 日期:[生成日期]
- 范围:${ANALYSIS_SCOPE}
Automatic Transformation Rules
自动转换规则
1. Mandatory Transformations
1. 强制转换规则
${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" : ""}
${AUTOMATION_LEVEL != "Conservative" ?
"[自动转换规则]
- 旧模式:[旧代码]
- 新模式:[新代码]
- 触发条件:何时检测该模式
- 操作:自动应用的转换步骤" : ""}
2. Transformations with Validation
2. 需要验证的转换规则
${VALIDATION_REQUIRED == "true" ?
"[TRANSFORMATIONS_WITH_VALIDATION]
- Detected Pattern: [DESCRIPTION]
- Suggested Transformation: [NEW_APPROACH]
- Required Validation: [VALIDATION_CRITERIA]
- Alternatives: [ALTERNATIVE_OPTIONS]" : ""}
${VALIDATION_REQUIRED == "true" ?
"[需验证的转换规则]
- 检测到的模式:[描述]
- 建议的转换方式:[新方案]
- 所需验证:[验证标准]
- 替代方案:[可选选项]" : ""}
3. API Correspondences
3. API对应表
${CHANGE_FOCUS == "API Changes" || MIGRATION_TYPE == "Framework Version" ?
"[API_CORRESPONDENCE_TABLE]
| Old API | New API | Notes | Example |
|---|---|---|---|
| [OLD_API] | [NEW_API] | [CHANGES] | [CODE_EXAMPLE] |
${CHANGE_FOCUS == "API Changes" || MIGRATION_TYPE == "Framework Version" ?
"[API对应表]
| 旧API | 新API | 说明 | 示例 |
|---|---|---|---|
| [旧API] | [新API] | [变更点] | [代码示例] |
4. New Patterns to Adopt
4. 需采用的新模式
[DETECTED_EMERGING_PATTERNS]
- Pattern: [PATTERN_NAME]
- Usage: [WHEN_TO_USE]
- Implementation: [HOW_TO_IMPLEMENT]
- Benefits: [ADVANTAGES]
[已识别的新兴模式]
- 模式:[模式名称]
- 适用场景:[何时使用]
- 实现方式:[如何实现]
- 优势:[好处]
5. Obsolete Patterns to Avoid
5. 需避免的废弃模式
[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]" : ""}
${GENERATE_EXAMPLES == "true" ?
"### 配置文件
[配置文件转换示例]
核心源文件
[源文件转换示例]
测试文件
[测试文件转换示例]" : ""}
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
```
如何向Copilot报告错误的转换:
- 用于优化规则的反馈模式
- 需记录的例外情况
- 对指令的调整建议
```
Phase 3: Contextual Examples Generation
阶段3:上下文示例生成
${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]
```" : ""}
${GENERATE_EXAMPLES == "true" ?
"#### 转换示例
针对每个识别到的模式,生成:
```
// 迁移前(${SOURCE_REFERENCE})
[旧代码示例]
// 迁移后(${TARGET_REFERENCE})
[新代码示例]
// Copilot 指令
当你检测到该模式[触发条件]时,按照以下步骤转换为[新模式]:[步骤]
```" : ""}
Phase 4: Validation and Optimization
阶段4:验证与优化
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" : ""}
${AUTOMATION_LEVEL == "Aggressive" ?
"- 细化规则以最大化自动化程度
- 减少检测中的误报
- 提升转换的准确性
- 记录经验总结" : ""}
Final Result
最终成果
Migration instructions that enable GitHub Copilot to:
- Automatically apply the same transformations during future modifications
- Maintain consistency with newly adopted conventions
- Avoid obsolete patterns by automatically proposing alternatives
- Accelerate future migrations by capitalizing on acquired experience
- 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.
"
undefined迁移指令可让GitHub Copilot实现:
- 自动应用:在未来的代码修改中自动执行相同的转换
- 保持一致性:与新采用的开发约定对齐
- 避免废弃模式:自动推荐替代方案
- 加速后续迁移:复用已积累的迁移经验
- 减少错误:自动化重复的转换操作
这些指令将Copilot转变为智能迁移助手,能够一致、可靠地复现你的技术演进决策。
"
undefinedTypical Use Cases
典型用例
Framework Version Migration
框架版本迁移
Perfect for documenting the transition from Angular 14 to Angular 17, React Class Components to Hooks, or .NET Framework to .NET Core. Automatically identifies breaking changes and generates corresponding transformation rules.
适用于记录从Angular 14到Angular 17、React类组件到Hooks、.NET Framework到.NET Core的过渡。自动识别破坏性变更并生成对应的转换规则。
Technology Stack Evolution
技术栈演进
Essential when replacing a technology entirely: jQuery to React, REST to GraphQL, SQL to NoSQL. Creates a comprehensive migration guide with pattern mappings.
在完全替换技术栈时必不可少:如jQuery到React、REST到GraphQL、SQL到NoSQL。创建包含模式映射的完整迁移指南。
Architecture Refactoring
架构重构
Ideal for large refactorings like Monolith to Microservices, MVC to Clean Architecture, or Component to Composable architecture. Preserves architectural knowledge for future similar transformations.
适用于大型重构场景,如单体应用到微服务、MVC到整洁架构、组件化到可组合架构。保留架构知识,用于未来类似的转换。
Design Pattern Modernization
设计模式现代化
Useful for adopting new patterns: Repository Pattern, Dependency Injection, Observer to Reactive Programming. Documents the rationale and implementation differences.
适用于采用新设计模式的场景:如仓储模式、依赖注入、观察者模式到响应式编程。记录设计思路和实现差异。
Unique Benefits
独特优势
🧠 Artificial Intelligence Enhancement
🧠 人工智能增强
Unlike traditional migration documentation, these instructions "train" GitHub Copilot to reproduce your technology evolution decisions automatically during future code modifications.
与传统迁移文档不同,这些指令会“训练”GitHub Copilot,使其在未来的代码修改中自动复现你的技术演进决策。
🔄 Knowledge Capitalization
🔄 知识沉淀
Transforms specific project experience into reusable rules, avoiding the loss of migration expertise and accelerating future similar transformations.
将特定项目的经验转化为可复用的规则,避免迁移专业知识的流失,加速未来类似的转换工作。
🎯 Context-Aware Precision
🎯 上下文感知的精准性
Instead of generic advice, generates instructions tailored to your specific codebase, with real before/after examples from your project evolution.
不提供通用建议,而是生成针对你的代码库量身定制的指令,包含项目演进过程中真实的前后示例。
⚡ Automated Consistency
⚡ 自动化一致性
Ensures that new code additions automatically follow the new conventions, preventing architectural regression and maintaining code evolution coherence.
确保新增代码自动遵循新的开发约定,防止架构退化,保持代码演进的连贯性。