mirror of
https://github.com/pewdiepie-archdaemon/odysseus.git
synced 2026-07-08 11:56:59 +00:00
Merge remote-tracking branch 'origin/dev'
# Conflicts: # routes/document_routes.py
This commit is contained in:
+39
-15
@@ -1384,6 +1384,9 @@ def _build_system_prompt(
|
||||
# the trusted system role. Bound up front so the insert block below can
|
||||
# always check it.
|
||||
_skills_message = None
|
||||
_email_style_message = None
|
||||
_integ_message = None
|
||||
_mcp_desc_message = None
|
||||
if active_document:
|
||||
set_active_document(active_document.id)
|
||||
_doc_raw = active_document.current_content or ""
|
||||
@@ -1614,9 +1617,9 @@ def _build_system_prompt(
|
||||
from src.settings import load_settings as _load_settings
|
||||
_style = (_load_settings().get("email_writing_style", "") or "").strip()
|
||||
if _style:
|
||||
# Hardcoded identity/style rules stay in the trusted system prompt.
|
||||
agent_prompt += (
|
||||
"\n\n📧 EMAIL WRITING STYLE AND IDENTITY — FOLLOW FOR ANY EMAIL DRAFT OR SEND:\n"
|
||||
f"{_style}\n\n"
|
||||
"\n\n"
|
||||
"Hard identity rule: write as the user/mailbox owner only. Do not sign as, speak as, "
|
||||
"or imply you are the recipient, original sender, quoted sender, spouse, assistant, "
|
||||
"company, or any other third party. If a signature is needed, use only the name/signature "
|
||||
@@ -1625,6 +1628,12 @@ def _build_system_prompt(
|
||||
"For English emails, default to Hi [Name] or Hiya from the saved style rather than Hey. "
|
||||
"If the saved style specifies Best/newline/name, use that sign-off when a sign-off is natural."
|
||||
)
|
||||
# User-editable style text is untrusted — wrap it so a malicious
|
||||
# style value cannot inject system-role instructions.
|
||||
_email_style_message = untrusted_context_message(
|
||||
"email writing style",
|
||||
"EMAIL WRITING STYLE AND IDENTITY — FOLLOW FOR ANY EMAIL DRAFT OR SEND:\n" + _style,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
@@ -1752,6 +1761,25 @@ def _build_system_prompt(
|
||||
except Exception as _sk_err:
|
||||
logger.debug(f"skill injection failed (non-fatal): {_sk_err}")
|
||||
|
||||
# Integration descriptions — user-editable fields, must not be in system role.
|
||||
if not suppress_local_context:
|
||||
try:
|
||||
from src.integrations import get_integrations_prompt
|
||||
_integ_prompt = get_integrations_prompt()
|
||||
if _integ_prompt:
|
||||
_integ_message = untrusted_context_message("integrations", _integ_prompt)
|
||||
except Exception as _integ_err:
|
||||
logger.debug(f"Integration prompt injection skipped: {_integ_err}")
|
||||
|
||||
# MCP tool descriptions — sourced from external servers, must not be in system role.
|
||||
if mcp_mgr:
|
||||
try:
|
||||
_mcp_desc = mcp_mgr.get_tool_descriptions_for_prompt(mcp_disabled_map or {})
|
||||
if _mcp_desc:
|
||||
_mcp_desc_message = untrusted_context_message("MCP tools", _mcp_desc)
|
||||
except Exception as _mcp_err:
|
||||
logger.debug(f"MCP description injection skipped: {_mcp_err}")
|
||||
|
||||
agent_msg = {"role": "system", "content": agent_prompt}
|
||||
insert_idx = 0
|
||||
for i, msg in enumerate(messages):
|
||||
@@ -1791,6 +1819,15 @@ def _build_system_prompt(
|
||||
if _email_message:
|
||||
merged.insert(last_user_idx, _email_message)
|
||||
last_user_idx += 1
|
||||
if _email_style_message:
|
||||
merged.insert(last_user_idx, _email_style_message)
|
||||
last_user_idx += 1
|
||||
if _integ_message:
|
||||
merged.insert(last_user_idx, _integ_message)
|
||||
last_user_idx += 1
|
||||
if _mcp_desc_message:
|
||||
merged.insert(last_user_idx, _mcp_desc_message)
|
||||
last_user_idx += 1
|
||||
if _skills_message:
|
||||
merged.insert(last_user_idx, _skills_message)
|
||||
last_user_idx += 1
|
||||
@@ -1897,19 +1934,6 @@ def _build_base_prompt(
|
||||
# Skill index is a soft enhancement — never fail prompt assembly on it.
|
||||
logger.debug(f"Skill-index injection skipped: {_e}")
|
||||
|
||||
# Inject integration descriptions
|
||||
if not suppress_local_context:
|
||||
from src.integrations import get_integrations_prompt
|
||||
integ_prompt = get_integrations_prompt()
|
||||
if integ_prompt:
|
||||
agent_prompt += "\n\n" + integ_prompt
|
||||
|
||||
# Inject MCP tool descriptions
|
||||
if mcp_mgr:
|
||||
mcp_desc = mcp_mgr.get_tool_descriptions_for_prompt(mcp_disabled_map or {})
|
||||
if mcp_desc:
|
||||
agent_prompt += mcp_desc
|
||||
|
||||
return agent_prompt, skill_index_block
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user