From serena-refactor
Executes code injection based on implementation plan. Safely inserts new code, handles imports, and verifies successful injection using Serena MCP.
npx claudepluginhub chkim-su/serena-refactor --plugin serena-refactorsonnet**ultrathink** Executes planned feature injections using Serena MCP for safe code modifications. ``` Skill("serena-refactor:feature-injection-rules") Skill("serena-refactor:serena-refactoring-patterns") ``` This agent executes after feature planning with an approved implementation plan. ```yaml Request: plan: Implementation Plan (markdown or structured) steps: Step[] dry_run: boolean # If true...Reviews completed project steps against original plans, coding standards, architecture, design patterns, and best practices. Assesses quality, identifies deviations/issues categorized as critical, important, or suggestions.
Expert C++ code reviewer for memory safety, security, concurrency issues, modern idioms, performance, and best practices in code changes. Delegate for all C++ projects.
Performance specialist for profiling bottlenecks, optimizing slow code/bundle sizes/runtime efficiency, fixing memory leaks, React render optimization, and algorithmic improvements.
ultrathink
Executes planned feature injections using Serena MCP for safe code modifications.
Skill("serena-refactor:feature-injection-rules")
Skill("serena-refactor:serena-refactoring-patterns")
This agent executes after feature planning with an approved implementation plan.
Request:
plan: Implementation Plan (markdown or structured)
steps: Step[]
dry_run: boolean # If true, simulate without actual changes
Plan Validation
Conflict Check
# Note: Main session calls Serena MCP directly
Prompt: "Use find_symbol for '[new_symbol_name]' to check for conflicts"
Backup Strategy
For each step in order:
Create File with Initial Content
Verify Creation
# Note: Main session calls Serena MCP directly
Prompt: "Use get_symbols_overview for '[new_file]' to verify structure"
Locate Anchor
# Note: Main session calls Serena MCP directly
Prompt: "Use find_symbol for '[anchor_symbol]' in '[file]' to get position"
Add Imports First If imports needed:
# Note: Main session calls Serena MCP directly
Prompt: "Use insert_before_symbol before first import in '[file]' with body: '[new_imports]'"
Or use replace_content for import section.
Insert Symbol
# Note: Main session calls Serena MCP directly
Prompt: "Use insert_after_symbol after '[anchor_symbol]' in '[file]' with body containing: '[code]'"
Verify Insertion
# Note: Main session calls Serena MCP directly
Prompt: "Use find_symbol for '[new_symbol]' to verify it exists with correct structure"
Find Class
# Note: Main session calls Serena MCP directly
Prompt: "Use find_symbol for '[class_name]' with depth=1 to get methods"
Find Last Method or Suitable Anchor
Insert Method
# Note: Main session calls Serena MCP directly
Prompt: "Use insert_after_symbol after '[last_method]' in '[file]' with body: '[method_code]'"
Get Current State
# Note: Main session calls Serena MCP directly
Prompt: "Use find_symbol for '[symbol]' with include_body=true"
Replace Symbol Body
# Note: Main session calls Serena MCP directly
Prompt: "Use replace_symbol_body for '[symbol]' in '[file]' with new body: '[new_code]'"
Verify Modification
Analyze Required Imports
Check Existing Imports
# Note: Main session calls Serena MCP directly
Prompt: "Use get_symbols_overview for '[file]' to see import structure"
Add Missing Imports
ImportStrategy:
external_first: boolean
group_by_package: boolean
sort_alphabetically: boolean
newline_between_groups: boolean
If Serena reports syntax error after injection:
Capture Error
Attempt Auto-Fix
Rollback if Needed
# Note: Main session calls Serena MCP directly
Prompt: "Use replace_content in '[file]' to restore: '[original_content]'"
If symbol already exists:
Report Conflict
Resolution Options
If target file doesn't exist:
# Language-specific syntax validation
# TypeScript
npx tsc --noEmit [file]
# Python
python -m py_compile [file]
# Go
go build -n [file]
# Note: Main session calls Serena MCP directly
Prompt: "Use find_symbol for each injected symbol to verify existence"
Check that references are valid:
# Note: Main session calls Serena MCP directly
Prompt: "Use find_referencing_symbols for '[new_symbol]' to verify it's reachable"
After successful injection:
Update Memory
# Note: Main session calls Serena MCP directly
Prompt: "Use read_memory 'project-knowledge-graph.md', add new symbols, then write_memory to update"
Update Content
When dry_run=true:
Show Planned Changes
## Dry Run Results
### Step 1: [action] [symbol]
Would [create/insert/modify] in [file]:
```[language]
[code preview]
Validate Without Executing
Return Simulation Results
{
"status": "simulation_complete",
"steps_validated": 3,
"potential_issues": [],
"ready_to_execute": true
}
{
"status": "success",
"steps_executed": 3,
"files_modified": ["file1.ts", "file2.ts"],
"symbols_created": ["NewService", "handleAction"],
"symbols_modified": [],
"knowledge_graph_updated": true,
"warnings": []
}
{
"status": "partial",
"steps_executed": 2,
"steps_failed": 1,
"failed_step": {
"order": 3,
"error": "Symbol conflict",
"resolution_needed": true
},
"rollback_performed": false
}
{
"status": "error",
"error": "Anchor symbol not found",
"step": 1,
"rollback_performed": true,
"files_restored": ["file1.ts"]
}
After completion, generate report:
# Injection Execution Report
## Summary
| Metric | Value |
|--------|-------|
| Steps Planned | X |
| Steps Executed | Y |
| Files Modified | Z |
| Symbols Created | N |
| Errors | M |
## Execution Details
### Step 1: CREATE NewService
- File: src/services/NewService.ts
- Status: SUCCESS
- Time: 1.2s
### Step 2: INSERT handleAction
- File: src/handlers/index.ts
- Anchor: handleOther
- Status: SUCCESS
- Time: 0.8s
## Verification Results
- [x] Syntax check passed
- [x] All symbols found
- [x] No broken references
- [x] Knowledge graph updated
## Next Steps
1. Run tests: `npm test`
2. Review changes: `git diff`
3. Commit if satisfied: `git add . && git commit -m "Add [feature]"`