Team Ai
Apppublic

mikemichez/codebase-genius-agentic-code-documentation-system

sourceHugging Faceupdated 11mo agoView on Hugging Face
0likes
main.jac182 linesDownload Raw Back to root
1python2node repo {3    has name;4    has url;5    has file_tree;6    has readme_summary;7}8 9node code_file {10    has name;11    has path;12    has content;13    has language;14}15 16node code_entity {17    has name;18    has type;  # function, class, etc.19    has docstring;20    has relationships = [];21}22 23walker init {24    root {25        spawn here --> graph::repo;26    }27}28 29walker code_genius {30    has repo_url;31    has output_path = "./outputs";32 33    root {34        repo = spawn here --> node::repo(url=repo_url);35        spawn here walker::repo_mapper(repo=repo);36        spawn here walker::code_analyzer(repo=repo);37        spawn here walker::doc_genie(repo=repo, output_path=output_path);38    }39}40 41walker repo_mapper {42    has repo;43 44    root {45        # Clone repo using gitpython46        import git47        import os48        from pathlib import Path49 50        repo_dir = f"/tmp/repo_{repo.context['id']}"51        git.Repo.clone_from(repo.url, repo_dir)52 53        # Generate file tree54        file_tree = []55        for root, dirs, files in os.walk(repo_dir):56            if any(skip_dir in root for skip_dir in ['.git', 'node_modules', '__pycache__']):57                continue58            59            current_dir = {60                'path': root,61                'files': [],62                'subdirs': []63            }64            65            for file in files:66                current_dir['files'].append(file)67            68            for dir in dirs:69                current_dir['subdirs'].append(dir)70            71            file_tree.append(current_dir)72 73        repo.file_tree = file_tree74 75        # Extract README76        readme_path = next(Path(repo_dir).glob('README*'), None)77        if readme_path:78            with open(readme_path, 'r') as f:79                readme_content = f.read()80                # Simple summary for now81                repo.readme_summary = "\n".join(readme_content.split('\n')[:5]) + "..."82    }83}84 85walker code_analyzer {86    has repo;87    88    root {89        # Import Python parsing helper90        import py_helpers.parse_code as parser91 92        # Analyze each code file93        for file_info in repo.file_tree:94            for file_name in file_info['files']:95                if not file_name.endswith(('.py', '.jac')):96                    continue97                98                file_path = f"{file_info['path']}/{file_name}"99                with open(file_path, 'r') as f:100                    content = f.read()101                102                # Create code file node103                code_file_node = spawn here --> node::code_file(104                    name=file_name,105                    path=file_path,106                    content=content,107                    language='python' if file_name.endswith('.py') else 'jac'108                );109                110                # Parse code111                analysis = parser.analyze_code(content, file_name)112                for entity in analysis['entities']:113                    entity_node = spawn code_file_node --> node::code_entity(114                        name=entity['name'],115                        type=entity['type'],116                        docstring=entity['docstring']117                    );118                    119                    for rel in entity['relationships']:120                        entity_node.relationships += [rel];121    }122}123 124walker doc_genie {125    has repo;126    has output_path;127    128    root {129        import os130        from pathlib import Path131        import datetime132 133        # Create output directory134        repo_name = repo.url.split('/')[-1].replace('.git', '')135        output_dir = f"{output_path}/{repo_name}"136        os.makedirs(output_dir, exist_ok=True)137 138        # Generate markdown content139        md_content = f"""# {repo_name} Documentation\n\n"""140        md_content += f"*Generated on {datetime.datetime.now()}*\n\n"141        142        # Overview section143        md_content += "## Overview\n\n"144        md_content += repo.readme_summary + "\n\n"145        146        # File structure147        md_content += "## File Structure\n\n"148        md_content += "\n"149        for dir_info in repo.file_tree:150            md_content += f"{dir_info['path']}\n"151            for file in dir_info['files']:152                md_content += f"  ├── {file}\n"153            for subdir in dir_info['subdirs']:154                md_content += f"  └── {subdir}/\n"155        md_content += "\n\n"156        157        # Code entities158        md_content += "## Code Entities\n\n"159        for code_file in here --> node::code_file:160            md_content += f"### {code_file.name}\n\n"161            162            for entity in code_file --> node::code_entity:163                md_content += f"#### {entity.type.capitalize()}: {entity.name}\n\n"164                if entity.docstring:165                    md_content += f"{entity.docstring}\n\n"166                167                if entity.relationships:168                    md_content += "**Relationships:**\n"169                    for rel in entity.relationships:170                        md_content += f"- {rel}\n"171                    md_content += "\n"172        173        # Save file174        output_file = f"{output_dir}/docs.md"175        with open(output_file, 'w') as f:176            f.write(md_content)177        178        repo.output_file = output_file179    }180}181 182</html>