From imersao
This skill should be used when the user asks to "find duplicated code", "map responsibilities", "consolidate code", "find code sprawl", "analyze duplication", "create consolidation plan", or mentions "código duplicado", "responsabilidades espalhadas", "consolidar". Analyzes codebases to identify scattered responsibilities that should be centralized.
How this skill is triggered — by the user, by Claude, or both
Slash command
/imersao:code-consolidationThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Analyze codebases to identify responsibilities scattered across multiple files that should be consolidated into single sources of truth.
Analyze codebases to identify responsibilities scattered across multiple files that should be consolidated into single sources of truth.
Map fragmented code responsibilities and generate actionable consolidation plans. Detect:
Scan for common duplication patterns using targeted searches:
# Type definitions scattered
grep -rn "export (type|interface) " --include="*.ts" | sort | uniq -d
# Similar function names in different files
grep -rn "export function \w+" --include="*.ts" | awk -F: '{print $3}' | sort | uniq -c | sort -rn
# Duplicate class definitions
grep -rn "class \w+Error" --include="*.ts" --include="*.py"
# Configuration objects with same structure
grep -rn "STATUS_CONFIG\|VARIANT_CONFIG" --include="*.ts"
# Factory patterns repeated
grep -rn "create.*Factory\|.*Factory\(" --include="*.ts"
For each detected pattern, classify by category:
| Category | Detection Pattern | Consolidation Target |
|---|---|---|
| Types | Same interface in 2+ packages | packages/types/ |
| Validators | Duplicate Zod schemas | packages/validators/ |
| Errors | Scattered error classes | app/errors/ or lib/errors/ |
| Config | Repeated status/variant configs | lib/{domain}-config-factory.ts |
| Utils | Similar functions across files | lib/utils/{domain}.ts |
| Constants | Duplicate magic values | lib/constants/{domain}.ts |
For each consolidation opportunity, assess:
Score opportunities using:
| Factor | Weight | Scoring |
|---|---|---|
| Files affected | 30% | 1-5 files (1pt), 6-10 (2pt), 11+ (3pt) |
| Maintenance burden | 25% | Low (1pt), Medium (2pt), High (3pt) |
| Bug risk | 25% | Low (1pt), Medium (2pt), High (3pt) |
| Effort required | 20% | High (1pt), Medium (2pt), Low (3pt) |
Priority = (Files × 0.30) + (Maintenance × 0.25) + (BugRisk × 0.25) + (Effort × 0.20)
Generate consolidation map in markdown:
# Consolidation Map: [Project Name]
## Executive Summary
- **Duplication Categories Found:** X
- **Files Affected:** Y
- **Estimated Lines to Eliminate:** Z
## Priority Matrix
| Priority | Category | Files | Impact | Effort | Score |
|----------|----------|-------|--------|--------|-------|
| 🔴 High | [name] | X | High | Low | 2.8 |
| 🟡 Med | [name] | X | Med | Med | 2.1 |
| 🟢 Low | [name] | X | Low | High | 1.4 |
## Detailed Findings
### 1. [Category Name] 🔴 High Priority
**Problem:** [Description]
**Duplicated Locations:**
- `path/to/file1.ts:line` - [what it exports]
- `path/to/file2.ts:line` - [what it exports]
**Consolidation Target:** `path/to/consolidated/location.ts`
**Migration Steps:**
1. Create consolidated module
2. Add backward-compatible re-exports
3. Update consumers incrementally
4. Remove deprecated locations
**Verification:**
```bash
# Check for remaining references
grep -rn "old_import" src/
## Consolidation Patterns
### Pattern: Factory Extraction
When multiple files define similar configuration objects:
**Before (scattered):**
```typescript
// file1/constants.ts
export const STATUS_CONFIG = { draft: {...}, published: {...} };
export function getStatusLabel(status) { return STATUS_CONFIG[status].label; }
// file2/constants.ts
export const STATUS_CONFIG = { active: {...}, archived: {...} };
export function getStatusLabel(status) { return STATUS_CONFIG[status].label; }
After (consolidated):
// lib/status-config-factory.ts
export function createStatusConfig<T extends string>(configs: Record<T, StatusDef>) { ... }
export function createStatusHelpers<T extends string>(configs: Record<T, StatusDef>) { ... }
// file1/constants.ts
import { createStatusConfig } from '@/lib/status-config-factory';
export const STATUS_CONFIG = createStatusConfig({ draft: {...}, published: {...} });
When error classes are scattered:
Before:
# service1.py
class Service1Error(Exception): pass
class ValidationError(Service1Error): pass
# service2.py
class Service2Error(Exception): pass
class ValidationError(Service2Error): pass # Duplicate name!
After:
# errors/__init__.py
from .base import AppError
from .service import ServiceError, ValidationError
# errors/service.py
class ServiceError(AppError): pass
class ValidationError(ServiceError): pass
When utilities sprawl across flat directories:
Before:
utils/
├── auth.ts
├── crypto.ts
├── email.ts
├── redis.ts
├── slug.ts
└── ... (40+ files)
After:
utils/
├── index.ts # Barrel export with categories
├── auth/ # Or just organized exports in index.ts
│ └── index.ts # export * from '../auth'; export * from '../crypto';
└── ...
Always maintain backward compatibility during migration:
// old/location.ts (deprecated)
export { Thing } from '@/new/location';
/**
* @deprecated Import from '@/new/location' instead
*/
export { Thing } from '@/new/location';
// When renaming, keep old name as alias
export const OldName = NewName;
After consolidation, verify no orphaned references:
# Find remaining imports from deprecated location
grep -rn "from ['\"].*deprecated/path" src/
# Type check
pnpm type-check
# Run tests
pnpm test
# Check for duplicate exports
grep -rn "export.*SameName" src/ | wc -l
After generating consolidation map, create tasks:
# Create consolidation tasks
pnpm task:new "Consolidar [Category]" --sprint -t CHORE -p [priority]
references/detection-patterns.md - Detailed grep/ripgrep patterns for each languagereferences/migration-strategies.md - Step-by-step migration guidesscripts/find-duplicates.sh - Automated duplicate detectionscripts/generate-consolidation-report.sh - Report generatornpx claudepluginhub parisgroup-ai/imersao-ia-setup --plugin imersaoProvides behavioral guidelines to reduce common LLM coding mistakes, focusing on simplicity, surgical changes, assumption surfacing, and verifiable success criteria.
Searches, retrieves, and installs Agent Skills from prompts.chat registry using MCP tools like search_skills and get_skill. Activates for finding skills, browsing catalogs, or extending Claude.