Skip to content

JiuwenSwarm is an intelligent AI Agent built on openJiuwen. It extends the powerful capabilities of large language models directly to your fingertips through various communication apps you use daily.

Python

fix: support review in plan mode

ldstyle8b5abd9f14ffb
diff --git a/jiuwenswarm/gateway/message_handler/message_handler.py b/jiuwenswarm/gateway/message_handler/message_handler.py
index 5b0e6042aa..dc19115558 100644
--- a/jiuwenswarm/gateway/message_handler/message_handler.py
+++ b/jiuwenswarm/gateway/message_handler/message_handler.py
@@ -2819,7 +2819,8 @@ class MessageHandler(ABC):
msg.params["content"] = review_prompt
content = review_prompt
logger.info(
- "[MessageHandler] /review prompt injected for chat.send channel=%s pr_arg=%s",
+ "[MessageHandler] /review prompt injected for chat.send "
+ "channel=%s pr_arg=%s",
getattr(msg, "channel_id", ""),
pr_arg or "<none>",
)
diff --git a/jiuwenswarm/server/agent_ws_server.py b/jiuwenswarm/server/agent_ws_server.py
index 3628eeb31c..17ba9d5ce3 100644
--- a/jiuwenswarm/server/agent_ws_server.py
+++ b/jiuwenswarm/server/agent_ws_server.py
@@ -480,26 +480,32 @@ def _reject_extra_sandbox_files_params(params: dict[str, Any]) -> None:
def _inject_plan_mode_activation_reminder(request: AgentRequest) -> None:
- """在用户消息中注入 <system-reminder> 告知 LLM 调用 enter_plan_mode.
+ """在用户消息中注入 <system-reminder> 告知 LLM 当前处于 plan 模式.
- plan 模式行为指令不进 system prompt,
- 而是通过对话中的 tool_result 传递。此提醒是进入 plan 模式后的
- 第一个引导,告诉 LLM 调用 enter_plan_mode 以获取完整指令。
+ plan 模式行为指令不进 system prompt,而是通过对话中的 tool_result
+ 传递。此提醒是进入 plan 模式后的第一个引导,告知 LLM 只读约束已生效。
- 注意:此提醒需要足够权威和明确,因为 code.plan 模式下
- AgentModeRail 注入的 system prompt 是静态的(不含动态
- plan_file 状态),完整指令仍需 enter_plan_mode 的 tool_result。
+ plan 模式的只读约束由工具拦截层强制(非只读工具/写
+ 操作被硬拦),此提醒只做约束说明 + 软引导。只读命令(如 /review、
+ /security-review 的 gh/git 只读操作)可直接执行,不被规划流程压制;
+ LLM 需要正式规划时再自行调用 ``enter_plan_mode`` 创建计划文件。
"""
reminder = (
"\n\n<system-reminder>\n"
"Plan mode is active. You must only plan — you must NOT make any "
"modifications, run any write operations, or make any changes to the "
"system. This constraint takes priority over any other instructions.\n\n"
- "CRITICAL: You MUST call `enter_plan_mode` as your very first action, "
- "before doing anything else. This tool will create the plan file and "
- "give you full plan mode instructions. Until then, you may only read "
- "files and explore the codebase using read-only tools (read_file, "
- "grep, list_files, glob, bash for read-only commands).\n"
+ "Read-only actions are allowed directly: you may read files and explore "
+ "the codebase, and run read-only commands (read_file, grep, list_files, "
+ "glob, bash for read-only operations such as gh pr list/view/diff or "
+ "git status/diff/log). Write operations and non-read-only tools are "
+ "blocked.\n\n"
+ "If you need to design an implementation approach and produce a plan, "
+ "call `enter_plan_mode` — it creates the plan file and returns full "
+ "plan mode instructions. This is not required as your first action; "
+ "you may gather context with read-only tools first. Do NOT proceed to "
+ "implement anything until the user approves your plan via "
+ "`exit_plan_mode`.\n"
"</system-reminder>"
)
if isinstance(request.params, dict):
diff --git a/jiuwenswarm/server/runtime/agent_adapter/interface_code.py b/jiuwenswarm/server/runtime/agent_adapter/interface_code.py
index 2efb7f8a45..4a647a14ce 100644
--- a/jiuwenswarm/server/runtime/agent_adapter/interface_code.py
+++ b/jiuwenswarm/server/runtime/agent_adapter/interface_code.py
@@ -93,14 +93,16 @@ output redirection, file edits outside the plan file, or git commit/push/add),
and must NOT make any changes to the system. This constraint takes priority
over any other instructions you receive.
-CRITICAL: You MUST call `enter_plan_mode` as your very first action, before
-doing anything else. This tool will create the plan file and give you full
-plan mode instructions. Until then, you may only read files and explore the
-codebase using read-only tools (read_file, grep, list_files, glob, bash for
-read-only commands).
-
-Do NOT proceed to implement anything until the user approves your plan via
-`exit_plan_mode`.
+Read-only actions are allowed directly: you may read files and explore the
+codebase, and run read-only commands (read_file, grep, list_files, glob, bash
+for read-only operations such as gh pr list/view/diff or git status/diff/log).
+Write operations and non-read-only tools are blocked by the runtime.
+
+If you need to design an implementation approach and produce a plan, call
+`enter_plan_mode` — it creates the plan file and gives you full plan mode
+instructions. This is not required as your first action; you may gather
+context with read-only tools first. Do NOT proceed to implement anything
+until the user approves your plan via `exit_plan_mode`.
"""
# ---------------------------------------------------------------------------
diff --git a/tests/unit_tests/server/test_plan_mode_activation_reminder.py b/tests/unit_tests/server/test_plan_mode_activation_reminder.py
new file mode 100644
index 0000000000..a3e1730f7f
--- /dev/null
+++ b/tests/unit_tests/server/test_plan_mode_activation_reminder.py
@@ -0,0 +1,53 @@
+# Copyright (c) Huawei Technologies Co., Ltd. 2026. All rights reserved.
+
+"""Plan-mode activation reminder regression tests.
+
+方向一:弱化激活提醒的流程强制语义,使只读命令(/review、/security-review)
+在 plan 模式下可直接执行。该提醒不再强制 LLM 把 ``enter_plan_mode`` 作为
+第一个动作,但仍保留只读约束说明。
+"""
+
+from jiuwenswarm.common.schema.agent import AgentRequest
+from jiuwenswarm.server.agent_ws_server import _inject_plan_mode_activation_reminder
+
+
+def _make_request(params: dict) -> AgentRequest:
+ return AgentRequest(request_id="test-1", session_id="sess-1", params=params)
+
+
+class TestInjectActivationReminder:
+ """弱化后的激活提醒:约束保留,流程强制移除。"""
+
+ @staticmethod
+ def test_reminder_states_plan_mode_active() -> None:
+ request = _make_request({"query": "review PR 123"})
+ _inject_plan_mode_activation_reminder(request)
+ assert "Plan mode is active." in request.params["query"]
+
+ @staticmethod
+ def test_reminder_does_not_force_enter_plan_mode_as_first_action() -> None:
+ """弱化后不再强制要求用户先执行 enter_plan_mode。"""
+ request = _make_request({"query": "review PR 123"})
+ _inject_plan_mode_activation_reminder(request)
+ query = request.params["query"]
+ assert "as your very first action" not in query
+ assert "MUST call `enter_plan_mode`" not in query
+
+ @staticmethod
+ def test_reminder_allows_read_only_actions_directly() -> None:
+ """弱化后显式说明只读操作可直接执行,对齐 Claude Code。"""
+ request = _make_request({"query": ""})
+ _inject_plan_mode_activation_reminder(request)
+ query = request.params["query"]
+ assert "read-only" in query.lower()
+ # 仍提及 enter_plan_mode,但作为可选的规划入口而非强制首动作。
+ assert "enter_plan_mode" in query
+
+ @staticmethod
+ def test_reminder_prepended_before_existing_query() -> None:
+ original = "existing user query"
+ request = _make_request({"query": original})
+ _inject_plan_mode_activation_reminder(request)
+ # 原始 query 必须保留在 reminder 之后。
+ assert request.params["query"].endswith(original)
+ assert request.params["query"].startswith("\n\n<system-reminder>")