@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.
Files changed (83) hide show
  1. package/LICENSE +21 -0
  2. package/dist/index.d.ts +40 -0
  3. package/dist/index.d.ts.map +1 -0
  4. package/dist/index.js +27 -0
  5. package/dist/parser/index.d.ts +6 -0
  6. package/dist/parser/index.d.ts.map +1 -0
  7. package/dist/parser/index.js +5 -0
  8. package/dist/parser/node-types.d.ts +119 -0
  9. package/dist/parser/node-types.d.ts.map +1 -0
  10. package/dist/parser/node-types.js +4 -0
  11. package/dist/parser/python-parser.d.ts +85 -0
  12. package/dist/parser/python-parser.d.ts.map +1 -0
  13. package/dist/parser/python-parser.js +477 -0
  14. package/dist/skills/index.d.ts +26 -0
  15. package/dist/skills/index.d.ts.map +1 -0
  16. package/dist/skills/index.js +36 -0
  17. package/dist/skills/python-best-practices.d.ts +7 -0
  18. package/dist/skills/python-best-practices.d.ts.map +1 -0
  19. package/dist/skills/python-best-practices.js +78 -0
  20. package/dist/skills/python-code-health.d.ts +7 -0
  21. package/dist/skills/python-code-health.d.ts.map +1 -0
  22. package/dist/skills/python-code-health.js +209 -0
  23. package/dist/skills/python-code-structure.d.ts +7 -0
  24. package/dist/skills/python-code-structure.d.ts.map +1 -0
  25. package/dist/skills/python-code-structure.js +155 -0
  26. package/dist/skills/python-dependency-audit.d.ts +7 -0
  27. package/dist/skills/python-dependency-audit.d.ts.map +1 -0
  28. package/dist/skills/python-dependency-audit.js +246 -0
  29. package/dist/skills/python-refactor-impact.d.ts +7 -0
  30. package/dist/skills/python-refactor-impact.d.ts.map +1 -0
  31. package/dist/skills/python-refactor-impact.js +232 -0
  32. package/dist/tools/extract-docstrings.d.ts +70 -0
  33. package/dist/tools/extract-docstrings.d.ts.map +1 -0
  34. package/dist/tools/extract-docstrings.js +575 -0
  35. package/dist/tools/find-dead-code.d.ts +62 -0
  36. package/dist/tools/find-dead-code.d.ts.map +1 -0
  37. package/dist/tools/find-dead-code.js +422 -0
  38. package/dist/tools/find-duplicates.d.ts +65 -0
  39. package/dist/tools/find-duplicates.d.ts.map +1 -0
  40. package/dist/tools/find-duplicates.js +289 -0
  41. package/dist/tools/find-implementations.d.ts +71 -0
  42. package/dist/tools/find-implementations.d.ts.map +1 -0
  43. package/dist/tools/find-implementations.js +342 -0
  44. package/dist/tools/find-patterns.d.ts +71 -0
  45. package/dist/tools/find-patterns.d.ts.map +1 -0
  46. package/dist/tools/find-patterns.js +477 -0
  47. package/dist/tools/find-references.d.ts +66 -0
  48. package/dist/tools/find-references.d.ts.map +1 -0
  49. package/dist/tools/find-references.js +306 -0
  50. package/dist/tools/find-symbol.d.ts +86 -0
  51. package/dist/tools/find-symbol.d.ts.map +1 -0
  52. package/dist/tools/find-symbol.js +414 -0
  53. package/dist/tools/get-call-graph.d.ts +89 -0
  54. package/dist/tools/get-call-graph.d.ts.map +1 -0
  55. package/dist/tools/get-call-graph.js +431 -0
  56. package/dist/tools/get-class-hierarchy.d.ts +38 -0
  57. package/dist/tools/get-class-hierarchy.d.ts.map +1 -0
  58. package/dist/tools/get-class-hierarchy.js +289 -0
  59. package/dist/tools/get-complexity.d.ts +61 -0
  60. package/dist/tools/get-complexity.d.ts.map +1 -0
  61. package/dist/tools/get-complexity.js +384 -0
  62. package/dist/tools/get-dependency-graph.d.ts +85 -0
  63. package/dist/tools/get-dependency-graph.d.ts.map +1 -0
  64. package/dist/tools/get-dependency-graph.js +387 -0
  65. package/dist/tools/get-exports.d.ts +78 -0
  66. package/dist/tools/get-exports.d.ts.map +1 -0
  67. package/dist/tools/get-exports.js +437 -0
  68. package/dist/tools/get-file-structure.d.ts +28 -0
  69. package/dist/tools/get-file-structure.d.ts.map +1 -0
  70. package/dist/tools/get-file-structure.js +186 -0
  71. package/dist/tools/get-imports.d.ts +34 -0
  72. package/dist/tools/get-imports.d.ts.map +1 -0
  73. package/dist/tools/get-imports.js +455 -0
  74. package/dist/tools/get-signature.d.ts +100 -0
  75. package/dist/tools/get-signature.d.ts.map +1 -0
  76. package/dist/tools/get-signature.js +800 -0
  77. package/dist/tools/index.d.ts +55 -0
  78. package/dist/tools/index.d.ts.map +1 -0
  79. package/dist/tools/index.js +75 -0
  80. package/dist/tools/types.d.ts +378 -0
  81. package/dist/tools/types.d.ts.map +1 -0
  82. package/dist/tools/types.js +4 -0
  83. package/package.json +85 -0
