diff --git a/src/daemon/spawner.py b/src/daemon/spawner.py index 6ddfce0..3ac998b 100644 --- a/src/daemon/spawner.py +++ b/src/daemon/spawner.py @@ -834,19 +834,26 @@ curl -X POST http://{api_host}:{api_port}/api/projects/{project_id}/tasks/{task_ @staticmethod def _parse_stdout_json(stdout_text: str) -> dict: - """解析 openclaw agent --json 的 stdout 输出""" + """解析 openclaw agent --json 的 stdout 输出 + + openclaw agent --json 输出格式: + { "kind": "agent-response", "response": { "meta": { "transport": ..., ... } } } + """ text = stdout_text.strip() if not text: return {} try: data = json.loads(text) - return data.get("meta", {}) + # 正确路径:data.response.meta + response = data.get("response", data) + return response.get("meta", {}) except json.JSONDecodeError: # 多行输出,找最后一个 JSON for line in reversed(text.splitlines()): try: data = json.loads(line) - return data.get("meta", {}) + response = data.get("response", data) + return response.get("meta", {}) except json.JSONDecodeError: continue return {}