fix: correct terminal_input error reporting
This commit is contained in:
parent
8fe06753bb
commit
b78921b1ca
@ -328,14 +328,18 @@ class TerminalManager:
|
|||||||
return {
|
return {
|
||||||
"success": False,
|
"success": False,
|
||||||
"error": "没有活动终端会话",
|
"error": "没有活动终端会话",
|
||||||
"suggestion": "请先使用 terminal_session 打开一个终端"
|
"suggestion": "请先使用 terminal_session 打开一个终端",
|
||||||
|
"status": "error",
|
||||||
|
"output": "没有活动终端会话"
|
||||||
}
|
}
|
||||||
|
|
||||||
if target_session not in self.terminals:
|
if target_session not in self.terminals:
|
||||||
return {
|
return {
|
||||||
"success": False,
|
"success": False,
|
||||||
"error": f"终端会话 '{target_session}' 不存在",
|
"error": f"终端会话 '{target_session}' 不存在",
|
||||||
"existing_sessions": list(self.terminals.keys())
|
"existing_sessions": list(self.terminals.keys()),
|
||||||
|
"status": "error",
|
||||||
|
"output": f"终端会话 '{target_session}' 不存在"
|
||||||
}
|
}
|
||||||
|
|
||||||
terminal = self.terminals[target_session]
|
terminal = self.terminals[target_session]
|
||||||
@ -479,14 +483,18 @@ class TerminalManager:
|
|||||||
return {
|
return {
|
||||||
"success": False,
|
"success": False,
|
||||||
"error": "没有活动终端会话",
|
"error": "没有活动终端会话",
|
||||||
"suggestion": "请先使用 terminal_session 打开一个终端"
|
"suggestion": "请先使用 terminal_session 打开一个终端",
|
||||||
|
"status": "error",
|
||||||
|
"output": "没有活动终端会话"
|
||||||
}
|
}
|
||||||
|
|
||||||
if target_session not in self.terminals:
|
if target_session not in self.terminals:
|
||||||
return {
|
return {
|
||||||
"success": False,
|
"success": False,
|
||||||
"error": f"终端会话 '{target_session}' 不存在",
|
"error": f"终端会话 '{target_session}' 不存在",
|
||||||
"existing_sessions": list(self.terminals.keys())
|
"existing_sessions": list(self.terminals.keys()),
|
||||||
|
"status": "error",
|
||||||
|
"output": f"终端会话 '{target_session}' 不存在"
|
||||||
}
|
}
|
||||||
|
|
||||||
# 发送命令
|
# 发送命令
|
||||||
|
|||||||
@ -308,6 +308,8 @@ def _plain_command_output(result_data: Dict[str, Any]) -> str:
|
|||||||
timeout = result_data.get("timeout")
|
timeout = result_data.get("timeout")
|
||||||
return_code = result_data.get("return_code")
|
return_code = result_data.get("return_code")
|
||||||
truncated = result_data.get("truncated")
|
truncated = result_data.get("truncated")
|
||||||
|
error = result_data.get("error")
|
||||||
|
message = result_data.get("message")
|
||||||
|
|
||||||
prefixes = []
|
prefixes = []
|
||||||
if status in {"timeout"} and timeout:
|
if status in {"timeout"} and timeout:
|
||||||
@ -328,6 +330,14 @@ def _plain_command_output(result_data: Dict[str, Any]) -> str:
|
|||||||
if truncated:
|
if truncated:
|
||||||
prefixes.append("[truncated]")
|
prefixes.append("[truncated]")
|
||||||
|
|
||||||
|
# 如果执行失败且没有输出,优先显示错误信息
|
||||||
|
if not result_data.get("success") and not output:
|
||||||
|
err_text = error or message
|
||||||
|
if err_text:
|
||||||
|
prefix_text = "".join(prefixes) if prefixes else "[error]"
|
||||||
|
return f"{prefix_text} {err_text}" if prefix_text else err_text
|
||||||
|
# 没有错误文本则仍走后面的输出逻辑(可能显示 no_output)
|
||||||
|
|
||||||
prefix_text = "".join(prefixes)
|
prefix_text = "".join(prefixes)
|
||||||
if prefix_text and output:
|
if prefix_text and output:
|
||||||
return f"{prefix_text}\n{output}"
|
return f"{prefix_text}\n{output}"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user