بنقرة واحدة
factorize
Scan the project for duplication and factorization opportunities
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
القائمة
Scan the project for duplication and factorization opportunities
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
استنادا إلى تصنيف SOC المهني
| name | factorize |
| description | Scan the project for duplication and factorization opportunities |
| argument-hint | ["path/to/dir | --dry-run | --scope <small|medium|large>"] |
Scan the codebase to detect duplicated code, repeated patterns, and factorization opportunities. Unlike /simplify (which refines recently changed code), this command performs a project-wide analysis.
Modes:
/factorize — full scan, all source files/factorize src/services — scoped to a specific directory/factorize --dry-run — report only, no code changes/factorize --scope small — override auto-detected project sizeRead CLAUDE.md to understand:
Detect project size:
Present the plan:
FACTORIZE — [project name]
Stack: [detected]
Scope: [full / directory]
Size: [X source files] → [small/medium/large]
Agents: [1-3]
Mode: [analysis + refactor / dry-run (report only)]
Proceed? [Y/n]
Launch agents in parallel (subagent_type: feature-dev:code-explorer).
Each agent receives its assigned files and this mission:
You are analyzing [project name] ([stack]) for factorization opportunities.
Your assigned files: [list].
Scan for these patterns:
1. **DUPLICATED CODE** — identical or near-identical blocks (>5 lines) that appear in 2+ files.
Report: both locations, the duplicated block, and a suggested shared function/module name.
2. **REPEATED PATTERNS** — same logical pattern implemented differently across files
(e.g., 3 different ways to validate input, 4 similar API call wrappers).
Report: all occurrences, the common pattern, and a suggested unified approach.
3. **MISSED ABSTRACTIONS** — operations that could benefit from a shared utility
(e.g., repeated string transformations, common data reshaping, recurring error handling).
Report: occurrences and suggested abstraction.
4. **COPY-PASTE DRIFT** — code that was clearly copied then modified slightly,
creating divergence that will cause bugs (one copy gets fixed, others don't).
Report: all copies, the differences, and which version is likely "correct".
For each finding, report:
- **Type**: DUPLICATION / PATTERN / ABSTRACTION / DRIFT
- **Impact**: HIGH (>3 occurrences or >20 lines each) / MEDIUM (2-3 occurrences) / LOW (minor)
- **Locations**: file:line for each occurrence
- **Code snippets**: the duplicated/similar blocks (abbreviated if >15 lines)
- **Suggestion**: concrete refactoring approach (function name, module location, signature)
Do NOT report:
- Similar test setup code (tests are allowed to be repetitive for readability)
- Framework boilerplate that cannot be abstracted (e.g., route definitions)
- Config files or generated code
- Differences that are intentional (check comments, commit messages)
After agents return, act as the senior architect:
Merge overlapping findings — if two agents found the same duplication from different files, merge into one finding.
Rank by ROI — for each finding, estimate:
Filter out low-ROI noise — if the effort exceeds the benefit (e.g., extracting a 3-line helper used twice), drop it with a 1-line justification.
Group into refactoring units — things that should be done together because they touch the same files or create the same abstraction.
Generate and save to factorize-reports/YYYY-MM-DD_HH-MM.md:
# Factorize Report — [project name]
**Date:** [timestamp]
**Stack:** [detected]
**Scope:** [full / directory path]
**Files analyzed:** [count]
**Agents used:** [count]
## Summary
| Type | HIGH | MEDIUM | LOW | Total |
|------|------|--------|-----|-------|
| Duplication | X | X | X | X |
| Repeated pattern | X | X | X | X |
| Missed abstraction | X | X | X | X |
| Copy-paste drift | X | X | X | X |
**Estimated impact:** ~[X] lines of code can be eliminated or consolidated.
## HIGH impact findings
### [F-1] [Type] — [short title]
- **Impact:** HIGH
- **Locations:**
- `file1.ext:L10-L25`
- `file2.ext:L42-L57`
- `file3.ext:L8-L23`
- **Duplicated block:**
```[lang]
[code snippet]
[module/function name] in [suggested path]| # | Type | Title | Locations | Suggestion | Effort |
|---|---|---|---|---|---|
| 1 | ... | ... | file1, file2 | ... | S |
[Brief list — no action expected unless convenient]
| # | Finding | Reason |
|---|---|---|
| 1 | ... | Intentional difference / framework constraint / ROI too low |
[function] from [files] → [target module]
Create `factorize-reports/` if it doesn't exist.
Add `factorize-reports/` to `.gitignore` if not already present.
## Step 5 — Apply (unless --dry-run)
If NOT in dry-run mode, ask:
[X] findings ready to apply. Recommended approach: Wave 1: [X] quick wins ([list of F-IDs]) Wave 2: [X] medium refactors Wave 3: [X] need discussion first
Apply Wave 1 now? [Y/n/all]
- **Y** → apply Wave 1 only, then ask for Wave 2
- **all** → apply Waves 1 + 2 (never auto-apply Wave 3)
- **n** → stop, report is saved
For each applied refactoring:
1. Create the shared function/module
2. Replace all occurrences with calls to the shared version
3. Run the project's test command (from CLAUDE.md) after each wave
4. If tests fail → revert the wave, report which refactoring caused the failure
## Step 6 — Tickets
For findings NOT applied (Wave 3, or if user chose dry-run):
- If `BACKLOG/` exists → create IMP tickets (scan IDs, anti-conflict)
- Use the standard ticket format with the factorize finding details
- Reference the report: `See factorize-reports/[filename].md, finding F-X`
## Rules — NON-NEGOTIABLE
- **Read CLAUDE.md first** — respect project conventions for where shared code lives
- **Wait for user confirmation** after the plan (Step 1) AND before applying (Step 5)
- **Never auto-apply Wave 3** — large refactorings need human decision
- **Run tests after each wave** — revert if broken
- **Never refactor test code** — tests can be repetitive, that's fine
- **Never create FEAT tickets** — factorization is improvement, not new features
- **Reports contain code snippets** — gitignore them
- **Dry-run is the safe default** — if user seems unsure, suggest --dry-run first
Compresser une session de debug en cours et produire un prompt forensique strict (donnees -> hypothese unique -> test decisif -> STOP). A utiliser quand un debug long ou complexe derive vers la speculation, ou quand le contexte de la conv est sature et qu'il faut basculer sur une session vierge sans perdre les eliminations deja faites.
Switch to supervisor/CTO mode — plan, delegate to workers, never write code directly
Auto-bootstrap codebase indexing in any project. Detects the stack, dispatches to the native installer if supported (Dart in v0.1), or generates a stack-appropriate indexer with strict guardrails (official AST parser, format contract, auto-validation, refinement loop) for TypeScript, Python, Go, or Rust.
Switch to expert-comptable / fiscaliste mode — optimisation fiscale FR, structuration de societes, expatriation, patrimoine
Generate API_CONTRACT.md by scanning existing routes and controllers
Check if API_CONTRACT.md is in sync with the actual code