with one click
dependency-analyzer
Dependency analysis agent for detecting circular dependencies and validating architecture layers.
Menu
Dependency analysis agent for detecting circular dependencies and validating architecture layers.
CI/CD pipeline creation, deployment automation, and troubleshooting for GitHub Actions and GitLab CI. Use when user says "CI pipeline", "CD pipeline", "GitHub Actions", "GitLab CI", "deployment automation", "pipeline debugging", "deployment pipeline", "workflow file".
Codebase statistics and technical debt tracking agent.
Docker environment validation agent for Stage 5 compliance. Validates Docker availability, captures pre-test state, runs Compose build/deploy, tests HTTP endpoints (authenticated and unauthenticated), detects 4xx/5xx errors, and restores Docker state to pre-test baseline.
Docker image building, container execution, and debugging patterns with security checklists.
Documentation writing skill for creating and editing markdown files. Use when creating, editing, or reviewing documentation files (markdown, MDX, README, guides). Use when the user asks to "write docs", "create documentation", "edit the README", "improve doc clarity", "make docs more readable", "follow the style guide", or "write user-facing content". Applies conversational, clear, and user-focused writing style.
Error handling standardization agent for converting inconsistent error patterns to emit_error().
| name | dependency-analyzer |
| description | Dependency analysis agent for detecting circular dependencies and validating architecture layers. |
| triggers | ["check dependencies","find circular imports","analyze layers","dependency graph","layer violations"] |
Analyze source dependencies across shell and Python modules, detect circular imports, and validate layered architecture constraints.
Read the following reference file(s) before proceeding with any workflow step:
references/layer-rules.md — Strict layered import rules that prevent circular dependencies and define which layers may import from which.source statements (shell) and import statements (Python)# Parse dependencies
python scripts/dependency_parser.py -o json . > deps.json
# Build + visualize graph
python scripts/graph_builder.py deps.json -o dot > deps.dot
dot -Tpng deps.dot -o deps.png
# Validate layer architecture
python scripts/layer_validator.py --config layers.json lib/
| Script | Purpose |
|---|---|
dependency_parser.py | Parse package files for dependencies |
graph_builder.py | Build dependency graph from parsed data |
layer_validator.py | Validate imports against layer rules |
Layer 3 Orchestration → may import 0, 1, 2
Layer 2 Business Logic → may import 0, 1
Layer 1 Basic Helpers → may import 0
Layer 0 Foundation → stdlib only
| Layer | Modules |
|---|---|
| 0 | exit-codes.sh, colors.sh, constants.sh |
| 1 | logging.sh, error-json.sh, config.sh, file-ops.sh |
| 2 | validation.sh, task-*.sh, phase-*.sh, session-*.sh |
| 3 | migrate.sh, backup.sh, doctor.sh |
| Layer | Modules |
|---|---|
| 0 | layer0/exit_codes.py, layer0/colors.py, layer0/constants.py |
| 1 | layer1/logging.py, layer1/error_json.py, layer1/config.py, layer1/file_ops.py, layer1/output_format.py |
| 2 | layer2/validation.py, layer2/task_ops.py |
| 3 | layer3/migrate.py, layer3/backup.py, layer3/doctor.py, layer3/hierarchy_unified.py |
Shell — parse source / . statements:
grep -E "^[[:space:]]*(source|\\.)[[:space:]]+" "$FILE" | \
sed -E 's/.*source[[:space:]]+["'\''"]?([^"'\''"]*)["'\''"]?.*/\1/' | \
sed 's|${LIB_DIR:-lib}/||; s|"${PROJECT_ROOT}"/lib/||'
Python — parse from lib. / import lib. / relative imports:
grep -rn "^from lib\.\|^import lib\.\|^from \.\|^from \.\." lib/layer*/*.py
Construct an adjacency list mapping each file to its dependencies:
{
"validation.sh": ["logging.sh", "file-ops.sh", "error-json.sh"],
"task-ops.sh": ["validation.sh", "logging.sh"]
}
DFS from each node, tracking the current path. A node visited twice in the same path is a cycle.
For each dependency: if dependency_layer >= source_layer, flag as a violation.
| Rule | Severity | Condition |
|---|---|---|
| No circular dependencies | CRITICAL | Any cycle → FAIL |
| Layer constraints | HIGH | Layer N sourcing Layer ≥ N → FAIL |
| Max coupling | MEDIUM | > 7 dependents or > 7 dependencies → WARNING |
| Orphan detection | LOW | 0 dependents → dead code candidate |
# Dependency Analysis Report
## Summary
| Metric | Value |
| ---------------------- | ----------- |
| Total Files | {N} |
| Total Dependencies | {N} |
| Circular Dependencies | {N} |
| Layer Violations | {N} |
| **Status** | PASS / FAIL |
## Dependency Graph
```mermaid
graph TD
A[validation.sh] --> B[logging.sh]
A --> C[file-ops.sh]
B --> D[colors.sh]
```
## Circular Dependencies
Cycle 1: `A.sh → B.sh → C.sh → A.sh`
Resolution: {recommendation}
## Layer Violations
| Source File | Layer | Depends On | Dep Layer | Violation |
| ----------- | ----- | ---------- | --------- | ------------------ |
| {file} | {N} | {dep} | {N} | Upward dependency |
## Coupling Analysis
| Module | Dependents | Dependencies | Coupling Score |
| ------ | ---------- | ------------ | -------------- |
| {file} | {N} | {N} | {score} |
## Recommendations
1. {Specific recommendation with file names}
| Token | Description | Example |
|---|---|---|
{{TARGET_DIR}} | Directory to analyze | lib/ |
{{LAYER_CONFIG}} | Layer definitions | JSON object |
{{EXCLUDE_PATTERNS}} | Files to skip | ["*test*", "*mock*"] |
{{SLUG}} | URL-safe topic name | dependency-audit |
| Pattern | Problem | Fix |
|---|---|---|
| Mutual sourcing | A sources B, B sources A | Extract shared code to Layer 0 |
| Layer skipping | L3 sources L0 directly | Source through intermediate layers |
| God module | One file with 20+ dependents | Split responsibilities |
| Deep chains | A→B→C→D→E→F | Flatten and consolidate |
| Input | From Skill | Description |
|---|---|---|
metrics | codebase-stats | File metrics for prioritization |
hotspots | codebase-stats | High-change files to focus on |
| Output | Format | Description |
|---|---|---|
coupling-analysis | JSON/Markdown | Module coupling metrics |
layer-violations | JSON array | Architecture constraint violations |
dependency-graph | DOT/Mermaid | Visual dependency graph |
hierarchy-unifier — consumes violations to consolidate and fix architecture issues.
lib/layer*/*.py files scanned