From 4c15c57abc3fbc9533052d121e4c0b99fc9021a0 Mon Sep 17 00:00:00 2001 From: sanjeed5 Date: Fri, 28 Feb 2025 14:14:19 +0530 Subject: [PATCH] Migrate to flat library structure with tag-based organization Update project to use a new, more flexible library organization approach: - Replace nested category/subcategory structure with a flat JSON format - Introduce tag-based library classification - Update generate_mdc_files.py to support new library structure - Modify README to reflect new organization - Update progress tracking and library processing logic Simplify library management and improve categorization flexibility by using a more dynamic tagging system --- README.md | 106 +++--- libraries.json | 600 +++++++++++++++++++++++++++++++ mdc_generation_progress.json | 86 +++++ src/generate_mdc_files.py | 213 ++++++----- src/libraries.json | 66 ---- src/mdc_generation_progress.json | 173 +++++---- 6 files changed, 953 insertions(+), 291 deletions(-) create mode 100644 libraries.json create mode 100644 mdc_generation_progress.json delete mode 100644 src/libraries.json diff --git a/README.md b/README.md index 1fa9266..88610fb 100644 --- a/README.md +++ b/README.md @@ -1,25 +1,25 @@ # MDC Generator for Library Best Practices -This repository contains Cursor rule files (.mdc) that provide AI-powered best practices and guidelines for various libraries and frameworks. The rules in `rules-mdc/` are the current, improved version which are more focused and comprehensive. (Note: The `rules-v0/` directory contains legacy rules and is kept for historical reference only - please use `rules-mdc/` for all new projects). +This repository contains Cursor rule files (.mdc) that provide AI-powered best practices and guidelines for various libraries and frameworks. The rules in `rules-mdc/` are comprehensive and focused, offering guidance for a wide range of programming libraries and frameworks. ## Repository Structure ``` . -├── rules-mdc/ # Current, comprehensive rule files (recommended) -│ ├── frontend/ -│ ├── backend/ -│ └── ... -├── src/ # Source code for rule generation +├── rules-mdc/ # Comprehensive rule files in a flat structure +├── cursor-rules-cli/ # Source code and configuration for rule generation │ ├── generate_mdc_files.py +│ ├── libraries.json │ ├── config.yaml │ └── ... -└── rules-v0/ # Legacy rules (deprecated) +└── logs/ # Log files from rule generation runs ``` ## Features -- **Configurable**: All settings can be adjusted in `src/config.yaml` +- **Tag-Based Library Organization**: Libraries are organized with tags instead of nested categories for more flexible categorization +- **Flat Directory Structure**: All MDC files are stored in a single directory for easier access +- **Configurable**: All settings can be adjusted in `config.yaml` - **Parallel Processing**: Process multiple libraries simultaneously - **Progress Tracking**: Resume from where you left off if the process is interrupted - **Smart Glob Pattern Generation**: Automatically determines appropriate glob patterns for different libraries @@ -35,17 +35,18 @@ This repository contains Cursor rule files (.mdc) that provide AI-powered best p ## Configuration -The script uses a configuration file (`src/config.yaml`) with the following structure: +The script uses a configuration file (`config.yaml`) with the following structure: ```yaml paths: mdc_instructions: "mdc-instructions.txt" libraries_json: "libraries.json" output_dir: "rules-mdc" + exa_results_dir: "exa_results" api: llm_model: "gemini/gemini-2.0-flash" - rate_limit_calls: 100 + rate_limit_calls: 2000 rate_limit_period: 60 max_retries: 3 retry_min_wait: 4 @@ -53,7 +54,11 @@ api: processing: max_workers: 4 - chunk_size: 25000 + chunk_size: 50000 + +tags: + primary_tags: ["python", "javascript", "typescript", "rust", "go", "java", "php", "ruby"] + category_tags: ["frontend", "backend", "database", "ai", "ml", "testing", "development"] ``` ## Usage @@ -61,80 +66,85 @@ processing: ### Basic Usage ```bash -uv run src/generate_mdc_files.py +uv run generate_mdc_files.py ``` ### Test Mode (Process Only One Library) ```bash -uv run src/generate_mdc_files.py --test +uv run generate_mdc_files.py --test ``` -### Process Specific Categories or Libraries +### Process Specific Tags or Libraries ```bash -uv run src/generate_mdc_files.py --category frontend_frameworks -uv run src/generate_mdc_files.py --subcategory react -uv run src/generate_mdc_files.py --library react +uv run generate_mdc_files.py --tag python +uv run generate_mdc_files.py --library react ``` ### Adjust Parallel Processing ```bash -uv run src/generate_mdc_files.py --workers 8 +uv run generate_mdc_files.py --workers 8 ``` ### Adjust Rate Limits ```bash -uv run src/generate_mdc_files.py --rate-limit 50 +uv run generate_mdc_files.py --rate-limit 50 ``` ### Verbose Logging ```bash -uv run src/generate_mdc_files.py --verbose +uv run generate_mdc_files.py --verbose ``` ## File Structure -The generated MDC files will be organized in the following structure: +The generated MDC files are organized in a flat structure: ``` rules-mdc/ -├── frontend/ -│ ├── react/ -│ │ ├── react.mdc -│ │ ├── react-native.mdc -│ │ └── ... -│ ├── vue/ -│ │ └── ... -│ └── ... -├── backend/ -│ ├── python/ -│ │ ├── django.mdc -│ │ ├── flask.mdc -│ │ └── ... -│ └── ... +├── react.mdc +├── vue.mdc +├── django.mdc +├── flask.mdc +├── pytest.mdc └── ... ``` ## Available Libraries -All currently supported libraries and their categories can be found in `src/libraries.json`. This file organizes libraries into categories like: -- Frontend Frameworks (React, Vue, Angular, etc.) -- Backend Frameworks (Node.js, Python, PHP, etc.) -- UI Libraries -- State Management -- Database Tools -- Development Tools -- Cross Platform -- AI/ML -- Web Technologies -- Blockchain -- Cloud Platforms +All currently supported libraries can be found in `libraries.json`. This file organizes libraries with tags for flexible categorization: -Each category contains relevant subcategories and specific libraries. Check `src/libraries.json` for the complete, up-to-date list of supported libraries. +```json +{ + "libraries": [ + { + "name": "react", + "tags": ["frontend", "framework", "javascript"] + }, + { + "name": "django", + "tags": ["backend", "framework", "python", "orm", "full-stack"] + }, + ... + ] +} +``` + +The libraries cover a wide range of categories including: +- Frontend frameworks and libraries +- Backend frameworks +- UI libraries and components +- State management solutions +- Database tools and ORMs +- Development tools (testing, linting, etc.) +- Cross-platform frameworks +- AI/ML libraries +- Web technologies +- And many more ## Progress Tracking diff --git a/libraries.json b/libraries.json new file mode 100644 index 0000000..7d625ec --- /dev/null +++ b/libraries.json @@ -0,0 +1,600 @@ +{ + "libraries": [ + { + "name": "react", + "tags": ["frontend", "framework", "javascript"] + }, + { + "name": "react-native", + "tags": ["frontend", "framework", "javascript", "mobile", "cross-platform"] + }, + { + "name": "react-query", + "tags": ["frontend", "javascript", "data-fetching"] + }, + { + "name": "react-redux", + "tags": ["frontend", "javascript", "state-management"] + }, + { + "name": "react-mobx", + "tags": ["frontend", "javascript", "state-management"] + }, + { + "name": "next.js", + "tags": ["frontend", "framework", "javascript", "react", "ssr"] + }, + { + "name": "vue", + "tags": ["frontend", "framework", "javascript"] + }, + { + "name": "vue3", + "tags": ["frontend", "framework", "javascript"] + }, + { + "name": "nuxt", + "tags": ["frontend", "framework", "javascript", "vue", "ssr"] + }, + { + "name": "angular", + "tags": ["frontend", "framework", "javascript", "typescript"] + }, + { + "name": "svelte", + "tags": ["frontend", "framework", "javascript"] + }, + { + "name": "sveltekit", + "tags": ["frontend", "framework", "javascript", "svelte", "ssr"] + }, + { + "name": "solidjs", + "tags": ["frontend", "framework", "javascript"] + }, + { + "name": "qwik", + "tags": ["frontend", "framework", "javascript"] + }, + { + "name": "express", + "tags": ["backend", "framework", "javascript", "nodejs"] + }, + { + "name": "nestjs", + "tags": ["backend", "framework", "javascript", "typescript", "nodejs"] + }, + { + "name": "bun", + "tags": ["backend", "javascript", "runtime", "nodejs-alternative"] + }, + { + "name": "django", + "tags": ["backend", "framework", "python", "orm", "full-stack"] + }, + { + "name": "flask", + "tags": ["backend", "framework", "python", "microframework"] + }, + { + "name": "fastapi", + "tags": ["backend", "framework", "python", "api", "async"] + }, + { + "name": "pyramid", + "tags": ["backend", "framework", "python"] + }, + { + "name": "tornado", + "tags": ["backend", "framework", "python", "async"] + }, + { + "name": "sanic", + "tags": ["backend", "framework", "python", "async"] + }, + { + "name": "bottle", + "tags": ["backend", "framework", "python", "microframework"] + }, + { + "name": "laravel", + "tags": ["backend", "framework", "php"] + }, + { + "name": "springboot", + "tags": ["backend", "framework", "java"] + }, + { + "name": "fiber", + "tags": ["backend", "framework", "go"] + }, + { + "name": "servemux", + "tags": ["backend", "framework", "go"] + }, + { + "name": "phoenix", + "tags": ["backend", "framework", "elixir"] + }, + { + "name": "actix-web", + "tags": ["backend", "framework", "rust"] + }, + { + "name": "rocket", + "tags": ["backend", "framework", "rust"] + }, + { + "name": "shadcn", + "tags": ["ui", "component-library", "react"] + }, + { + "name": "chakra-ui", + "tags": ["ui", "component-library", "react"] + }, + { + "name": "material-ui", + "tags": ["ui", "component-library", "react"] + }, + { + "name": "tailwind", + "tags": ["ui", "css", "utility-first"] + }, + { + "name": "jetpack-compose", + "tags": ["ui", "mobile", "android", "kotlin"] + }, + { + "name": "tkinter", + "tags": ["ui", "gui", "python", "desktop"] + }, + { + "name": "pyqt", + "tags": ["ui", "gui", "python", "desktop", "qt"] + }, + { + "name": "pyside", + "tags": ["ui", "gui", "python", "desktop", "qt"] + }, + { + "name": "kivy", + "tags": ["ui", "gui", "python", "cross-platform", "mobile"] + }, + { + "name": "pygame", + "tags": ["ui", "gui", "python", "game-development"] + }, + { + "name": "customtkinter", + "tags": ["ui", "gui", "python", "desktop", "tkinter"] + }, + { + "name": "redux", + "tags": ["state-management", "javascript", "react"] + }, + { + "name": "mobx", + "tags": ["state-management", "javascript", "react"] + }, + { + "name": "zustand", + "tags": ["state-management", "javascript", "react"] + }, + { + "name": "riverpod", + "tags": ["state-management", "flutter", "dart"] + }, + { + "name": "supabase", + "tags": ["database", "sql", "postgresql", "backend-as-service"] + }, + { + "name": "postgresql", + "tags": ["database", "sql", "relational"] + }, + { + "name": "prisma", + "tags": ["database", "orm", "typescript", "javascript"] + }, + { + "name": "mongodb", + "tags": ["database", "nosql", "document"] + }, + { + "name": "redis", + "tags": ["database", "nosql", "key-value", "in-memory"] + }, + { + "name": "duckdb", + "tags": ["database", "analytics", "sql", "olap"] + }, + { + "name": "sqlalchemy", + "tags": ["database", "orm", "python", "sql"] + }, + { + "name": "peewee", + "tags": ["database", "orm", "python", "sql"] + }, + { + "name": "pony", + "tags": ["database", "orm", "python", "sql"] + }, + { + "name": "tortoise-orm", + "tags": ["database", "orm", "python", "sql", "async"] + }, + { + "name": "django-orm", + "tags": ["database", "orm", "python", "sql", "django"] + }, + { + "name": "vite", + "tags": ["development", "build-tool", "javascript"] + }, + { + "name": "webpack", + "tags": ["development", "build-tool", "javascript"] + }, + { + "name": "turbopack", + "tags": ["development", "build-tool", "javascript"] + }, + { + "name": "poetry", + "tags": ["development", "build-tool", "python", "dependency-management"] + }, + { + "name": "setuptools", + "tags": ["development", "build-tool", "python", "packaging"] + }, + { + "name": "jest", + "tags": ["development", "testing", "javascript"] + }, + { + "name": "detox", + "tags": ["development", "testing", "javascript", "react-native", "e2e"] + }, + { + "name": "playwright", + "tags": ["development", "testing", "javascript", "e2e", "browser"] + }, + { + "name": "vitest", + "tags": ["development", "testing", "javascript", "vite"] + }, + { + "name": "pytest", + "tags": ["development", "testing", "python"] + }, + { + "name": "unittest", + "tags": ["development", "testing", "python", "standard-library"] + }, + { + "name": "nose2", + "tags": ["development", "testing", "python"] + }, + { + "name": "hypothesis", + "tags": ["development", "testing", "python", "property-based"] + }, + { + "name": "behave", + "tags": ["development", "testing", "python", "bdd"] + }, + { + "name": "docker", + "tags": ["development", "containerization", "devops"] + }, + { + "name": "kubernetes", + "tags": ["development", "containerization", "orchestration", "devops"] + }, + { + "name": "git", + "tags": ["development", "version-control"] + }, + { + "name": "mkdocs", + "tags": ["development", "documentation", "markdown"] + }, + { + "name": "sphinx", + "tags": ["development", "documentation", "python", "rst"] + }, + { + "name": "pdoc", + "tags": ["development", "documentation", "python", "auto-generation"] + }, + { + "name": "github-actions", + "tags": ["development", "ci-cd", "devops"] + }, + { + "name": "terraform", + "tags": ["development", "infrastructure", "iac", "devops"] + }, + { + "name": "black", + "tags": ["development", "python", "formatter", "linting"] + }, + { + "name": "flake8", + "tags": ["development", "python", "linting"] + }, + { + "name": "pylint", + "tags": ["development", "python", "linting", "static-analysis"] + }, + { + "name": "mypy", + "tags": ["development", "python", "type-checking", "static-analysis"] + }, + { + "name": "isort", + "tags": ["development", "python", "formatter", "imports"] + }, + { + "name": "pydantic", + "tags": ["development", "python", "data-validation", "type-checking"] + }, + { + "name": "pyright", + "tags": ["development", "python", "type-checking", "static-analysis"] + }, + { + "name": "tauri", + "tags": ["cross-platform", "desktop", "rust", "javascript"] + }, + { + "name": "electron", + "tags": ["cross-platform", "desktop", "javascript"] + }, + { + "name": "expo", + "tags": ["cross-platform", "mobile", "react-native"] + }, + { + "name": "flutter", + "tags": ["cross-platform", "mobile", "dart"] + }, + { + "name": "pytorch", + "tags": ["ai", "ml", "machine-learning", "python", "deep-learning"] + }, + { + "name": "scikit-learn", + "tags": ["ai", "ml", "machine-learning", "python", "data-science"] + }, + { + "name": "pandas", + "tags": ["ai", "ml", "data-science", "python", "data-analysis"] + }, + { + "name": "tensorflow", + "tags": ["ai", "ml", "machine-learning", "python", "deep-learning"] + }, + { + "name": "keras", + "tags": ["ai", "ml", "machine-learning", "python", "deep-learning"] + }, + { + "name": "xgboost", + "tags": ["ai", "ml", "machine-learning", "python", "gradient-boosting"] + }, + { + "name": "lightgbm", + "tags": ["ai", "ml", "machine-learning", "python", "gradient-boosting"] + }, + { + "name": "cuda", + "tags": ["ai", "ml", "gpu-computing", "parallel-computing"] + }, + { + "name": "numba", + "tags": ["ai", "ml", "gpu-computing", "python", "jit-compiler"] + }, + { + "name": "langchain", + "tags": ["ai", "ml", "llm", "python"] + }, + { + "name": "huggingface", + "tags": ["ai", "ml", "llm", "python", "transformers"] + }, + { + "name": "vllm", + "tags": ["ai", "ml", "llm", "python", "inference"] + }, + { + "name": "llama-index", + "tags": ["ai", "ml", "llm", "python", "rag"] + }, + { + "name": "modal", + "tags": ["ai", "ml", "cloud-inference", "serverless", "deployment"] + }, + { + "name": "numpy", + "tags": ["ai", "ml", "data-science", "python", "numerical-computing"] + }, + { + "name": "scipy", + "tags": ["ai", "ml", "data-science", "python", "scientific-computing"] + }, + { + "name": "matplotlib", + "tags": ["ai", "ml", "data-science", "python", "data-visualization"] + }, + { + "name": "seaborn", + "tags": ["ai", "ml", "data-science", "python", "data-visualization"] + }, + { + "name": "plotly", + "tags": ["ai", "ml", "data-science", "python", "interactive-visualization"] + }, + { + "name": "statsmodels", + "tags": ["ai", "ml", "data-science", "python", "statistics"] + }, + { + "name": "dask", + "tags": ["ai", "ml", "data-science", "python", "parallel-computing", "big-data"] + }, + { + "name": "htmx", + "tags": ["web", "javascript", "modern-patterns"] + }, + { + "name": "trpc", + "tags": ["web", "typescript", "api", "modern-patterns"] + }, + { + "name": "typescript", + "tags": ["web", "javascript", "type-checking", "language"] + }, + { + "name": "zod", + "tags": ["web", "typescript", "validation", "type-checking"] + }, + { + "name": "axios", + "tags": ["web", "javascript", "http-client"] + }, + { + "name": "guzzle", + "tags": ["web", "php", "http-client"] + }, + { + "name": "requests", + "tags": ["web", "python", "http-client"] + }, + { + "name": "httpx", + "tags": ["web", "python", "http-client", "async"] + }, + { + "name": "aiohttp", + "tags": ["web", "python", "http-client", "async"] + }, + { + "name": "graphql", + "tags": ["web", "api", "query-language"] + }, + { + "name": "apollo-client", + "tags": ["web", "api", "graphql", "javascript"] + }, + { + "name": "flask-restful", + "tags": ["web", "api", "python", "flask"] + }, + { + "name": "solidity", + "tags": ["blockchain", "ethereum", "smart-contracts", "language"] + }, + { + "name": "hardhat", + "tags": ["blockchain", "ethereum", "development", "javascript"] + }, + { + "name": "vercel", + "tags": ["cloud", "deployment", "serverless", "frontend"] + }, + { + "name": "cloudflare", + "tags": ["cloud", "deployment", "edge-computing", "cdn"] + }, + { + "name": "aws-lambda", + "tags": ["cloud", "serverless", "aws"] + }, + { + "name": "aws", + "tags": ["cloud", "major-platform"] + }, + { + "name": "gcp", + "tags": ["cloud", "major-platform"] + }, + { + "name": "azure", + "tags": ["cloud", "major-platform"] + }, + { + "name": "beautifulsoup4", + "tags": ["python", "web-scraping", "html-parsing"] + }, + { + "name": "scrapy", + "tags": ["python", "web-scraping", "crawler", "framework"] + }, + { + "name": "selenium", + "tags": ["python", "web-scraping", "browser-automation", "testing"] + }, + { + "name": "asyncio", + "tags": ["python", "async", "standard-library"] + }, + { + "name": "trio", + "tags": ["python", "async"] + }, + { + "name": "anyio", + "tags": ["python", "async", "compatibility-layer"] + }, + { + "name": "nltk", + "tags": ["python", "nlp", "text-processing"] + }, + { + "name": "spacy", + "tags": ["python", "nlp", "text-processing"] + }, + { + "name": "gensim", + "tags": ["python", "nlp", "topic-modeling"] + }, + { + "name": "transformers", + "tags": ["python", "nlp", "deep-learning", "huggingface"] + }, + { + "name": "pillow", + "tags": ["python", "image-processing"] + }, + { + "name": "opencv-python", + "tags": ["python", "image-processing", "computer-vision"] + }, + { + "name": "scikit-image", + "tags": ["python", "image-processing", "scientific-computing"] + }, + { + "name": "tqdm", + "tags": ["python", "utilities", "progress-bar"] + }, + { + "name": "rich", + "tags": ["python", "utilities", "terminal", "formatting"] + }, + { + "name": "click", + "tags": ["python", "utilities", "cli"] + }, + { + "name": "typer", + "tags": ["python", "utilities", "cli"] + }, + { + "name": "streamlit", + "tags": ["python", "utilities", "data-apps", "dashboard"] + } + ] +} \ No newline at end of file diff --git a/mdc_generation_progress.json b/mdc_generation_progress.json new file mode 100644 index 0000000..f306295 --- /dev/null +++ b/mdc_generation_progress.json @@ -0,0 +1,86 @@ +{ + "next-js": "completed", + "langchain": "completed", + "cuda": "completed", + "react-native": "completed", + "zod": "completed", + "vue": "completed", + "cloudflare": "completed", + "webpack": "completed", + "expo": "completed", + "supabase": "completed", + "gcp": "completed", + "vitest": "completed", + "express": "completed", + "aws": "completed", + "nuxt": "completed", + "solidity": "completed", + "huggingface": "completed", + "tailwind": "completed", + "flutter": "completed", + "pandas": "completed", + "angular": "completed", + "git": "completed", + "docker": "completed", + "chakra-ui": "completed", + "kubernetes": "completed", + "shadcn": "completed", + "tensorflow": "completed", + "react-redux": "completed", + "react-query": "completed", + "turbopack": "completed", + "material-ui": "completed", + "axios": "completed", + "bun": "completed", + "flask": "completed", + "sveltekit": "completed", + "vite": "completed", + "terraform": "completed", + "fastapi": "completed", + "modal": "completed", + "electron": "completed", + "detox": "completed", + "solidjs": "completed", + "riverpod": "completed", + "zustand": "completed", + "playwright": "completed", + "mongodb": "completed", + "svelte": "completed", + "mkdocs": "completed", + "laravel": "completed", + "vue3": "completed", + "vercel": "completed", + "typescript": "completed", + "github-actions": "completed", + "guzzle": "completed", + "servemux": "completed", + "css": "completed", + "jest": "completed", + "nestjs": "completed", + "pytorch": "completed", + "apollo-client": "completed", + "aws-lambda": "completed", + "qwik": "completed", + "azure": "completed", + "redux": "completed", + "htmx": "completed", + "mobx": "completed", + "fiber": "completed", + "hardhat": "completed", + "redis": "completed", + "react": "completed", + "react-mobx": "completed", + "graphql": "completed", + "springboot": "completed", + "jetpack-compose": "completed", + "django": "completed", + "rocket": "completed", + "tauri": "completed", + "scikit-learn": "completed", + "actix-web": "completed", + "trpc": "completed", + "postgresql": "completed", + "duckdb": "completed", + "prisma": "completed", + "vllm": "completed" +} \ No newline at end of file diff --git a/src/generate_mdc_files.py b/src/generate_mdc_files.py index 9b9d56c..d3740dc 100644 --- a/src/generate_mdc_files.py +++ b/src/generate_mdc_files.py @@ -50,7 +50,7 @@ DEFAULT_CONFIG = { "mdc_instructions": "mdc-instructions.txt", "libraries_json": "libraries.json", "output_dir": "rules-mdc", - "exa_results_dir": "exa_results" # New directory to store Exa results + "exa_results_dir": "exa_results" # Directory to store Exa results }, "api": { "llm_model": "gemini/gemini-2.0-flash", @@ -108,9 +108,8 @@ class MDCRule(BaseModel): class LibraryInfo(BaseModel): """Model for library information.""" - category: str - subcategory: str name: str + tags: List[str] best_practices: str = "" citations: List[Dict[str, Any]] = [] @@ -185,9 +184,6 @@ def get_library_best_practices_exa(library_name: str, exa_client: Optional[Exa] "citations": result.citations if hasattr(result, 'citations') else [] } - # Log the full Exa result - # logger.info(f"Exa result for {library_name}: {result_dict}") - # Save the Exa result to a file exa_results_dir = Path(CONFIG["paths"]["exa_results_dir"]) exa_results_dir.mkdir(parents=True, exist_ok=True) @@ -213,6 +209,50 @@ def get_library_best_practices_exa(library_name: str, exa_client: Optional[Exa] logger.error(f"Error fetching from Exa for {library_name}: {str(e)}") return {"answer": "", "citations": []} +def determine_glob_pattern(library_name: str, tags: List[str]) -> str: + """Determine the appropriate glob pattern based on library name and tags.""" + # Default glob pattern + default_glob = "**/*" + + # Check for language-specific patterns + if "python" in tags: + return "**/*.py" + elif "javascript" in tags or "typescript" in tags: + if "react" in tags: + return "**/*.{jsx,tsx}" + elif "vue" in tags: + return "**/*.vue" + elif "svelte" in tags: + return "**/*.svelte" + elif "angular" in tags: + return "**/*.{ts,html}" + return "**/*.{js,ts,jsx,tsx}" + elif "rust" in tags: + return "**/*.rs" + elif "go" in tags: + return "**/*.go" + elif "java" in tags: + return "**/*.java" + elif "php" in tags: + return "**/*.php" + elif "ruby" in tags: + return "**/*.rb" + + # Check for specific libraries with known file extensions + if library_name == "django": + return "**/*.{py,html}" + elif library_name == "flask": + return "**/*.py" + elif library_name == "fastapi": + return "**/*.py" + elif library_name == "pytest": + return "**/test_*.py" + elif library_name == "tailwind": + return "**/*.{css,html,jsx,tsx}" + + # Return default if no specific pattern found + return default_glob + @sleep_and_retry @limits(calls=CONFIG["api"]["rate_limit_calls"], period=CONFIG["api"]["rate_limit_period"]) @retry(stop=stop_after_attempt(CONFIG["api"]["max_retries"]), @@ -247,6 +287,12 @@ def generate_mdc_rules_from_exa(library_info: LibraryInfo, exa_results: Dict[str # Combine all citation texts - Gemini can handle much larger inputs all_citation_text = "\n\n".join(citation_texts) + # Suggest a glob pattern based on library tags + suggested_glob = determine_glob_pattern(library_info.name, library_info.tags) + + # Format tags for prompt + tags_str = ", ".join(library_info.tags) + # Enhanced prompt template for both cases enhanced_prompt_template = """Create a comprehensive Cursor rule file (.mdc) for the {library_name} library following these guidelines: @@ -254,8 +300,8 @@ def generate_mdc_rules_from_exa(library_info: LibraryInfo, exa_results: Dict[str Library Information: - Name: {library_name} -- Category: {library_category} -- Subcategory: {library_subcategory} +- Tags: {tags} +- Suggested glob pattern: {suggested_glob} {exa_content_section} @@ -312,7 +358,7 @@ Your task is to create an EXTREMELY DETAILED and COMPREHENSIVE guide that covers Format your response as a valid JSON object with exactly these keys: - name: a short descriptive name for the rule (e.g., "{library_name} Best Practices") - - glob_pattern: the most appropriate glob pattern for this library based on the file types it typically works with + - glob_pattern: the most appropriate glob pattern for this library based on the file types it typically works with (you can use the suggested pattern or improve it) - description: a clear 1-2 sentence description of what the rule covers - content: the formatted rule content with comprehensive best practices in markdown format """ @@ -328,8 +374,8 @@ Your guidance should be useful for both beginners and experienced developers. prompt = enhanced_prompt_template.format( library_name=library_info.name, - library_category=library_info.category, - library_subcategory=library_info.subcategory, + tags=tags_str, + suggested_glob=suggested_glob, exa_content_section=exa_content_section, mdc_instructions=mdc_instructions ) @@ -350,8 +396,8 @@ Add any important best practices that might be missing from the search results. prompt = enhanced_prompt_template.format( library_name=library_info.name, - library_category=library_info.category, - library_subcategory=library_info.subcategory, + tags=tags_str, + suggested_glob=suggested_glob, exa_content_section=exa_content_section, mdc_instructions=mdc_instructions ) @@ -429,62 +475,60 @@ globs: {rule.glob_pattern} f.write(mdc_content) logger.info(f"Created {output_path}") -def process_single_library(category: str, subcategory: str, library: str, output_dir: str, exa_client: Optional[Exa] = None) -> Tuple[str, bool]: +def process_single_library(library_info: Dict[str, Any], output_dir: str, exa_client: Optional[Exa] = None) -> Tuple[str, bool]: """Process a single library and generate MDC file. Returns (library_key, success).""" - library_key = f"{category}/{subcategory}/{library}" - logger.info(f"Processing library: {library} (Category: {category}, Subcategory: {subcategory})") + library_name = library_info["name"] + library_tags = library_info["tags"] + + # Create a unique key for this library - using just the name for flat structure + library_key = library_name + + logger.info(f"Processing library: {library_name} (Tags: {', '.join(library_tags)})") try: # Create output directory structure output_path = Path(output_dir) - category_dir = output_path / category - subcategory_dir = category_dir / subcategory - - # Create directories if they don't exist - for directory in [output_path, category_dir, subcategory_dir]: - if not directory.exists(): - directory.mkdir(exist_ok=True) + if not output_path.exists(): + output_path.mkdir(parents=True, exist_ok=True) # Create library info object - library_info = LibraryInfo( - category=category, - subcategory=subcategory, - name=library + library_obj = LibraryInfo( + name=library_name, + tags=library_tags ) # Get best practices using Exa - logger.info(f"Getting best practices for {library} using Exa") - exa_results = get_library_best_practices_exa(library, exa_client) + logger.info(f"Getting best practices for {library_name} using Exa") + exa_results = get_library_best_practices_exa(library_name, exa_client) # Store citations in library info - library_info.citations = exa_results.get("citations", []) + library_obj.citations = exa_results.get("citations", []) # Generate MDC rules directly from Exa results - logger.info(f"Generating MDC rules for {library} directly from Exa results") - rules = generate_mdc_rules_from_exa(library_info, exa_results) + logger.info(f"Generating MDC rules for {library_name} directly from Exa results") + rules = generate_mdc_rules_from_exa(library_obj, exa_results) # Save each rule to a file for rule in rules: # Create safe filename - safe_name = re.sub('[^a-z0-9-]+', '-', library.lower()).strip('-') + safe_name = re.sub('[^a-z0-9-]+', '-', library_name.lower()).strip('-') mdc_filename = f"{safe_name}.mdc" - # Determine output path - output_file = subcategory_dir / mdc_filename + # Determine output path - directly in the output directory + output_file = output_path / mdc_filename # Create MDC file create_mdc_file(rule, output_file) - logger.info(f"Successfully processed {library}") + logger.info(f"Successfully processed {library_name}") return (library_key, True) except Exception as e: - logger.error(f"Error processing library {library}: {str(e)}") + logger.error(f"Error processing library {library_name}: {str(e)}") return (library_key, False) def process_libraries_json(json_path: str, output_dir: str, test_mode: bool = False, - target_category: str = None, target_subcategory: str = None, - target_library: str = None) -> None: + target_tag: str = None, target_library: str = None) -> None: """Process libraries.json and generate MDC files.""" # Check if libraries.json exists if not Path(json_path).exists(): @@ -495,6 +539,11 @@ def process_libraries_json(json_path: str, output_dir: str, test_mode: bool = Fa with open(json_path, 'r') as f: libraries_data = json.load(f) + # Check if the new flat structure is used + if "libraries" not in libraries_data: + logger.error("The libraries.json file does not use the expected flat structure with tags.") + return + # Create progress tracker progress_tracker = ProgressTracker() @@ -508,56 +557,46 @@ def process_libraries_json(json_path: str, output_dir: str, test_mode: bool = Fa if not output_path.exists(): output_path.mkdir(parents=True, exist_ok=True) + # Get libraries list + libraries = libraries_data["libraries"] + + # Filter libraries based on target tag or library if specified + if target_tag or target_library: + filtered_libraries = [] + for lib in libraries: + if target_library and lib["name"] == target_library: + filtered_libraries.append(lib) + elif target_tag and target_tag in lib["tags"]: + filtered_libraries.append(lib) + libraries = filtered_libraries + # If test mode is enabled, just process one library if test_mode: - # Use React as the test library if no specific target is provided - test_category = target_category or "frontend_frameworks" - test_subcategory = target_subcategory or "react" - test_library = target_library or "react" - - # Check if the test library exists in the JSON - if test_category in libraries_data and test_subcategory in libraries_data[test_category]: - if test_library in libraries_data[test_category][test_subcategory]: - library_key, success = process_single_library(test_category, test_subcategory, test_library, output_dir, exa_client) - if success: - progress_tracker.mark_library_completed(library_key) - else: - progress_tracker.mark_library_failed(library_key) + if libraries: + test_library = libraries[0] + library_key, success = process_single_library(test_library, output_dir, exa_client) + if success: + progress_tracker.mark_library_completed(library_key) else: - logger.error(f"Test library {test_library} not found in {test_category}/{test_subcategory}") + progress_tracker.mark_library_failed(library_key) else: - logger.error(f"Test category/subcategory {test_category}/{test_subcategory} not found") - + logger.error("No libraries found to process in test mode") return # Prepare list of libraries to process libraries_to_process = [] - for category, subcategories in libraries_data.items(): - # Skip if a specific category is targeted and this isn't it - if target_category and category != target_category: + for library in libraries: + # Create a unique key for this library + library_key = library["name"] + + # Skip if already processed + if progress_tracker.is_library_processed(library_key): + logger.info(f"Skipping already processed library: {library['name']}") continue - - for subcategory, libraries in subcategories.items(): - # Skip if a specific subcategory is targeted and this isn't it - if target_subcategory and subcategory != target_subcategory: - continue - - for library in libraries: - # Skip if a specific library is targeted and this isn't it - if target_library and library != target_library: - continue - - # Create a unique key for this library - library_key = f"{category}/{subcategory}/{library}" - - # Skip if already processed - if progress_tracker.is_library_processed(library_key): - logger.info(f"Skipping already processed library: {library}") - continue - - # Add to processing list - libraries_to_process.append((category, subcategory, library)) + + # Add to processing list + libraries_to_process.append(library) # Process libraries in parallel max_workers = CONFIG["processing"]["max_workers"] @@ -569,13 +608,13 @@ def process_libraries_json(json_path: str, output_dir: str, test_mode: bool = Fa # Submit all tasks future_to_library = { - executor.submit(process_func, category, subcategory, library): (category, subcategory, library) - for category, subcategory, library in libraries_to_process + executor.submit(process_func, library): library + for library in libraries_to_process } # Process results as they complete for future in concurrent.futures.as_completed(future_to_library): - category, subcategory, library = future_to_library[future] + library = future_to_library[future] try: library_key, success = future.result() if success: @@ -583,16 +622,15 @@ def process_libraries_json(json_path: str, output_dir: str, test_mode: bool = Fa else: progress_tracker.mark_library_failed(library_key) except Exception as e: - logger.error(f"Exception processing {category}/{subcategory}/{library}: {str(e)}") - progress_tracker.mark_library_failed(f"{category}/{subcategory}/{library}") + logger.error(f"Exception processing {library['name']}: {str(e)}") + progress_tracker.mark_library_failed(library['name']) def main(): """Main function to run the MDC generation process.""" # Parse command line arguments parser = argparse.ArgumentParser(description="Generate MDC files from libraries.json") parser.add_argument("--test", action="store_true", help="Run in test mode (process only one library)") - parser.add_argument("--category", type=str, help="Process only a specific category") - parser.add_argument("--subcategory", type=str, help="Process only a specific subcategory") + parser.add_argument("--tag", type=str, help="Process only libraries with a specific tag") parser.add_argument("--library", type=str, help="Process only a specific library") parser.add_argument("--output", type=str, default=CONFIG["paths"]["output_dir"], help="Output directory for MDC files") parser.add_argument("--verbose", action="store_true", help="Enable verbose logging") @@ -636,8 +674,7 @@ def main(): libraries_json_path, output_dir, test_mode=args.test, - target_category=args.category, - target_subcategory=args.subcategory, + target_tag=args.tag, target_library=args.library ) logger.info("MDC generation completed successfully!") diff --git a/src/libraries.json b/src/libraries.json deleted file mode 100644 index 703b91a..0000000 --- a/src/libraries.json +++ /dev/null @@ -1,66 +0,0 @@ -{ - "frontend_frameworks": { - "react": ["react", "react-native", "react-query", "react-redux", "react-mobx", "next.js"], - "vue": ["vue", "vue3", "nuxt"], - "angular": ["angular"], - "svelte": ["svelte", "sveltekit"], - "solid": ["solidjs"], - "qwik": ["qwik"] - }, - "backend_frameworks": { - "nodejs": ["express", "nestjs", "bun"], - "python": ["django", "flask", "fastapi"], - "php": ["laravel"], - "java": ["springboot"], - "go": ["fiber", "servemux"], - "elixir": ["phoenix"], - "rust": ["actix-web", "rocket"] - }, - "ui_libraries": { - "component_libraries": ["shadcn", "chakra-ui", "material-ui", "tailwind"], - "mobile_ui": ["jetpack-compose"] - }, - "state_management": { - "react": ["redux", "mobx", "zustand"], - "flutter": ["riverpod"] - }, - "database_tools": { - "sql": ["supabase", "postgresql", "prisma"], - "nosql": ["mongodb", "redis"], - "analytics": ["duckdb"] - }, - "development_tools": { - "build_tools": ["vite", "webpack", "turbopack"], - "testing": ["jest", "detox", "playwright", "vitest"], - "containerization": ["docker", "kubernetes"], - "version_control": ["git"], - "documentation": ["mkdocs"], - "ci_cd": ["github-actions"], - "infrastructure": ["terraform"] - }, - "cross_platform": { - "desktop": ["tauri", "electron"], - "mobile": ["react-native", "flutter", "expo"] - }, - "ai_ml": { - "machine_learning": ["pytorch", "scikit-learn", "pandas", "tensorflow"], - "gpu_computing": ["cuda"], - "llm_tools": ["langchain", "huggingface", "vllm"], - "cloud_inference": ["modal"] - }, - "web_technologies": { - "styling": ["tailwind", "css"], - "modern_patterns": ["htmx", "trpc"], - "type_checking": ["typescript", "zod"], - "http_client": ["axios", "guzzle"], - "api": ["graphql", "apollo-client"] - }, - "blockchain": { - "ethereum": ["solidity", "hardhat"] - }, - "cloud_platforms": { - "deployment": ["vercel", "cloudflare", "modal"], - "serverless": ["aws-lambda", "modal"], - "major_platforms": ["aws", "gcp", "azure"] - } -} \ No newline at end of file diff --git a/src/mdc_generation_progress.json b/src/mdc_generation_progress.json index 9e49fdc..f306295 100644 --- a/src/mdc_generation_progress.json +++ b/src/mdc_generation_progress.json @@ -1,91 +1,86 @@ { - "frontend_frameworks/react/react": "completed", - "frontend_frameworks/react/react-native": "completed", - "frontend_frameworks/react/react-query": "completed", - "frontend_frameworks/react/react-redux": "completed", - "frontend_frameworks/react/react-mobx": "completed", - "frontend_frameworks/vue/vue": "completed", - "frontend_frameworks/vue/vue3": "completed", - "frontend_frameworks/angular/angular": "completed", - "frontend_frameworks/react/next.js": "completed", - "frontend_frameworks/svelte/sveltekit": "completed", - "frontend_frameworks/qwik/qwik": "completed", - "frontend_frameworks/vue/nuxt": "completed", - "frontend_frameworks/svelte/svelte": "completed", - "backend_frameworks/nodejs/nestjs": "completed", - "backend_frameworks/python/django": "completed", - "backend_frameworks/nodejs/express": "completed", - "frontend_frameworks/solid/solidjs": "completed", - "backend_frameworks/python/flask": "completed", - "backend_frameworks/php/laravel": "completed", - "backend_frameworks/go/fiber": "completed", - "backend_frameworks/java/springboot": "completed", - "backend_frameworks/nodejs/bun": "completed", - "backend_frameworks/python/fastapi": "completed", - "backend_frameworks/rust/rocket": "completed", - "backend_frameworks/go/servemux": "completed", - "ui_libraries/component_libraries/shadcn": "completed", - "backend_frameworks/elixir/phoenix": "failed", - "backend_frameworks/rust/actix-web": "completed", - "ui_libraries/component_libraries/tailwind": "completed", - "ui_libraries/component_libraries/chakra-ui": "completed", - "ui_libraries/mobile_ui/jetpack-compose": "completed", - "state_management/react/mobx": "completed", - "state_management/react/redux": "completed", - "ui_libraries/component_libraries/material-ui": "completed", - "database_tools/sql/postgresql": "completed", - "state_management/flutter/riverpod": "completed", - "state_management/react/zustand": "completed", - "database_tools/sql/supabase": "completed", - "database_tools/nosql/mongodb": "completed", - "database_tools/nosql/redis": "completed", - "database_tools/sql/prisma": "completed", - "database_tools/analytics/duckdb": "completed", - "development_tools/build_tools/vite": "completed", - "development_tools/build_tools/webpack": "completed", - "development_tools/testing/jest": "completed", - "development_tools/build_tools/turbopack": "completed", - "development_tools/testing/playwright": "completed", - "development_tools/testing/detox": "completed", - "development_tools/version_control/git": "completed", - "development_tools/testing/vitest": "completed", - "development_tools/containerization/docker": "completed", - "development_tools/ci_cd/github-actions": "completed", - "development_tools/containerization/kubernetes": "completed", - "development_tools/infrastructure/terraform": "completed", - "development_tools/documentation/mkdocs": "completed", - "cross_platform/desktop/electron": "completed", - "cross_platform/mobile/react-native": "completed", - "cross_platform/mobile/expo": "completed", - "cross_platform/mobile/flutter": "completed", - "cross_platform/desktop/tauri": "completed", - "ai_ml/machine_learning/scikit-learn": "completed", - "ai_ml/machine_learning/pandas": "completed", - "ai_ml/gpu_computing/cuda": "completed", - "ai_ml/machine_learning/tensorflow": "completed", - "ai_ml/llm_tools/huggingface": "completed", - "ai_ml/llm_tools/vllm": "completed", - "ai_ml/cloud_inference/modal": "completed", - "web_technologies/styling/tailwind": "completed", - "web_technologies/styling/css": "completed", - "ai_ml/machine_learning/pytorch": "completed", - "ai_ml/llm_tools/langchain": "completed", - "web_technologies/type_checking/zod": "completed", - "web_technologies/type_checking/typescript": "completed", - "web_technologies/modern_patterns/trpc": "completed", - "web_technologies/http_client/axios": "completed", - "web_technologies/api/graphql": "completed", - "web_technologies/http_client/guzzle": "completed", - "web_technologies/api/apollo-client": "completed", - "cloud_platforms/deployment/vercel": "completed", - "blockchain/ethereum/solidity": "completed", - "cloud_platforms/deployment/modal": "completed", - "web_technologies/modern_patterns/htmx": "completed", - "cloud_platforms/deployment/cloudflare": "completed", - "blockchain/ethereum/hardhat": "completed", - "cloud_platforms/serverless/aws-lambda": "completed", - "cloud_platforms/major_platforms/gcp": "completed", - "cloud_platforms/serverless/modal": "completed", - "cloud_platforms/major_platforms/azure": "completed", - "cloud_platforms/major_platforms/aws": "completed" + "next-js": "completed", + "langchain": "completed", + "cuda": "completed", + "react-native": "completed", + "zod": "completed", + "vue": "completed", + "cloudflare": "completed", + "webpack": "completed", + "expo": "completed", + "supabase": "completed", + "gcp": "completed", + "vitest": "completed", + "express": "completed", + "aws": "completed", + "nuxt": "completed", + "solidity": "completed", + "huggingface": "completed", + "tailwind": "completed", + "flutter": "completed", + "pandas": "completed", + "angular": "completed", + "git": "completed", + "docker": "completed", + "chakra-ui": "completed", + "kubernetes": "completed", + "shadcn": "completed", + "tensorflow": "completed", + "react-redux": "completed", + "react-query": "completed", + "turbopack": "completed", + "material-ui": "completed", + "axios": "completed", + "bun": "completed", + "flask": "completed", + "sveltekit": "completed", + "vite": "completed", + "terraform": "completed", + "fastapi": "completed", + "modal": "completed", + "electron": "completed", + "detox": "completed", + "solidjs": "completed", + "riverpod": "completed", + "zustand": "completed", + "playwright": "completed", + "mongodb": "completed", + "svelte": "completed", + "mkdocs": "completed", + "laravel": "completed", + "vue3": "completed", + "vercel": "completed", + "typescript": "completed", + "github-actions": "completed", + "guzzle": "completed", + "servemux": "completed", + "css": "completed", + "jest": "completed", + "nestjs": "completed", + "pytorch": "completed", + "apollo-client": "completed", + "aws-lambda": "completed", + "qwik": "completed", + "azure": "completed", + "redux": "completed", + "htmx": "completed", + "mobx": "completed", + "fiber": "completed", + "hardhat": "completed", + "redis": "completed", + "react": "completed", + "react-mobx": "completed", + "graphql": "completed", + "springboot": "completed", + "jetpack-compose": "completed", + "django": "completed", + "rocket": "completed", + "tauri": "completed", + "scikit-learn": "completed", + "actix-web": "completed", + "trpc": "completed", + "postgresql": "completed", + "duckdb": "completed", + "prisma": "completed", + "vllm": "completed" } \ No newline at end of file