fix: 新建对话后切换执行环境 prompt 未更新
根因:frozen_permission_prompt / frozen_execution_prompt 在对话创建时就被 提前构建并缓存到 conversation_metadata,后续切换模式后 build_messages 直接 返回旧缓存,不会根据当前模式重建。 修复: - 删除 _ensure_conversation / create_new_conversation 中提前预置冻结 prompt - conversation_manager 默认值从 '' 改为 None(空字符串会被误判为已缓存) - _get_or_init_frozen_prompt 增加非空判断(防御性加固) 冻结时机改为第一次 build_messages 懒加载,确保首次发消息前任意模式切换都生效。
This commit is contained in:
parent
a6775598dc
commit
56882f3169
@ -654,8 +654,7 @@ class MainTerminal(MainTerminalCommandMixin, MainTerminalContextMixin, MainTermi
|
|||||||
"execution_mode": self.get_execution_mode(),
|
"execution_mode": self.get_execution_mode(),
|
||||||
"pending_permission_mode": None,
|
"pending_permission_mode": None,
|
||||||
"pending_execution_mode": None,
|
"pending_execution_mode": None,
|
||||||
"frozen_permission_prompt": self._build_permission_mode_message() or "",
|
# frozen_*_prompt 不在创建时预设,由第一次 build_messages 根据当时的实际模式懒加载并冻结
|
||||||
"frozen_execution_prompt": self._build_execution_mode_message() or "",
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
print(f"{OUTPUT_FORMATS['info']} 新建对话: {conversation_id}")
|
print(f"{OUTPUT_FORMATS['info']} 新建对话: {conversation_id}")
|
||||||
|
|||||||
@ -211,7 +211,7 @@ class MainTerminalContextMixin:
|
|||||||
cm = getattr(self, "context_manager", None)
|
cm = getattr(self, "context_manager", None)
|
||||||
meta = getattr(cm, "conversation_metadata", {}) if cm else {}
|
meta = getattr(cm, "conversation_metadata", {}) if cm else {}
|
||||||
cached = meta.get(key) if isinstance(meta, dict) else None
|
cached = meta.get(key) if isinstance(meta, dict) else None
|
||||||
if isinstance(cached, str):
|
if isinstance(cached, str) and cached:
|
||||||
return cached
|
return cached
|
||||||
|
|
||||||
built = builder() or ""
|
built = builder() or ""
|
||||||
|
|||||||
@ -174,8 +174,7 @@ class WebTerminal(MainTerminal):
|
|||||||
"execution_mode": self.get_execution_mode() if hasattr(self, "get_execution_mode") else "sandbox",
|
"execution_mode": self.get_execution_mode() if hasattr(self, "get_execution_mode") else "sandbox",
|
||||||
"pending_permission_mode": None,
|
"pending_permission_mode": None,
|
||||||
"pending_execution_mode": None,
|
"pending_execution_mode": None,
|
||||||
"frozen_permission_prompt": self._build_permission_mode_message() or "",
|
# frozen_*_prompt 不在创建时预设,由第一次 build_messages 根据当时的实际模式懒加载并冻结
|
||||||
"frozen_execution_prompt": self._build_execution_mode_message() or "",
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@ -512,8 +512,8 @@ class ConversationManager:
|
|||||||
"execution_mode": "sandbox",
|
"execution_mode": "sandbox",
|
||||||
"pending_permission_mode": None,
|
"pending_permission_mode": None,
|
||||||
"pending_execution_mode": None,
|
"pending_execution_mode": None,
|
||||||
"frozen_permission_prompt": "",
|
"frozen_permission_prompt": None,
|
||||||
"frozen_execution_prompt": "",
|
"frozen_execution_prompt": None,
|
||||||
"has_images": has_images,
|
"has_images": has_images,
|
||||||
"has_videos": has_videos,
|
"has_videos": has_videos,
|
||||||
# 首次对话尚未生成文件树快照,待首次用户消息时填充
|
# 首次对话尚未生成文件树快照,待首次用户消息时填充
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user