@@ -0,0 +1,232 @@
1
+ /**
2
+ * Python Refactor Impact Skill
3
+ *
4
+ * Assesses the impact of potential code changes and refactoring.
5
+ */
6
+ import { defineSkill } from "@compilr-dev/agents";
7
+ export const pythonRefactorImpactSkill = defineSkill({
8
+ name: "python-refactor-impact",
9
+ description: "Assess impact of Python code changes and refactoring",
10
+ version: "1.1.0",
11
+ tags: ["python", "refactoring", "impact", "analysis"],
12
+ prompt: `You are in Python refactor impact analysis mode. Use these tools systematically:
13
+
14
+ ## Impact Analysis Workflow
15
+
16
+ ### Step 1: Find the Symbol
17
+ Use **find_symbol_python** to locate what you want to change:
18
+ - Function definition
19
+ - Class definition
20
+ - Method or constant
21
+
22
+ ### Step 2: Find All References
23
+ Use **find_references_python** to understand usage:
24
+ - **definition**: Where it's defined
25
+ - **read**: Where it's used/accessed
26
+ - **write**: Where it's assigned
27
+ - **call**: Where it's called as a function
28
+ - **import**: Where it's imported
29
+ - **attribute**: Where it's accessed as an attribute
30
+
31
+ ### Step 3: Analyze Call Graph
32
+ Use **get_call_graph_python** to understand function relationships:
33
+ - Who calls this function?
34
+ - What functions does it call?
35
+ - Trace impact through call chains
36
+
37
+ \`\`\`
38
+ get_call_graph_python({
39
+ startFunction: "process_order",
40
+ path: "/path/to/project",
41
+ direction: "both", // "callers", "callees", or "both"
42
+ maxDepth: 3
43
+ })
44
+ \`\`\`
45
+
46
+ ### Step 4: Understand the Hierarchy
47
+ Use **get_class_hierarchy_python** for class changes:
48
+ - What classes inherit from this?
49
+ - What does this class inherit from?
50
+ - How will changes propagate?
51
+
52
+ ### Step 5: Find Implementations
53
+ Use **find_implementations_python** for ABC/Protocol changes:
54
+ - Find all concrete implementations of an abstract class
55
+ - Find all classes implementing a Protocol
56
+ - Understand which classes need updating
57
+
58
+ \`\`\`
59
+ find_implementations_python({
60
+ name: "BaseHandler",
61
+ scope: "/path/to/project"
62
+ })
63
+ \`\`\`
64
+
65
+ ### Step 6: Check Dependencies
66
+ Use **get_imports_python** to see module dependencies:
67
+ - What imports this module?
68
+ - Breaking changes affect all importers
69
+
70
+ ### Step 7: Assess Complexity
71
+ Use **get_complexity_python** to understand scope:
72
+ - How complex is the current code?
73
+ - Will the refactor simplify it?
74
+
75
+ ## Impact Categories
76
+
77
+ ### High Impact Changes
78
+ - Renaming public classes/functions
79
+ - Changing function signatures
80
+ - Modifying class hierarchy (adding/removing base classes)
81
+ - Changing module structure (moving files)
82
+ - Modifying __init__.py exports
83
+
84
+ ### Medium Impact Changes
85
+ - Adding optional parameters
86
+ - Changing implementation (keeping signature)
87
+ - Adding new methods to classes
88
+ - Deprecating old interfaces
89
+
90
+ ### Low Impact Changes
91
+ - Renaming private members (_name)
92
+ - Changing internal implementation details
93
+ - Adding docstrings
94
+ - Fixing bugs without API changes
95
+
96
+ ## Python-Specific Considerations
97
+
98
+ ### Duck Typing Impact
99
+ - Python uses duck typing - changes affect any code expecting the interface
100
+ - No compiler to catch broken references
101
+ - Tests are critical for catching breakage
102
+
103
+ ### Dynamic Imports
104
+ \`\`\`python
105
+ # These won't be caught by static analysis
106
+ module = importlib.import_module(f"plugins.{name}")
107
+ getattr(obj, "method_name")()
108
+ \`\`\`
109
+
110
+ ### Magic Methods
111
+ \`\`\`python
112
+ # Changes to __init__, __str__, etc. have wide impact
113
+ def __eq__(self, other): # Affects dict keys, set membership
114
+ def __hash__(self): # Affects dict/set operations
115
+ def __iter__(self): # Affects for loops, unpacking
116
+ \`\`\`
117
+
118
+ ### Decorators
119
+ \`\`\`python
120
+ @property # Changes how attribute is accessed
121
+ @classmethod # Changes how method is called
122
+ @staticmethod # Changes binding behavior
123
+ \`\`\`
124
+
125
+ ## Impact Assessment Checklist
126
+
127
+ ### Before Renaming
128
+ - [ ] Find all references (find_references_python)
129
+ - [ ] Check for string-based access (getattr, dictionary keys)
130
+ - [ ] Check for dynamic imports
131
+ - [ ] Check test files
132
+ - [ ] Check config files
133
+
134
+ ### Before Changing Signature
135
+ - [ ] Find all call sites (find_references_python with type: call)
136
+ - [ ] Check for **kwargs usage (may hide callers)
137
+ - [ ] Check for partial/functools.partial usage
138
+ - [ ] Consider adding deprecation warning first
139
+
140
+ ### Before Changing Inheritance
141
+ - [ ] Find all subclasses (get_class_hierarchy_python)
142
+ - [ ] Check for super() calls
143
+ - [ ] Check for overridden methods
144
+ - [ ] Check for ABC abstract methods
145
+
146
+ ### Before Moving Code
147
+ - [ ] Find all imports (find_references_python with type: import)
148
+ - [ ] Check for relative imports
149
+ - [ ] Update __init__.py exports
150
+ - [ ] Consider re-exporting from old location temporarily
151
+
152
+ ## Impact Report Template
153
+
154
+ \`\`\`markdown
155
+ # Refactor Impact Analysis
156
+
157
+ ## Change Description
158
+ - **Target**: function/class name
159
+ - **Change**: rename/modify signature/move/delete
160
+ - **Location**: file:line
161
+
162
+ ## Impact Summary
163
+ - Files affected: N
164
+ - Direct references: N
165
+ - Indirect references: N
166
+ - Risk level: High/Medium/Low
167
+
168
+ ## Direct References
169
+ | File | Line | Type | Code Snippet |
170
+ |------|------|------|--------------|
171
+ | a.py | 42 | call | foo() |
172
+ | b.py | 15 | import | from m import foo |
173
+
174
+ ## Inheritance Impact (for classes)
175
+ - Subclasses: ChildA, ChildB
176
+ - Methods overridden by: 3 classes
177
+
178
+ ## Test Coverage
179
+ - Related tests: N
180
+ - Test files: test_foo.py, test_bar.py
181
+
182
+ ## Migration Plan
183
+ 1. Add deprecation warning
184
+ 2. Create new function with new signature
185
+ 3. Update internal callers
186
+ 4. Update external callers
187
+ 5. Remove deprecated function
188
+
189
+ ## Risks
190
+ - Dynamic imports may be missed
191
+ - String-based getattr usage
192
+ \`\`\`
193
+
194
+ ## Safe Refactoring Strategies
195
+
196
+ ### 1. Deprecation Path
197
+ \`\`\`python
198
+ import warnings
199
+
200
+ def old_function():
201
+ warnings.warn(
202
+ "old_function is deprecated, use new_function instead",
203
+ DeprecationWarning,
204
+ stacklevel=2
205
+ )
206
+ return new_function()
207
+ \`\`\`
208
+
209
+ ### 2. Backwards-Compatible Signature
210
+ \`\`\`python
211
+ def function(new_param=None, *, old_param=None):
212
+ if old_param is not None:
213
+ warnings.warn("old_param is deprecated", DeprecationWarning)
214
+ new_param = old_param
215
+ # ...
216
+ \`\`\`
217
+
218
+ ### 3. Re-export After Move
219
+ \`\`\`python
220
+ # In old location's __init__.py
221
+ from new_location import moved_function # Re-export for backwards compat
222
+ \`\`\`
223
+
224
+ ## When to Use This Skill
225
+
226
+ - Before any refactoring
227
+ - Planning breaking changes
228
+ - Assessing technical debt cleanup
229
+ - Preparing deprecation plans
230
+ - Code review of refactoring PRs
231
+ `,
232
+ });
@@ -0,0 +1,70 @@
1
+ /**
2
+ * extractDocstrings Tool
3
+ *
4
+ * Extract and parse docstrings from Python files.
5
+ * Supports Google, NumPy, Sphinx, and Epytext formats.
6
+ */
7
+ import type { Tool } from "@compilr-dev/agents";
8
+ import type { DocumentationResult, ParsedDocstring } from "./types.js";
9
+ /**
10
+ * Input for extractDocstrings tool
11
+ */
12
+ export interface ExtractDocstringsInput {
13
+ /** File or directory to analyze */
14
+ path: string;
15
+ /** Recursive analysis for directories (default: false) */
16
+ recursive?: boolean;
17
+ /** Filter by symbol kinds */
18
+ kinds?: Array<"function" | "class" | "method" | "module">;
19
+ /** Only include documented symbols (default: false) */
20
+ documentedOnly?: boolean;
21
+ /** Maximum files to analyze (default: 50) */
22
+ maxFiles?: number;
23
+ }
24
+ /**
25
+ * Extracted documentation for a file
26
+ */
27
+ export interface FileDocumentation {
28
+ /** File path */
29
+ path: string;
30
+ /** Module-level docstring */
31
+ moduleDoc?: ParsedDocstring;
32
+ /** Documented symbols */
33
+ symbols: DocumentationResult[];
34
+ /** Statistics */
35
+ stats: {
36
+ totalSymbols: number;
37
+ documentedSymbols: number;
38
+ undocumentedSymbols: number;
39
+ coveragePercent: number;
40
+ };
41
+ }
42
+ /**
43
+ * Output from extractDocstrings tool
44
+ */
45
+ export interface ExtractDocstringsResult {
46
+ /** Analyzed path */
47
+ path: string;
48
+ /** Documentation by file */
49
+ files: FileDocumentation[];
50
+ /** Summary statistics */
51
+ summary: {
52
+ totalFiles: number;
53
+ totalSymbols: number;
54
+ documentedSymbols: number;
55
+ undocumentedSymbols: number;
56
+ coveragePercent: number;
57
+ };
58
+ }
59
+ /**
60
+ * extractDocstrings tool - Extract Python documentation
61
+ */
62
+ export declare const extractDocstringsTool: Tool<ExtractDocstringsInput>;
63
+ /**
64
+ * Factory function to create a customized extractDocstrings tool
65
+ */
66
+ export declare function createExtractDocstringsTool(options?: {
67
+ defaultRecursive?: boolean;
68
+ defaultDocumentedOnly?: boolean;
69
+ }): Tool<ExtractDocstringsInput>;
70
+ //# sourceMappingURL=extract-docstrings.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extract-docstrings.d.ts","sourceRoot":"","sources":["../../src/tools/extract-docstrings.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AASH,OAAO,KAAK,EAAE,IAAI,EAAuB,MAAM,qBAAqB,CAAC;AAQrE,OAAO,KAAK,EACV,mBAAmB,EACnB,eAAe,EAKhB,MAAM,YAAY,CAAC;AAEpB;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,mCAAmC;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,0DAA0D;IAC1D,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,6BAA6B;IAC7B,KAAK,CAAC,EAAE,KAAK,CAAC,UAAU,GAAG,OAAO,GAAG,QAAQ,GAAG,QAAQ,CAAC,CAAC;IAC1D,uDAAuD;IACvD,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,6CAA6C;IA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