feat: 添加可配置的命令前缀以避免与Claude Code冲突

引入可配置的COMMAND_PREFIX参数,默认设置为"//"以避免与Claude Code的"/"命令冲突
修改相关文件以支持新的命令前缀,包括配置解析、路由逻辑和命令处理
更新帮助文档和提示信息以反映新的命令前缀
This commit is contained in:
Yuyao Huang (Sam)
2026-03-30 00:11:41 +08:00
parent ed70588d95
commit a278ece348
5 changed files with 85 additions and 56 deletions
+31 -18
View File
@@ -21,7 +21,7 @@ from langchain_core.messages import (
from langchain_openai import ChatOpenAI
from agent.manager import manager
from config import OPENAI_API_KEY, OPENAI_BASE_URL, OPENAI_MODEL, WORKING_DIR
from config import OPENAI_API_KEY, OPENAI_BASE_URL, OPENAI_MODEL, WORKING_DIR, COMMAND_PREFIX as _P
from orchestrator.tools import TOOLS, set_current_user
logger = logging.getLogger(__name__)
@@ -39,27 +39,29 @@ Pass these names directly to `create_conversation` — the tool resolves them au
{active_session_line}
Bot command prefix: {prefix}
## Tools — two distinct categories
### Bot control commands (use `run_command`)
`run_command` executes PhoneWork slash commands. Use it when the user asks to:
- Change permission mode: "切换到只读模式" → run_command("/perm plan")
- Close/switch sessions: "关掉第一个" → run_command("/close 1")
- Change routing mode: "切换到直连模式" → run_command("/direct")
- Set a reminder: "10分钟后提醒我" → run_command("/remind 10m 提醒我")
- Check status: "看看现在有哪些 session" → run_command("/status")
- Any other /command the user would type manually
`run_command` executes PhoneWork commands. Use it when the user asks to:
- Change permission mode: "切换到只读模式" → run_command("{prefix}perm plan")
- Close/switch sessions: "关掉第一个" → run_command("{prefix}close 1")
- Change routing mode: "切换到直连模式" → run_command("{prefix}direct")
- Set a reminder: "10分钟后提醒我" → run_command("{prefix}remind 10m 提醒我")
- Check status: "看看现在有哪些 session" → run_command("{prefix}status")
- Any other command the user would type manually
Available bot commands (pass verbatim to run_command):
/new <dir> [msg] [--perm bypass|accept|plan] — create session
/close [n|conv_id] — close session
/switch <n> — switch active session
/perm <mode> [conv_id] — permission mode: bypass (default), accept, plan
/direct — direct mode (bypass LLM for CC messages)
/smart — smart mode (LLM routing, default)
/status — list sessions
/remind <Ns|Nm|Nh> <msg> — one-shot reminder
/tasks — list background tasks
{prefix}new <dir> [msg] [--perm bypass|accept|plan] — create session
{prefix}close [n|conv_id] — close session
{prefix}switch <n> — switch active session
{prefix}perm <mode> [conv_id] — permission mode: bypass (default), accept, plan
{prefix}direct — direct mode (bypass LLM for CC messages)
{prefix}smart — smart mode (LLM routing, default)
{prefix}status — list sessions
{prefix}remind <Ns|Nm|Nh> <msg> — one-shot reminder
{prefix}tasks — list background tasks
### Host shell commands (use `run_shell`)
`run_shell` executes shell commands on the host machine (git, ls, cat, pip, etc.).
@@ -69,7 +71,7 @@ NEVER use `run_shell` for bot control. NEVER use `run_command` for shell command
1. NEW session: call `create_conversation` with the project name/path. \
If the user's message also contains a task, pass it as `initial_message` too.
2. Follow-up to ACTIVE session: call `send_to_conversation` with the active conv_id shown above.
3. BOT CONTROL: call `run_command` with the appropriate slash command.
3. BOT CONTROL: call `run_command` with the appropriate command.
4. GENERAL QUESTIONS: answer directly — do NOT create a session for simple Q&A.
5. WEB / SEARCH: use `web` at most twice, then synthesize and reply.
6. BACKGROUND TASKS: when a task starts, reply immediately — do NOT poll `task_status`.
@@ -119,6 +121,7 @@ class OrchestrationAgent:
working_dir=WORKING_DIR,
active_session_line=active_line,
today=today,
prefix=_P,
)
def get_active_conv(self, user_id: str) -> Optional[str]:
@@ -143,6 +146,16 @@ class OrchestrationAgent:
logger.info(">>> user=...%s conv=%s msg=%r", short_uid, active_conv, text[:80])
logger.debug(" history_len=%d", len(self._history[user_id]))
# Always handle bot commands first — even in passthrough mode.
# Bot commands must never reach Claude Code.
from config import COMMAND_PREFIX
if text.strip().startswith(COMMAND_PREFIX):
from bot.commands import handle_command
result = await handle_command(user_id, text)
if result is not None:
return result
logger.debug(" unknown command, falling through to LLM")
# Passthrough mode: if enabled and active session, bypass LLM
if self._passthrough[user_id] and active_conv:
try: