fix: prevent /no_think tag from leaking into user message content
The /no_think directive was appended directly to the user's message text, causing the LLM to interpret it as user input (e.g., referencing it as a directory path). Now injected as a separate system message after the last user message. Also adds which, jq, type, and file to shell allowed_commands (were mistakenly placed in permissions.auto_approve). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -94,24 +94,23 @@ class AgentLoop:
|
|||||||
def _get_messages_with_system_prompt(self) -> list[Message]:
|
def _get_messages_with_system_prompt(self) -> list[Message]:
|
||||||
"""Prepend the system prompt to conversation history.
|
"""Prepend the system prompt to conversation history.
|
||||||
|
|
||||||
When thinking is disabled, injects a /no_think tag into the last user
|
When thinking is disabled, appends a system-level /no_think directive
|
||||||
message so Qwen 3.x (and similar) chat templates see it regardless of
|
after the last user message so Qwen 3.x (and similar) chat templates
|
||||||
where tool-result messages fall in the history.
|
see it, without polluting the user's actual message content.
|
||||||
"""
|
"""
|
||||||
system_msg = Message(role="system", content=self._system_prompt)
|
system_msg = Message(role="system", content=self._system_prompt)
|
||||||
history = self._ctx.get_history()
|
history = self._ctx.get_history()
|
||||||
|
|
||||||
if not self._config.llm.thinking and history:
|
if not self._config.llm.thinking and history:
|
||||||
history = list(history)
|
history = list(history)
|
||||||
|
# Find last user message and insert a system hint after it
|
||||||
for i in range(len(history) - 1, -1, -1):
|
for i in range(len(history) - 1, -1, -1):
|
||||||
if history[i].role == "user":
|
if history[i].role == "user":
|
||||||
original = history[i]
|
no_think_msg = Message(
|
||||||
history[i] = Message(
|
role="system",
|
||||||
role="user",
|
content="/no_think",
|
||||||
content=(original.content or "") + " /no_think",
|
|
||||||
tool_call_id=original.tool_call_id,
|
|
||||||
name=original.name,
|
|
||||||
)
|
)
|
||||||
|
history.insert(i + 1, no_think_msg)
|
||||||
break
|
break
|
||||||
|
|
||||||
return [system_msg] + history
|
return [system_msg] + history
|
||||||
|
|||||||
@@ -56,6 +56,10 @@ tools:
|
|||||||
- grep
|
- grep
|
||||||
- find
|
- find
|
||||||
- echo
|
- echo
|
||||||
|
- which
|
||||||
|
- jq
|
||||||
|
- type
|
||||||
|
- file
|
||||||
denied_commands:
|
denied_commands:
|
||||||
- rm -rf /
|
- rm -rf /
|
||||||
- sudo
|
- sudo
|
||||||
|
|||||||
Reference in New Issue
Block a user