@compilr-dev/agents-coding-python 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/index.d.ts +40 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +27 -0
- package/dist/parser/index.d.ts +6 -0
- package/dist/parser/index.d.ts.map +1 -0
- package/dist/parser/index.js +5 -0
- package/dist/parser/node-types.d.ts +119 -0
- package/dist/parser/node-types.d.ts.map +1 -0
- package/dist/parser/node-types.js +4 -0
- package/dist/parser/python-parser.d.ts +85 -0
- package/dist/parser/python-parser.d.ts.map +1 -0
- package/dist/parser/python-parser.js +477 -0
- package/dist/skills/index.d.ts +26 -0
- package/dist/skills/index.d.ts.map +1 -0
- package/dist/skills/index.js +36 -0
- package/dist/skills/python-best-practices.d.ts +7 -0
- package/dist/skills/python-best-practices.d.ts.map +1 -0
- package/dist/skills/python-best-practices.js +78 -0
- package/dist/skills/python-code-health.d.ts +7 -0
- package/dist/skills/python-code-health.d.ts.map +1 -0
- package/dist/skills/python-code-health.js +209 -0
- package/dist/skills/python-code-structure.d.ts +7 -0
- package/dist/skills/python-code-structure.d.ts.map +1 -0
- package/dist/skills/python-code-structure.js +155 -0
- package/dist/skills/python-dependency-audit.d.ts +7 -0
- package/dist/skills/python-dependency-audit.d.ts.map +1 -0
- package/dist/skills/python-dependency-audit.js +246 -0
- package/dist/skills/python-refactor-impact.d.ts +7 -0
- package/dist/skills/python-refactor-impact.d.ts.map +1 -0
- package/dist/skills/python-refactor-impact.js +232 -0
- package/dist/tools/extract-docstrings.d.ts +70 -0
- package/dist/tools/extract-docstrings.d.ts.map +1 -0
- package/dist/tools/extract-docstrings.js +575 -0
- package/dist/tools/find-dead-code.d.ts +62 -0
- package/dist/tools/find-dead-code.d.ts.map +1 -0
- package/dist/tools/find-dead-code.js +422 -0
- package/dist/tools/find-duplicates.d.ts +65 -0
- package/dist/tools/find-duplicates.d.ts.map +1 -0
- package/dist/tools/find-duplicates.js +289 -0
- package/dist/tools/find-implementations.d.ts +71 -0
- package/dist/tools/find-implementations.d.ts.map +1 -0
- package/dist/tools/find-implementations.js +342 -0
- package/dist/tools/find-patterns.d.ts +71 -0
- package/dist/tools/find-patterns.d.ts.map +1 -0
- package/dist/tools/find-patterns.js +477 -0
- package/dist/tools/find-references.d.ts +66 -0
- package/dist/tools/find-references.d.ts.map +1 -0
- package/dist/tools/find-references.js +306 -0
- package/dist/tools/find-symbol.d.ts +86 -0
- package/dist/tools/find-symbol.d.ts.map +1 -0
- package/dist/tools/find-symbol.js +414 -0
- package/dist/tools/get-call-graph.d.ts +89 -0
- package/dist/tools/get-call-graph.d.ts.map +1 -0
- package/dist/tools/get-call-graph.js +431 -0
- package/dist/tools/get-class-hierarchy.d.ts +38 -0
- package/dist/tools/get-class-hierarchy.d.ts.map +1 -0
- package/dist/tools/get-class-hierarchy.js +289 -0
- package/dist/tools/get-complexity.d.ts +61 -0
- package/dist/tools/get-complexity.d.ts.map +1 -0
- package/dist/tools/get-complexity.js +384 -0
- package/dist/tools/get-dependency-graph.d.ts +85 -0
- package/dist/tools/get-dependency-graph.d.ts.map +1 -0
- package/dist/tools/get-dependency-graph.js +387 -0
- package/dist/tools/get-exports.d.ts +78 -0
- package/dist/tools/get-exports.d.ts.map +1 -0
- package/dist/tools/get-exports.js +437 -0
- package/dist/tools/get-file-structure.d.ts +28 -0
- package/dist/tools/get-file-structure.d.ts.map +1 -0
- package/dist/tools/get-file-structure.js +186 -0
- package/dist/tools/get-imports.d.ts +34 -0
- package/dist/tools/get-imports.d.ts.map +1 -0
- package/dist/tools/get-imports.js +455 -0
- package/dist/tools/get-signature.d.ts +100 -0
- package/dist/tools/get-signature.d.ts.map +1 -0
- package/dist/tools/get-signature.js +800 -0
- package/dist/tools/index.d.ts +55 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +75 -0
- package/dist/tools/types.d.ts +378 -0
- package/dist/tools/types.d.ts.map +1 -0
- package/dist/tools/types.js +4 -0
- package/package.json +85 -0
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Python Code Health Skill
|
|
3
|
+
*
|
|
4
|
+
* Orchestrates code quality analysis using complexity, dead code, duplicates, patterns, and other tools.
|
|
5
|
+
*/
|
|
6
|
+
import { defineSkill } from "@compilr-dev/agents";
|
|
7
|
+
export const pythonCodeHealthSkill = defineSkill({
|
|
8
|
+
name: "python-code-health",
|
|
9
|
+
description: "Comprehensive Python code quality and health analysis",
|
|
10
|
+
version: "1.1.0",
|
|
11
|
+
tags: ["python", "code-health", "quality", "analysis"],
|
|
12
|
+
prompt: `You are in Python code health analysis mode. Use these tools systematically:
|
|
13
|
+
|
|
14
|
+
## Health Check Workflow
|
|
15
|
+
|
|
16
|
+
### Step 1: Complexity Analysis
|
|
17
|
+
Use **get_complexity_python** to find complex code:
|
|
18
|
+
- Cyclomatic complexity > 10 indicates complex logic
|
|
19
|
+
- Cognitive complexity > 15 indicates hard-to-understand code
|
|
20
|
+
- High nesting depth suggests refactoring needed
|
|
21
|
+
- Functions with many parameters need restructuring
|
|
22
|
+
|
|
23
|
+
### Step 2: Dead Code Detection
|
|
24
|
+
Use **find_dead_code_python** to find unused code:
|
|
25
|
+
- Unused functions (defined but never called)
|
|
26
|
+
- Unused classes (defined but never instantiated)
|
|
27
|
+
- Unused variables (declared but never used)
|
|
28
|
+
- Confidence levels (high/medium/low)
|
|
29
|
+
|
|
30
|
+
### Step 3: Code Duplication
|
|
31
|
+
Use **find_duplicates_python** to detect duplicated code:
|
|
32
|
+
- Content-based hashing for exact matches
|
|
33
|
+
- Normalized comparison (ignores formatting)
|
|
34
|
+
- Identifies refactoring opportunities
|
|
35
|
+
- Shows duplication percentage
|
|
36
|
+
|
|
37
|
+
### Step 4: Anti-Patterns and Code Smells
|
|
38
|
+
Use **find_patterns_python** to find issues:
|
|
39
|
+
- Security issues (eval, exec, pickle with untrusted data)
|
|
40
|
+
- Performance issues (star imports, bare except)
|
|
41
|
+
- Maintainability issues (mutable default args, magic numbers)
|
|
42
|
+
- Custom pattern support
|
|
43
|
+
|
|
44
|
+
### Step 5: Documentation Coverage
|
|
45
|
+
Use **extract_docstrings_python** to check documentation:
|
|
46
|
+
- Functions without docstrings need documentation
|
|
47
|
+
- Missing parameter descriptions
|
|
48
|
+
- Missing return type documentation
|
|
49
|
+
- Missing exception documentation
|
|
50
|
+
|
|
51
|
+
### Step 6: Import Analysis
|
|
52
|
+
Use **get_imports_python** to review dependencies:
|
|
53
|
+
- High third-party dependency count increases risk
|
|
54
|
+
- Unused imports add clutter
|
|
55
|
+
- Circular import patterns cause issues
|
|
56
|
+
- Prefer stdlib over third-party when possible
|
|
57
|
+
|
|
58
|
+
### Step 7: Code Structure
|
|
59
|
+
Use **get_file_structure_python** to understand organization:
|
|
60
|
+
- God classes with too many methods
|
|
61
|
+
- Files with too many classes/functions
|
|
62
|
+
- Deep class hierarchies
|
|
63
|
+
- Missing __all__ for public API
|
|
64
|
+
|
|
65
|
+
## Health Metrics
|
|
66
|
+
|
|
67
|
+
### Code Complexity
|
|
68
|
+
| Metric | Good | Acceptable | Needs Work |
|
|
69
|
+
|--------|------|------------|------------|
|
|
70
|
+
| Cyclomatic | < 5 | 5-10 | > 10 |
|
|
71
|
+
| Cognitive | < 8 | 8-15 | > 15 |
|
|
72
|
+
| Nesting | < 3 | 3-4 | > 4 |
|
|
73
|
+
| Parameters | < 4 | 4-6 | > 6 |
|
|
74
|
+
|
|
75
|
+
### Dead Code
|
|
76
|
+
| Metric | Good | Acceptable | Needs Work |
|
|
77
|
+
|--------|------|------------|------------|
|
|
78
|
+
| Unused functions | 0 | 1-3 | > 3 |
|
|
79
|
+
| Unused classes | 0 | 1-2 | > 2 |
|
|
80
|
+
| Confidence HIGH items | 0 | 0 | > 0 |
|
|
81
|
+
|
|
82
|
+
### Code Duplication
|
|
83
|
+
| Metric | Good | Acceptable | Needs Work |
|
|
84
|
+
|--------|------|------------|------------|
|
|
85
|
+
| Duplication % | < 3% | 3-7% | > 7% |
|
|
86
|
+
| Duplicate blocks | < 3 | 3-5 | > 5 |
|
|
87
|
+
|
|
88
|
+
### Pattern Issues
|
|
89
|
+
| Metric | Good | Acceptable | Needs Work |
|
|
90
|
+
|--------|------|------------|------------|
|
|
91
|
+
| Security issues | 0 | 0 | > 0 |
|
|
92
|
+
| Performance issues | < 3 | 3-5 | > 5 |
|
|
93
|
+
| Maintainability | < 5 | 5-10 | > 10 |
|
|
94
|
+
|
|
95
|
+
### Documentation
|
|
96
|
+
| Metric | Good | Acceptable | Needs Work |
|
|
97
|
+
|--------|------|------------|------------|
|
|
98
|
+
| Public funcs documented | 100% | > 80% | < 80% |
|
|
99
|
+
| Params documented | 100% | > 70% | < 70% |
|
|
100
|
+
| Classes with docstrings | 100% | > 90% | < 90% |
|
|
101
|
+
|
|
102
|
+
### Dependencies
|
|
103
|
+
| Metric | Good | Acceptable | Needs Work |
|
|
104
|
+
|--------|------|------------|------------|
|
|
105
|
+
| Third-party imports | < 10 | 10-20 | > 20 |
|
|
106
|
+
| Local circular deps | 0 | 1-2 | > 2 |
|
|
107
|
+
|
|
108
|
+
## Quick Health Check (use for rapid assessment)
|
|
109
|
+
|
|
110
|
+
\`\`\`
|
|
111
|
+
// Step 1: Check complexity hotspots
|
|
112
|
+
get_complexity_python({
|
|
113
|
+
path: "/path/to/project",
|
|
114
|
+
recursive: true,
|
|
115
|
+
threshold: 10,
|
|
116
|
+
onlyAboveThreshold: true
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
// Step 2: Find critical patterns
|
|
120
|
+
find_patterns_python({
|
|
121
|
+
path: "/path/to/project",
|
|
122
|
+
categories: ["security", "performance"]
|
|
123
|
+
})
|
|
124
|
+
\`\`\`
|
|
125
|
+
|
|
126
|
+
## Full Health Audit
|
|
127
|
+
|
|
128
|
+
\`\`\`
|
|
129
|
+
// Step 1: Complexity analysis
|
|
130
|
+
get_complexity_python({ path: "/path/to/project", recursive: true })
|
|
131
|
+
|
|
132
|
+
// Step 2: Dead code detection
|
|
133
|
+
find_dead_code_python({ path: "/path/to/project" })
|
|
134
|
+
|
|
135
|
+
// Step 3: Duplication analysis
|
|
136
|
+
find_duplicates_python({ path: "/path/to/project", minLines: 6 })
|
|
137
|
+
|
|
138
|
+
// Step 4: Pattern analysis
|
|
139
|
+
find_patterns_python({ path: "/path/to/project", categories: ["all"] })
|
|
140
|
+
|
|
141
|
+
// Step 5: Documentation coverage
|
|
142
|
+
extract_docstrings_python({ path: "/path/to/project" })
|
|
143
|
+
\`\`\`
|
|
144
|
+
|
|
145
|
+
## Analysis Report Template
|
|
146
|
+
|
|
147
|
+
\`\`\`markdown
|
|
148
|
+
# Code Health Report
|
|
149
|
+
|
|
150
|
+
## Summary
|
|
151
|
+
| Metric | Value | Status |
|
|
152
|
+
|--------|-------|--------|
|
|
153
|
+
| Files analyzed | N | - |
|
|
154
|
+
| Avg complexity | X | Good/Warning/Critical |
|
|
155
|
+
| Max complexity | Y | Good/Warning/Critical |
|
|
156
|
+
| Dead code items | N | Good/Warning/Critical |
|
|
157
|
+
| Duplicate blocks | M | Good/Warning/Critical |
|
|
158
|
+
| Duplication % | X% | Good/Warning/Critical |
|
|
159
|
+
| Security issues | S | Good/Warning/Critical |
|
|
160
|
+
| Performance issues | P | Good/Warning/Critical |
|
|
161
|
+
|
|
162
|
+
## Complexity Hotspots (top 5)
|
|
163
|
+
| Function | File | Cyclomatic | Cognitive | Action |
|
|
164
|
+
|----------|------|------------|-----------|--------|
|
|
165
|
+
| process_order | orders.py:45 | 25 | 32 | Refactor immediately |
|
|
166
|
+
| validate_input | utils.py:120 | 15 | 18 | Consider splitting |
|
|
167
|
+
|
|
168
|
+
## Dead Code
|
|
169
|
+
| Name | File | Type | Confidence |
|
|
170
|
+
|------|------|------|------------|
|
|
171
|
+
| old_helper | utils.py:89 | function | HIGH |
|
|
172
|
+
| LegacyClass | models.py:12 | class | MEDIUM |
|
|
173
|
+
|
|
174
|
+
## Code Duplication
|
|
175
|
+
| ID | Lines | Files | Sample |
|
|
176
|
+
|----|-------|-------|--------|
|
|
177
|
+
| DUP-1 | 15 | 3 | \`def validate...\` |
|
|
178
|
+
|
|
179
|
+
## Pattern Issues
|
|
180
|
+
| Pattern | Severity | Count | Files |
|
|
181
|
+
|---------|----------|-------|-------|
|
|
182
|
+
| eval-usage | ERROR | 2 | api.py, utils.py |
|
|
183
|
+
| bare-except | WARNING | 5 | various |
|
|
184
|
+
| mutable-default | WARNING | 3 | models.py |
|
|
185
|
+
|
|
186
|
+
## Recommendations (prioritized)
|
|
187
|
+
|
|
188
|
+
### Critical (fix immediately)
|
|
189
|
+
1. **Security**: Remove eval() usage in api.py:45
|
|
190
|
+
2. **Complexity**: Refactor process_order() - split into smaller functions
|
|
191
|
+
|
|
192
|
+
### Important (fix soon)
|
|
193
|
+
1. **Dead code**: Remove unused LegacyClass
|
|
194
|
+
2. **Duplication**: Extract common validation logic (DUP-1)
|
|
195
|
+
|
|
196
|
+
### Suggestions (improve when touching these files)
|
|
197
|
+
1. Add docstrings to undocumented public functions
|
|
198
|
+
2. Fix bare except clauses - catch specific exceptions
|
|
199
|
+
\`\`\`
|
|
200
|
+
|
|
201
|
+
## When to Use This Skill
|
|
202
|
+
|
|
203
|
+
- Before code review
|
|
204
|
+
- After major refactoring
|
|
205
|
+
- During tech debt assessment
|
|
206
|
+
- For new team member onboarding
|
|
207
|
+
- Regular health checks (weekly/monthly)
|
|
208
|
+
`,
|
|
209
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"python-code-structure.d.ts","sourceRoot":"","sources":["../../src/skills/python-code-structure.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,eAAO,MAAM,wBAAwB,qCAoJnC,CAAC"}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Python Code Structure Skill
|
|
3
|
+
*
|
|
4
|
+
* Analyzes Python codebase structure, organization, and architecture patterns.
|
|
5
|
+
*/
|
|
6
|
+
import { defineSkill } from "@compilr-dev/agents";
|
|
7
|
+
export const pythonCodeStructureSkill = defineSkill({
|
|
8
|
+
name: "python-code-structure",
|
|
9
|
+
description: "Analyze Python codebase structure and organization",
|
|
10
|
+
version: "1.0.0",
|
|
11
|
+
tags: ["python", "structure", "architecture", "analysis"],
|
|
12
|
+
prompt: `You are in Python code structure analysis mode. Use these tools systematically:
|
|
13
|
+
|
|
14
|
+
## Structure Analysis Workflow
|
|
15
|
+
|
|
16
|
+
### Step 1: File-Level Overview
|
|
17
|
+
Use **get_file_structure_python** to understand each file:
|
|
18
|
+
- Classes and their methods
|
|
19
|
+
- Standalone functions
|
|
20
|
+
- Module-level constants
|
|
21
|
+
- Import organization
|
|
22
|
+
|
|
23
|
+
### Step 2: Class Hierarchy
|
|
24
|
+
Use **get_class_hierarchy_python** to understand inheritance:
|
|
25
|
+
- Find parent classes (ancestors)
|
|
26
|
+
- Find child classes (descendants)
|
|
27
|
+
- Understand Method Resolution Order (MRO)
|
|
28
|
+
- Identify mixin patterns
|
|
29
|
+
|
|
30
|
+
### Step 3: Symbol Navigation
|
|
31
|
+
Use **find_symbol_python** to locate definitions:
|
|
32
|
+
- Find where functions are defined
|
|
33
|
+
- Locate class definitions
|
|
34
|
+
- Find constant declarations
|
|
35
|
+
|
|
36
|
+
### Step 4: Usage Analysis
|
|
37
|
+
Use **find_references_python** to understand usage:
|
|
38
|
+
- How classes/functions are used
|
|
39
|
+
- Import patterns across the codebase
|
|
40
|
+
- Call sites and data flow
|
|
41
|
+
|
|
42
|
+
## Python Package Structure
|
|
43
|
+
|
|
44
|
+
### Standard Package Layout
|
|
45
|
+
\`\`\`
|
|
46
|
+
my_package/
|
|
47
|
+
├── __init__.py # Package exports (__all__)
|
|
48
|
+
├── __main__.py # Entry point for python -m
|
|
49
|
+
├── core/
|
|
50
|
+
│ ├── __init__.py
|
|
51
|
+
│ └── models.py
|
|
52
|
+
├── utils/
|
|
53
|
+
│ ├── __init__.py
|
|
54
|
+
│ └── helpers.py
|
|
55
|
+
├── cli.py # CLI entry point
|
|
56
|
+
└── py.typed # PEP 561 marker
|
|
57
|
+
\`\`\`
|
|
58
|
+
|
|
59
|
+
### Test Structure
|
|
60
|
+
\`\`\`
|
|
61
|
+
tests/
|
|
62
|
+
├── __init__.py
|
|
63
|
+
├── conftest.py # pytest fixtures
|
|
64
|
+
├── test_core/
|
|
65
|
+
│ └── test_models.py
|
|
66
|
+
└── test_utils/
|
|
67
|
+
└── test_helpers.py
|
|
68
|
+
\`\`\`
|
|
69
|
+
|
|
70
|
+
## Patterns to Look For
|
|
71
|
+
|
|
72
|
+
### Good Patterns
|
|
73
|
+
- **Layered Architecture**: Clear separation of concerns
|
|
74
|
+
- **Dependency Injection**: Loose coupling via constructor params
|
|
75
|
+
- **Interface Segregation**: Small, focused abstract base classes
|
|
76
|
+
- **Composition over Inheritance**: Prefer has-a over is-a
|
|
77
|
+
|
|
78
|
+
### Anti-Patterns
|
|
79
|
+
- **God Class**: Class with too many responsibilities (>10 methods, >500 lines)
|
|
80
|
+
- **Circular Dependencies**: Module A imports B, B imports A
|
|
81
|
+
- **Deep Inheritance**: More than 3 levels of inheritance
|
|
82
|
+
- **Spaghetti Code**: No clear structure or organization
|
|
83
|
+
- **Feature Envy**: Methods that use other class's data more than their own
|
|
84
|
+
|
|
85
|
+
## Structure Metrics
|
|
86
|
+
|
|
87
|
+
### File Level
|
|
88
|
+
| Metric | Good | Acceptable | Needs Work |
|
|
89
|
+
|--------|------|------------|------------|
|
|
90
|
+
| Lines per file | < 300 | 300-500 | > 500 |
|
|
91
|
+
| Classes per file | 1-3 | 4-5 | > 5 |
|
|
92
|
+
| Functions per file | < 15 | 15-25 | > 25 |
|
|
93
|
+
| Imports | < 15 | 15-25 | > 25 |
|
|
94
|
+
|
|
95
|
+
### Class Level
|
|
96
|
+
| Metric | Good | Acceptable | Needs Work |
|
|
97
|
+
|--------|------|------------|------------|
|
|
98
|
+
| Methods per class | < 10 | 10-15 | > 15 |
|
|
99
|
+
| Lines per class | < 200 | 200-400 | > 400 |
|
|
100
|
+
| Inheritance depth | 1-2 | 3 | > 3 |
|
|
101
|
+
| Public methods | < 8 | 8-12 | > 12 |
|
|
102
|
+
|
|
103
|
+
### Function Level
|
|
104
|
+
| Metric | Good | Acceptable | Needs Work |
|
|
105
|
+
|--------|------|------------|------------|
|
|
106
|
+
| Lines per function | < 20 | 20-40 | > 40 |
|
|
107
|
+
| Parameters | < 4 | 4-6 | > 6 |
|
|
108
|
+
| Return paths | < 3 | 3-5 | > 5 |
|
|
109
|
+
|
|
110
|
+
## Common Refactoring Suggestions
|
|
111
|
+
|
|
112
|
+
1. **Extract Class**: Split large class into smaller focused ones
|
|
113
|
+
2. **Extract Function**: Break long functions into smaller ones
|
|
114
|
+
3. **Move Method**: Move method to class where data lives
|
|
115
|
+
4. **Introduce Abstract Base Class**: Create interface for polymorphism
|
|
116
|
+
5. **Replace Inheritance with Composition**: Use delegation instead
|
|
117
|
+
|
|
118
|
+
## Structure Report Template
|
|
119
|
+
|
|
120
|
+
\`\`\`markdown
|
|
121
|
+
# Code Structure Report
|
|
122
|
+
|
|
123
|
+
## Overview
|
|
124
|
+
- Total files: N
|
|
125
|
+
- Total classes: N
|
|
126
|
+
- Total functions: N
|
|
127
|
+
|
|
128
|
+
## Package Organization
|
|
129
|
+
- Root: my_package/
|
|
130
|
+
- Key modules: core, utils, api
|
|
131
|
+
|
|
132
|
+
## Class Hierarchy
|
|
133
|
+
1. BaseClass
|
|
134
|
+
├── ChildA
|
|
135
|
+
└── ChildB
|
|
136
|
+
└── GrandChild
|
|
137
|
+
|
|
138
|
+
## Hotspots
|
|
139
|
+
1. large_module.py - 600 lines, 8 classes
|
|
140
|
+
2. god_class.py::MegaClass - 25 methods
|
|
141
|
+
|
|
142
|
+
## Recommendations
|
|
143
|
+
1. Split large_module.py into smaller modules
|
|
144
|
+
2. Extract responsibilities from MegaClass
|
|
145
|
+
\`\`\`
|
|
146
|
+
|
|
147
|
+
## When to Use This Skill
|
|
148
|
+
|
|
149
|
+
- Onboarding to a new codebase
|
|
150
|
+
- Before major refactoring
|
|
151
|
+
- Architecture review
|
|
152
|
+
- Documentation generation
|
|
153
|
+
- Understanding legacy code
|
|
154
|
+
`,
|
|
155
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Python Dependency Audit Skill
|
|
3
|
+
*
|
|
4
|
+
* Analyzes Python imports, dependencies, and finds circular dependency issues.
|
|
5
|
+
*/
|
|
6
|
+
export declare const pythonDependencyAuditSkill: import("@compilr-dev/agents").Skill;
|
|
7
|
+
//# sourceMappingURL=python-dependency-audit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"python-dependency-audit.d.ts","sourceRoot":"","sources":["../../src/skills/python-dependency-audit.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,eAAO,MAAM,0BAA0B,qCA+OrC,CAAC"}
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Python Dependency Audit Skill
|
|
3
|
+
*
|
|
4
|
+
* Analyzes Python imports, dependencies, and finds circular dependency issues.
|
|
5
|
+
*/
|
|
6
|
+
import { defineSkill } from "@compilr-dev/agents";
|
|
7
|
+
export const pythonDependencyAuditSkill = defineSkill({
|
|
8
|
+
name: "python-dependency-audit",
|
|
9
|
+
description: "Audit Python imports and dependencies for issues",
|
|
10
|
+
version: "1.1.0",
|
|
11
|
+
tags: ["python", "dependencies", "imports", "audit"],
|
|
12
|
+
prompt: `You are in Python dependency audit mode. Use these tools systematically:
|
|
13
|
+
|
|
14
|
+
## Dependency Audit Workflow
|
|
15
|
+
|
|
16
|
+
### Step 1: Build Dependency Graph
|
|
17
|
+
Use **get_dependency_graph_python** to build a complete module dependency graph:
|
|
18
|
+
- Detect circular dependencies
|
|
19
|
+
- Identify external vs internal dependencies
|
|
20
|
+
- Find modules with excessive dependencies
|
|
21
|
+
- Find highly-depended-upon modules
|
|
22
|
+
|
|
23
|
+
\`\`\`
|
|
24
|
+
get_dependency_graph_python({
|
|
25
|
+
path: "/path/to/project",
|
|
26
|
+
includeExternal: true
|
|
27
|
+
})
|
|
28
|
+
\`\`\`
|
|
29
|
+
|
|
30
|
+
### Step 2: Import Analysis
|
|
31
|
+
Use **get_imports_python** to categorize all imports:
|
|
32
|
+
- **stdlib**: Python standard library (safe, always available)
|
|
33
|
+
- **third_party**: External packages (need installation)
|
|
34
|
+
- **local**: Project-internal modules
|
|
35
|
+
|
|
36
|
+
### Step 3: Reference Mapping
|
|
37
|
+
Use **find_references_python** to understand usage:
|
|
38
|
+
- How modules depend on each other
|
|
39
|
+
- What functions/classes are imported where
|
|
40
|
+
- Which modules are most heavily used
|
|
41
|
+
|
|
42
|
+
### Step 4: Structure Review
|
|
43
|
+
Use **get_file_structure_python** to see module organization:
|
|
44
|
+
- What each module exports
|
|
45
|
+
- Public API surface (__all__)
|
|
46
|
+
- Internal vs public modules
|
|
47
|
+
|
|
48
|
+
### Step 5: Export Analysis
|
|
49
|
+
Use **get_exports_python** to understand public API:
|
|
50
|
+
- What symbols are in __all__
|
|
51
|
+
- Public vs private symbols
|
|
52
|
+
- Re-exports from submodules
|
|
53
|
+
|
|
54
|
+
## Python Dependency Types
|
|
55
|
+
|
|
56
|
+
### Direct Dependencies
|
|
57
|
+
\`\`\`python
|
|
58
|
+
import requests # Whole module
|
|
59
|
+
from flask import Flask # Specific import
|
|
60
|
+
\`\`\`
|
|
61
|
+
|
|
62
|
+
### Relative Imports (Local)
|
|
63
|
+
\`\`\`python
|
|
64
|
+
from . import utils # Same package
|
|
65
|
+
from ..core import models # Parent package
|
|
66
|
+
from .helpers import parse # Same package, specific
|
|
67
|
+
\`\`\`
|
|
68
|
+
|
|
69
|
+
### Conditional/Lazy Imports
|
|
70
|
+
\`\`\`python
|
|
71
|
+
if TYPE_CHECKING:
|
|
72
|
+
from heavy_module import BigClass # Type-only
|
|
73
|
+
|
|
74
|
+
def get_thing():
|
|
75
|
+
from expensive import Thing # Lazy load
|
|
76
|
+
return Thing()
|
|
77
|
+
\`\`\`
|
|
78
|
+
|
|
79
|
+
## Circular Dependency Detection
|
|
80
|
+
|
|
81
|
+
### Using get_dependency_graph_python
|
|
82
|
+
The tool automatically detects circular dependencies:
|
|
83
|
+
\`\`\`
|
|
84
|
+
get_dependency_graph_python({ path: "/path/to/project" })
|
|
85
|
+
// Check result.circularDependencies array
|
|
86
|
+
// Each cycle shows: [A → B → C → A]
|
|
87
|
+
\`\`\`
|
|
88
|
+
|
|
89
|
+
### Severity Assessment
|
|
90
|
+
- 2-node cycles: HIGH - direct mutual dependency
|
|
91
|
+
- 3-node cycles: MEDIUM - triangular dependency
|
|
92
|
+
- 4+ node cycles: LOW - long chain, often architectural
|
|
93
|
+
|
|
94
|
+
### Common Solutions
|
|
95
|
+
1. **Extract Common Code**: Move shared code to a third module
|
|
96
|
+
2. **Use Lazy Imports**: Import inside functions, not at module level
|
|
97
|
+
3. **Dependency Inversion**: Depend on abstractions, not concrete modules
|
|
98
|
+
4. **TYPE_CHECKING Guard**: For type hints only, use conditional import
|
|
99
|
+
|
|
100
|
+
\`\`\`python
|
|
101
|
+
from typing import TYPE_CHECKING
|
|
102
|
+
|
|
103
|
+
if TYPE_CHECKING:
|
|
104
|
+
from other_module import SomeClass # Only for type checking
|
|
105
|
+
\`\`\`
|
|
106
|
+
|
|
107
|
+
## Import Best Practices
|
|
108
|
+
|
|
109
|
+
### Order (PEP 8)
|
|
110
|
+
\`\`\`python
|
|
111
|
+
# 1. Standard library
|
|
112
|
+
import os
|
|
113
|
+
import sys
|
|
114
|
+
|
|
115
|
+
# 2. Third-party
|
|
116
|
+
import requests
|
|
117
|
+
import flask
|
|
118
|
+
|
|
119
|
+
# 3. Local
|
|
120
|
+
from . import utils
|
|
121
|
+
from .models import User
|
|
122
|
+
\`\`\`
|
|
123
|
+
|
|
124
|
+
### What to Avoid
|
|
125
|
+
- **\`from module import *\`**: Pollutes namespace, unclear dependencies
|
|
126
|
+
- **Unused imports**: Adds clutter, confuses readers
|
|
127
|
+
- **Circular imports**: Causes runtime errors
|
|
128
|
+
- **Absolute imports of local modules**: Use relative imports within package
|
|
129
|
+
|
|
130
|
+
## Dependency Metrics
|
|
131
|
+
|
|
132
|
+
### Import Health
|
|
133
|
+
| Metric | Good | Acceptable | Needs Work |
|
|
134
|
+
|--------|------|------------|------------|
|
|
135
|
+
| Third-party deps | < 10 | 10-20 | > 20 |
|
|
136
|
+
| Circular deps | 0 | 1-2 | > 2 |
|
|
137
|
+
| Star imports | 0 | 0 | > 0 |
|
|
138
|
+
| Unused imports | 0 | 1-3 | > 3 |
|
|
139
|
+
|
|
140
|
+
### Module Coupling
|
|
141
|
+
| Metric | Good | Acceptable | Needs Work |
|
|
142
|
+
|--------|------|------------|------------|
|
|
143
|
+
| Inbound refs | < 10 | 10-20 | > 20 |
|
|
144
|
+
| Outbound deps | < 8 | 8-15 | > 15 |
|
|
145
|
+
| Depth in hierarchy | < 3 | 3-4 | > 4 |
|
|
146
|
+
|
|
147
|
+
### Dependency Graph Stats
|
|
148
|
+
| Metric | Good | Acceptable | Needs Work |
|
|
149
|
+
|--------|------|------------|------------|
|
|
150
|
+
| Total modules | < 50 | 50-100 | > 100 |
|
|
151
|
+
| Avg deps per module | < 5 | 5-10 | > 10 |
|
|
152
|
+
| Most depended-upon | < 15 | 15-25 | > 25 |
|
|
153
|
+
|
|
154
|
+
## Audit Report Template
|
|
155
|
+
|
|
156
|
+
\`\`\`markdown
|
|
157
|
+
# Dependency Audit Report
|
|
158
|
+
|
|
159
|
+
## Dependency Graph Summary
|
|
160
|
+
| Metric | Value |
|
|
161
|
+
|--------|-------|
|
|
162
|
+
| Total modules | X |
|
|
163
|
+
| Internal modules | Y |
|
|
164
|
+
| External packages | Z |
|
|
165
|
+
| Total edges | N |
|
|
166
|
+
| Circular dependencies | M |
|
|
167
|
+
|
|
168
|
+
## Circular Dependencies (if any)
|
|
169
|
+
1. \`module_a.py\` → \`module_b.py\` → \`module_a.py\`
|
|
170
|
+
- Severity: HIGH (2-node cycle)
|
|
171
|
+
- Suggested fix: Extract shared code to new module
|
|
172
|
+
|
|
173
|
+
## Hot Spots
|
|
174
|
+
| Module | Incoming | Outgoing | Risk |
|
|
175
|
+
|--------|----------|----------|------|
|
|
176
|
+
| utils/__init__.py | 15 | 3 | HIGH - God module |
|
|
177
|
+
| services/api.py | 2 | 12 | MEDIUM - Many deps |
|
|
178
|
+
|
|
179
|
+
## External Packages (N total)
|
|
180
|
+
- **Core**: requests, flask, sqlalchemy
|
|
181
|
+
- **Dev**: pytest, mypy, black
|
|
182
|
+
- **Potential issues**:
|
|
183
|
+
- requests + httpx (duplicate functionality)
|
|
184
|
+
|
|
185
|
+
## Import Breakdown
|
|
186
|
+
| Category | Count | % |
|
|
187
|
+
|----------|-------|---|
|
|
188
|
+
| stdlib | N | X% |
|
|
189
|
+
| third_party | N | X% |
|
|
190
|
+
| local | N | X% |
|
|
191
|
+
|
|
192
|
+
## Unused Imports
|
|
193
|
+
1. module.py:5 - unused import 'os'
|
|
194
|
+
|
|
195
|
+
## Recommendations
|
|
196
|
+
1. Break up utils/__init__.py into focused modules
|
|
197
|
+
2. Resolve circular dependency between A and B
|
|
198
|
+
3. Consider replacing requests with httpx for async support
|
|
199
|
+
4. Remove unused imports (N total)
|
|
200
|
+
\`\`\`
|
|
201
|
+
|
|
202
|
+
## Common Scenarios
|
|
203
|
+
|
|
204
|
+
### "What does this module depend on?"
|
|
205
|
+
\`\`\`
|
|
206
|
+
get_imports_python({ path: "module.py" })
|
|
207
|
+
\`\`\`
|
|
208
|
+
|
|
209
|
+
### "What depends on this module?"
|
|
210
|
+
\`\`\`
|
|
211
|
+
find_references_python({ name: "my_module", filterType: "import" })
|
|
212
|
+
\`\`\`
|
|
213
|
+
|
|
214
|
+
### "Find all circular dependencies"
|
|
215
|
+
\`\`\`
|
|
216
|
+
get_dependency_graph_python({ path: "/path/to/project" })
|
|
217
|
+
// Check circularDependencies in result
|
|
218
|
+
\`\`\`
|
|
219
|
+
|
|
220
|
+
### "Find all third-party dependencies"
|
|
221
|
+
\`\`\`
|
|
222
|
+
get_imports_python({ path: ".", recursive: true })
|
|
223
|
+
// Filter result for category: "third_party"
|
|
224
|
+
\`\`\`
|
|
225
|
+
|
|
226
|
+
### "Check for import issues in a directory"
|
|
227
|
+
\`\`\`
|
|
228
|
+
get_imports_python({ path: "src/", recursive: true })
|
|
229
|
+
// Look for: star imports, unused, circular patterns
|
|
230
|
+
\`\`\`
|
|
231
|
+
|
|
232
|
+
### "Analyze module's public API"
|
|
233
|
+
\`\`\`
|
|
234
|
+
get_exports_python({ path: "module.py" })
|
|
235
|
+
// Shows __all__, public symbols, re-exports
|
|
236
|
+
\`\`\`
|
|
237
|
+
|
|
238
|
+
## When to Use This Skill
|
|
239
|
+
|
|
240
|
+
- Before adding new dependencies
|
|
241
|
+
- During code review
|
|
242
|
+
- Debugging import errors
|
|
243
|
+
- Planning module restructuring
|
|
244
|
+
- Dependency cleanup sprints
|
|
245
|
+
`,
|
|
246
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"python-refactor-impact.d.ts","sourceRoot":"","sources":["../../src/skills/python-refactor-impact.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,eAAO,MAAM,yBAAyB,qCAiOpC,CAAC"}
|