feat: add /manual command + fix cross-engine command routing
- /manual → switch to manual engine (CLI + TUI) - /manual status → run manual engine sub-commands - /manual restart → restart manual terminal - /engine.manual status → now works from any engine (not just manual) - Fixed handle_engine_command to route to correct engine by name
This commit is contained in:
1 parent
03685ab5e7
commit
0d27f2b774
4 files changed
+49
-1
No files matched your search
@@ -0,0 +1 @@
|
||||
[]
|
||||
+13
-1
@@ -355,7 +355,19 @@ class BaseAICLI:
|
||||
engine.max_history = self.max_history
|
||||
|
||||
def handle_engine_command(self, command):
|
||||
"""处理引擎特定命令"""
|
||||
"""处理引擎特定命令(支持跨引擎调用,如 /engine.manual status)"""
|
||||
# 先检查是否指定了引擎名(如 "manual status" → 引擎=manual, 命令=status)
|
||||
parts = command.split(' ', 1)
|
||||
target_name = parts[0]
|
||||
rest = parts[1] if len(parts) > 1 else ""
|
||||
|
||||
# 如果目标名是某个已加载的引擎,直接调用该引擎
|
||||
if target_name in self.engines:
|
||||
target_engine = self.engines[target_name]
|
||||
if hasattr(target_engine, 'handle_command'):
|
||||
return target_engine.handle_command(rest)
|
||||
|
||||
# 否则当作当前引擎的命令
|
||||
if not hasattr(self.current_engine, 'handle_command'):
|
||||
return False
|
||||
engine_name = getattr(self.current_engine, 'name', '')
|
||||
|
||||
@@ -1102,6 +1102,22 @@ multi 操作支持一次修改多处:
|
||||
print(f"{Fore.RED}当前引擎不支持该命令或命令执行失败{Style.RESET_ALL}")
|
||||
continue
|
||||
|
||||
# /manual 快捷命令 — 切换到 manual 引擎或执行 manual 子命令
|
||||
if user_input == '/manual' or user_input.startswith('/manual '):
|
||||
args = user_input[8:].strip() if user_input.startswith('/manual ') else ''
|
||||
if 'manual' not in self.engines:
|
||||
print(f"{Fore.RED}manual 引擎未加载{Style.RESET_ALL}")
|
||||
elif not args:
|
||||
# 无参数:切换到 manual 引擎
|
||||
self.switch_engine('manual')
|
||||
print(f"{Fore.GREEN}已切换到 manual 引擎{Style.RESET_ALL}")
|
||||
else:
|
||||
# 有参数:执行 manual 引擎命令(如 status, restart)
|
||||
result = self.engines['manual'].handle_command(args)
|
||||
if result:
|
||||
print(f"{Fore.GREEN}{result}{Style.RESET_ALL}")
|
||||
continue
|
||||
|
||||
if user_input.startswith('/file.read '):
|
||||
args = user_input[11:].strip()
|
||||
parts = args.split(' ', 2)
|
||||
|
||||
@@ -719,6 +719,7 @@ if TEXTUAL_AVAILABLE:
|
||||
'tools': lambda: self._show_tools(),
|
||||
'engines': lambda: self._show_engines(),
|
||||
'tui': lambda: self._system("已在 TUI 模式中"),
|
||||
'manual': lambda: self._handle_manual(args),
|
||||
}
|
||||
|
||||
handler = cmds.get(name)
|
||||
@@ -753,6 +754,24 @@ if TEXTUAL_AVAILABLE:
|
||||
Enter 换行 Tab 缩进"""
|
||||
self._system(help_text)
|
||||
|
||||
def _handle_manual(self, args):
|
||||
"""处理 /manual 命令"""
|
||||
if 'manual' not in self.cli.engines:
|
||||
self._error("manual 引擎未加载")
|
||||
return
|
||||
if not args:
|
||||
# 切换到 manual 引擎
|
||||
if self.bridge.switch_engine('manual'):
|
||||
self._system("已切换到 manual 引擎")
|
||||
self._update_sidebar()
|
||||
else:
|
||||
self._error("切换失败")
|
||||
else:
|
||||
# 执行 manual 引擎子命令
|
||||
result = self.cli.engines['manual'].handle_command(args)
|
||||
if result:
|
||||
self._system(result)
|
||||
|
||||
def _switch_cli(self):
|
||||
self._system("切换到命令行模式...")
|
||||
self.cli.tui_output_callback = None
|
||||
|
||||
Reference in new issue
Block a user