-
-
Notifications
You must be signed in to change notification settings - Fork 109
Expand file tree
/
Copy pathproject_analyzer.py
More file actions
358 lines (293 loc) · 11 KB
/
project_analyzer.py
File metadata and controls
358 lines (293 loc) · 11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
"""
Project Analyzer for Codex CLI Bridge
Analyzes Claude Code project structure:
- Auto-detect project root and type
- Discover all Claude Code assets (skills, agents, commands)
- Generate project metadata
- Build reference map
- Categorize skills by type
"""
import os
import json
from typing import Dict, List, Optional, Any
from pathlib import Path
from dataclasses import dataclass, field, asdict
from claude_parser import ClaudeProjectParser, SkillInfo, AgentInfo
@dataclass
class ProjectMetadata:
"""Complete project metadata."""
name: str
root: str
type: str # GREENFIELD_NEW, ENTERPRISE_REFACTOR, LEGACY_MODERNIZATION
description: str
has_claude_md: bool
has_agents_md: bool
skill_count: int
agent_count: int
documentation_exists: bool
@dataclass
class ProjectStructure:
"""Project folder structure."""
folders: List[str] = field(default_factory=list)
key_files: List[str] = field(default_factory=list)
documentation_files: List[str] = field(default_factory=list)
class ProjectAnalyzer:
"""
Comprehensive project analysis.
Combines parsing with analysis to build complete project understanding.
"""
def __init__(self, project_root: str):
"""
Initialize analyzer.
Args:
project_root: Path to project root directory
"""
self.project_root = Path(project_root).resolve()
self.parser = ClaudeProjectParser(str(self.project_root))
# Analysis results
self.metadata: Optional[ProjectMetadata] = None
self.structure: Optional[ProjectStructure] = None
self.parsed_data: Optional[Dict] = None
def analyze(self) -> Dict[str, Any]:
"""
Perform complete project analysis.
Returns:
Dictionary with all analysis results
"""
print("🔍 Analyzing project structure...")
# Parse project
self.parsed_data = self.parser.parse_all()
# Generate metadata
self.metadata = self._generate_metadata()
# Analyze structure
self.structure = self._analyze_structure()
# Categorize skills
functional_skills = [s for s in self.parsed_data["skills"] if s.is_functional]
prompt_skills = [s for s in self.parsed_data["skills"] if not s.is_functional]
print(f" 📊 Project: {self.metadata.name}")
print(f" 📁 Type: {self.metadata.type}")
print(f" 📦 Skills: {self.metadata.skill_count} ({len(functional_skills)} functional, {len(prompt_skills)} prompt-only)")
print(f" 🤖 Agents: {self.metadata.agent_count}")
print()
return {
"metadata": asdict(self.metadata),
"structure": asdict(self.structure),
"parsed_data": self.parsed_data,
"functional_skills": functional_skills,
"prompt_skills": prompt_skills
}
def _generate_metadata(self) -> ProjectMetadata:
"""Generate project metadata."""
# Get project name
name = self.project_root.name
# Detect project type from CLAUDE.md or default
project_type = self._detect_project_type()
# Get description
description = self.parser.get_overview_section() or f"{name} project"
if len(description) > 200:
description = description[:197] + "..."
# Check for files
has_claude_md = (self.project_root / "CLAUDE.md").exists()
has_agents_md = (self.project_root / "AGENTS.md").exists()
documentation_exists = (self.project_root / "documentation").exists()
return ProjectMetadata(
name=name,
root=str(self.project_root),
type=project_type,
description=description,
has_claude_md=has_claude_md,
has_agents_md=has_agents_md,
skill_count=len(self.parsed_data["skills"]),
agent_count=len(self.parsed_data["agents"]),
documentation_exists=documentation_exists
)
def _detect_project_type(self) -> str:
"""
Detect project type from CLAUDE.md or structure.
Returns:
GREENFIELD_NEW, ENTERPRISE_REFACTOR, or LEGACY_MODERNIZATION
"""
# Check CLAUDE.md for type mentions
if self.parsed_data.get("claude_md_sections"):
for section in self.parsed_data["claude_md_sections"]:
content = section.content.lower()
if "greenfield_new" in content or "greenfield new" in content:
return "GREENFIELD_NEW"
elif "enterprise_refactor" in content or "enterprise refactor" in content:
return "ENTERPRISE_REFACTOR"
elif "legacy_modernization" in content or "legacy modernization" in content:
return "LEGACY_MODERNIZATION"
# Default
return "GREENFIELD_NEW"
def _analyze_structure(self) -> ProjectStructure:
"""Analyze project folder structure."""
folders = []
key_files = []
documentation_files = []
# Key folders to check
important_folders = [
".claude/skills",
".claude/agents",
".claude/commands",
"documentation",
"generated-skills",
"claude-skills-examples",
"src",
"lib",
"tests"
]
for folder in important_folders:
folder_path = self.project_root / folder
if folder_path.exists():
folders.append(folder)
# Key files to check
important_files = [
"CLAUDE.md",
"AGENTS.md",
"README.md",
"CHANGELOG.md",
"package.json",
"requirements.txt",
"pyproject.toml",
".gitignore"
]
for file in important_files:
file_path = self.project_root / file
if file_path.exists():
key_files.append(file)
# Documentation files
docs_dir = self.project_root / "documentation"
if docs_dir.exists():
for doc_file in docs_dir.rglob("*.md"):
rel_path = doc_file.relative_to(self.project_root)
documentation_files.append(str(rel_path))
return ProjectStructure(
folders=folders,
key_files=key_files,
documentation_files=documentation_files
)
def get_skill_by_name(self, name: str) -> Optional[SkillInfo]:
"""
Find skill by name.
Args:
name: Skill name
Returns:
SkillInfo or None
"""
if not self.parsed_data:
return None
for skill in self.parsed_data["skills"]:
if skill.name == name:
return skill
return None
def get_agent_by_name(self, name: str) -> Optional[AgentInfo]:
"""
Find agent by name.
Args:
name: Agent name
Returns:
AgentInfo or None
"""
if not self.parsed_data:
return None
for agent in self.parsed_data["agents"]:
if agent.name == name:
return agent
return None
def generate_summary_report(self) -> str:
"""
Generate human-readable summary report.
Returns:
Formatted summary string
"""
if not self.metadata or not self.structure:
return "No analysis performed yet. Run analyze() first."
report = f"""
╔══════════════════════════════════════════════════════════════╗
║ PROJECT ANALYSIS SUMMARY ║
╚══════════════════════════════════════════════════════════════╝
📁 Project Information
Name: {self.metadata.name}
Type: {self.metadata.type}
Root: {self.metadata.root}
Description: {self.metadata.description}
📄 Key Files
CLAUDE.md: {'✅ Yes' if self.metadata.has_claude_md else '❌ No'}
AGENTS.md: {'✅ Yes' if self.metadata.has_agents_md else '❌ No'}
Documentation: {'✅ Yes' if self.metadata.documentation_exists else '❌ No'}
📊 Statistics
Skills: {self.metadata.skill_count}
Agents: {self.metadata.agent_count}
Folders: {len(self.structure.folders)}
Key Files: {len(self.structure.key_files)}
Doc Files: {len(self.structure.documentation_files)}
📁 Project Structure
"""
# Add folders
if self.structure.folders:
report += "\n Folders:\n"
for folder in sorted(self.structure.folders):
report += f" ✓ {folder}\n"
# Add key files
if self.structure.key_files:
report += "\n Key Files:\n"
for file in sorted(self.structure.key_files):
report += f" ✓ {file}\n"
report += "\n" + "=" * 64 + "\n"
return report
def main():
"""Demo usage of ProjectAnalyzer."""
import argparse
parser = argparse.ArgumentParser(description="Analyze Claude Code project")
parser.add_argument(
"--project-root",
default=".",
help="Project root directory (default: current directory)"
)
parser.add_argument(
"--output",
choices=["summary", "json", "report"],
default="summary",
help="Output format"
)
args = parser.parse_args()
# Analyze project
analyzer = ProjectAnalyzer(args.project_root)
analysis = analyzer.analyze()
if args.output == "summary":
print("=" * 64)
print("ANALYSIS COMPLETE")
print("=" * 64)
print(f"Project: {analysis['metadata']['name']}")
print(f"Skills: {analysis['metadata']['skill_count']}")
print(f"Agents: {analysis['metadata']['agent_count']}")
print(f"Functional skills: {len(analysis['functional_skills'])}")
print(f"Prompt skills: {len(analysis['prompt_skills'])}")
elif args.output == "report":
print(analyzer.generate_summary_report())
elif args.output == "json":
# Convert dataclasses to dicts for JSON
output = {
"metadata": analysis["metadata"],
"structure": analysis["structure"],
"skills": [
{
"name": s.name,
"description": s.description,
"location": s.location,
"is_functional": s.is_functional
}
for s in analysis["parsed_data"]["skills"]
],
"agents": [
{
"name": a.name,
"description": a.description,
"location": a.location
}
for a in analysis["parsed_data"]["agents"]
]
}
print(json.dumps(output, indent=2))
if __name__ == "__main__":
main()