From 6aae0474013aa63064d97bef6861786dbe188fc8 Mon Sep 17 00:00:00 2001 From: Chris Dumas Date: Thu, 15 Oct 2026 20:59:33 +0000 Subject: [PATCH] Route references found in full chunk prompts --- prompt_builder.py | 12 +++++++++++- tests/test_sequence_prompt_builder.py | 22 ++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/prompt_builder.py b/prompt_builder.py index 29a0db6..8b01493 100644 --- a/prompt_builder.py +++ b/prompt_builder.py @@ -181,10 +181,20 @@ class DumasH3SequencePromptBuilder: default_seconds=float(default_chunk_seconds), ) selectors = [] + directive = str(shared_directive or "").strip() + sound = str(soundscape or "").strip() or "N/A" + music_text = str(music or "").strip() or "N/A" for reference_index in range(1, 10): chunks = [] for chunk_index, clip in enumerate(sequence["clips"], start=1): - text = "\n".join(str(slot.get("text", "")) for slot in clip["slots"]) + # Match against the same per-chunk content emitted by + # format_sequence_prompt, not only the editable shot lines. + text = "\n".join([ + directive, + *(str(slot.get("text", "")) for slot in clip["slots"]), + f"overall_soundscape: {sound}", + f"non_diegetic_music: {music_text}", + ]) if kwargs.get(f"reference_image_{reference_index}") is not None and re.search( rf"@(R{reference_index}|image{reference_index})(?![A-Za-z0-9_])", text, diff --git a/tests/test_sequence_prompt_builder.py b/tests/test_sequence_prompt_builder.py index 0390853..7184c65 100644 --- a/tests/test_sequence_prompt_builder.py +++ b/tests/test_sequence_prompt_builder.py @@ -100,3 +100,25 @@ def test_builder_routes_connected_references_only_to_mentioning_chunks(): assert bundle.reference_use == "Per chunk" assert bundle.selectors == ("1", "1,2", "off", "off", "off", "off", "off", "off", "off") assert bundle.images[0] is not None and bundle.images[1] is not None + + +def test_builder_routes_references_mentioned_anywhere_in_each_chunk_prompt(): + value = { + "clips": [ + {"slots": [{"start": 0, "end": 4, "text": "The subject walks."}]}, + {"slots": [{"start": 0, "end": 4, "text": "The subject stops."}]}, + ] + } + result = DumasH3SequencePromptBuilder().build( + 2, + 4, + "Preserve the environment from @R1.", + json.dumps(value), + "Use ambience from @R2.", + "Music follows @R3.", + reference_image_1=object(), + reference_image_2=object(), + reference_image_3=object(), + ) + + assert result[3].selectors[:3] == ("1,2", "1,2", "1,2")