diff --git a/pipeline_service/agent_loop_v2.py b/pipeline_service/agent_loop_v2.py index 532babf..38f6acc 100644 --- a/pipeline_service/agent_loop_v2.py +++ b/pipeline_service/agent_loop_v2.py @@ -775,8 +775,21 @@ class AgentExecutor: try: if not os.path.isfile(full): return f"FAIL: 文件不存在 {path}" - with open(full, encoding="utf-8") as f: - return f.read()[:30000] + ext = os.path.splitext(full)[1].lower() + # docx:提取 word/document.xml 文本 + if ext == '.docx': + import zipfile + import re as _re + with zipfile.ZipFile(full) as z: + xml = z.read('word/document.xml').decode('utf-8', errors='ignore') + texts = _re.findall(r']*>(.*?)', xml) + return ('\n'.join(texts)[:30000]) or '(docx 无文本内容)' + # 纯文本类:直接读 + if ext in ('.txt', '.md', '.json', '.csv', '.py', '.log', '.yaml', '.yml', '.xml', '.html', '.ini', ''): + with open(full, encoding="utf-8", errors="ignore") as f: + return f.read()[:30000] + # 其他二进制 + return f"该文件是二进制格式({ext or '无扩展名'}),无法直接读取文本。可改用 run_command 处理,或让用户上传文本版本。" except Exception as e: return f"ERROR: {str(e)[:300]}"