| import os |
| import json |
| import re |
|
|
| class IntelliModBridge: |
| def __init__(self, repo_root="intellimod"): |
| |
| |
| self.root = os.path.join(os.path.dirname(__file__), "intellimod_system") |
| |
| |
| |
| self.registry_path = os.path.join( |
| self.root, |
| "system-reference/tig-routing-cards/tig-routing-registry.md" |
| ) |
| self.registry_data = self._load_registry() |
|
|
| def _load_registry(self): |
| """ |
| Reads the Markdown file, extracts the JSON block, and loads it. |
| """ |
| if not os.path.exists(self.registry_path): |
| print(f"[!] IntelliMod Registry not found at: {self.registry_path}") |
| return {} |
| |
| with open(self.registry_path, "r", encoding="utf-8") as f: |
| content = f.read() |
| |
| |
| match = re.search(r"```json\s*(\{.*?\})\s*```", content, re.DOTALL) |
| if match: |
| try: |
| return json.loads(match.group(1)) |
| except json.JSONDecodeError as e: |
| print(f"[!] Registry JSON Error: {e}") |
| return {} |
| return {} |
|
|
| def get_tig_recommendation(self, intent): |
| """ |
| Maps a TIG Intent (e.g., 'coding') to a file path from your Registry. |
| """ |
| target_category = None |
| target_keyword = None |
|
|
| |
| if intent == "coding": |
| target_category = "Anthropic" |
| target_keyword = "sonnet" |
| elif intent == "creative_text": |
| target_category = "Open AI" |
| target_keyword = "gpt-5" |
| elif intent == "research": |
| target_category = "Google" |
| target_keyword = "gemini" |
| elif intent == "visual_image": |
| target_category = "Tool Cards" |
| target_keyword = "image" |
| |
| if not target_category: |
| return None |
|
|
| |
| file_list = self.registry_data.get(target_category, []) |
| best_match = None |
| |
| for file_path in file_list: |
| if target_keyword and target_keyword in file_path.lower(): |
| best_match = file_path |
| break |
| |
| |
| if not best_match and file_list: |
| best_match = file_list[0] |
| |
| if best_match: |
| return { |
| "intent": intent, |
| "category": target_category, |
| "card_name": os.path.basename(best_match), |
| "full_path": os.path.join(self.root, best_match) |
| } |
| |
| return None |