perf: 启动输出瘦身 + FC 能力探测缓存,修复测试套件失效
自用体验(同时以人类和被接入 AI 的视角)暴露出三个问题,一并处理:
1. 启动太吵:117 行 / 16983 字符的开屏,人还没开始用就先刷屏
- 完整 ASCII 开机动画改为 --logo / --banner 按需召唤,默认两行紧凑标识
- 21 行命令说明折叠成一行「/help 全部命令 · /quit 退出 · ...」,
完整速查表挪进 /help(新增 show_quick_commands)
- 插件/引擎/工具的逐条加载日志改走 vprint,由 --verbose / -v /
XCLI_VERBOSE=1 召唤;工具加载汇总成一行
- 日志控制台 handler 降到 WARNING(文件仍留全量 INFO),并静音
httpx/httpcore/urllib3 等第三方心跳日志
=> 默认启动 10 行 / 475 字符,--verbose 仍可看到全部 36 行细节
2. 不支持 FC 的模型每次会话都白撞一发 500
讯飞 xophunyuan7bmt 不支持 Function Calling,请求带 tools 字段必报
500 Invalid Params,虽有降级重试兜底,但每个新会话都要先错一次。
- 新增 xcli_core/fc_tools 能力缓存(按 base_url::model 落盘 .fc_support.json)
- 降级重试成功后记住该模型不支持 FC,后续直接不发 tools
- 降级也失败时不写缓存,避免把别的故障误判成 FC 问题
- 新增 /fc [reset] 查看与清除缓存
3. diff 弹窗模式每次启动都要重新问一遍
- 首次选择后经 config.json 持久化,新增 /diff [popup|inline] 随时切换
测试:
- 新增 tests/test_startup_and_fc.py(27 项,含假 HTTP 验证降级与缓存链路)
- 修复 tests/test_plugins.py 长期失效:插件入口类早已由 Plugin 改名 Liugin,
8 处 fixture 未跟进导致 65 个用例直接 error;断言也未适配 ToolResult 返回值
与「❌」错误前缀。改为 plugin_class() / as_text() / is_error() 语义判断。
- 全量:217 passed(此前 152 passed + 65 error + 27 failed)
This commit is contained in:
1 parent
d2ac6896ad
commit
3a86da7444
12 files changed
+728
-167
No files matched your search
+11
-10
@@ -10,6 +10,7 @@ from .constants import (
|
||||
UNIFIED_TOOL_MANAGER_AVAILABLE, TEXTUAL_AVAILABLE,
|
||||
)
|
||||
from .config import get_system_config, set_system_config, logger
|
||||
from .verbose import vprint
|
||||
from .plugin_manager import LiuginManager
|
||||
from .process_protection import get_protection, enable_process_protection
|
||||
|
||||
@@ -70,11 +71,11 @@ class BaseAICLI:
|
||||
# 设置默认引擎,优先使用配置文件指定的引擎
|
||||
if default_engine_name in self.engines:
|
||||
self.current_engine = self.engines[default_engine_name]
|
||||
print(f"{Fore.GREEN}使用配置的默认AI引擎: {default_engine_name}{Style.RESET_ALL}")
|
||||
vprint(f"{Fore.GREEN}使用配置的默认AI引擎: {default_engine_name}{Style.RESET_ALL}")
|
||||
elif self.engines:
|
||||
first_engine_name = next(iter(self.engines))
|
||||
self.current_engine = self.engines[first_engine_name]
|
||||
print(f"{Fore.GREEN}使用默认AI引擎: {first_engine_name}{Style.RESET_ALL}")
|
||||
vprint(f"{Fore.GREEN}使用默认AI引擎: {first_engine_name}{Style.RESET_ALL}")
|
||||
else:
|
||||
print(f"{Fore.RED}警告: 没有可用的AI引擎,请检查ai_engines目录{Style.RESET_ALL}")
|
||||
self.current_engine = None
|
||||
@@ -153,7 +154,7 @@ class BaseAICLI:
|
||||
|
||||
def load_ai_engines(self):
|
||||
"""动态加载AI引擎插件"""
|
||||
print(f"{Fore.GREEN}正在加载AI引擎插件...{Style.RESET_ALL}")
|
||||
vprint(f"{Fore.GREEN}正在加载AI引擎插件...{Style.RESET_ALL}")
|
||||
ai_engines_dir = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "ai_engines")
|
||||
if os.path.exists(ai_engines_dir):
|
||||
for filename in os.listdir(ai_engines_dir):
|
||||
@@ -171,7 +172,7 @@ class BaseAICLI:
|
||||
engine_key = getattr(engine_instance, 'name', engine_name)
|
||||
if engine_key not in self.engines:
|
||||
self.engines[engine_key] = engine_instance
|
||||
print(f"{Fore.GREEN}已加载AI引擎: {engine_key} ({class_name}){Style.RESET_ALL}")
|
||||
vprint(f"{Fore.GREEN}已加载AI引擎: {engine_key} ({class_name}){Style.RESET_ALL}")
|
||||
else:
|
||||
print(f"{Fore.YELLOW}AI引擎 {engine_key} 已存在,跳过加载{Style.RESET_ALL}")
|
||||
else:
|
||||
@@ -185,7 +186,7 @@ class BaseAICLI:
|
||||
except Exception as e:
|
||||
logger.error(f"加载AI引擎插件时发生未知错误 {filename}: {e}")
|
||||
print(f"{Fore.RED}加载AI引擎插件失败 {filename}: {e}{Style.RESET_ALL}")
|
||||
print(f"{Fore.GREEN}总共加载了 {len(self.engines)} 个AI引擎{Style.RESET_ALL}")
|
||||
vprint(f"{Fore.GREEN}总共加载了 {len(self.engines)} 个AI引擎{Style.RESET_ALL}")
|
||||
|
||||
def _find_engine_class(self, module, engine_name):
|
||||
"""查找AI引擎类,使用动态方式避免硬编码类名"""
|
||||
@@ -213,7 +214,7 @@ class BaseAICLI:
|
||||
|
||||
def load_liugins(self, liugins_dir=None, skills_dir=None):
|
||||
"""加载liugin和技能"""
|
||||
print(f"{Fore.GREEN}正在加载工具...{Style.RESET_ALL}")
|
||||
vprint(f"{Fore.GREEN}正在加载工具...{Style.RESET_ALL}")
|
||||
|
||||
if self._use_unified_manager:
|
||||
self.liugin_manager.initialize(liugins_dir or "plugins", skills_dir or "skills")
|
||||
@@ -242,19 +243,19 @@ class BaseAICLI:
|
||||
tool_info = plugin_instance.get_tool_info()
|
||||
tool_info['handler'] = plugin_instance.handle
|
||||
self.liugin_manager.tools.append(tool_info)
|
||||
print(f"{Fore.GREEN}已加载liugin: {liugin_name}{Style.RESET_ALL}")
|
||||
vprint(f"{Fore.GREEN}已加载liugin: {liugin_name}{Style.RESET_ALL}")
|
||||
except Exception as e:
|
||||
print(f"{Fore.RED}加载liugin失败 {filename}: {e}{Style.RESET_ALL}")
|
||||
print(f"{Fore.GREEN}总共加载了 {len(self.liugin_manager.tools)} 个工具插件{Style.RESET_ALL}")
|
||||
vprint(f"{Fore.GREEN}总共加载了 {len(self.liugin_manager.tools)} 个工具插件{Style.RESET_ALL}")
|
||||
|
||||
print(f"{Fore.GREEN}工具加载完成!{Style.RESET_ALL}")
|
||||
vprint(f"{Fore.GREEN}工具加载完成!{Style.RESET_ALL}")
|
||||
|
||||
# ── 命令注册 ──
|
||||
|
||||
def register_liugin_command(self, command, handler):
|
||||
"""注册插件命令"""
|
||||
self.liugin_commands[command] = handler
|
||||
print(f"{Fore.GREEN}已注册插件命令: {command}{Style.RESET_ALL}")
|
||||
vprint(f"{Fore.GREEN}已注册插件命令: {command}{Style.RESET_ALL}")
|
||||
|
||||
def unregister_liugin_command(self, command):
|
||||
"""注销插件命令"""
|
||||
|
||||
Reference in new issue
Block a user