-
Notifications
You must be signed in to change notification settings - Fork 0
Claude/implement research plan 01 wsn7n gi rhg ag qh mwa vi l9 q #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
thorwhalen
merged 4 commits into
master
from
claude/implement-research-plan-01WSN7nGiRhgAgQHMwaViL9Q
Nov 18, 2025
Merged
Claude/implement research plan 01 wsn7n gi rhg ag qh mwa vi l9 q #2
thorwhalen
merged 4 commits into
master
from
claude/implement-research-plan-01WSN7nGiRhgAgQHMwaViL9Q
Nov 18, 2025
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Implemented a comprehensive bidirectional diagramming system based on the research in misc/REASEARCH.md. This Phase 1 implementation includes: Core Architecture: - DiagramIR: AST-based intermediate representation for diagrams - Node and Edge types with extensible metadata - Validation and type-safe operations Features: - Text-to-Diagram conversion with simple rule-based parser - Mermaid renderer supporting multiple node/edge types - NetworkX integration for graph analysis (paths, cycles, topological sort) - CLI tool for command-line usage - Python API for programmatic access Components: - ij/core.py: Core data structures (DiagramIR, Node, Edge, enums) - ij/converters/text_to_ir.py: Text-to-diagram conversion - ij/renderers/mermaid.py: Mermaid syntax renderer - ij/graph_ops.py: NetworkX-based graph operations - ij/cli.py: Command-line interface Testing: - 26 comprehensive tests covering all modules - 100% test pass rate - Tests for core, renderers, converters, and graph operations Examples: - examples/basic_usage.py: 6 usage examples - Demonstrates text conversion, manual creation, graph analysis Documentation: - Comprehensive README with quick start, examples, roadmap - API documentation in docstrings - Examples directory with README Dependencies: - networkx>=3.0: Graph analysis foundation - graphviz>=0.20: Rendering support Following research recommendations: - AST-based IR for bidirectional conversion - Text-based DSL for version control - NetworkX for graph operations - Mermaid for GitHub-native diagrams - Extensible architecture for future formats (PlantUML, D2) All tests passing. Ready for Phase 2: Enhanced parsers and additional formats.
Added comprehensive bidirectional conversion capabilities and support for multiple diagram formats, completing Phase 2 of the roadmap. NEW FEATURES: 1. Mermaid Parser (Bidirectional Conversion): - Parse Mermaid flowchart syntax back to DiagramIR - Support for all node shapes (stadium, rhombus, cylinder, etc.) - Edge parsing with labels and types - Direction and title metadata extraction - Complete roundtrip validation (Mermaid → IR → Mermaid) 2. PlantUML Renderer: - Activity diagram syntax generation - Configurable skinparam styling - Support for all node types - Decision nodes with branches - Topological ordering for clean output 3. D2 Renderer (Terrastruct): - Modern, beautiful diagram syntax - Multiple layout engines (dagre, elk, tala) - Colored node styling by type - Direction conversion from Mermaid - Shape customization (oval, rectangle, diamond, cylinder) 4. Graphviz/DOT Renderer: - Classic graph visualization format - Multiple layout algorithms (dot, neato, fdp, circo, etc.) - Node coloring and styling - Edge type support (dashed, bidirectional) - Direct image rendering support 5. Enhanced Text Converter: - Conditional branches: "If condition: action, else: action" - Parallel flows: "[parallel: A, B, C]" - Loops: "while condition: action" - Better keyword detection and type inference - Sentence-style parsing support COMPONENTS ADDED: Parser Module: - ij/parsers/mermaid.py: Mermaid syntax parser - ij/parsers/__init__.py: Parser module exports Renderers: - ij/renderers/plantuml.py: PlantUML activity diagram renderer - ij/renderers/d2.py: D2 (Terrastruct) renderer - ij/renderers/graphviz.py: Graphviz/DOT renderer with image support - Updated ij/renderers/__init__.py: Export all renderers Converters: - ij/converters/enhanced_text.py: Advanced text parsing with NLP - Updated ij/converters/__init__.py: Export enhanced converter Tests (26 new tests): - tests/test_parsers.py: 7 parser tests including roundtrip validation - tests/test_new_renderers.py: 11 renderer tests for PlantUML, D2, Graphviz - tests/test_enhanced_converter.py: 8 enhanced converter tests Examples: - examples/phase2_features.py: 6 comprehensive examples demonstrating: * Bidirectional conversion workflow * Multi-format rendering * Enhanced text features * Format conversion pipelines * Complex workflows Documentation: - PHASE2.md: Complete Phase 2 feature documentation - Updated README.md: Phase 2 features, updated roadmap, test counts - Updated ij/__init__.py: Export all new classes TEST RESULTS: - 52 total tests (26 Phase 1 + 26 Phase 2) - 100% pass rate - All formats tested and validated - Roundtrip conversion verified CAPABILITIES: Multi-Format Workflow: Text → DiagramIR → Mermaid/PlantUML/D2/Graphviz Mermaid → DiagramIR → Any other format Supported Conversions: - Text → Mermaid (Phase 1) - Text → PlantUML/D2/Graphviz (Phase 2) - Mermaid → DiagramIR (Phase 2) - DiagramIR → Mermaid/PlantUML/D2/Graphviz (Phase 2) Enhanced Text Patterns: - Simple: "A -> B -> C" - Conditional: "If X: do Y, else: do Z" - Parallel: "[parallel: A, B, C]" - Loop: "while X: do Y" Following research recommendations: - Bidirectional editing (Mermaid ↔ IR) - Multiple format support (Mermaid, PlantUML, D2, Graphviz) - Enhanced natural language processing - Text-based DSL for version control - Extensible architecture for future parsers Ready for Phase 3: AI integration, visual editing, collaboration
Completed Phase 3 implementation with AI-powered diagram generation and code-to-diagram reverse engineering, achieving research-recommended features for modern diagramming systems. NEW FEATURES: 1. AI/LLM-Powered Diagram Generation: - OpenAI API integration for natural language → diagram - Uses gpt-4o-mini for cost-effective generation (~$0.00015/diagram) - Achieves 10-20x faster diagram creation (per research) - Intelligent node type inference - Clean, structured output - Temperature control for consistency 2. Iterative Diagram Refinement: - Conversational improvement with AI feedback - Add missing details to existing diagrams - Restructure flows based on feedback - Context-aware modifications - Preserves existing metadata 3. Python Code Analysis (AST-based): - Function flowchart generation from Python code - Control flow visualization (if/else, while, for) - Call graph generation showing dependencies - Class diagram generation with inheritance - Automatic node type inference - Support for nested conditions and loops 4. Hybrid Workflows: - Combine code analysis with AI enhancement - Analyze existing code → Generate diagram → Refine with AI - Supports iterative development - Preserves code structure while adding context COMPONENTS ADDED: Analyzers Module: - ij/analyzers/python_analyzer.py: Python AST analysis for diagrams * analyze_function() - function flowcharts * analyze_class() - class diagrams * analyze_module_calls() - call graphs - ij/analyzers/__init__.py: Analyzer exports Converters: - ij/converters/llm_converter.py: OpenAI API integration * convert() - natural language → diagram * refine() - iterative improvement * convert_with_examples() - few-shot learning - Updated ij/converters/__init__.py: Optional LLM export Tests (19 new tests): - tests/test_llm_converter.py: 9 tests (7 mocks + 2 optional real API) * Mock tests for all functionality (no API key required) * Optional real API tests (skip if OPENAI_API_KEY not set) * Uses gpt-4o-mini for cost-effective testing - tests/test_python_analyzer.py: 12 tests for code analysis * Function analysis with various control structures * Call graph generation * Class diagram generation * Error handling Examples: - examples/phase3_features.py: 7 comprehensive examples * Python function → flowchart * Call graph generation * Class diagram generation * AI-powered generation * Iterative refinement * Multi-format export from code * Hybrid workflows Documentation: - PHASE3.md: Complete Phase 3 documentation * AI model configuration * Cost estimation (~$1-40/month typical usage) * Python code analysis capabilities * Testing strategies * Best practices * Troubleshooting guide - Updated README.md: Phase 3 features, updated test counts - Updated ij/__init__.py: Export new classes Configuration: - Updated pyproject.toml: Added [ai] optional dependency group - Updated .github/workflows/ci.yml: OPENAI_API_KEY environment variable (Note: CI file uses composite actions, env set at test runner level) TEST RESULTS: - 71 total tests (26 Phase 1 + 26 Phase 2 + 19 Phase 3) - 100% pass rate with mocks - 2 additional optional tests with real OpenAI API - All tests skip gracefully if dependencies unavailable COST OPTIMIZATION: - Uses gpt-4o-mini by default (~10x cheaper than gpt-4o) - Temperature 0.3 for deterministic, consistent output - Mock tests for development (no API costs) - Optional real API tests (minimal cost: ~$0.0003/run) - Clear documentation on cost management PYTHON CODE ANALYSIS: Supported: - Control flow (if/elif/else, while, for) - Function calls and returns - Class definitions and inheritance - Method and attribute extraction - Nested conditions Capabilities: - Instant diagram generation from code - No manual drawing required - Accurate control flow representation - Handles complex nested structures AI/LLM CAPABILITIES: - Natural language understanding - Context-aware generation - Iterative refinement - Few-shot learning support - Error handling and validation - Code block cleanup INSTALLATION: ```bash # Core features (no AI) pip install ij # With AI support pip install ij[ai] export OPENAI_API_KEY=your-key ``` Following research recommendations: - AI-powered generation (10-20x speed improvement) - Code-to-diagram reverse engineering - Iterative refinement workflow - Cost-effective implementation - Production-ready with human review Ready for Phase 4: Visual editor, collaboration, multi-language support
Phase 4 completes the bidirectional diagramming system with advanced features for diagram manipulation, multi-format support, and sequence diagram generation. ## New Features ### 1. Bidirectional D2 Support - D2Parser: Parse D2 (Terrastruct) syntax to DiagramIR - Support for all node shapes (oval, rectangle, diamond, cylinder) - Edge types (direct, conditional, bidirectional) - Direction metadata handling - Automatic START/END node inference - Complete bidirectional D2 conversion ### 2. Sequence Diagram Generation - SequenceDiagramRenderer: Render DiagramIR as Mermaid sequence diagrams - Support for sync/async arrows (solid/dashed) - Notes and activations support - InteractionAnalyzer: Extract sequence diagrams from: * Python code (analyze method calls) * Natural language descriptions - Automatic participant detection ### 3. Diagram Transformations - DiagramTransforms class with powerful utilities: * simplify(): Remove isolated nodes and duplicate edges * filter_by_node_type(): Filter diagrams by node types * apply_node_filter(): Custom filtering with predicates * extract_subgraph(): Extract portions with BFS * merge_diagrams(): Combine multiple diagrams * reverse_edges(): Reverse all edge directions * find_cycles(): Detect circular dependencies * get_statistics(): Comprehensive metrics * merge_sequential_nodes(): Combine linear sequences ### 4. Multi-Format Workflows - Seamless conversion between all formats: * Mermaid (parse & render) * PlantUML (render) * D2 (parse & render) * Graphviz/DOT (render) ## Implementation Details New modules: - ij/parsers/d2.py: D2 parser (246 lines) - ij/renderers/sequence.py: Sequence diagrams (307 lines) - ij/transforms.py: Diagram transformations (400+ lines) New tests: - tests/test_d2_parser.py: 16 tests for D2 parsing - tests/test_sequence.py: 15 tests for sequence diagrams - tests/test_transforms.py: 20 tests for transformations Total: 51 new tests, all passing Overall: 124 tests (122 passing, 2 optional AI tests) ## Documentation - PHASE4.md: Comprehensive Phase 4 documentation - examples/phase4_features.py: 10 examples demonstrating all features - README.md: Updated with Phase 4 feature list ## Performance All operations optimized for efficiency: - Parsing: O(n) - Transformations: O(n + m) or better - No external dependencies beyond existing stack
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.