ast-analyzer
Deep Abstract Syntax Tree analysis for understanding code structure, dependencies, impact analysis, and pattern detection at the structural level across multiple programming languages
What this skill does
## AST Analyzer Skill
Provides comprehensive Abstract Syntax Tree (AST) analysis capabilities for understanding code at a structural level, identifying patterns, dependencies, and potential issues that simple text analysis would miss.
## Core Philosophy
**Beyond Text Analysis**: While traditional code analysis works with text patterns, AST analysis understands the actual structure and semantics of code, enabling:
- Precise refactoring without breaking logic
- Accurate dependency tracking
- Reliable impact analysis
- Language-aware pattern detection
## Core Capabilities
### 1. AST Parsing
**Multi-Language Support**:
```python
# Python example using ast module
import ast
def parse_python_code(source_code):
tree = ast.parse(source_code)
# Extract all function definitions
functions = [
node for node in ast.walk(tree)
if isinstance(node, ast.FunctionDef)
]
# Extract all class definitions
classes = [
node for node in ast.walk(tree)
if isinstance(node, ast.ClassDef)
]
return {
"functions": len(functions),
"classes": len(classes),
"function_details": [
{
"name": f.name,
"args": [arg.arg for arg in f.args.args],
"line": f.lineno,
"decorators": [d.id for d in f.decorator_list if isinstance(d, ast.Name)]
}
for f in functions
]
}
```
**JavaScript/TypeScript Support**:
```javascript
// Using babel or acorn parser
const parser = require('@babel/parser');
const traverse = require('@babel/traverse').default;
function parseJavaScriptCode(sourceCode) {
const ast = parser.parse(sourceCode, {
sourceType: 'module',
plugins: ['jsx', 'typescript']
});
const analysis = {
functions: [],
classes: [],
imports: [],
exports: []
};
traverse(ast, {
FunctionDeclaration(path) {
analysis.functions.push({
name: path.node.id.name,
params: path.node.params.map(p => p.name),
async: path.node.async
});
},
ClassDeclaration(path) {
analysis.classes.push({
name: path.node.id.name,
methods: path.node.body.body.filter(
m => m.type === 'ClassMethod'
)
});
}
});
return analysis;
}
```
### 2. Function and Class Hierarchy Analysis
**Hierarchy Extraction**:
```python
def analyze_class_hierarchy(ast_tree):
"""Extract complete class inheritance hierarchy."""
hierarchy = {}
for node in ast.walk(ast_tree):
if isinstance(node, ast.ClassDef):
class_info = {
"name": node.name,
"bases": [
base.id if isinstance(base, ast.Name) else str(base)
for base in node.bases
],
"methods": [
m.name for m in node.body
if isinstance(m, ast.FunctionDef)
],
"decorators": [
d.id for d in node.decorator_list
if isinstance(d, ast.Name)
],
"line": node.lineno
}
hierarchy[node.name] = class_info
# Build inheritance tree
for class_name, info in hierarchy.items():
info["children"] = [
name for name, data in hierarchy.items()
if class_name in data["bases"]
]
return hierarchy
```
**Method Call Graph**:
```python
def build_call_graph(ast_tree):
"""Build function call graph showing dependencies."""
call_graph = {}
for node in ast.walk(ast_tree):
if isinstance(node, ast.FunctionDef):
function_name = node.name
calls = []
# Find all function calls within this function
for child in ast.walk(node):
if isinstance(child, ast.Call):
if isinstance(child.func, ast.Name):
calls.append(child.func.id)
elif isinstance(child.func, ast.Attribute):
calls.append(f"{child.func.value.id}.{child.func.attr}")
call_graph[function_name] = {
"calls": list(set(calls)),
"complexity": calculate_complexity(node)
}
return call_graph
```
### 3. Variable Scope and Lifetime Tracking
**Scope Analysis**:
```python
def analyze_variable_scope(ast_tree):
"""Track variable definitions, assignments, and usage scope."""
scopes = []
class ScopeAnalyzer(ast.NodeVisitor):
def __init__(self):
self.current_scope = None
self.scopes = {}
def visit_FunctionDef(self, node):
# Enter new scope
scope_name = f"{self.current_scope}.{node.name}" if self.current_scope else node.name
self.scopes[scope_name] = {
"type": "function",
"variables": {},
"params": [arg.arg for arg in node.args.args],
"line": node.lineno
}
old_scope = self.current_scope
self.current_scope = scope_name
# Analyze variable assignments in this scope
for child in ast.walk(node):
if isinstance(child, ast.Assign):
for target in child.targets:
if isinstance(target, ast.Name):
self.scopes[scope_name]["variables"][target.id] = {
"first_assignment": child.lineno,
"type": "local"
}
self.current_scope = old_scope
def visit_ClassDef(self, node):
# Similar scope tracking for classes
scope_name = f"{self.current_scope}.{node.name}" if self.current_scope else node.name
self.scopes[scope_name] = {
"type": "class",
"variables": {},
"methods": [m.name for m in node.body if isinstance(m, ast.FunctionDef)],
"line": node.lineno
}
analyzer = ScopeAnalyzer()
analyzer.visit(ast_tree)
return analyzer.scopes
```
### 4. Code Pattern and Anti-Pattern Detection
**Common Patterns**:
```python
def detect_patterns(ast_tree):
"""Detect common code patterns and anti-patterns."""
patterns_found = {
"design_patterns": [],
"anti_patterns": [],
"code_smells": []
}
# Singleton pattern detection
for node in ast.walk(ast_tree):
if isinstance(node, ast.ClassDef):
# Check for singleton indicators
has_instance_attr = any(
isinstance(n, ast.Assign) and
any(isinstance(t, ast.Name) and t.id == '_instance' for t in n.targets)
for n in node.body
)
has_new_method = any(
isinstance(n, ast.FunctionDef) and n.name == '__new__'
for n in node.body
)
if has_instance_attr and has_new_method:
patterns_found["design_patterns"].append({
"pattern": "Singleton",
"class": node.name,
"line": node.lineno
})
# Anti-pattern: God class (too many methods)
for node in ast.walk(ast_tree):
if isinstance(node, ast.ClassDef):
method_count = sum(1 for n in node.body if isinstance(n, ast.FunctionDef))
if method_count > 20:
patterns_found["anti_patterns"].append({
"pattern": "God Class",
"class": node.name,
"method_count": method_count,
"line": node.lineno,
"severity": "high"
})
# Code smell: Long function
for node iRelated in General
modeling-omnistudio-epc-catalog
IncludedSalesforce Industries CME EPC product-modeling skill for Product2-based catalog creation. Use when creating EPC products, configuring product attributes, building offer bundles with Product Child Items, or reviewing EPC DataPack JSON metadata for product catalog changes. TRIGGER when: user creates or updates Product2 EPC records, AttributeAssignment payloads, AttributeMetadata/AttributeDefaultValues, Offer bundles, or ProductChildItem relationships. DO NOT TRIGGER when: designing OmniScripts/FlexCards/Integration Procedures (use building-omnistudio-omniscript, building-omnistudio-flexcard, or building-omnistudio-integration-procedure), implementing Apex business logic (use generating-apex), or troubleshooting deployment pipelines (use deploying-metadata).
relationship-science-coach
IncludedUse this skill for direct, practical adult relationship coaching: couples conflict, repair, trust, marriage, dating, flirting, attachment patterns, emotional connection, sex, desire differences, eroticism, kink negotiation, affection, love languages, breakups, and long-term passion. Draw on Gottman, EFT and Hold Me Tight, attachment science, modern sex research, Perel, Nagoski, Kerner, Schnarch, Love and Stosny, and flexible love-language tools. Be concrete and low-hedge. Redirect only for imminent danger, abuse, coercive control, minors, non-consent, self-harm, stalking, or medical/legal/psychiatric decisions.
building-sf-integrations
IncludedSalesforce integration architecture and runtime plumbing with 120-point scoring. Use this skill to set up Named Credentials, External Credentials, External Services, REST/SOAP callout patterns, Platform Events, and Change Data Capture. TRIGGER when: user sets up Named Credentials, External Services, REST/SOAP callouts, Platform Events, CDC, or touches .namedCredential-meta.xml files. DO NOT TRIGGER when: Connected App/OAuth config (use configuring-connected-apps), Apex-only logic (use generating-apex), or data import/export (use handling-sf-data).
venue-templates
IncludedAccess comprehensive LaTeX templates, formatting requirements, and submission guidelines for major scientific publication venues (Nature, Science, PLOS, IEEE, ACM), academic conferences (NeurIPS, ICML, CVPR, CHI), research posters, and grant proposals (NSF, NIH, DOE, DARPA). This skill should be used when preparing manuscripts for journal submission, conference papers, research posters, or grant proposals and need venue-specific formatting requirements and templates.
let-fate-decide
IncludedDraws the 12 Houses of the Zodiac Tarot spread to inject entropy into planning when prompts are vague, ambiguous, or casually delegated. Interprets the spread to guide next steps. Use when the user says 'let fate decide', 'YOLO', 'whatever', 'idk', or other nonchalant phrases, makes Yu-Gi-Oh references, or when you are about to arbitrarily pick between multiple reasonable approaches. Prefer over ask-questions-if-underspecified when the user's tone is casual or playful rather than precision-seeking.
net-ops
IncludedCross-platform network troubleshooting (Windows, macOS, Linux) via local or remote shell. Use for: DNS broken, can't resolve hostnames, nslookup/dig works but apps fail, NRPT, WFP, scutil, /etc/resolver, systemd-resolved, /etc/resolv.conf, NetworkManager, VPN DNS leak residue (ProtonVPN/Mullvad/WireGuard/AnyConnect), AV/firewall blocking DNS or DoH, Tailscale DNS interaction, intermittent connectivity, remote diagnostics over SSH.