| name | analyzing-dependencies |
| description | Guides dependency analysis and safe cleanup operations in Topcat. Use when analyzing dead branches, finding orphans, detecting cycles, cleaning unused files, or integrating with CI/CD pipelines. |
Analyzing Dependencies
When to Use This Skill
- Analyzing dependency graphs for dead code
- Safely cleaning up unused files
- Detecting circular dependencies or missing refs
- Setting up CI/CD checks
- Protecting critical entry points from deletion
Quick Command Reference
topcat analyze -i sql/ -e sql dead-branches
topcat analyze -i sql/ -e sql orphans
topcat analyze -i sql/ -e sql cycles
topcat analyze -i sql/ -e sql missing
topcat analyze -i sql/ -e sql file path.sql
topcat clean -i sql/ -e sql dead-branches
topcat clean -i sql/ -e sql orphans --no-dry-run
topcat analyze -i sql/ -e sql --quiet cycles
Safe Cleanup Workflow
Follow this checklist when cleaning up files:
Pre-Cleanup Checklist:
- [ ] Step 1: Identify candidates
topcat analyze -i sql/ -e sql dead-branches
- [ ] Step 2: Add external usage checking
topcat analyze -i sql/ -e sql --external-check-dir src/ --external-check-pattern "*.py" dead-branches
- [ ] Step 3: Protect entry points
topcat analyze -i sql/ -e sql --root-pattern "**/api/*.sql" dead-branches
- [ ] Step 4: Preview deletion (dry-run)
topcat clean -i sql/ -e sql --root-pattern "**/api/*.sql" dead-branches
- [ ] Step 5: Execute with confirmation
topcat clean -i sql/ -e sql --root-pattern "**/api/*.sql" dead-branches --no-dry-run
- [ ] Step 6: Force mode for automation (optional)
topcat clean -i sql/ -e sql --root-pattern "**/api/*.sql" dead-branches --no-dry-run --force
Analysis Commands
Dead Branches
Finds complete dead subtrees (transitive closure):
topcat analyze -i sql/ -e sql dead-branches
topcat analyze -i sql/ -e sql \
--root-nodes api_main \
--external-check-dir src/ \
--external-check-pattern "*.py" \
dead-branches
Shows 🍃 leaf vs 🌿 branch nodes and deletion iteration savings.
Node Classification
orphans
leaf-nodes
root-nodes
unrequired
Health Checks
cycles
missing
file <path>
Root Node Protection
Protect critical entry points from being marked as dead:
Four Methods
--root-nodes api_main --root-nodes worker_main
--root-pattern "**/api/*.sql" --root-pattern "**/migrations/*.sql"
--root-regex "^api_.*" --root-regex "^worker_.*"
--root-dir sql/entry_points/ --root-dir sql/migrations/
Config File
[analysis]
root_patterns = ["**/api/*.sql", "**/workers/*.sql"]
root_nodes = ["critical_function"]
Then:
topcat analyze -i sql/ -e sql --sql-config topcat.toml dead-branches
External Usage Checking
Prevent false positives by checking external references:
topcat analyze -i sql/ -e sql \
--external-check-dir src/api \
--external-check-dir src/workers \
--external-check-pattern "*.py" \
--external-check-pattern "*.rs" \
dead-branches
Uses parallel scanning with caching for performance.
Cleanup Operations
Safety Features
All cleanup commands include:
- Dry-run by default (must use
--no-dry-run)
- Confirmation prompts (unless
--force)
- Root node protection
- External usage checking
- Dependency validation
Commands
topcat clean -i sql/ -e sql dead-branches
topcat clean -i sql/ -e sql dead-branches --no-dry-run
topcat clean -i sql/ -e sql dead-branches --no-dry-run --force
Cleanup types: dead-branches, orphans, unrequired, targets <pattern>
CI/CD Integration
Quiet Mode
topcat analyze -i sql/ -e sql --quiet cycles
if ! topcat analyze -i sql/ -e sql --quiet cycles; then
echo "ERROR: Circular dependencies detected!"
exit 1
fi
Pre-commit Hook
#!/bin/bash
topcat analyze -i sql/ -e sql --quiet cycles || {
echo "Commit rejected: circular dependencies found"
exit 1
}
Automated Cleanup
topcat clean -i sql/ -e sql \
--root-pattern "**/api/*.sql" \
--sql-config topcat.toml \
orphans --no-dry-run --force
Schema Filtering
Limit analysis/cleanup to specific schemas:
topcat analyze -i sql/ -e sql --schema my_schema dead-branches
topcat clean -i sql/ -e sql --schema billing orphans --no-dry-run
See managing-schemas skill for detailed schema workflows.
Common Issues
| Issue | Solution |
|---|
| False positives | Add --external-check-dir to check external code |
| Entry points marked dead | Use --root-nodes or --root-pattern |
| Too aggressive cleanup | Preview with dry-run, add more protection |
| Cycles blocking concat | Use analyze cycles to identify, break with layers |
Detailed References
Related Skills
managing-schemas - Schema-based organization and filtering
exporting-graphs - Visualize dependencies before cleanup
understanding-architecture - How analysis algorithms work