Skip to content

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

forbidden npm run dev command

黄伟韬1b07a42d2832
diff --git a/metagpt/prompts/di/engineer2.py b/metagpt/prompts/di/engineer2.py
index 66ed47932..6a4392623 100644
--- a/metagpt/prompts/di/engineer2.py
+++ b/metagpt/prompts/di/engineer2.py
@@ -79,8 +79,8 @@ Note:
21. When planning, consider whether images are needed. If you are developing a showcase website, start by using ImageGetter.get_image to obtain the necessary images.
22. When planning, merge multiple tasks that operate on the same file into a single task. For example, create one task for writing unit tests for all functions in a class. Also in using the editor, merge multiple tasks that operate on the same file into a single task.
23. When create unit tests for a code file, use Editor.read() to read the code file before planing. And create one plan to writing the unit test for the whole file.
-24. Follow the Sytem Design and Project Schedule if exists. Otherwise, use default template folder of Vite, React, MUI and Tailwind CSS. If the template does not exist, use native HTML.
-25. When writing Vue/React project: The Vue template is in the {vue_template_path}, the React template is in the {react_template_path}.
+24. Follow the Sytem Design and Project Schedule if exists. Otherwise, use default template folder of Vite, React, MUI and Tailwind CSS. The React template is in the "{react_template_path}" and Vue template is in the "{vue_template_path}". If the template does not exist, use native HTML.
+25. When writing Vue/React project:
25.1. Create the project folder first. Use cmd " mkdir -p {{project_name}} "
25.2. Copy a Vue/React template to your project and view all files. This must be a single respond. Use cmd "cp -r {{template_folder}}/* {{workspace}}/{{project_name}}/ && cd {{workspace}}/{{project_name}} && pwd && tree -f".
25.3. Read the content of each file and use the write_new_code command to rewrite the code. Be sure you are in the {{project_name}}.
diff --git a/metagpt/roles/di/engineer2.py b/metagpt/roles/di/engineer2.py
index 2fb9d05ee..2ff696a54 100644
--- a/metagpt/roles/di/engineer2.py
+++ b/metagpt/roles/di/engineer2.py
@@ -34,6 +34,8 @@ class Engineer2(RoleZero):
goal: str = "Take on game, app, and web development."
instruction: str = ENGINEER2_INSTRUCTION
terminal: Terminal = Field(default_factory=Terminal, exclude=True)
+ # The cmd in forbidden_terminal_commands will be replace by pass ana return the advise.
+ forbidden_terminal_commands: dict = {"npm run dev": "Use Deployer.deploy_to_public instead."}
deployer: Deployer = Field(default_factory=Deployer)
tools: list[str] = [
"Plan",
diff --git a/metagpt/roles/di/role_zero.py b/metagpt/roles/di/role_zero.py
index 041990372..175309523 100644
--- a/metagpt/roles/di/role_zero.py
+++ b/metagpt/roles/di/role_zero.py
@@ -85,6 +85,8 @@ class RoleZero(Role):
"Editor.append_file",
"Editor.open_file",
]
+ # The cmd in forbidden_terminal_commands will be replace by pass ana return the advise. {"cmd":"forbidden_reason/advice"}
+ forbidden_terminal_commands: dict = {}
# Equipped with three basic tools by default for optional use
editor: Editor = Editor(enable_auto_lint=True)
browser: Browser = Browser()
@@ -544,11 +546,16 @@ class RoleZero(Role):
return human_response
# output from bash.run may be empty, add decorations to the output to ensure visibility.
elif cmd["command_name"] == "Terminal.run_command":
- if "npm run dev" in cmd["args"]:
- command_output = "command run failed! Pleae use Delopyer to deploy your project after build."
- return command_output
+ tool_output = ""
+ # Remove forbidden commands
+ if any([forbidden_cmd in cmd["args"]["cmd"] for forbidden_cmd in self.forbidden_terminal_commands.keys()]):
+ for cmd_name, reason in self.forbidden_terminal_commands.items():
+ # 'true' is a pass command in linux terminal.
+ cmd["args"]["cmd"] = cmd["args"]["cmd"].replace(cmd_name, "true")
+ tool_output += f"{cmd_name} is failed to executed. {reason}\n"
+
tool_obj = self.tool_execution_map[cmd["command_name"]]
- tool_output = await tool_obj(**cmd["args"])
+ tool_output += await tool_obj(**cmd["args"])
if len(tool_output) <= 10:
command_output += (
f"\n[command]: {cmd['args']['cmd']} \n[command output] : {tool_output} (pay attention to this.)"