Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion scripts/lib/reflect_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,8 @@ def backup_timestamp() -> str:
# Structural patterns indicating FALSE POSITIVES (language-agnostic)
# These focus on MESSAGE STRUCTURE rather than specific words
FALSE_POSITIVE_PATTERNS = [
r"\?$", # Ends with question mark → question, not correction
r"[?\uff1f]$", # Ends with question mark (ASCII ? or full-width ?)
r"[嗎吗呢か까]$", # Ends with CJK question particle
r"^(please|can you|could you|would you|help me)\b", # Task request openers
r"(help|fix|check|review|figure out|set up)\s+(this|that|it|the)\b", # Task verbs
r"(error|failed|could not|cannot|can't|unable to)\s+\w+", # Error descriptions
Expand Down Expand Up @@ -524,6 +525,10 @@ def detect_patterns(text: str) -> Tuple[Optional[str], str, float, str, int]:
if re.search(pattern, text, re.IGNORECASE):
return ("explicit", name, confidence, "correction", decay)

# Too short to be actionable (e.g. "OK", "好")
if len(text.strip()) <= 4:
return (None, "", 0.0, "correction", 90)

# Check for guardrail patterns - "don't do X unless" constraints
# These are high-confidence corrections about unwanted behavior
for pattern, name, confidence, decay in GUARDRAIL_PATTERNS:
Expand Down
18 changes: 18 additions & 0 deletions tests/test_reflect_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,24 @@ def test_long_message_confidence_reduced(self):
if item_type == "auto":
self.assertLessEqual(confidence, 0.65)

def test_short_message_rejected(self):
"""Test that very short messages (<=4 chars) are rejected."""
result = detect_patterns("OK")
self.assertIsNone(result[0])

result = detect_patterns("好")
self.assertIsNone(result[0])

def test_cjk_question_particle_rejected(self):
"""Test that messages ending with CJK question particles are rejected."""
result = detect_patterns("這是什麼嗎")
self.assertIsNone(result[0])

def test_fullwidth_question_mark_rejected(self):
"""Test that full-width question marks are rejected."""
result = detect_patterns("這是什麼?")
self.assertIsNone(result[0])


class TestQueueItemCreation(unittest.TestCase):
"""Tests for queue item creation."""
Expand Down
Loading