Move cmd restrictions from RoleZero to the terminal

This commit is contained in:
黄伟韬 2024-10-12 14:26:27 +08:00
parent 1b07a42d28
commit 86ad3edaca
4 changed files with 30 additions and 28 deletions

View file

@ -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",

View file

@ -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.)"