|
|
@@ -4,8 +4,8 @@
|
|
|
提供暂停/继续、交互式菜单、经验总结等功能。
|
|
|
"""
|
|
|
|
|
|
+import logging
|
|
|
import sys
|
|
|
-import asyncio
|
|
|
from typing import Optional, Dict, Any
|
|
|
from pathlib import Path
|
|
|
|
|
|
@@ -13,6 +13,8 @@ from agent.core.runner import AgentRunner
|
|
|
from agent.trace import TraceStore
|
|
|
from agent.trace.models import Message, Trace
|
|
|
|
|
|
+logger = logging.getLogger(__name__)
|
|
|
+
|
|
|
|
|
|
# ===== 非阻塞 stdin 检测 =====
|
|
|
|
|
|
@@ -43,8 +45,8 @@ def check_stdin() -> Optional[str]:
|
|
|
return 'pause'
|
|
|
if cmd in ('q', 'quit'):
|
|
|
return 'quit'
|
|
|
- except Exception:
|
|
|
- pass
|
|
|
+ except (OSError, UnicodeError) as exc:
|
|
|
+ logger.debug("Failed to read agent control file: %s", exc)
|
|
|
|
|
|
# 2. 检查终端/管道输入
|
|
|
if sys.platform == 'win32':
|
|
|
@@ -68,8 +70,8 @@ def check_stdin() -> Optional[str]:
|
|
|
return 'pause'
|
|
|
if line in ('q', 'quit'):
|
|
|
return 'quit'
|
|
|
- except Exception:
|
|
|
- pass
|
|
|
+ except (OSError, ValueError) as exc:
|
|
|
+ logger.debug("Failed to poll stdin: %s", exc)
|
|
|
return None
|
|
|
else:
|
|
|
# Unix/Mac: 使用 select(支持终端和管道)
|
|
|
@@ -191,7 +193,7 @@ class InteractiveController:
|
|
|
print("未输入任何内容,取消操作")
|
|
|
continue
|
|
|
|
|
|
- print(f"\n将插入干预消息并继续执行...")
|
|
|
+ print("\n将插入干预消息并继续执行...")
|
|
|
# 从 store 读取实际的 last_sequence
|
|
|
live_trace = await self.store.get_trace(trace_id)
|
|
|
actual_sequence = live_trace.last_sequence if live_trace and live_trace.last_sequence else current_sequence
|
|
|
@@ -431,7 +433,7 @@ class InteractiveController:
|
|
|
messages_to_add = []
|
|
|
if intervention_msg:
|
|
|
messages_to_add.append({"role": "user", "content": intervention_msg})
|
|
|
- print(f"\n✓ 将插入干预消息")
|
|
|
+ print("\n✓ 将插入干预消息")
|
|
|
|
|
|
# 调用 runner.run() 续跑
|
|
|
print("\n开始执行...")
|