fix(synastry): drop a section title repeated at the start of the body

The gate now rejects that opening and asks for a rewrite, and the saved text no longer keeps the duplicate.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
jesse-ux
2026-10-21 18:09:19 +08:00
co-authored by Cursor
parent dc80a43aae
commit e1afd0ea3d
8 changed files with 151 additions and 8 deletions
@@ -225,6 +225,15 @@ def _scan_prose(text: str, language: str, section: str, *, opening: bool) -> lis
return failures
def _opens_with_title(text: str, title: str) -> bool:
heading = title.strip()
body = text.lstrip()
if not heading or not body.startswith(heading):
return False
rest = body[len(heading):]
return rest == "" or rest[:1].isspace() or rest.startswith(heading)
def validate_synastry_reader(
delivery: dict[str, Any],
section_inputs: dict[str, Any] | None = None,
@@ -254,6 +263,9 @@ def validate_synastry_reader(
failures.append(_fail(section_id, "missing_section", section_id))
continue
text = str(row.get("text") or "")
title = str(row.get("title") or "")
if _opens_with_title(text, title):
failures.append(_fail(section_id, "repeated_heading", title))
prose_characters += len(re.sub(r"\s+", "", text))
prose_words += len(re.findall(r"\b[\w']+\b", text))
minimum = ZH_SECTION_MINIMUM if language == "zh" else EN_SECTION_MINIMUM