Skip to content

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

fixbug: source code path

莘权 马f0ca7e6a8fc3
diff --git a/metagpt/roles/engineer.py b/metagpt/roles/engineer.py
index a58e0f047..1cd180793 100644
--- a/metagpt/roles/engineer.py
+++ b/metagpt/roles/engineer.py
@@ -45,7 +45,12 @@ from metagpt.schema import (
Documents,
Message,
)
-from metagpt.utils.common import any_to_name, any_to_str, any_to_str_set, aread
+from metagpt.utils.common import (
+ any_to_name,
+ any_to_str,
+ any_to_str_set,
+ get_project_srcs_path,
+)
IS_PASS_PROMPT = """
{context}
@@ -239,8 +244,7 @@ class Engineer(Role):
async def _think(self) -> Action | None:
if not self.src_workspace:
- name = await self._get_src_workspace_name()
- self.src_workspace = self.git_repo.workdir / name
+ self.src_workspace = get_project_srcs_path(self.project_repo.workdir)
write_plan_and_change_filters = any_to_str_set([WriteTasks, FixBug])
write_code_filters = any_to_str_set([WriteTasks, WriteCodePlanAndChange, SummarizeCode])
summarize_code_filters = any_to_str_set([WriteCode, WriteCodeReview])
@@ -384,10 +388,3 @@ class Engineer(Role):
def action_description(self) -> str:
"""AgentStore uses this attribute to display to the user what actions the current role should take."""
return self.next_todo_action
-
- async def _get_src_workspace_name(self):
- name = self.git_repo.workdir.name
- src_workspace_filename = self.git_repo.workdir / ".src_workspace"
- if src_workspace_filename.exists():
- name = await aread(filename=src_workspace_filename)
- return name
diff --git a/metagpt/utils/common.py b/metagpt/utils/common.py
index 3d9fc5a9f..22bfc356e 100644
--- a/metagpt/utils/common.py
+++ b/metagpt/utils/common.py
@@ -879,3 +879,13 @@ def get_markdown_codeblock_type(filename: str = None, mime_type: str = None) ->
"application/xml": "xml",
}
return mappings.get(mime_type, "text")
+
+
+def get_project_srcs_path(workdir: str | Path) -> Path:
+ src_workdir_path = workdir / ".src_workspace"
+ if src_workdir_path.exists():
+ with open(src_workdir_path, "r") as file:
+ src_name = file.read()
+ else:
+ src_name = Path(workdir).name
+ return Path(workdir) / src_name
diff --git a/metagpt/utils/project_repo.py b/metagpt/utils/project_repo.py
index bb18b520c..fce918570 100644
--- a/metagpt/utils/project_repo.py
+++ b/metagpt/utils/project_repo.py
@@ -35,6 +35,7 @@ from metagpt.const import (
TEST_OUTPUTS_FILE_REPO,
VISUAL_GRAPH_REPO_FILE_REPO,
)
+from metagpt.utils.common import get_project_srcs_path
from metagpt.utils.file_repository import FileRepository
from metagpt.utils.git_repository import GitRepository
@@ -129,11 +130,10 @@ class ProjectRepo(FileRepository):
return self._git_repo.new_file_repository(self._srcs_path)
def code_files_exists(self) -> bool:
- git_workdir = self.git_repo.workdir
- src_workdir = git_workdir / git_workdir.name
+ src_workdir = get_project_srcs_path(self.git_repo.workdir)
if not src_workdir.exists():
return False
- code_files = self.with_src_path(path=git_workdir / git_workdir.name).srcs.all_files
+ code_files = self.with_src_path(path=src_workdir).srcs.all_files
if not code_files:
return False
return bool(code_files)