mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-04-26 01:06:27 +02:00
Move cmd restrictions from RoleZero to the terminal
This commit is contained in:
parent
1b07a42d28
commit
86ad3edaca
4 changed files with 30 additions and 28 deletions
|
|
@ -34,8 +34,6 @@ 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",
|
||||
|
|
|
|||
|
|
@ -85,8 +85,6 @@ 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()
|
||||
|
|
@ -546,16 +544,8 @@ 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":
|
||||
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.)"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue