Destynova2/cli-code-skills / cli-audit-tangle
cli-audit-tangle
VerifiedDetect spaghetti code and dependency cycles using graph theory, spectral analysis, and biomimetic patterns. Finds god functions, circular dependencies, dead code, suboptimal module boundaries, CI/CD pipeline deadlocks, and inefficient call patterns. Uses call graph topology (not just line-level metrics) to identify structural problems invisible to linters. Provides concrete fix patterns per domain. Use when the user says 'spaghetti', 'tangle', 'untangle', 'god function', 'god object', 'circular dependency', 'cycle detection', 'call graph', 'module coupling', 'dead code', 'code topology', 'complexity analysis', 'who calls who', 'démêler', 'couplage', 'dépendances circulaires', 'fonction dieu', 'code mort', 'import cycle', 'ImportError', 'pipeline deadlock', 'CI stuck', 'needs deadlock', 'everything depends on everything'. Also triggers on 'refactor structure', 'split module', 'too coupled', 'architecture debt', 'dependency diagnostic', 'workflow cycle'.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 22.2 KB |
| references/analogies.md | markdown | 4.6 KB |
| references/analysis-methods.md | markdown | 6.6 KB |
| references/anti-patterns.md | markdown | 4.3 KB |
| references/fix-patterns.md | markdown | 6.7 KB |
references/anti-patterns.md
View on GitHub# Tangle Anti-Patterns — Named Patterns & Detection
> **When to read:** After Step 3 analysis, to match findings against named anti-patterns.
---
## Contents
- 8 Structural Anti-Patterns
- Detection heuristics
- Pre-mortem: What can go wrong with this analysis
---
## 8 Structural Anti-Patterns
| # | Anti-Pattern | Biology/Physics | Detection | Severity |
|---|-------------|----------------|-----------|----------|
| 1 | **God Function** | Fire ant gripping 12 neighbors | god_score > threshold, in° + out° + betweenness all high | Critical |
| 2 | **Circular Dependency** | DNA knot — topoisomerase needed | SCC with > 1 node across module boundaries | Critical |
| 3 | **Shotgun Surgery** | Cutting one strand breaks 10 others | One change requires modifying > 3 files/modules | High |
| 4 | **Feature Envy** | Function that calls outside more than its own module | out-degree to other modules > out-degree within module | High |
| 5 | **Dead Weight** | Dead cell not eliminated (no apoptosis) | in_degree = 0, not entry point, last modified > 3 months | Warning |
| 6 | **Hub and Spoke** | Starfish without redundancy — hub falls, everything falls | One module has > 50% of all inter-module edges | High |
| 7 | **Layering Violation** | Current flowing upward (short circuit) | Lower layer calls upper layer (e.g., data layer calls API layer) | Critical |
| 8 | **Copy-Paste Cluster** | Cellular clones — same code, silent divergence | Multiple functions with near-identical call patterns (same out-edges) | Warning |
---
## Detection heuristics
### 1. God Function
```
in_degree > P90 of all functions
AND out_degree > P75 of all functions
AND betweenness_centrality > P90
AND NOT entry_point
```
**Recommendation:** Type I refactor — extract sub-functions by responsibility.
### 2. Circular Dependency
```
Tarjan SCC with > 1 node
AND nodes span > 1 module
```
**Recommendation:** Type II refactor — introduce trait/interface at the weakest edge.
### 3. Shotgun Surgery
```
For a function F, count how many different modules contain functions
that call F or are called by F.
If module_count > 3 → shotgun surgery risk.
```
**Recommendation:** Consolidate related logic. If F is a utility, it should be in a shared module.
### 4. Feature Envy
```
For function F in module M:
external_calls = calls to functions outside M
internal_calls = calls to functions inside M
If external_calls > internal_calls × 2 → feature envy
```
**Recommendation:** Move F to the module it calls most.
### 5. Dead Weight
```
in_degree == 0
AND NOT (main | test | pub API | FFI | trait impl | macro-referenced)
AND last_git_modification > 90 days
```
**Recommendation:** Confirm with mutation testing, then remove.
### 6. Hub and Spoke
```
For each module M:
inter_module_edges(M) / total_inter_module_edges > 0.5
```
**Recommendation:** Split the hub. Introduce intermediate modules or traits.
### 7. Layering Violation
```
Define layer ordering: presentation → business → data → infra
For each call edge A→B:
If layer(A) is lower than layer(B) → violation
```
**Recommendation:** Invert the dependency (callback, trait, event).
**Layer detection heuristic:**
- Files in `api/`, `handler/`, `route/` → presentation
- Files in `service/`, `domain/`, `core/` → business
- Files in `repo/`, `db/`, `store/` → data
- Files in `infra/`, `config/`, `util/` → infra
### 8. Copy-Paste Cluster
```
For functions F1, F2:
If out_edges(F1) ∩ out_edges(F2) > 0.8 × max(|out_edges(F1)|, |out_edges(F2)|)
AND F1 and F2 are in different locations
→ probable copy-paste
```
**Recommendation:** Extract shared logic to a common function.
---
## Pre-mortem: What can go wrong with this analysis
| Risk | Symptom | Mitigation |
|------|---------|-----------|
| God score threshold too low | Too many false positives, good dispatcher functions flagged | Exclude entry points and routers explicitly |
| Cycle detection misses dynamic dispatch | `dyn Trait` calls are invisible in static graph | Flag modules using `dyn` for manual review |
| Dead code detection hits macro-generated code | Removing it breaks the build | Always confirm with mutation testing before recommending removal |
| Fiedler analysis on disconnected graph | Meaningless partitioning | Check connectivity first, analyze components separately |
| Layer detection by filename | Files named inconsistently | Fall back to import analysis if heuristic fails |
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| rea-analysis-optimizationmorluto/reaOptimize REA providers and shared analysis workflows for agent context, latency, CPU, and memory while preserving correctness and Evidence. Use for analysis bottlenecks and cache or query design; CI/test-suite optimization belongs to rea-ci-tests-audit. | Stars: 469k | Updated | Claude CodeCodex | Verified | Install |
| rea-ci-tests-auditmorluto/reaAudit REA CI and test suites for correctness, fixture drift, false passes, and measured performance; use for suite or workflow investigations and efficiency changes, rather than ordinary feature testing or a single test failure. | Stars: 469k | Updated | Claude CodeCodex | Verified | Install |
| rea-tool-designmorluto/reaAudit, investigate, design, or change REA investigation tools, CLI/MCP contracts, provider capabilities, and Evidence semantics. | Stars: 469k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-auditDietrichGebert/ponytailQuality audit of the whole repo: bugs, security, real load, missing tests, speed, and what to delete. Most important first. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |