@@ -26,7 +26,7 @@ def __init__(self):
2626 api_key = os .environ .get ("OPENROUTER_API_KEY" ),
2727 )
2828
29- def extract_description_from_readme (self , readme_content : str ) -> str :
29+ def extract_description_from_readme (self , readme_content : str , repo_url : str = "" ) -> str :
3030 """Extract a concise description from README content.
3131
3232 Looks for the first meaningful description paragraph near the beginning
@@ -35,6 +35,7 @@ def extract_description_from_readme(self, readme_content: str) -> str:
3535
3636 Args:
3737 readme_content: Contents of README.md
38+ repo_url: GitHub repository URL to extract name for title matching
3839
3940 Returns:
4041 Extracted description or empty string if not found
@@ -90,10 +91,10 @@ def extract_description_from_readme(self, readme_content: str) -> str:
9091
9192 # If we couldn't find a good description in regular text,
9293 # check content under main repo name heading
93- if not description :
94+ if not description and repo_url :
9495 for heading , content in title_content .items ():
9596 # Look for the repo name in the heading
96- if heading and "/" in repo_url :
97+ if heading :
9798 repo_name = repo_url .strip ('/' ).split ('/' )[- 1 ].lower ()
9899 if repo_name .lower () in heading .lower ():
99100 for line in content :
@@ -184,13 +185,31 @@ def _convert_to_raw_url(self, repo_url: str) -> str:
184185 if "github.com" not in repo_url :
185186 raise ValueError (f"Invalid GitHub URL: { repo_url } " )
186187
188+ # Handle subdirectory URLs (tree format)
187189 if "/tree/" in repo_url :
188- return repo_url .replace ("/tree/" , "/raw/" )
190+ # For URLs like github.com/user/repo/tree/branch/path/to/dir
191+ parts = repo_url .split ("/tree/" )
192+ base_url = parts [0 ].replace (
193+ "github.com" , "raw.githubusercontent.com" )
194+ path_parts = parts [1 ].split ("/" , 1 )
195+
196+ if len (path_parts ) > 1 :
197+ branch = path_parts [0 ]
198+ subdir = path_parts [1 ]
199+ return f"{ base_url } /{ branch } /{ subdir } /README.md"
200+ else :
201+ branch = path_parts [0 ]
202+ return f"{ base_url } /{ branch } /README.md"
189203
204+ # Handle direct file URLs
190205 if "/blob/" in repo_url :
191206 raw_url = repo_url .replace ("/blob/" , "/raw/" )
192- return raw_url if raw_url .endswith (".md" ) else f"{ raw_url } /README.md"
207+ if raw_url .endswith (".md" ):
208+ return raw_url
209+ else :
210+ return f"{ raw_url } /README.md"
193211
212+ # Handle repository root URLs
194213 raw_url = repo_url .replace ("github.com" , "raw.githubusercontent.com" )
195214 return f"{ raw_url .rstrip ('/' )} /main/README.md"
196215
@@ -434,7 +453,15 @@ def generate_manifest(self, repo_url: str, server_name: Optional[str] = None) ->
434453 # Extract repo info
435454 parts = repo_url .strip ("/" ).split ("/" )
436455 owner = parts [3 ]
437- name = parts [4 ]
456+
457+ # Extract name, handling subdirectories in tree format
458+ if "/tree/" in repo_url and "/src/" in repo_url :
459+ # For subdirectories in the src folder, use the subdirectory name
460+ src_path = repo_url .split ("/src/" )[1 ]
461+ name = src_path .split ("/" )[0 ]
462+ else :
463+ # Default is the last path component
464+ name = parts [- 1 ]
438465
439466 # If no server name was explicitly provided, use the one from URL
440467 if server_name :
@@ -445,7 +472,6 @@ def generate_manifest(self, repo_url: str, server_name: Optional[str] = None) ->
445472
446473 # Get prompt as tuple and extract manifest
447474 manifest = self .extract_with_llms (repo_url , readme_content )
448-
449475 # Update manifest with repository information
450476 manifest .update ({
451477 "name" : name ,
@@ -455,7 +481,8 @@ def generate_manifest(self, repo_url: str, server_name: Optional[str] = None) ->
455481 })
456482
457483 # Update manifest with description
458- description = self .extract_description_from_readme (readme_content )
484+ description = self .extract_description_from_readme (
485+ readme_content , repo_url )
459486 if not description :
460487 description = self .extract_description_from_readme_with_llms (
461488 readme_content )
@@ -620,7 +647,6 @@ def main(repo_url: str, is_official: bool = False):
620647 sys .exit (1 )
621648
622649 repo_url = sys .argv [1 ].strip ()
623-
624650 # Check if the URL is a simple URL without protocol
625651 if not repo_url .startswith (("http://" , "https://" )):
626652 # Add https:// if it's a github.com URL without protocol
0 commit comments