بنقرة واحدة
refactor
Analyze code for structural improvement opportunities and produce a prioritized refactoring plan
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
القائمة
Analyze code for structural improvement opportunities and produce a prioritized refactoring plan
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
استنادا إلى تصنيف SOC المهني
Run parallel code review agents and consolidate findings into a unified report
Capture a follow-up idea or task as a work-item draft without interrupting current work. Use to quickly jot down something you think of mid-task so it gets tracked. Works with nibs, GitHub, Azure DevOps, or a Markdown fallback.
Take an under-specified work item and make it actionable — resolve its open questions through a short interview grounded in the code, and give it acceptance criteria. Use on a captured draft, or any item too vague to start on.
Reconcile what was built against what was planned, record decisions and deviations, close the item (a single phase or a whole plan), and file follow-ups for deferred work. Use after finishing a phase or plan to keep planned and actual from drifting apart.
Orchestrate execution of MULTIPLE nibs in one run. Selects a queue, understands the nibs collectively (including how they fit together), then chooses the best execution mechanism per cluster — single series agent, parallel fan-out, scripted workflow, or agent team — and dispatches with ONE approval gate. Use when the user wants to work several nibs together (in parallel or series) rather than one at a time. Complements /decaf-build:auto-dev and /decaf-build:auto-tdd (which handle a single nib).
Direct development with automated review. Plans implementation, executes via subagent, then auto-reviews. Use for work that isn't test-driven (UI, config, styling, infrastructure, scaffolding).
| name | refactor |
| description | Analyze code for structural improvement opportunities and produce a prioritized refactoring plan |
| argument-hint | [quick|deep] [path|glob|full] [instructions] |
This command analyzes existing code for structural improvement opportunities and produces a prioritized, actionable refactoring plan. It focuses on high-impact opportunities, not exhaustive issue lists. The output is a local plan; walk and act on it with /decaf-quality:resolve-refactor.
Parse $ARGUMENTS to determine:
quick or deep (default when no mode keyword given)full, or changed files (default)| Mode | Agents | Use Case |
|---|---|---|
quick | structural-analyst only (1) | Fast local quality check on specific files |
deep (default) | structural-analyst + coherence-analyst (2) | Full analysis including cross-cutting patterns |
| Input | Behavior |
|---|---|
| (none) | Changed files from git diff HEAD --name-only. Fall back to git diff HEAD~1..HEAD --name-only if no uncommitted changes. |
src/Services/ | All source files in that directory (recursive) |
src/**/*.cs | Files matching the glob pattern |
src/OrderProcessor.cs | That single file |
full | Entire project — smart-sampled (see below) |
full ScopeWhen scope is full, the codebase may be too large to analyze entirely. Apply smart sampling:
To determine exclusions, check CLAUDE.md for generated/vendored file patterns. Use .gitignore as baseline.
Determine which files to analyze based on scope resolution above.
# For default scope (changed files):
git diff HEAD --name-only
# For directory scope:
# Use Glob tool to find source files
# For full scope:
# Use Glob + smart sampling
If scope is empty (no files match), inform the user and exit:
No files found matching the specified scope. Provide a file path, directory, or glob pattern.
Read the project's CLAUDE.md to understand:
quick mode1 agent — no cross-file analysis:
decaf-quality:structural-analystdeep mode (default)2 agents in parallel:
decaf-quality:structural-analystdecaf-quality:coherence-analystCRITICAL: In deep mode, both agents MUST be launched in a single message with multiple Agent tool calls. This ensures true parallel execution.
structural-analyst prompt:
Analyze the following files for per-file structural improvement opportunities.
Focus on your area of expertise. Follow your own output format instructions.
## Files to Analyze
<list each file path, and paste file contents>
## Project Context
<relevant CLAUDE.md excerpts — language, conventions, architecture>
## Additional Instructions
<any user-provided instructions from $ARGUMENTS>
coherence-analyst prompt (deep mode only):
Analyze the following files for cross-file structural patterns and improvement opportunities.
Focus on your area of expertise. Follow your own output format instructions.
## Files to Analyze
<list each file path>
## Project Context
<relevant CLAUDE.md excerpts — language, conventions, architecture, module structure>
## Additional Instructions
<any user-provided instructions from $ARGUMENTS>
Note: You have access to Grep and Glob tools to search the broader codebase
for patterns beyond the listed files. Use them to verify cross-file patterns.
Wait for all agents to complete. Each agent returns opportunities in JSON format.
Apply the consolidation rules:
@../../conventions/refactoring.md
For each agent's "Considered But Not Flagged" section:
Create a timestamped plan file in .decaf/refactoring-plans/ at the repo root. Never overwrite existing plans.
Filename: .decaf/refactoring-plans/REFACTOR_PLAN_<YYYY-MM-DD>_<HH-MM-SS>.md using the current date and time you know from context. Do NOT shell out to date — construct the filename directly. Create the .decaf/refactoring-plans/ directory first if it doesn't exist.
Plan format:
# Refactoring Plan
**Mode**: <mode> | **Analysts**: <agent list> | **Date**: <YYYY-MM-DD>
**Scope**: N files analyzed
## Value Matrix
| Rating | Count |
|--------|-------|
| ★★★ | X |
| ★★ | X |
**Total opportunities:** N (grouped into M refactoring units)
---
## Refactoring Units
### #1 ★★★ Extract PaymentValidation domain service
| | |
|---|---|
| **Impact** | High |
| **Effort** | Medium |
| **Files** | `src/OrderProcessor.cs`, `src/PaymentService.cs`, `src/RefundHandler.cs` |
| **Category** | validation-scattering |
| **Found by** | coherence-analyst (High), structural-analyst (Medium) |
| **Confidence** | 88/100 |
**Problem:** Payment validation logic is duplicated across 3 services with subtly different implementations. The OrderProcessor validates card expiry differently than PaymentService, creating inconsistent behavior.
**Before:**
```csharp
// OrderProcessor.cs:45
if (card.ExpiryDate < DateTime.Now) ...
// PaymentService.cs:72
if (card.ExpiryDate <= DateTime.UtcNow) ...
After:
// PaymentValidation.cs
public static bool IsCardExpired(Card card)
=> card.ExpiryDate <= DateTime.UtcNow;
Steps:
PaymentValidation service with consolidated rules| Impact | High |
| Effort | Small |
| Files | src/OrderProcessor.cs |
| Category | god-function |
| Found by | structural-analyst |
| Confidence | 92/100 |
Problem: ProcessOrder() is 85 lines mixing validation, persistence, and notification concerns at different abstraction levels.
Before:
public async Task ProcessOrder(Order order)
{
// 85 lines mixing validation, DB calls, email sending
}
After:
public async Task ProcessOrder(Order order)
{
Validate(order);
await Persist(order);
await NotifyCustomer(order);
}
Steps:
...
[Items examined but below inclusion threshold or determined to be acceptable design, grouped by agent with rationale.]
Scope: [Description of what was analyzed] Sampling: [If full mode, note which files were sampled/excluded] Limitations: [What cross-cutting patterns may have been missed due to scope]
### Severity Icons for Star Ratings
- ★★★ — High-value: address first
- ★★ — Worthwhile: address when nearby
- ★ — Low-value (not included in main plan)
**Always use literal Unicode star characters (★), never `:shortcode:` syntax.**
### Output Notification
After creating the plan file, inform the user:
✅ Refactoring plan complete: .decaf/refactoring-plans/REFACTOR_PLAN_2026-03-03_14-30-45.md
★★★ High-value: X opportunities ★★ Worthwhile: Y opportunities Total: Z refactoring units
Run /decaf-quality:resolve-refactor to walk through opportunities interactively.
## Example Usage
/decaf-quality:refactor # deep mode, changed files /decaf-quality:refactor quick # quick mode (structural only) /decaf-quality:refactor src/Services/ # deep mode, specific directory /decaf-quality:refactor src/**/*.cs # deep mode, glob pattern /decaf-quality:refactor src/OrderProcessor.cs # deep mode, single file /decaf-quality:refactor full # deep mode, entire project (sampled) /decaf-quality:refactor quick src/OrderProcessor.cs # quick mode, single file /decaf-quality:refactor focus on error handling # deep mode with instructions