Automate detection and removal of duplicate files/functions in TypeScript, JavaScript, and Python projects. Safely refactor imports, validate with tests, and deploy changes with zero risk of breaking the system.
Automate detection and removal of duplicate files/functions in TypeScript, JavaScript, and Python projects. Safely refactor imports, validate with tests, and deploy changes with zero risk of breaking the system.
Designed for daily incremental fixes that keep architecture clean without chaos.
project_root: Path to projectmode: 'daily' | 'aggressive' | 'analysis' (default: 'daily')--dry-run: Preview only, don't modify.duplicate-report.json: Detection results.keep-remove-map.json: Decision mapping (keep/remove).refactor-log.json: Files changed, imports updated.validation-log.json: Test/lint/build results.deploy-log.json: Commit/PR status.pipeline-log.json: Full execution logsrc/utils or src/servicessrc/helpers, src/utils, src/servicesNaming convention:
src/
utils/ # General utilities (helper.ts, formatter.ts)
helpers/ # (DEPRECATED: merge to utils)
services/ # Business logic (userService.ts, authService.ts)
hooks/ # React hooks
components/ # UI components
constants/ # Constants
/common or /core packageExample structure:
src/
common/ # Shared utilities (helpers.py, validators.py)
core/ # Core business logic
services/ # Service classes
models/ # Data models
Command: npm run check <project> -- --format=json --min-tokens=50
Alternative (direct): node scripts/detect.js <project> --format=json --min-tokens=50
Process:
.ts, .tsx, .js, .jsx, .py files.duplicate-report.jsonTools:
jscpd: Copy-paste detectionts-morph / babel: AST parsingpython ast: Python structural analysisCommand: npm run decide <project> -- --report=.duplicate-report.json --strategy=test-coverage-first
Alternative (direct): node scripts/decide.js <project> --report=.duplicate-report.json --strategy=test-coverage-first
Decision ranking (highest score wins):
Example:
File A (helper.ts):
- 5 test cases → 15 points
- imported by 3 files → 6 points
- has types → 5 points
- follows convention → 3 points
Total: 29 points
File B (helpers/util.ts):
- 0 tests → 0 points
- imported by 1 file → 2 points
- no types → 0 points
- doesn't follow convention → 0 points
Total: 2 points
Decision: KEEP A, REMOVE B
Output: .keep-remove-map.json
Command: npm run refactor <project>
Alternative (direct): node scripts/refactor.js <project>
Process:
import x and from x import y statementsindex.ts, __init__.py).refactor-log.jsonSafety checks:
Command: npm run validate <project>
Alternative (direct): bash scripts/validate.sh <project>
Validation stack:
npm run test:ci / pytesttsc --noEmiteslint / flake8npm run buildIf ANY fails:
git checkout -- ..validation-log.jsonOutput: .validation-log.json
Command: npm run deploy <project> -- --auto-merge
Alternative (direct): node scripts/deploy.js <project> --auto-merge
Process:
git status for changesgit add -A).deploy-log.jsonCommit message:
Auto-fix: Remove duplicates and refactor imports
Files deleted: 5
Imports updated: 12
Automated by auto-duplicate-fixer skill
On Test Failure:
git checkout -- .
# Log failure to validation log
echo '{"status": "failed", "reason": "tests-failed", "timestamp": "'$(date -Iseconds)'"}' >> .validation-log.json
On TypeScript Errors:
npx tsc --noEmit --pretty
On Build Failure:
On Conflict:
npm run daily /path/to/project
npm run aggressive /path/to/project
npm run dry-run /path/to/project
# Detect only
npm run check /path/to/project
# View decisions
cat /path/to/project/.keep-remove-map.json
# Refactor
npm run refactor /path/to/project
# Validate
npm run validate /path/to/project
# Deploy
npm run deploy /path/to/project
Schedule daily at 2 AM (requires git access):
# Add to crontab
0 2 * * * cd /path/to/project && npm run daily
# Or in GitHub Actions