From e0b7001593ee00837efcbd1e30af143f851ae524 Mon Sep 17 00:00:00 2001 From: Chris Dumas Date: Fri, 28 Aug 2026 09:03:44 +0000 Subject: [PATCH] Strengthen H3 reference prompt placement --- dumas_h3_longvideos.py | 18 +++++++----------- tests/test_dumas_h3_longvideos.py | 6 +++--- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/dumas_h3_longvideos.py b/dumas_h3_longvideos.py index 988eeb3..389908c 100644 --- a/dumas_h3_longvideos.py +++ b/dumas_h3_longvideos.py @@ -4416,19 +4416,15 @@ def _inject_reference_context(block, context): text = str(block or "").strip() if not text: return context - match = re.match(r"^(\[Generation \d+\]\s*)(.*)$", text, re.S) + match = re.match(r"^(\[Generation \d+\]\s*)", text) if not match: return f"{context} {text}".strip() - prefix, body = match.groups() - body = body.strip() - split_at = body.find(". ") - if split_at == -1: - return f"{prefix}{body} {context}".strip() - anchor = body[: split_at + 1] - rest = body[split_at + 2 :].strip() - if not rest: - return f"{prefix}{anchor} {context}".strip() - return f"{prefix}{anchor} {context} {rest}".strip() + return re.sub( + r"^(\[Generation \d+\]\s*)", + lambda m: m.group(1) + context + " ", + text, + count=1, + ) def _reference_character_memory(ref_slots): diff --git a/tests/test_dumas_h3_longvideos.py b/tests/test_dumas_h3_longvideos.py index 23245b4..c5b8703 100644 --- a/tests/test_dumas_h3_longvideos.py +++ b/tests/test_dumas_h3_longvideos.py @@ -536,7 +536,7 @@ class DumasH3LongVideosHelperTests(unittest.TestCase): self.assertIn("Persistent appearance for Mara: silver hair.", context) self.assertIn("Persistent wardrobe/style for Mara: red jacket.", context) - def test_reference_context_injects_after_anchor_sentence(self): + def test_reference_context_injects_immediately_after_generation_label(self): block = ( "[Generation 1] Classic sitcom lighting and staging. " "Duke walks into the room." @@ -547,8 +547,8 @@ class DumasH3LongVideosHelperTests(unittest.TestCase): self.assertEqual( result, - "[Generation 1] Classic sitcom lighting and staging. " - "Character facts for Duke: female, 25 years old. " + "[Generation 1] Character facts for Duke: female, 25 years old. " + "Classic sitcom lighting and staging. " "Duke walks into the room.", )