style: fix ruff formatting
This commit is contained in:
@@ -202,7 +202,9 @@ def tool_get_taxonomy():
|
|||||||
return {"taxonomy": taxonomy}
|
return {"taxonomy": taxonomy}
|
||||||
|
|
||||||
|
|
||||||
def tool_search(query: str, limit: int = 5, wing: str = None, room: str = None, context: str = None):
|
def tool_search(
|
||||||
|
query: str, limit: int = 5, wing: str = None, room: str = None, context: str = None
|
||||||
|
):
|
||||||
# Mitigate system prompt contamination (Issue #333)
|
# Mitigate system prompt contamination (Issue #333)
|
||||||
sanitized = sanitize_query(query)
|
sanitized = sanitize_query(query)
|
||||||
result = search_memories(
|
result = search_memories(
|
||||||
|
|||||||
@@ -24,12 +24,12 @@ import logging
|
|||||||
logger = logging.getLogger("mempalace_mcp")
|
logger = logging.getLogger("mempalace_mcp")
|
||||||
|
|
||||||
# --- Constants ---
|
# --- Constants ---
|
||||||
MAX_QUERY_LENGTH = 500 # Above this, system prompt almost certainly dominates
|
MAX_QUERY_LENGTH = 500 # Above this, system prompt almost certainly dominates
|
||||||
SAFE_QUERY_LENGTH = 200 # Below this, query is almost certainly clean
|
SAFE_QUERY_LENGTH = 200 # Below this, query is almost certainly clean
|
||||||
MIN_QUERY_LENGTH = 10 # Extracted result shorter than this = extraction failed
|
MIN_QUERY_LENGTH = 10 # Extracted result shorter than this = extraction failed
|
||||||
|
|
||||||
# Sentence splitter: split on . ! ? (including fullwidth) and newlines
|
# Sentence splitter: split on . ! ? (including fullwidth) and newlines
|
||||||
_SENTENCE_SPLIT = re.compile(r'[.!?。!?\n]+')
|
_SENTENCE_SPLIT = re.compile(r"[.!?。!?\n]+")
|
||||||
|
|
||||||
# Question detector: ends with ? or ? (possibly with trailing whitespace/quotes)
|
# Question detector: ends with ? or ? (possibly with trailing whitespace/quotes)
|
||||||
_QUESTION_MARK = re.compile(r'[??]\s*["\']?\s*$')
|
_QUESTION_MARK = re.compile(r'[??]\s*["\']?\s*$')
|
||||||
@@ -109,7 +109,8 @@ def sanitize_query(raw_query: str) -> dict:
|
|||||||
candidate = candidate[-MAX_QUERY_LENGTH:]
|
candidate = candidate[-MAX_QUERY_LENGTH:]
|
||||||
logger.warning(
|
logger.warning(
|
||||||
"Query sanitized: %d → %d chars (method=question_extraction)",
|
"Query sanitized: %d → %d chars (method=question_extraction)",
|
||||||
original_length, len(candidate)
|
original_length,
|
||||||
|
len(candidate),
|
||||||
)
|
)
|
||||||
return {
|
return {
|
||||||
"clean_query": candidate,
|
"clean_query": candidate,
|
||||||
@@ -130,7 +131,8 @@ def sanitize_query(raw_query: str) -> dict:
|
|||||||
candidate = candidate[-MAX_QUERY_LENGTH:]
|
candidate = candidate[-MAX_QUERY_LENGTH:]
|
||||||
logger.warning(
|
logger.warning(
|
||||||
"Query sanitized: %d → %d chars (method=tail_sentence)",
|
"Query sanitized: %d → %d chars (method=tail_sentence)",
|
||||||
original_length, len(candidate)
|
original_length,
|
||||||
|
len(candidate),
|
||||||
)
|
)
|
||||||
return {
|
return {
|
||||||
"clean_query": candidate,
|
"clean_query": candidate,
|
||||||
@@ -144,8 +146,7 @@ def sanitize_query(raw_query: str) -> dict:
|
|||||||
# Nothing worked — just take the last MAX_QUERY_LENGTH characters.
|
# Nothing worked — just take the last MAX_QUERY_LENGTH characters.
|
||||||
candidate = raw_query[-MAX_QUERY_LENGTH:].strip()
|
candidate = raw_query[-MAX_QUERY_LENGTH:].strip()
|
||||||
logger.warning(
|
logger.warning(
|
||||||
"Query sanitized: %d → %d chars (method=tail_truncation)",
|
"Query sanitized: %d → %d chars (method=tail_truncation)", original_length, len(candidate)
|
||||||
original_length, len(candidate)
|
|
||||||
)
|
)
|
||||||
return {
|
return {
|
||||||
"clean_query": candidate,
|
"clean_query": candidate,
|
||||||
|
|||||||
Reference in New Issue
Block a user