| name | legacy-migration |
| description | This skill should be used when migrating features from src.legacy/ to the new kernel implementation or removing legacy code after reaching feature parity. Use for systematic legacy code removal, updating FEATURE_COMPARISON.md, verifying feature equivalence, and ensuring safe code retirement. |
Legacy Code Migration for Breenix
Systematically migrate features from legacy kernel and remove old code when parity is reached.
Purpose
Breenix is transitioning from a legacy kernel (src.legacy/) to a modern implementation (kernel/). This skill provides patterns for safely migrating features, verifying parity, and removing legacy code.
When to Use
- Feature migration: Porting legacy features to new kernel
- Parity verification: Confirming new implementation matches legacy behavior
- Legacy removal: Safely removing old code after feature completion
- Documentation updates: Keeping FEATURE_COMPARISON.md current
- Risk assessment: Evaluating what can be safely removed
Legacy Migration Principle (from CLAUDE.md)
When new implementation reaches parity:
1. Remove code from src.legacy/
2. Update FEATURE_COMPARISON.md
3. Include removal in same commit as feature completion
Key Point: Don't accumulate dead code. Remove legacy as soon as parity is reached.
Migration Workflow
Phase 1: Identify Feature for Migration
Review FEATURE_COMPARISON.md:
cat docs/planning/legacy-migration/FEATURE_COMPARISON.md | grep "❌"
cat docs/planning/legacy-migration/FEATURE_COMPARISON.md | grep "🚧"
Common patterns:
- ✅ Fully implemented (safe to remove if in both)
- 🚧 Partially implemented (needs work)
- ❌ Not implemented (needs migration or decision)
- 🔄 Different approach (verify equivalence)
Phase 2: Analyze Legacy Implementation
Locate the legacy code:
find src.legacy -name "*feature_name*"
grep -r "feature_function" src.legacy/
Understand the implementation:
- What does it do? (API, behavior, edge cases)
- Why does it exist? (requirements it satisfies)
- How does it work? (algorithm, data structures)
- What depends on it? (other modules, tests)
Extract key characteristics:
- Public API surface
- Critical behavior
- Edge case handling
- Error conditions
- Test coverage
Phase 3: Implement in New Kernel
Follow Breenix standards:
Quality checklist:
Phase 4: Verify Parity
Functional equivalence:
cargo test feature_name
cargo test
API compatibility:
- If API is public: Must match exactly
- If internal: Can improve design
- Document any intentional differences
Behavioral parity checklist:
Phase 5: Update Documentation
Update FEATURE_COMPARISON.md:
### Feature Category
| Feature | Legacy | New | Notes |
|---------|--------|-----|-------|
| Feature X | ~~✅ Full~~ (removed) | ✅ | Migrated in PR #123, legacy removed |
Patterns:
- Change legacy column to
~~✅ Full~~ (removed)
- Update new column to ✅
- Add note about migration PR
- Include date if significant
Document any differences:
## Implementation Differences
### Feature X
- **Legacy**: Used approach A
- **New**: Uses approach B (reason)
- **Rationale**: Cleaner design, better performance, etc.
Phase 6: Remove Legacy Code
In the SAME commit as feature completion:
git rm src.legacy/path/to/feature.rs
git rm -r src.legacy/module/
git add docs/planning/legacy-migration/FEATURE_COMPARISON.md
git commit -m "Complete Feature X implementation and remove legacy
- Implement Feature X in kernel/src/module/feature.rs
- Full parity with legacy implementation
- Remove legacy code from src.legacy/
- Update FEATURE_COMPARISON.md
Tested with: cargo test feature_x
"
Critical: Legacy removal MUST be in the same commit to maintain atomicity.
Legacy Code Categories
1. Direct Migration
What: Feature can be ported directly with minimal changes
Example: VGA text mode removed after framebuffer complete
Process:
- Understand legacy implementation
- Port to new codebase
- Test thoroughly
- Remove legacy
- Update docs
2. Reimplementation
What: New approach taken, but achieves same goals
Example: Timer system (different RTC implementation)
Process:
- Identify requirements from legacy
- Design new approach
- Implement with modern patterns
- Verify equivalent behavior
- Remove legacy
- Document differences
3. Obsolete Features
What: Feature no longer needed or superseded
Example: VGA text after framebuffer works
Process:
- Verify feature truly obsolete
- Check no dependencies
- Remove from legacy
- Update FEATURE_COMPARISON.md with rationale
4. Deferred Features
What: Features not yet needed in new kernel
Example: Network stack (not current priority)
Process:
- Document decision to defer
- Mark as ❌ in FEATURE_COMPARISON.md
- Leave in legacy as reference
- Add to future roadmap
Common Migration Patterns
Pattern: Device Driver
pub struct DeviceX {
}
impl DeviceX {
pub fn new() -> Self { ... }
}
impl DeviceX {
pub fn operation(&mut self) { ... }
}
#[cfg(test)]
mod tests {
#[test]
fn test_device_x() { ... }
}
Pattern: System Call
pub const SYS_FEATURE: u64 = N;
pub fn syscall_handler(num: u64, args: ...) {
match num {
SYS_FEATURE => sys_feature(args),
}
}
fn sys_feature(args: ...) -> u64 {
}
Pattern: Infrastructure
Risk Assessment
Before removing legacy code, assess:
High Risk (Don't Remove Yet)
- Features not yet implemented in new kernel
- Complex subsystems (network, filesystem)
- Code with unique algorithms or logic
- Reference implementations for future work
Medium Risk (Remove with Caution)
- Features with partial new implementation
- Code with subtle edge cases
- Infrastructure with many dependencies
Low Risk (Safe to Remove)
- Features fully implemented and tested
- Obsolete approaches (VGA text mode)
- Dead code (never called)
- Superseded implementations
Integration with Development
During Feature Development
grep -r "feature_name" src.legacy/
less src.legacy/path/to/feature.rs
cargo test feature_name
git rm src.legacy/path/to/feature.rs
git commit -m "Implement feature_name and remove legacy"
PR Review Checklist
When reviewing PRs that claim feature parity:
Current Migration Status
Based on FEATURE_COMPARISON.md (as of latest):
Completed Migrations:
- Memory management (frame allocator, paging, heap) ✅
- Async executor and task management ✅
- Timer system (PIT + RTC) ✅
- Keyboard driver ✅
- Serial output ✅
- Test infrastructure ✅
- Syscall infrastructure ✅
- Fork/exec system calls ✅
Not Yet Migrated:
- Network drivers (Intel E1000, RTL8139) ❌
- PCI bus support ❌
- Interrupt statistics tracking ❌
- Event system ❌
Different Approach:
- Print macros (log system vs direct print) 🔄
- Display (framebuffer vs VGA text) 🔄
Special Cases
When Legacy Has Better Implementation
Scenario: Legacy code is actually better designed
Action:
- Port legacy approach to new kernel
- Improve if possible
- Remove legacy
- Document that you used legacy as reference
When API Must Change
Scenario: Legacy API is poor, new needs different design
Action:
- Design better API
- Document differences in FEATURE_COMPARISON.md
- Explain rationale in commit message
- Remove legacy
When Uncertain
Scenario: Not sure if new implementation is equivalent
Action:
- Write comprehensive tests
- Compare outputs on same inputs
- Ask for review
- Document any known differences
- Only remove legacy when confident
Best Practices
- Remove in same commit: Legacy removal with feature completion
- Update docs immediately: Don't accumulate documentation debt
- Test thoroughly: Verify parity before removing legacy
- Document differences: Explain any intentional changes
- Keep reference: For complex features, document algorithm before removing
- Atomic operations: Feature + removal + docs in one commit
- Review carefully: PRs that remove legacy need extra scrutiny
Example Migration Session
cat docs/planning/legacy-migration/FEATURE_COMPARISON.md | grep "❌"
less src.legacy/events/mod.rs
grep -r "Event" src.legacy/
cargo test events
git rm -r src.legacy/events/
git add kernel/src/events/ tests/test_events.rs
git add docs/planning/legacy-migration/FEATURE_COMPARISON.md
git commit -m "Implement event system and remove legacy
- Add event system in kernel/src/events/
- Full parity with legacy implementation
- Enhanced with better error handling
- Remove src.legacy/events/
- Update FEATURE_COMPARISON.md
Tested with: cargo test events
All tests passing, no regressions.
"
Summary
Legacy code migration requires:
- Systematic analysis of legacy implementation
- Full parity verification with tests
- Atomic commits (feature + removal + docs)
- FEATURE_COMPARISON.md updates
- Risk assessment before removal
- Documentation of differences
The goal: Clean codebase with no dead code accumulation.