1---2name: generate-custom-instructions-from-codebase-23description: Generate GitHub Copilot migration and code-evolution instructions by comparing branches, commits, tags, or releases and extracting transformation rules. Use when the user is doing framework upgrades, architecture refactors, technology migrations, dependency updates, pattern changes, API changes, obsolete pattern avoidance, and preserving project conventions during future code modifications.4---56# Generate custom instructions from codebase78Compare two project states, extract real before/after transformation patterns, and write `.github/copilot-migration-instructions.md` so GitHub Copilot can preserve the migration's conventions in future edits.910## When to invoke1112- "Generate Copilot instructions from this migration branch."13- "Compare these commits and document the new conventions."14- "Create migration instructions for our framework upgrade."15- "Teach GitHub Copilot to avoid obsolete patterns after this refactor."16- "Build a before/after API correspondence guide from the codebase."1718## Inputs1920Use `$ARGUMENTS` for the migration configuration. Required values are `MIGRATION_TYPE`, `SOURCE_REFERENCE`, and `TARGET_REFERENCE`; optional values are `ANALYSIS_SCOPE`, `CHANGE_FOCUS`, `AUTOMATION_LEVEL`, `GENERATE_EXAMPLES`, and `VALIDATION_REQUIRED`.2122## Configuration model2324| Variable | Allowed values | Purpose |25| --- | --- | --- |26| `MIGRATION_TYPE` | `Framework Version`, `Architecture Refactoring`, `Technology Migration`, `Dependencies Update`, `Pattern Changes` | Defines the migration lens. |27| `SOURCE_REFERENCE` | `branch`, `commit`, `tag` | Before-state reference. |28| `TARGET_REFERENCE` | `branch`, `commit`, `tag` | After-state reference. |29| `ANALYSIS_SCOPE` | `Entire project`, `Specific folder`, `Modified files only` | Limits the comparison. |30| `CHANGE_FOCUS` | `Breaking Changes`, `New Conventions`, `Obsolete Patterns`, `API Changes`, `Configuration` | Prioritizes findings. |31| `AUTOMATION_LEVEL` | `Conservative`, `Balanced`, `Aggressive` | Controls how confidently instructions should automate future suggestions. |32| `GENERATE_EXAMPLES` | `true`, `false` | Includes before/after transformations. |33| `VALIDATION_REQUIRED` | `true`, `false` | Marks transformations that require checks before application. |3435## Procedure36371. Resolve `SOURCE_REFERENCE` and `TARGET_REFERENCE` to concrete commits, branches, or tags.382. Compare folder structure and detect moved, renamed, deleted, and added files.393. Analyze configuration changes, new dependencies, and removed dependencies.404. Extract code transformation patterns based on `MIGRATION_TYPE` and `CHANGE_FOCUS`.415. Build a before/after correspondence matrix with mandatory transformations, validation-required transformations, API mappings, new patterns, and obsolete patterns.426. Generate `.github/copilot-migration-instructions.md` with examples when `GENERATE_EXAMPLES=true`.437. Test the instructions against representative changed code, then adjust rules and exceptions.4445## Migration analysis focus4647| Migration type | Extract |48| --- | --- |49| Framework Version | API changes, new features being used, obsolete methods/properties, syntax or convention changes. |50| Architecture Refactoring | Architectural pattern changes, new abstractions, responsibility reorganization, data flow changes. |51| Technology Migration | Functional equivalences, API and syntax changes, new dependencies, configuration changes. |52| Dependencies Update | Package replacements, version constraints, import changes, config changes, compatibility rules. |53| Pattern Changes | Repetitive transformations, old/new format rules, exceptions, and special cases. |5455## Instruction sections5657| Section | Include |58| --- | --- |59| Migration Context | `MIGRATION_TYPE`, `SOURCE_REFERENCE`, `TARGET_REFERENCE`, `GENERATION_DATE`, and `ANALYSIS_SCOPE`. |60| Mandatory Transformations | `AUTOMATIC_TRANSFORMATION_RULES` with `OLD_CODE`, `NEW_CODE`, trigger, and action when `AUTOMATION_LEVEL` is not `Conservative`. |61| Transformations with Validation | `TRANSFORMATIONS_WITH_VALIDATION`, `NEW_APPROACH`, `VALIDATION_CRITERIA`, and `ALTERNATIVE_OPTIONS` when `VALIDATION_REQUIRED=true`. |62| API Correspondences | `API_CORRESPONDENCE_TABLE` with `OLD_API`, `NEW_API`, changes, and `CODE_EXAMPLE` when `CHANGE_FOCUS=API Changes` or `MIGRATION_TYPE=Framework Version`. |63| New Patterns to Adopt | `DETECTED_EMERGING_PATTERNS`, `PATTERN_NAME`, `WHEN_TO_USE`, `HOW_TO_IMPLEMENT`, and benefits. |64| Obsolete Patterns to Avoid | `DETECTED_OBSOLETE_PATTERNS`, `OLD_PATTERN`, why avoid, `NEW_PATTERN`, and `CONVERSION_STEPS`. |65| File Type Specific Instructions | `CONFIG_TRANSFORMATION_EXAMPLES`, `SOURCE_TRANSFORMATION_EXAMPLES`, and `TEST_TRANSFORMATION_EXAMPLES` when `GENERATE_EXAMPLES=true`. |66| Validation and Security | Automatic control points plus manual escalation for `COMPLEX_CASES_LIST`, `ARCHITECTURAL_DECISIONS`, and `BUSINESS_IMPACTS`. |67| Migration Monitoring | Migration percentage, manual validations, automatic transformation error rate, and average migration time per file. |6869## Generated file template7071```markdown72# GitHub Copilot Migration Instructions7374## Migration Context75- **Type**: <MIGRATION_TYPE>76- **From**: <SOURCE_REFERENCE>77- **To**: <TARGET_REFERENCE>78- **Date**: <GENERATION_DATE>79- **Scope**: <ANALYSIS_SCOPE>8081## Automatic Transformation Rules8283### 1. Mandatory Transformations84- **Old Pattern**: <OLD_CODE>85- **New Pattern**: <NEW_CODE>86- **Trigger**: <when to detect this pattern>87- **Action**: <transformation to apply automatically>8889### 2. Transformations with Validation90- **Detected Pattern**: <description>91- **Suggested Transformation**: <NEW_APPROACH>92- **Required Validation**: <VALIDATION_CRITERIA>93- **Alternatives**: <ALTERNATIVE_OPTIONS>9495### 3. API Correspondences96| Old API | New API | Notes | Example |97| --- | --- | --- | --- |98| <OLD_API> | <NEW_API> | <changes> | <CODE_EXAMPLE> |99100### 4. New Patterns to Adopt101- **Pattern**: <PATTERN_NAME>102- **Usage**: <WHEN_TO_USE>103- **Implementation**: <HOW_TO_IMPLEMENT>104- **Benefits**: <advantages>105106### 5. Obsolete Patterns to Avoid107- **Obsolete Pattern**: <OLD_PATTERN>108- **Why Avoid**: <reasons>109- **Alternative**: <NEW_PATTERN>110- **Migration**: <CONVERSION_STEPS>111112## File Type Specific Instructions113114### Configuration Files115<CONFIG_TRANSFORMATION_EXAMPLES>116117### Main Source Files118<SOURCE_TRANSFORMATION_EXAMPLES>119120### Test Files121<TEST_TRANSFORMATION_EXAMPLES>122123## Validation and Security124125### Automatic Control Points126- <tests, performance metrics, compatibility checks>127128### Manual Escalation129- <COMPLEX_CASES_LIST>130- <ARCHITECTURAL_DECISIONS>131- <BUSINESS_IMPACTS>132133## Migration Monitoring134135### Tracking Metrics136- Percentage of code automatically migrated137- Number of manual validations required138- Error rate of automatic transformations139- Average migration time per file140141### Error Reporting142- Feedback patterns to improve rules143- Exceptions to document144- Adjustments to make to instructions145```146147## Transformation example format148149```text150// BEFORE (<SOURCE_REFERENCE>)151<OLD_CODE_EXAMPLE>152153// AFTER (<TARGET_REFERENCE>)154<NEW_CODE_EXAMPLE>155156// COPILOT INSTRUCTIONS157When you see this pattern <trigger>, transform it to <NEW_PATTERN> following these steps: <steps>.158```159160## Typical use cases161162| Use case | Good output |163| --- | --- |164| Framework Version Migration | Angular 14 to Angular 17, React Class Components to Hooks, .NET Framework to .NET Core rules with breaking changes. |165| Technology Stack Evolution | jQuery to React, REST to GraphQL, SQL to NoSQL functional mappings. |166| Architecture Refactoring | Monolith to Microservices, MVC to Clean Architecture, Component to Composable architecture. |167| Design Pattern Modernization | Repository Pattern, Dependency Injection, Observer to Reactive Programming adoption guidance. |168169## Criteria170171- [ ] Instructions are based on actual diffs, not generic migration advice.172- [ ] Automatic rules are only used when the old pattern has a reliable trigger and deterministic replacement.173- [ ] Validation-required transformations name concrete tests, compatibility checks, or manual review criteria.174- [ ] API correspondence entries preserve old/new names and examples from the codebase.175- [ ] Obsolete patterns explain why they are wrong and what to use instead.176- [ ] Security and business-impact changes are escalated for human review.177178## Migration placeholders179180Preserve placeholders used by generated migration instructions: `ADVANTAGES`, `CHANGES`, `DESCRIPTION`, `REASONS`, `STEPS`, `TRIGGER`, and `cross-version`.181182## Output template183184```markdown185## Copilot migration instructions result186187**Status:** generated | needs validation | blocked188**Output file:** `.github/copilot-migration-instructions.md`189**Migration:** `<MIGRATION_TYPE>` from `<SOURCE_REFERENCE>` to `<TARGET_REFERENCE>`190191### Patterns extracted192| Category | Count | Examples |193| --- | --- | --- |194| Mandatory transformations | <count> | <summary> |195| Transformations with validation | <count> | <summary> |196| API correspondences | <count> | <summary> |197| New patterns | <count> | <summary> |198| Obsolete patterns | <count> | <summary> |199200### Validation201- Test application on sample code: pass | fail | not run202- Exceptions documented: pass | fail203- Manual escalations listed: pass | fail204```205206## Quality gate207208- [ ] `MIGRATION_TYPE`, `SOURCE_REFERENCE`, `TARGET_REFERENCE`, `ANALYSIS_SCOPE`, `CHANGE_FOCUS`, `AUTOMATION_LEVEL`, `GENERATE_EXAMPLES`, and `VALIDATION_REQUIRED` are recorded.209- [ ] `.github/copilot-migration-instructions.md` is generated with migration context and transformation rules.210- [ ] API mappings retain `OLD_API`, `NEW_API`, and `CODE_EXAMPLE` when API changes are in scope.211- [ ] Examples include `OLD_CODE_EXAMPLE` and `NEW_CODE_EXAMPLE` when requested.212- [ ] `COMPLEX_CASES_LIST`, `ARCHITECTURAL_DECISIONS`, and `BUSINESS_IMPACTS` are escalated instead of automated.213- [ ] Validation and monitoring guidance is concrete enough for future GitHub Copilot edits.