From f96300bb863eefac7da7dfbfad732459b68ab7b1 Mon Sep 17 00:00:00 2001 From: matrix9neonebuchadnezzar2199-sketch <あなたのメールアドレス> Date: Fri, 10 Apr 2026 05:02:48 +0900 Subject: [PATCH] style: fix ruff formatting --- mempalace/mcp_server.py | 4 +++- mempalace/query_sanitizer.py | 17 +++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/mempalace/mcp_server.py b/mempalace/mcp_server.py index c4a570a..aa9ecd9 100644 --- a/mempalace/mcp_server.py +++ b/mempalace/mcp_server.py @@ -202,7 +202,9 @@ def tool_get_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) sanitized = sanitize_query(query) result = search_memories( diff --git a/mempalace/query_sanitizer.py b/mempalace/query_sanitizer.py index a246a67..450dd13 100644 --- a/mempalace/query_sanitizer.py +++ b/mempalace/query_sanitizer.py @@ -24,12 +24,12 @@ import logging logger = logging.getLogger("mempalace_mcp") # --- Constants --- -MAX_QUERY_LENGTH = 500 # Above this, system prompt almost certainly dominates -SAFE_QUERY_LENGTH = 200 # Below this, query is almost certainly clean -MIN_QUERY_LENGTH = 10 # Extracted result shorter than this = extraction failed +MAX_QUERY_LENGTH = 500 # Above this, system prompt almost certainly dominates +SAFE_QUERY_LENGTH = 200 # Below this, query is almost certainly clean +MIN_QUERY_LENGTH = 10 # Extracted result shorter than this = extraction failed # 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_MARK = re.compile(r'[??]\s*["\']?\s*$') @@ -109,7 +109,8 @@ def sanitize_query(raw_query: str) -> dict: candidate = candidate[-MAX_QUERY_LENGTH:] logger.warning( "Query sanitized: %d → %d chars (method=question_extraction)", - original_length, len(candidate) + original_length, + len(candidate), ) return { "clean_query": candidate, @@ -130,7 +131,8 @@ def sanitize_query(raw_query: str) -> dict: candidate = candidate[-MAX_QUERY_LENGTH:] logger.warning( "Query sanitized: %d → %d chars (method=tail_sentence)", - original_length, len(candidate) + original_length, + len(candidate), ) return { "clean_query": candidate, @@ -144,8 +146,7 @@ def sanitize_query(raw_query: str) -> dict: # Nothing worked — just take the last MAX_QUERY_LENGTH characters. candidate = raw_query[-MAX_QUERY_LENGTH:].strip() logger.warning( - "Query sanitized: %d → %d chars (method=tail_truncation)", - original_length, len(candidate) + "Query sanitized: %d → %d chars (method=tail_truncation)", original_length, len(candidate) ) return { "clean_query": candidate,