Add tabbed H3 sequence prompt builder
tests / test (push) Canceled after 0s
tests / windows-storage (push) Canceled after 0s

This commit is contained in:
2026-10-15 08:05:41 +00:00
parent b3a7b34f93
commit 22849f3d44
7 changed files with 360 additions and 0 deletions
+5
View File
@@ -1,5 +1,10 @@
# Changelog
## Unreleased
- Add the DUMAS H3 Sequence Prompt Builder with clip tabs, local timeline
slots, and one canonical absolute Timeline prompt output.
## 3.9.4 — Registry packaging repair (2026-10-14)
Include the declared Review restoration guide and exclude repository-only prompt-authoring files from the Registry ZIP. The publishing workflow now builds the actual package and checks its exact file set, CRC and every Registry Manifest hash before uploading. Runtime behavior, twelve public node IDs, workflows and saved Runs/Takes are unchanged. GitHub Releases 3.9.3 and 3.9.2 remain available.
+29
View File
@@ -1,5 +1,34 @@
# DUMAS H3 Continuum Tiled 3.9.4.post1 — V3.9 fork
## DUMAS H3 Sequence Prompt Builder
`DUMAS H3 Sequence Prompt Builder` creates the single multiline `STRING`
prompt expected by the Continuum sampler. Its editor provides one tab per
clip and editable local time slots inside each clip. Clip-local times are
flattened to absolute timeline positions when the node executes, so it can be
connected directly to `Sequence Prompt` with `Prompt Format = Timeline` (or
`Auto`).
The node keeps the shared visual directive, soundscape, and non-diegetic music
outside the clip tabs. The editor state is stored in a serializable JSON
widget, making saved workflows portable even when the optional browser panel
is unavailable.
Example output:
```text
Preserve the same character and environment.
[0-4s]
The character walks forward and looks toward the light.
[4-8s]
Continue seamlessly as the character raises one hand.
overall_soundscape: Quiet room tone and footsteps.
non_diegetic_music: Low cinematic pulse.
```
## Dumas per-clip tiled latent upscale
This fork adds **H3 Continuum Tiled Latent Upscale (Per Clip)**. Connect the
+9
View File
@@ -1,5 +1,14 @@
# Public development log
## 2026-10-15 — Sequence prompt builder
- Add `DumasH3SequencePromptBuilder` and its tabbed ComfyUI editor.
- Validate clip-local slot ranges and deterministically convert them to
absolute `[start-end]` timeline blocks, preserving one STRING output for
direct wiring into Continuum.
- Add focused unit coverage for formatting, normalization, validation, and
registration/schema behavior.
## 2026-10-14 — package 3.9.4 Registry packaging repair
- Reconcile the actual Registry ZIP with its declared Manifest: include the Review restoration guide and exclude prompt-authoring source files.
+7
View File
@@ -461,9 +461,15 @@ from .v3.video_adapter_nodes import H3ContinuumVideoAdapter
NODE_CLASS_MAPPINGS["H3ContinuumVideoAdapter"] = H3ContinuumVideoAdapter
from .decode_cache.nodes import H3DecodeCacheHelper
from .prompt_builder import (
NODE_CLASS_MAPPINGS as PROMPT_BUILDER_NODE_CLASS_MAPPINGS,
NODE_DISPLAY_NAME_MAPPINGS as PROMPT_BUILDER_NODE_DISPLAY_NAME_MAPPINGS,
)
NODE_CLASS_MAPPINGS["H3DecodeCacheHelper"] = H3DecodeCacheHelper
NODE_DISPLAY_NAME_MAPPINGS["H3DecodeCacheHelper"] = "Decode Cache Helper"
NODE_CLASS_MAPPINGS.update(PROMPT_BUILDER_NODE_CLASS_MAPPINGS)
NODE_DISPLAY_NAME_MAPPINGS.update(PROMPT_BUILDER_NODE_DISPLAY_NAME_MAPPINGS)
# V3.8 exports only its audited launch surface. The imports and merged mappings
# above intentionally stay in place because the V3.8 implementation still
@@ -484,6 +490,7 @@ _PUBLIC_NODE_DISPLAY_NAMES = {
"H3ContinuumTiledLatentUpscalePerClip": (
"H3 Continuum Tiled Latent Upscale (Per Clip)"
),
"DumasH3SequencePromptBuilder": "H3 Sequence Prompt Builder",
}
NODE_CLASS_MAPPINGS = {
node_id: NODE_CLASS_MAPPINGS[node_id]
+156
View File
@@ -0,0 +1,156 @@
"""UI-backed sequence prompt construction for H3 Continuum."""
from __future__ import annotations
import json
from typing import Any, Mapping
MAX_CLIPS = 16
DEFAULT_CLIP_SECONDS = 4.0
def _number(value: Any, name: str, *, minimum: float = 0.0) -> float:
if isinstance(value, bool):
raise ValueError(f"{name} must be a number")
try:
result = float(value)
except (TypeError, ValueError) as exc:
raise ValueError(f"{name} must be a number") from exc
if result < minimum:
raise ValueError(f"{name} must be >= {minimum}")
return result
def default_sequence(clip_count: int = 2, clip_seconds: float = DEFAULT_CLIP_SECONDS) -> dict[str, Any]:
"""Return a portable editor state with one slot per clip."""
count = int(clip_count)
if count < 1 or count > MAX_CLIPS:
raise ValueError(f"clip_count must be between 1 and {MAX_CLIPS}")
duration = _number(clip_seconds, "clip_seconds", minimum=0.1)
return {
"version": 1,
"clips": [
{
"duration": duration,
"slots": [{"start": 0.0, "end": duration, "text": ""}],
}
for _ in range(count)
],
}
def normalize_sequence(value: Any, *, clip_count: int, default_seconds: float) -> dict[str, Any]:
"""Validate and normalize editor JSON without changing user-authored text."""
if isinstance(value, str):
try:
value = json.loads(value or "{}")
except json.JSONDecodeError as exc:
raise ValueError(f"timeline_json is not valid JSON: {exc.msg}") from exc
if not isinstance(value, Mapping):
raise ValueError("timeline_json must be a JSON object")
raw_clips = value.get("clips", [])
if not isinstance(raw_clips, list):
raise ValueError("timeline_json.clips must be a list")
count = int(clip_count)
if count < 1 or count > MAX_CLIPS:
raise ValueError(f"clip_count must be between 1 and {MAX_CLIPS}")
fallback_duration = _number(default_seconds, "default_chunk_seconds", minimum=0.1)
clips: list[dict[str, Any]] = []
for clip_index in range(count):
raw_clip = raw_clips[clip_index] if clip_index < len(raw_clips) else {}
if not isinstance(raw_clip, Mapping):
raise ValueError(f"clip {clip_index + 1} must be an object")
duration = _number(raw_clip.get("duration", fallback_duration), f"clip {clip_index + 1} duration", minimum=0.1)
raw_slots = raw_clip.get("slots", [])
if not isinstance(raw_slots, list):
raise ValueError(f"clip {clip_index + 1} slots must be a list")
slots: list[dict[str, Any]] = []
for slot_index, raw_slot in enumerate(raw_slots):
if not isinstance(raw_slot, Mapping):
raise ValueError(f"clip {clip_index + 1} slot {slot_index + 1} must be an object")
start = _number(raw_slot.get("start", 0), f"clip {clip_index + 1} slot {slot_index + 1} start")
end = _number(raw_slot.get("end", duration), f"clip {clip_index + 1} slot {slot_index + 1} end")
if end <= start:
raise ValueError(f"clip {clip_index + 1} slot {slot_index + 1} end must be after start")
if end > duration + 1e-6:
raise ValueError(f"clip {clip_index + 1} slot {slot_index + 1} ends after the clip duration")
text = str(raw_slot.get("text", "")).strip()
if text:
slots.append({"start": start, "end": end, "text": text})
slots.sort(key=lambda slot: (slot["start"], slot["end"]))
clips.append({"duration": duration, "slots": slots})
return {"version": 1, "clips": clips}
def format_sequence_prompt(
*,
shared_directive: str,
sequence: Mapping[str, Any],
soundscape: str = "",
music: str = "",
) -> str:
"""Flatten clip-local slots into the absolute H3 Timeline prompt format."""
sections: list[str] = []
directive = str(shared_directive or "").strip()
if directive:
sections.append(directive)
cursor = 0.0
for clip in sequence["clips"]:
for slot in clip["slots"]:
start = cursor + float(slot["start"])
end = cursor + float(slot["end"])
sections.append(f"[{start:g}-{end:g}s]\n{slot['text']}")
cursor += float(clip["duration"])
sections.append(f"overall_soundscape: {str(soundscape or '').strip() or 'N/A'}")
sections.append(f"non_diegetic_music: {str(music or '').strip() or 'N/A'}")
return "\n\n".join(sections).strip()
class DumasH3SequencePromptBuilder:
"""Build one Timeline prompt from clip tabs and clip-local time slots."""
DESCRIPTION = (
"DUMAS H3 prompt editor. Define clips and local time slots in the UI; "
"the node emits one absolute Timeline prompt for Sequence Prompt."
)
CATEGORY = "DUMAS H3/Prompt"
RETURN_TYPES = ("STRING",)
RETURN_NAMES = ("sequence_prompt",)
FUNCTION = "build"
@classmethod
def INPUT_TYPES(cls):
state = json.dumps(default_sequence(), separators=(",", ":"))
return {
"required": {
"clip_count": ("INT", {"default": 2, "min": 1, "max": MAX_CLIPS, "step": 1}),
"default_chunk_seconds": ("FLOAT", {"default": DEFAULT_CLIP_SECONDS, "min": 0.1, "max": 30.0, "step": 0.1}),
"shared_directive": ("STRING", {"default": "", "multiline": True}),
"timeline_json": ("STRING", {"default": state, "multiline": True}),
"soundscape": ("STRING", {"default": "", "multiline": True}),
"music": ("STRING", {"default": "", "multiline": True}),
}
}
def build(self, clip_count, default_chunk_seconds, shared_directive, timeline_json, soundscape, music):
sequence = normalize_sequence(
timeline_json,
clip_count=int(clip_count),
default_seconds=float(default_chunk_seconds),
)
return (format_sequence_prompt(
shared_directive=shared_directive,
sequence=sequence,
soundscape=soundscape,
music=music,
),)
NODE_CLASS_MAPPINGS = {"DumasH3SequencePromptBuilder": DumasH3SequencePromptBuilder}
NODE_DISPLAY_NAME_MAPPINGS = {
"DumasH3SequencePromptBuilder": "DUMAS H3 Sequence Prompt Builder",
}
+63
View File
@@ -0,0 +1,63 @@
from __future__ import annotations
import json
import pytest
from ComfyUI_H3_Continuum_Join.prompt_builder import (
DumasH3SequencePromptBuilder,
default_sequence,
format_sequence_prompt,
normalize_sequence,
)
def test_builder_emits_one_absolute_timeline_prompt_from_clip_local_slots():
sequence = normalize_sequence(
{"clips": [
{"duration": 4, "slots": [{"start": 0, "end": 2, "text": "Walk forward."}]},
{"duration": 5, "slots": [{"start": 1, "end": 5, "text": "Turn toward the light."}]},
]},
clip_count=2,
default_seconds=4,
)
result = format_sequence_prompt(
shared_directive="Preserve the same character and environment.",
sequence=sequence,
soundscape="Quiet street ambience.",
music="Low cinematic pulse.",
)
assert "[0-2s]" in result
assert "[5-9s]" in result
assert "overall_soundscape: Quiet street ambience." in result
assert "non_diegetic_music: Low cinematic pulse." in result
def test_normalizer_orders_slots_and_fills_missing_clips():
value = normalize_sequence(
json.dumps({"clips": [{"duration": 6, "slots": [
{"start": 3, "end": 6, "text": "Second."},
{"start": 0, "end": 3, "text": "First."},
]}]}),
clip_count=2,
default_seconds=4,
)
assert value["clips"][0]["slots"][0]["text"] == "First."
assert value["clips"][1]["duration"] == 4.0
@pytest.mark.parametrize("bad", [
{"clips": [{"duration": 4, "slots": [{"start": 3, "end": 2, "text": "bad"}]}]},
{"clips": [{"duration": 4, "slots": [{"start": 0, "end": 5, "text": "bad"}]}]},
])
def test_normalizer_rejects_invalid_slot_ranges(bad):
with pytest.raises(ValueError):
normalize_sequence(bad, clip_count=1, default_seconds=4)
def test_node_schema_has_single_string_output_and_serialized_editor_state():
schema = DumasH3SequencePromptBuilder.INPUT_TYPES()["required"]
assert DumasH3SequencePromptBuilder.RETURN_TYPES == ("STRING",)
assert schema["timeline_json"][1]["multiline"] is True
result = DumasH3SequencePromptBuilder().build(1, 4, "Directive", json.dumps(default_sequence(1, 4)), "N/A", "N/A")
assert result[0].startswith("Directive\n\noverall_soundscape:")
+91
View File
@@ -0,0 +1,91 @@
import { app } from "../../scripts/app.js";
const CLASS = "DumasH3SequencePromptBuilder";
const MAX_CLIPS = 16;
const get = (node, name) => node.widgets?.find((widget) => widget.name === name);
const el = (tag, text = "") => { const item = document.createElement(tag); item.textContent = text; return item; };
function defaultState(count, seconds) {
return { version: 1, clips: Array.from({ length: count }, () => ({
duration: seconds, slots: [{ start: 0, end: seconds, text: "" }],
})) };
}
function readState(widget, count, seconds) {
try {
const value = JSON.parse(String(widget?.value || ""));
if (Array.isArray(value.clips)) return value;
} catch (_) { /* replace malformed editor state with a usable default */ }
return defaultState(count, seconds);
}
function hide(widget) {
if (!widget) return;
widget.type = "hidden"; widget.hidden = true; widget.options ||= {};
widget.options.hidden = true; widget.computeSize = () => [0, 0]; widget.draw = () => {};
}
function configure(node) {
if (node?.comfyClass !== CLASS || typeof document === "undefined" || typeof node.addDOMWidget !== "function") return;
if (node.__dumasSequencePromptBuilder) return node.__dumasSequencePromptBuilder();
const countWidget = get(node, "clip_count");
const secondsWidget = get(node, "default_chunk_seconds");
const stateWidget = get(node, "timeline_json");
if (!countWidget || !secondsWidget || !stateWidget) return;
hide(stateWidget);
const panel = el("div");
panel.style.cssText = "box-sizing:border-box;min-width:360px;padding:7px;color:#e7f4e9;background:#203827;font:12px Arial;pointer-events:auto";
const host = el("div"); host.style.cssText = "pointer-events:auto"; host.append(panel);
["pointerdown", "mousedown", "mouseup", "dblclick"].forEach((name) => host.addEventListener(name, (event) => event.stopPropagation()));
const display = node.addDOMWidget("clip_tabs", "dumas_h3_clip_tabs", host, { serialize: false });
display.options ||= {}; display.options.serialize = false;
let active = 0;
let state = readState(stateWidget, Number(countWidget.value) || 2, Number(secondsWidget.value) || 4);
const setState = () => {
stateWidget.value = JSON.stringify(state);
stateWidget.callback?.(stateWidget.value);
node.setDirtyCanvas?.(true, true);
};
const input = (type, value, onChange) => {
const item = el("input"); item.type = type; item.value = value;
item.style.cssText = "width:100%;box-sizing:border-box;margin:2px 0;color:#111";
item.onchange = () => onChange(item.value); return item;
};
const render = () => {
const count = Math.max(1, Math.min(MAX_CLIPS, Number(countWidget.value) || 1));
while (state.clips.length < count) state.clips.push({ duration: Number(secondsWidget.value) || 4, slots: [] });
state.clips = state.clips.slice(0, count); active = Math.min(active, count - 1);
panel.replaceChildren();
const tabs = el("div"); tabs.style.cssText = "display:flex;flex-wrap:wrap;gap:3px;margin-bottom:6px";
state.clips.forEach((clip, index) => { const button = el("button", `Clip ${index + 1}`); button.type = "button"; button.disabled = index === active; button.onclick = () => { active = index; render(); }; tabs.append(button); });
panel.append(tabs);
const clip = state.clips[active];
const durationLabel = el("label", "Chunk duration (seconds)");
panel.append(durationLabel, input("number", clip.duration, (value) => { clip.duration = Math.max(0.1, Number(value) || 0.1); clip.slots.forEach((slot) => { slot.end = Math.min(slot.end, clip.duration); }); setState(); render(); }));
const heading = el("div", "Time slots are local to this clip; output is converted to absolute times."); heading.style.cssText = "margin:5px 0;color:#b7d6bf"; panel.append(heading);
clip.slots.forEach((slot, slotIndex) => {
const row = el("fieldset"); row.style.cssText = "border:1px solid #4a7255;margin:5px 0;padding:4px";
const legend = el("legend", `Slot ${slotIndex + 1}`); row.append(legend);
const times = el("div"); times.style.cssText = "display:flex;gap:4px";
times.append(el("span", "Start"), input("number", slot.start, (value) => { slot.start = Math.max(0, Number(value) || 0); setState(); }), el("span", "End"), input("number", slot.end, (value) => { slot.end = Math.max(slot.start + 0.1, Number(value) || slot.start + 0.1); setState(); })); row.append(times);
const text = el("textarea"); text.value = slot.text || ""; text.rows = 3; text.style.cssText = "width:100%;box-sizing:border-box;color:#111"; text.onchange = () => { slot.text = text.value; setState(); }; row.append(text);
const remove = el("button", "Remove slot"); remove.type = "button"; remove.onclick = () => { clip.slots.splice(slotIndex, 1); setState(); render(); }; row.append(remove); panel.append(row);
});
const add = el("button", "Add time slot"); add.type = "button"; add.onclick = () => { const start = clip.slots.length ? Number(clip.slots.at(-1).end) : 0; clip.slots.push({ start, end: Math.min(start + 1, Number(clip.duration)), text: "" }); setState(); render(); }; panel.append(add);
display.computeSize = (width) => [Math.max(360, Number(width) || 360), Math.min(620, 110 + clip.slots.length * 150)];
node.setSize?.([Math.max(360, Number(node.size?.[0]) || 360), Number(node.computeSize?.()[1]) || 420]);
};
const refresh = () => { state = readState(stateWidget, Number(countWidget.value) || 2, Number(secondsWidget.value) || 4); render(); setState(); };
countWidget.callback = ((previous) => function(...args) { const result = previous?.apply(this, args); refresh(); return result; })(countWidget.callback);
secondsWidget.callback = ((previous) => function(...args) { const result = previous?.apply(this, args); render(); return result; })(secondsWidget.callback);
stateWidget.callback = ((previous) => function(...args) { const result = previous?.apply(this, args); render(); return result; })(stateWidget.callback);
node.__dumasSequencePromptBuilder = refresh;
refresh();
}
app.registerExtension({
name: "DUMAS.H3.SequencePromptBuilder",
nodeCreated(node) { setTimeout(() => configure(node), 0); },
loadedGraphNode(node) { setTimeout(() => configure(node), 0); },
afterConfigureGraph() { for (const node of app.graph?._nodes || []) configure(node); },
});