Skip to content

🌟 The Multi-Agent Framework: First AI Software Company, Towards Natural Language Programming

fixbug: repo2markdown

莘权 马073366f89c4b
diff --git a/metagpt/utils/repo_to_markdown.py b/metagpt/utils/repo_to_markdown.py
index 76dfe1b82..df916eb5d 100644
--- a/metagpt/utils/repo_to_markdown.py
+++ b/metagpt/utils/repo_to_markdown.py
@@ -11,6 +11,7 @@ from pathlib import Path
from gitignore_parser import parse_gitignore
from metagpt.logs import logger
+from metagpt.tools.libs.shell import execute
from metagpt.utils.common import aread, awrite, get_markdown_codeblock_type, list_files
from metagpt.utils.tree import tree
@@ -69,6 +70,15 @@ async def _write_file(filename: Path, repo_path: Path) -> str:
markdown = f"## {relative_path}\n"
mime_type, _ = mimetypes.guess_type(filename.name)
+ if not mime_type:
+ try:
+ stdout, stderr = await execute(f"file {str(filename)}")
+ if "text" in stdout.lower():
+ mime_type = "text/*"
+ except Exception as e:
+ logger.debug(f"file:{filename}, error:{e}")
+ mime_type = "unknown"
+
if "text/" not in mime_type:
logger.info(f"Ignore content: {filename}")
markdown += "<binary file>\n---\n\n"