🌟 The Multi-Agent Framework: First AI Software Company, Towards Natural Language Programming
fixbug: terminal
莘权 马d8aea069fadf
diff --git a/metagpt/logs.py b/metagpt/logs.pyindex 480477e6b..4f87b62e8 100644--- a/metagpt/logs.py+++ b/metagpt/logs.py@@ -26,7 +26,7 @@ class ToolLogItem(BaseModel):TOOL_LOG_END_MARKER = ToolLogItem(- type="str", name="end_marker", value="#END#"+ type="str", name="end_marker", value="\x18\x19\x1B\x18") # A special log item to suggest the end of a stream logdiff --git a/metagpt/tools/libs/terminal.py b/metagpt/tools/libs/terminal.pyindex a23ebb86a..351aa4f6f 100644--- a/metagpt/tools/libs/terminal.py+++ b/metagpt/tools/libs/terminal.py@@ -39,7 +39,7 @@ class Terminal:# Send the commandself.process.stdin.write(cmd + self.command_terminator)self.process.stdin.write(- f'echo "{TOOL_LOG_END_MARKER.value}"' + self.command_terminator+ f'echo "{TOOL_LOG_END_MARKER.value}"' + self.command_terminator # write EOF) # Unique marker to signal command endself.process.stdin.flush()log_tool_output(@@ -49,7 +49,14 @@ class Terminal:# Read the output until the unique marker is foundwhile True:line = self.process.stdout.readline()- if line.strip() == TOOL_LOG_END_MARKER.value:+ ix = line.rfind(TOOL_LOG_END_MARKER.value)+ if ix >= 0:+ line = line[0:ix]+ if line:+ log_tool_output(+ output=ToolLogItem(name="output", value=line), tool_name="Terminal"+ ) # log stdout in real-time+ cmd_output.append(line)log_tool_output(TOOL_LOG_END_MARKER)breaklog_tool_output(diff --git a/tests/metagpt/tools/libs/test_terminal.py b/tests/metagpt/tools/libs/test_terminal.pyindex 97c33b977..98ed63dd8 100644--- a/tests/metagpt/tools/libs/test_terminal.py+++ b/tests/metagpt/tools/libs/test_terminal.py@@ -1,3 +1,5 @@+import pytest+from metagpt.const import DATA_PATH, METAGPT_ROOTfrom metagpt.tools.libs.terminal import Terminal@@ -13,3 +15,7 @@ def test_terminal():terminal.run_command("cd data")output = terminal.run_command("pwd")assert output.strip() == str(DATA_PATH)+++if __name__ == "__main__":+ pytest.main([__file__, "-s"])