@melite/models-h3 0.1.5-pre-alpha → 0.2.0-alpha

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/actions.js CHANGED
@@ -1,30 +1,199 @@
1
1
  import { fireControlNets } from '@melite/comfyui-card-kit/guard';
2
2
  import { saveAudio } from '@melite/comfyui-card-kit';
3
- import { FAMILIES, paramSchema, wireList, H3_RECOMMENDED_SAMPLERS } from "./schema.js";
3
+ import { mediaKindOf } from '@melite/contracts/mediaKinds';
4
+ import { assertKeyframeRowShape, FAMILIES, paramSchema, wireList, H3_RECOMMENDED_SAMPLERS } from './schema.js';
4
5
  import { H3_LORA_ROWS } from '@melite/models-h3/mods/loras';
5
6
  import { SAMPLER_OPTIONS, SCHEDULER_OPTIONS } from '@melite/comfyui-card-kit/vocab';
6
- import { computeFilmMix, parseFilmMixClips, stanzaSecs } from "./filmMix.js";
7
- import { GRID_REMAINDER, GRID_STEP_FRAMES, IMAGE_BUS_SLOTS, REF_CAPS, assertGridLength, assertSpanGrid, imageReferenceCap, spanStanzaFrames, transitionOverlap, } from "./timelineContract.js";
8
-
9
- // the ByteDance DMAD row — operator: "the one from bytedance" is the
10
- // default): the DMAD 4-step row, built from the family lora
11
- // CATALOG (mods/loras.ts — the one owner of every lora filename and
12
- // default strength; the value was restated as a literal here, which
13
- // is how a catalog edit would have silently missed the default).
14
- // The wire shape matches a resolved bag row: on, lora (filename),
15
- // str (default_strength), plus the four fixed mode flags. A missing
16
- // catalog row refuses at load — the default would have no source.
7
+ import { computeFilmMix, parseFilmMixClips, spanOverlap, stanzaSecs } from './filmMix.js';
8
+ import { GRID_REMAINDER, GRID_STEP_FRAMES, IMAGE_BUS_SLOTS, REF_CAPS, assertGridLength, assertSpanGrid, imageReferenceCap, isGridLength, isMediaRef, DOC_FPS_DEFAULT, spanStanzaFrames, transitionOverlap, } from './timelineContract.js';
9
+ import { applyH3ReshootCond, applyH3ReshootModel, buildH3Reshoot, reshootArmed, reshootPrompt, } from './reshoot.js';
10
+
11
+
12
+
13
+ // default seat, preferred for detail at 8 steps; the standalone
14
+ // LightX2V turbos stay in the catalog for the audio/dialogue
15
+ // routes). THE ROW IS `h3_lightx2v_turbo` — the LightX2V turbo
16
+ // 4-to-8-step × dareties v4 step600 merge (label "LightX2V Turbo
17
+ // 4-8 step", strength 0.6, designed 4–8 steps); there is NO separate
18
+ // catalog row labelled "Larry + LightX2V" — F34b's finding was this
19
+ // prose naming a row the catalog never held. The row is resolved from the
20
+ // family lora CATALOG (mods/loras.ts — the one owner of every lora
21
+ // filename and default strength; the value was restated as a
22
+ // literal here, which is how a catalog edit would have silently
23
+ // missed the default). The wire shape matches a resolved bag row:
24
+ // on, lora (filename), str (default_strength), plus the four fixed
25
+ // mode flags. A missing catalog row refuses at load — the default
26
+ // would have no source.
27
+
28
+ export const H3_DEFAULT_LORA_ID = 'h3_lightx2v_turbo';
29
+ /** The absent-bag default as a RESOLVED ROW — the same catalog row the
30
+ * compose default builds, exposed so the card can serve it as the
31
+ * ghost chip: the face then shows the adapter the film will actually
32
+ * run instead of an empty bag. One owner: the catalog. */
33
+ export const h3DefaultLoraEntry = () => {
34
+ const row = H3_LORA_ROWS.find((r) => r.id === H3_DEFAULT_LORA_ID);
35
+ if (row === undefined) {
36
+ throw new Error(`h3 action: the lora catalog has no '${H3_DEFAULT_LORA_ID}' row — the absent-bag default has no source; fix the catalog row id`);
37
+ }
38
+ return {
39
+ id: row.id,
40
+ strength: row.default_strength ?? 1,
41
+ steps: row.steps ?? 8,
42
+ };
43
+ };
17
44
  const loraStackDefault = () => {
18
- const row = H3_LORA_ROWS.find((r) => r.id === 'h3_dmad_4step');
45
+ const row = H3_LORA_ROWS.find((r) => r.id === H3_DEFAULT_LORA_ID);
19
46
  if (row === undefined) {
20
- throw new Error("h3 action: the lora catalog has no 'h3_dmad_4step' row — the absent-bag default has no source; fix the catalog row id");
47
+ throw new Error(`h3 action: the lora catalog has no '${H3_DEFAULT_LORA_ID}' row — the absent-bag default has no source; fix the catalog row id`);
21
48
  }
22
49
  return JSON.stringify([{ on: true, lora: row.filename, str: row.default_strength, v: 1, a: 1, t: 1 }]);
23
50
  };
51
+
52
+
53
+
54
+
55
+
56
+
57
+
58
+ export function h3LoraStackOf(p) {
59
+ return Array.isArray(p.loras)
60
+ ? JSON.stringify(p.loras.map((r) => ({
61
+ // the service resolves every row against the family catalog
62
+ // (unknown ids refuse LOUD upstream) — {name, strength} is
63
+ // the guaranteed wire shape, read directly
64
+ on: true,
65
+ lora: r.name,
66
+ str: r.strength,
67
+ v: 1, a: 1, t: 1,
68
+ })))
69
+ : loraStackDefault();
70
+ }
71
+ /** THE MARRIED SHIFT'S ONE OWNER (same law as the lora plane): the
72
+ * sigma-shift grid the doc's lora plane owns — a pinned shift is the
73
+ * user's word, an unstated one marries the bag's highest-count row
74
+ * (marriedBagKnob), else the doc's own row. Both renderers read this.
75
+ * @param p the walked doc params */
76
+ export function h3ShiftVideoOf(p) {
77
+ const married = marriedBagKnob(p, 'shift_video');
78
+ return p.__shift_pinned === true || married === null
79
+ ? p.shift_video
80
+ : married;
81
+ }
82
+
83
+ // marriage's own math, one spelling for both knobs): while a
84
+ // counting bag row rides, the married knob (steps, shift_video) is
85
+ // the ROW'S — stated on the entry first, else the catalog row's
86
+ // declared default, Math.max across the bag ("8 steps on a 4-step
87
+ // distill is fine, 4 on an 8-step is undercooked"; the shift grid
88
+ // follows the same highest-count-wins law — the 8-step member of a
89
+ // stacked pair owns the grid). The estate's resolver stamps the
90
+ // row's defaults onto resolved wire rows; hand-authored and
91
+ // agent-shaped bags fall back to the catalog row BY FILENAME (the
92
+ // wire's `name` — fictional filenames marry nothing, the
93
+ // door-spec's walk-default law). PURE, no I/O.
94
+ const marriedBagKnob = (p, knob) => {
95
+ if (!Array.isArray(p.loras))
96
+ return null;
97
+ const counts = [];
98
+ for (const row of p.loras) {
99
+ if (row === null || typeof row !== 'object')
100
+ continue;
101
+ const stated = row[knob];
102
+ if (typeof stated === 'number' && Number.isFinite(stated)) {
103
+ counts.push(stated);
104
+ continue;
105
+ }
106
+ const name = row['name'];
107
+ const fromCatalog = typeof name === 'string'
108
+ ? H3_LORA_ROWS.find((r) => r.filename === name)?.[knob]
109
+ : undefined;
110
+ if (typeof fromCatalog === 'number' && Number.isFinite(fromCatalog))
111
+ counts.push(fromCatalog);
112
+ }
113
+ return counts.length > 0 ? Math.max(...counts) : null;
114
+ };
115
+
116
+ // refine seats were served-but-dead: the schema admits refine_lora /
117
+ // _strength / _steps and the film params row carries them, but
118
+ // nothing built the rider's {name, strength, steps} object, so the
119
+ // T3 rider never mounted and the plain pass rendered under stating
120
+ // seats). The assembly lives HERE — inside renderH3Window, the
121
+ // single choke point both the film loop and the single-window face
122
+ // call — so neither face can mount the rider without it (the G6
123
+ // two-face law). Unknown ids refuse LOUD naming refine_lora (the
124
+ // schema's LORAS-ARE-ONLY-MODS promise); master-off or empty id =
125
+ // no rider (the legacy byte-stable plain pass).
126
+ function resolveRefineSeat(p) {
127
+ if (p.second_pass_enabled !== true)
128
+ return undefined;
129
+ const id = p.refine_lora;
130
+ if (typeof id !== "string" || id === "")
131
+ return undefined;
132
+ const row = H3_LORA_ROWS.find((r) => r.id === id);
133
+ if (row === undefined) {
134
+ throw new Error(`h3 action: refine_lora '${id}' names no served loras row — pick from the flavor catalog, never a hand-spelled id (the compose door refuses unknown ids loud)`);
135
+ }
136
+
137
+ // refine-steps-range law moves here, its only assembler: a stated
138
+ // count outside the named row's declared [min, max] refuses LOUD
139
+ // naming the domain. The door carries NO steps-required or
140
+ // strength-fallback branches: every served row declares steps +
141
+ // default_strength (the wall's ARM 9 locks the 11/11), so those
142
+ // branches would be dead code refusing coverage. The table is an
143
+ // `as const` union where only domain rows carry steps_min/max, so
144
+ // the bounds read through `in`-narrowing (no cast, no table touch).
145
+ const steps = (p.refine_steps ?? row.steps);
146
+ const lo = ('steps_min' in row) ? row.steps_min : undefined;
147
+ const hi = ('steps_max' in row) ? row.steps_max : undefined;
148
+ if ((lo !== undefined && steps < lo) || (hi !== undefined && steps > hi)) {
149
+ throw new Error(`h3 action: refine_steps ${steps} for refine_lora '${id}' falls outside the row's declared domain [${lo ?? '…'}, ${hi ?? '…'}] — pick a count the instrument serves, never force one (the compose door enforces the row domain)`);
150
+ }
151
+ // THE REFINE WINDOW (SOTA plan limb 1, H3_TIMELINE_RESERACH Stage
152
+
153
+ // rides the DECLARED 0.35 default — the research's refinement
154
+ // window (0.30–0.35: pass 1's structure stays, the rider polishes
155
+ // texture); 1.0 stays stateable, the TaoMate full-denoise mechanic.
156
+ // Domain [0.05, 1] — ONE law
157
+ // with the schema row and the film.params row below (audit
158
+
159
+ // [0.05, 1] disagreed at 0 < d < 0.05, and the walk owned every
160
+ // real-doc refusal before compose — the resolver's voice had no
161
+ // firing arm. Both seats now state the same bounds and ARM 4f
162
+ // judges the resolver at the family plane, its own seat).
163
+ // P2 SHARES THE SEAT (SOTA plan Phase P2): the latent-upscale
164
+ // handoff reads the SAME refine_denoise as its own Stage-2 window
165
+ // (rider or none — pass 1's structure stays either way), so the
166
+ // assembly moves to resolveStage2Denoise below (one owner, two
167
+ // consumers — the rider keeps its voice, the arm borrows it).
168
+ const denoise = resolveStage2Denoise(p);
169
+ return {
170
+ name: row.filename,
171
+ strength: p.refine_strength ?? row.default_strength,
172
+ steps,
173
+ denoise,
174
+ };
175
+ }
176
+ // THE STAGE-2 DENOISE (SOTA plan Phase P2 — one owner, two
177
+ // consumers): the refine rider AND the latent-upscale handoff read the
178
+ // SAME refine_denoise seat. The rider's window over the pass-1 latent;
179
+ // the handoff's own partial-denoise inside the LBH kernel over the
180
+ // upscaled latent (rider or none — pass 1's structure stays either
181
+ // way). Unstated rides the DECLARED 0.35 (the SOTA refinement window);
182
+ // the voice is the rider's (ARM 4f judges it at the family plane),
183
+ // borrowed verbatim by the arm.
184
+ function resolveStage2Denoise(p) {
185
+ const denoise = p.refine_denoise ?? 0.35;
186
+ if (!(denoise >= 0.05 && denoise <= 1)) {
187
+ throw new Error(`h3 action: refine_denoise ${String(p.refine_denoise)} falls outside the refinement window [0.05, 1] — 1 is the full-denoise taomate mechanic, 0.30–0.35 the SOTA refinement window; a dead or over-terminal second pass never composes`);
188
+ }
189
+ return denoise;
190
+ }
24
191
  // His 17k+5 grid, in-graph (ComfyMathExpression): snap latent steps to 2 mod 5
25
192
  // (the card's own principles row: "Length snaps to the 17k+5 frame grid
26
- // at 24fps" — the principles).
27
- const MATH_STEPS_GOLD = `max(${GRID_REMAINDER}, round(a * 24)) + (${GRID_REMAINDER} - (max(${GRID_REMAINDER}, round(a * 24)) % ${GRID_STEP_FRAMES})) % ${GRID_STEP_FRAMES}`;
193
+ // at 24fps" — the principles). The seconds→frames multiplier is the
194
+ // caller's DOC CLOCK (a hardcoded *24 scaled every non-24 window —
195
+ // AUDIO-2's fifth seat); the grid snap is clock-independent.
196
+ const mathStepsGold = (fps) => `max(${GRID_REMAINDER}, round(a * ${fps})) + (${GRID_REMAINDER} - (max(${GRID_REMAINDER}, round(a * ${fps})) % ${GRID_STEP_FRAMES})) % ${GRID_STEP_FRAMES}`;
28
197
 
29
198
  // finding #4): MiniMaxH3ImageToVideo exists in the serialized graph
30
199
  // ONLY as the t4r family marker (finalizeH3 keys on it to skip the
@@ -51,7 +220,7 @@ const SHARPEN_DEFAULTS = { method: 'rcas', strength: 0.3, radius: 1.0, threshold
51
220
 
52
221
 
53
222
 
54
- const LANE_FILES = {
223
+ export const LANE_FILES = {
55
224
  clip: 'qwen3vl_32b_minimax_h3_int8_convrot.safetensors',
56
225
  vae_video: 'minimax_h3_video_vae_int8_convrot.safetensors',
57
226
  vae_audio: 'minimax_h3_audio_vae_fp32.safetensors',
@@ -64,6 +233,25 @@ const LANE_FILES = {
64
233
 
65
234
 
66
235
  const FILM_BIT_DEPTH = 8;
236
+
237
+
238
+
239
+
240
+
241
+
242
+ export const FILM_AUDIO_RATE = 48000;
243
+ /** THE JOIN-RATE DOOR: one spelling for every audio leg that feeds a
244
+ * join's CreateVideo — the leg passes MeliteAudioResample at
245
+ * FILM_AUDIO_RATE (engine-core bandlimited sinc; equal-rate input
246
+ * passes the SAME dict through, so a leg already at the film rate
247
+ * pays nothing but the stated law).
248
+ * @param g the run's graph builder
249
+ * @param audio the leg's AUDIO output handle */
250
+ export function filmJoinAudio(g, audio) {
251
+ return g.node('MeliteAudioResample', {
252
+ audio, sample_rate: FILM_AUDIO_RATE,
253
+ }).out(0);
254
+ }
67
255
  export function parseH3Facts(raw) {
68
256
  const lane = (raw ?? {});
69
257
  const unet = lane.unet;
@@ -88,6 +276,63 @@ export const assertOverlayGated = (doc, where) => {
88
276
  throw new Error(`${where}: ${String(e)}`);
89
277
  }
90
278
  };
279
+
280
+
281
+
282
+
283
+
284
+
285
+
286
+
287
+
288
+
289
+
290
+ export function chainSaveBoundaries(g, saves) {
291
+ if (saves.length === 0) {
292
+ throw new Error('[h3-timeline] the boundary chain needs at least one save — a join with nothing to order refuses loud');
293
+ }
294
+ let boundaryAfter;
295
+ for (const save of saves) {
296
+ boundaryAfter = g.node('MeliteUnload', {
297
+ video: save, unload_models: false,
298
+ ...(boundaryAfter !== undefined ? { after: boundaryAfter } : {}),
299
+ }).out(0);
300
+ }
301
+ return boundaryAfter;
302
+ }
303
+ /** THE FILE-JOIN PRIMITIVE, half 2 — the concat + container (the
304
+ * film tail's own law, ONE spelling for every join-by-file seat):
305
+ * MeliteConcatVideos decodes the saved FILES back CPU-side strictly
306
+ * after the boundary token; CreateVideo → SaveVideo delivers the
307
+ * joined film.
308
+ * @param g the run's graph builder
309
+ * @param prefixes the members' SaveVideo prefixes, film order
310
+ * @param after the boundary chain's final token (the ordering proof)
311
+ * @param out the joined film's filename_prefix
312
+ * @param opts.audio an audio override for the container mux (the
313
+ * film's mixed stem); absent = the concat's own decoded audio
314
+ * @param opts.append an exact saved-file path wired as the LAST
315
+ * member after the prefix list (the multi-window extend's assembled
316
+ * extension — ChainAssemble's video_path output; DAG-proven by its
317
+ * own data dependency, no boundary needed)
318
+ * @returns the joined film's SaveVideo passthrough */
319
+ export function concatSavedFilms(g, prefixes, after, out, opts = {}) {
320
+ if (prefixes.length === 0) {
321
+ throw new Error('[h3-timeline] the concat needs at least one member prefix — a join with nothing to stitch refuses loud');
322
+ }
323
+ const concat = g.node('MeliteConcatVideos', {
324
+ videos: prefixes.join(','),
325
+ ...(opts.append !== undefined ? { append: opts.append } : {}),
326
+ after,
327
+ });
328
+ const created = g.node('CreateVideo', {
329
+ images: concat.out(0), audio: opts.audio ?? concat.out(1), fps: concat.out(2),
330
+ bit_depth: FILM_BIT_DEPTH,
331
+ });
332
+ return g.node('SaveVideo', {
333
+ video: created.out(), filename_prefix: out, format: 'mp4', codec: 'h264',
334
+ }).out();
335
+ }
91
336
  /** THE MERGED FILM: ONE prompt, N windows under `window${k}_`
92
337
  * scopes (GraphBuilder.scoped), with real seam edges between scopes
93
338
  * (the executor orders windows off the graph) and per-window
@@ -99,7 +344,7 @@ export const assertOverlayGated = (doc, where) => {
99
344
  * (the node's context_frames arm). prev_sec scales the carry:
100
345
  * picture snapped to the node's legal context lengths (5/22/39/56
101
346
  * frames — only whole latent steps), audio at 24 frames/second. */
102
- function renderH3Film(p, g, facts, model) {
347
+ function renderH3Film(p, g, facts, model, runId) {
103
348
  // (the compose dispatch guarantees calls is a non-empty array here)
104
349
  const calls = p.calls;
105
350
  const str = (v) => (typeof v === 'string' ? v : '');
@@ -150,6 +395,13 @@ function renderH3Film(p, g, facts, model) {
150
395
  // (the words law), a textless row is music (the historical
151
396
  // Music-row behavior, byte-identical for existing docs).
152
397
  const clips = parseFilmMixClips(Array.isArray(p.audio_clips) ? p.audio_clips : []);
398
+ // THE RE-SHOOT CHAIN, BUILT ONCE (feature 024): an armed re-shoot
399
+ // builds its depth → warp → mask subgraph ONCE on the run's graph
400
+ // (never per window — a multi-window film pays for the depth model
401
+ // and the reprojection exactly once) and stamps the shared handles
402
+ // onto every stanza (the __prev precedent — the __-prefix internal
403
+ // channel). Every window's sampler then renders from the moved
404
+ // camera through its own apply seat.
153
405
  // THE FILM DOC'S SPANS — the clock's own rows, one per call, doc
154
406
  // frames with the seam word (filmMix.ts owns the law). The stanza
155
407
  // snap rides these (spanStanzaFrames): the render loop below and
@@ -165,6 +417,37 @@ function renderH3Film(p, g, facts, model) {
165
417
  // including absent IS extend); no card-side re-encoding
166
418
  transition: str(c.transition),
167
419
  }));
420
+ // THE RE-SHOOT CHAIN, BUILT ONCE (feature 024): an armed re-shoot
421
+ // builds its depth → warp → mask subgraph ONCE on the run's graph
422
+ // (never per window — a multi-window film pays for the depth model
423
+ // and the reprojection exactly once) and stamps the shared handles
424
+ // onto every stanza (the __prev precedent — the __-prefix internal
425
+ // channel). Every window's sampler then renders from the moved
426
+ // camera through its own apply seat.
427
+
428
+ // length derives from the SHORTEST one this run renders (the stanza
429
+ // snap the render loop and the clock share) — the round-4 burn
430
+ // pinned a 124-frame guide into a 90-frame window and the engine
431
+ // refused at the AddGuide seat, killing every film with a short
432
+ // call.
433
+ // F28 (folded, round-6 audit): a call's knobs.length PIN overrides
434
+ // the span snap for that window, so the shortest-generation min must
435
+ // count the pinned number too — the round-5 cure derived from spans
436
+ // alone and a film whose short call PINNED its length still pinned a
437
+ // longer guide than that call renders.
438
+ const windowFrames = spans.map((s, i) => {
439
+ const pin = (calls[i]?.knobs ?? {})['length'];
440
+ // only a grid-legal pin counts here: an off-grid or mistyped pin
441
+ // is the film loop's own gate to refuse (one voice, the span
442
+ // voice — the loop's assertGridLength names the window and span),
443
+ // so the min falls through to the snap it will never render.
444
+ if (typeof pin === 'number' && isGridLength(pin))
445
+ return pin;
446
+ return spanStanzaFrames(s, i > 0 ? spanOverlap(s) : 0);
447
+ });
448
+ const reshootChain = reshootArmed(p)
449
+ ? buildH3Reshoot(p, g, Math.min(...windowFrames), runId)
450
+ : undefined;
168
451
  // (the clip text law lives where the text is consumed: THE
169
452
  // TRANSCRIPT — dialogue words ride the <d> prompt tag, sfx text
170
453
  // the soundscape field, music text non_diegetic_music. In every
@@ -177,13 +460,26 @@ function renderH3Film(p, g, facts, model) {
177
460
  // default; a user-stacked pair runs at the HIGHER count — 8 steps
178
461
  // on a 4-step distill is fine, 4 on an 8-step is undercooked).
179
462
  const loraRows = Array.isArray(p.loras) ? p.loras : [];
180
- const loraStepsList = loraRows
181
- .map((r) => r.steps)
182
- .filter((v) => typeof v === 'number' && Number.isFinite(v));
183
- const loraStepsApplied = loraStepsList.length > 0 ? Math.max(...loraStepsList) : null;
463
+ // THE MARRIED CONSULT (one spelling — marriedBagKnob): the
464
+ // marriage consult goes through the shared helper so the catalog
465
+ // fallback (a row's unstated count read from the family table by
466
+ // filename) is the same math on every face.
467
+ const loraStepsApplied = marriedBagKnob(p, 'steps');
184
468
  calls.forEach((call, i) => {
185
469
  const k = i + 1;
186
- const guide = str(call.image ?? call.ref_image ?? call.image_name);
470
+ // THE OPENER ANCHOR (cure 8's film arm — session 384a13cd's bread
471
+ // and butter: "turn this image into the video, two short clips
472
+ // combined"). A DOC-level guide is the film's OPENING FRAME:
473
+ // window 1 seats it when its call states none; windows 2+ continue
474
+ // from the generation head and never re-anchor on it (the stanza
475
+ // delete below carries that half). Before this lift the doc-level
476
+ // guide was silently unused by the film loop — the conflict guard
477
+ // then refused the write with a cure ("state no variant") that was
478
+ // already true, the lying-cure class the operator named.
479
+ const callGuide = str(call.image ?? call.ref_image ?? call.image_name);
480
+ const guide = callGuide !== ''
481
+ ? callGuide
482
+ : (i === 0 ? str(p.image ?? p.image_name ?? p.ref_image) : '');
187
483
  // A CALL OWNS ITS TEXT (the operator's no-fallbacks law, enforced
188
484
 
189
485
  // a source substitution, the exact crime class the law bans). The
@@ -229,7 +525,13 @@ function renderH3Film(p, g, facts, model) {
229
525
  const hi = Math.min(clip.start + clip.dur, ef);
230
526
  if (hi - lo < 2.4)
231
527
  continue; // below the slice node's 0.1s floor
232
- const ms = (frames) => Math.round((frames / 24) * 1000) / 1000;
528
+ // ONE CLOCK (journey audit AUDIO-2): the stamps' seconds
529
+ // speak the DOC CLOCK — p.fps when stated, the schema row's
530
+ // default otherwise. The /24 literal stretched a 16fps
531
+ // film's dialogue and sfx slices by 1.5x (lip-sync drift,
532
+ // the audit's worst burn).
533
+ const stampFps = typeof p.fps === 'number' && p.fps > 0 ? p.fps : DOC_FPS_DEFAULT;
534
+ const ms = (frames) => Math.round((frames / stampFps) * 1000) / 1000;
233
535
  stamps[clip.cls] = {
234
536
  src: clip.src,
235
537
  slice_start_seconds: ms(Math.max(0, genStart - clip.start)),
@@ -327,9 +629,23 @@ function renderH3Film(p, g, facts, model) {
327
629
  const hasDirectRefs = wireList(call.ref_images).length + wireList(call.ref_videos).length + wireList(call.ref_audios).length > 0
328
630
  || (typeof call.last_frame === 'string' && call.last_frame.trim() !== '');
329
631
  const anyStamp = stamps.dialogue !== undefined || stamps.sfx !== undefined || stamps.music !== undefined;
330
- stanza.variant = (guide !== '' || hasRefs || hasDirectRefs || anyStamp) ? 't4r' : chainLike ? 't4_chain' : 't4_open';
632
+ // THE KEYFRAME PIN CHANNEL'S WINDOW RIDES (slice 2): an interior
633
+ // pin is an image guide — the window derives the reference lane by
634
+ // the same seats-beat-stated law the guide spellings ride (the
635
+ // derivation knows every seat the compose knows — one law here and
636
+ // in renderH3Window's family line, never a window that claims
637
+ // t4_open while its chain rides the reference arm).
638
+ const winPins = (p.__keyframe_pins ?? {})[String(k)] ?? [];
639
+ stanza.variant = (guide !== '' || hasRefs || hasDirectRefs || anyStamp || winPins.length > 0) ? 't4r' : chainLike ? 't4_chain' : 't4_open';
331
640
  // the distill's steps apply unless this call's knobs pinned steps
332
- if (knobs.steps === undefined && loraStepsApplied !== null)
641
+ // — or the DOC did (the __steps_pinned stamp, the walk's own
642
+ // explicit-keys fact; the single-window marriage always consulted
643
+ // it, the film loop did not — the split-brain that stomped a
644
+ // user-stated doc steps with the bag's count on every multi-call
645
+
646
+ // ONLY FOUR STEPS"). One law, both arms: the user's stated steps
647
+ // — doc-level or per-call knob — never loses to the bag.
648
+ if (knobs.steps === undefined && loraStepsApplied !== null && p.__steps_pinned !== true)
333
649
  stanza.steps = loraStepsApplied;
334
650
  // THE DOOR GUARD, voice arm: a dialogue/sfx-pinned window mutes
335
651
  // the user ref audios (film-level and per-call) — the pins own
@@ -354,6 +670,19 @@ function renderH3Film(p, g, facts, model) {
354
670
  stanza.image = guide;
355
671
  else
356
672
  delete stanza.image;
673
+ // THE STATED-FAMILY BYPASS'S LOUD FLOOR (calls-stanza audit #2,
674
+
675
+ // whole shot-law sweep (schema.ts guards every row/span law on
676
+ // variant === undefined) — the agent plane can state a family
677
+ // and hand a reversed span past it. The old guard (ef > sf)
678
+ // SILENTLY SKIPPED assertSpanGrid and the length lift for
679
+ // exactly that shape: the window rendered at the doc length with
680
+ // a span the manifest booked backwards. A stated pair that does
681
+ // not advance refuses LOUD here — the walk's own law, stated at
682
+ // the loop's floor, on the path the walk cannot see.
683
+ if (sf !== null && ef !== null && ef <= sf) {
684
+ throw new Error(`h3-timeline window ${k}: reversed span (end_frame ${String(ef)} <= start_frame ${String(sf)}) — a stated family bypasses the walk's span laws, never the compose's`);
685
+ }
357
686
  if (sf !== null && ef !== null && ef > sf) {
358
687
  // THE UNIFORM SPAN GATE, second door: a stale or hand-built
359
688
  // document re-rides the same law the walk admitted under, so
@@ -380,10 +709,18 @@ function renderH3Film(p, g, facts, model) {
380
709
  // (The snap itself is filmMix's spanStanzaFrames — the ONE
381
710
  // law the render loop and the film manifest share; the old
382
711
  // inline 22+17k twin died here.)
383
- if (knobs.fps_seconds === undefined) {
384
- stanza.fps_seconds = Math.round((stanza.length / 24) * 1000) / 1000;
385
- }
386
712
  }
713
+
714
+ // STALE ANYWHERE"): the row is INTERNAL (the declared surface's
715
+ // own words — the per-window rows k, noise_seed, fps_seconds are
716
+ // internal), and the old restatement skipped DEFINED knobs, so a
717
+ // pin stated by an older span outlived every later drag — the
718
+ // render clock (fps_seconds) and the bar clock (the span) then
719
+ // disagreed forever: a 5-second span on the bar rendered a
720
+ // 10-second mush. The compose OWNS internal rows unconditionally
721
+ // — fps_seconds derives at renderH3Window's own head (the one
722
+ // owner, both arms) from the window's actual generation length.
723
+ // No pin survives. No fallback. No silent disagreement.
387
724
  // THE GRID GATE (§26): a knob-pinned length bypassed the snap
388
725
  // above — validate, never trust. Refuses at compose (zero GPU)
389
726
  // with the span, the nearest legal length, and the proven
@@ -395,6 +732,8 @@ function renderH3Film(p, g, facts, model) {
395
732
  }
396
733
  if (prev !== undefined)
397
734
  stanza.__prev = prev;
735
+ if (reshootChain !== undefined)
736
+ stanza.__reshoot = reshootChain;
398
737
 
399
738
  // bed arm retired with the bed the same day): a pinned window
400
739
  // owns its audio conditioning — the normal inputs stand down for
@@ -416,7 +755,7 @@ function renderH3Film(p, g, facts, model) {
416
755
  stanza.sfx_slice = stamps.sfx;
417
756
  if (stamps.music !== undefined)
418
757
  stanza.music_slice = stamps.music;
419
- const h = g.scoped(`window${k}_`, (w) => renderH3Window(stanza, w, facts, model));
758
+ const h = g.scoped(`window${k}_`, (w) => renderH3Window(stanza, w, facts, model, runId));
420
759
  prev = h;
421
760
  /* v8 ignore next 1 -- both family arms assign the passthrough (every path saves); a future arm that forgets is refused loud at the film tail */
422
761
  if (h.savePassthrough !== undefined)
@@ -474,10 +813,16 @@ function renderH3Film(p, g, facts, model) {
474
813
  if (windowSaves.length === 0) {
475
814
  throw new Error('[h3-timeline] a family arm saved no clip to pass the film boundary — the film tail cannot order its loads');
476
815
  }
816
+ // ONE CLOCK (AUDIO-2): the stanza durations and the owner map's
817
+ // joins speak the same doc clock as the stamps above and the
818
+ // container's frame_rate — never a /24 literal beside a 16fps
819
+ // film.
820
+ const docFps = typeof p.fps === 'number' && p.fps > 0 ? p.fps : DOC_FPS_DEFAULT;
477
821
  const manifest = computeFilmMix({
478
822
  spans,
479
823
  clips,
480
- windowSecs: stanzaSecs(spans),
824
+ windowSecs: stanzaSecs(spans, docFps),
825
+ fps: docFps,
481
826
  // the knob's declared default (−14) walks through the schema
482
827
  // door; computeFilmMix owns the fallback for the absent key
483
828
  duckDb: p.duck_depth_db,
@@ -487,23 +832,22 @@ function renderH3Film(p, g, facts, model) {
487
832
  // stitch: 960×576 leftovers globbed as windows) and
488
833
  // run-18ea8c810104 (loud no-match refusal on h3_t4_w2): cut
489
834
  // windows chain NOTHING and even chained windows' SAVE nodes are
490
- // not downstream of one another, so the old single boundary on
491
- // the LAST save rode a scheduler tie-break — window 2's save was
492
- // an unordered island the loader could beat). Every window's
493
- // SaveVideo passthrough feeds its OWN boundary; each boundary's
494
- // optional 'after' wires the prior boundary's token, so the final
495
- // token (the concat's 'after') transitively depends on EVERY
496
- // save — and each window's passthrough tensor still dies at its
497
- // own boundary (the §20 law; the flush is idempotent, weights
498
- // stay resident).
499
- let boundaryAfter;
500
- for (const save of windowSaves) {
501
- boundaryAfter = g.node('MeliteUnload', {
502
- video: save, unload_models: false,
503
- ...(boundaryAfter !== undefined ? { after: boundaryAfter } : {}),
504
- }).out(0);
505
- }
506
- const after = boundaryAfter;
835
+ // not downstream of one another, so the old single boundary on the
836
+ // LAST save rode a scheduler tie-break — window 2's save was an
837
+ // unordered island the loader could beat). The shared boundary
838
+
839
+ // unification) carries the law: every window's SaveVideo
840
+ // passthrough feeds its OWN boundary and the final token
841
+ // transitively depends on EVERY save, while each window's
842
+ // passthrough tensor dies at its own boundary (the §20 law; the
843
+ // flush is idempotent, weights stay resident).
844
+
845
+ // saves, the windows' saves, and this concat/mix prefix list are
846
+ // ONE truth (`<runId>/h3_t4_w<k>` both sides), so the file tail
847
+ // resolves them under the output root's `<runId>/` subfolder and
848
+ // the harvest walks them run-scoped like every chain save.
849
+ const windowPrefixes = calls.map((_c, i) => `${runId}/h3_t4_w${i + 1}`);
850
+ const after = chainSaveBoundaries(g, windowSaves);
507
851
  if (clips.length > 0) {
508
852
 
509
853
 
@@ -520,7 +864,7 @@ function renderH3Film(p, g, facts, model) {
520
864
  // the mix, not the raw concat audio. Early return: the
521
865
  // clips-free arm below stays byte-frozen.
522
866
  const mix = g.node('MeliteFilmAudioMix', {
523
- videos: calls.map((_c, i) => `h3_t4_w${i + 1}`).join(','),
867
+ videos: windowPrefixes.join(','),
524
868
  after,
525
869
  // the manifest rendered verbatim: every placement's source,
526
870
  // film seat, duration, and class — doc order kept (the node's
@@ -543,34 +887,16 @@ function renderH3Film(p, g, facts, model) {
543
887
  // calibrated against ffmpeg's ebur128 to within 0.1 LU on tones,
544
888
  // noise, gating, and mono.
545
889
  const meter = g.node('MeliteLoudness', { audio: mix.out(0) });
546
- saveAudio(g, meter.out(0), 'h3_t4_film_audio');
890
+ saveAudio(g, meter.out(0), `${runId}/h3_t4_film_audio`);
547
891
  // THE FILM MP4 (GAP 1): the same file-tail video join the
548
892
  // clips-free arm rides — container mux only (CreateVideo +
549
893
  // SaveVideo h264/mp4 on the decoded window files), never the
550
894
  // mix. The mix rides it: audio carries the node's output.
551
- const join = g.node('MeliteConcatVideos', {
552
- videos: calls.map((_c, i) => `h3_t4_w${i + 1}`).join(','),
553
- after,
554
- });
555
- const filmCreated = g.node('CreateVideo', {
556
- images: join.out(0), audio: meter.out(0), fps: join.out(2), bit_depth: FILM_BIT_DEPTH,
895
+ return concatSavedFilms(g, windowPrefixes, after, `${runId}/h3_t4_film`, {
896
+ audio: meter.out(0),
557
897
  });
558
- return g.node('SaveVideo', {
559
- video: filmCreated.out(), filename_prefix: 'h3_t4_film',
560
- format: 'mp4', codec: 'h264',
561
- }).out();
562
898
  }
563
- const concat = g.node('MeliteConcatVideos', {
564
- videos: calls.map((_c, i) => `h3_t4_w${i + 1}`).join(','),
565
- after,
566
- });
567
- const filmCreated = g.node('CreateVideo', {
568
- images: concat.out(0), audio: concat.out(1), fps: concat.out(2), bit_depth: FILM_BIT_DEPTH,
569
- });
570
- return g.node('SaveVideo', {
571
- video: filmCreated.out(), filename_prefix: 'h3_t4_film',
572
- format: 'mp4', codec: 'h264',
573
- }).out();
899
+ return concatSavedFilms(g, windowPrefixes, after, `${runId}/h3_t4_film`);
574
900
  }
575
901
  /** THE FUN-CONTROLNET CHAIN (002 H2/H4 + 007 L7): family-owned,
576
902
  * the LTX_lora_loader precedent — the node pair is the family's
@@ -608,7 +934,7 @@ function applyH3FunControlNets(g, model, vae, picks) {
608
934
  }
609
935
  return cur;
610
936
  }
611
- function renderH3Window(p, g, facts, model) {
937
+ function renderH3Window(p, g, facts, model, runId) {
612
938
  // REFS IMPLY THE R2V LANE (the bundle IS the r2v input): a
613
939
  // refs-carrying window is t4r even without a guide still — the
614
940
  // same law the film renderer applies per call. The DECLARED input
@@ -632,15 +958,54 @@ function renderH3Window(p, g, facts, model) {
632
958
  const statedFamily = typeof p.variant === 'string' && FAMILIES.includes(p.variant)
633
959
  ? p.variant : undefined;
634
960
  const guide0 = [p.image, p.image_name, p.ref_image].some((v) => typeof v === 'string' && v.trim() !== '');
635
- const family = (hasRefs || guide0) ? 't4r' : (statedFamily ?? 't4_open');
961
+ // THE KEYFRAME PIN CHANNEL (slice 2): this window's interior pins —
962
+ // keyed by the 1-based window k (the mapping's channel). Pins are an
963
+ // image-guide seat: a pin-carrying window derives the reference lane
964
+ // (the AddGuide chain only exists on the t4r arm), seats beat stated.
636
965
  const k = (p.k ?? 1);
966
+ const winPins = (p.__keyframe_pins ?? {});
967
+ const pinsHere = winPins[String(k)] ?? [];
968
+ const family = (hasRefs || guide0 || pinsHere.length > 0) ? 't4r' : (statedFamily ?? 't4_open');
637
969
  // THE GRID GATE (§26, defense in depth): no window renders
638
970
  // off-grid — the film loop's pin check voices the call span, this
639
971
  // one catches the single-call path and any direct caller.
640
972
  assertGridLength(p.length, `h3-timeline window ${k}`);
973
+
974
+ // STALE ANYWHERE"): fps_seconds is INTERNAL and derives from THIS
975
+ // window's actual render length, every compose, BOTH arms — the
976
+ // film loop's stanzas and the frozen single-window doc alike (one
977
+ // owner: this seat; the film loop's old copy is deleted). The
978
+ // removed .default(10) left this arm serializing
979
+ // PrimitiveFloat{value: undefined} — the engine's 400 on every
980
+ // keyframed single-call doc. No default, no doc pin, no fallback:
981
+ // the length owns the clock. THE DIVISOR IS THE DOC'S OWN FPS
982
+ // (audit f1cc1197, the bar-clock mismatch): /24 booked 3.75s while
983
+ // a stated fps 16 container PLAYED 5.625s — the seconds seat and
984
+ // the play seat must share one clock or the bar lies. The 24
985
+ // mirror is the row's own declared default (schema.ts fps
986
+ // .default(24) — the walk fills it on every real door; raw
987
+ // walk-bypass callers get the declared default, never an invented
988
+ // one).
989
+ const fpsClock = typeof p.fps === 'number' && p.fps > 0 ? p.fps : DOC_FPS_DEFAULT;
990
+ p.fps_seconds = Math.round((p.length / fpsClock) * 1000) / 1000;
641
991
  const isT4r = family === 't4r';
642
992
  const isChain = family === 't4_chain';
643
993
 
994
+ // second_pass_enabled AND the upscale_route sub-gate — the vendored
995
+ // xmarre pack's MinimaxH3LatentUpscaler3DRefineHandoff rides
996
+ // in-band on the pass-1 joint AV latent (upscale + the low-sigma
997
+ // refinement inside the 3D-conv kernel, lock_audio true — z_v
998
+ // through the LBH kernel, z_a preserved).
999
+ const upscaleOn = p.second_pass_enabled === true && p.upscale_route === "latent_2x";
1000
+ // THE HEAD HALVES UNDER THE ARM (both r2v seats below): pass 1
1001
+ // composes the quarter grid the kernel was distilled on
1002
+ // (1344×768 → 672×384); the handoff doubles the latent in-band
1003
+ // before the second pass. Route off = stated geometry (ARM 41's
1004
+ // byte-stable plain pass — the halving never touches the legacy
1005
+ // graph).
1006
+ const headW = upscaleOn ? p.width / 2 : p.width;
1007
+ const headH = upscaleOn ? p.height / 2 : p.height;
1008
+
644
1009
  // is the fresh-card admission, not a fallback crime. The window
645
1010
  // shape's text face is p.prompt (declared required=True, "optional
646
1011
 
@@ -651,11 +1016,27 @@ function renderH3Window(p, g, facts, model) {
651
1016
  // lawfully write p.prompt from call text because in the one-window
652
1017
  // shape p.prompt IS the text owner — never a substitute.)
653
1018
  const prompt = (p.prompt ?? '');
1019
+
1020
+ // built ONCE per window render — the film loop stamps the shared
1021
+ // handles (__reshoot, one build per film), the single-window
1022
+ // shape builds its own here. Every re-shoot seat below reads this
1023
+ // one const: the r2v prompt trigger, the ref_video_0 override,
1024
+ // the guide pin, the model LoRA. THE PROMPT SEAT: the official
1025
+ // chain's prompt is exactly `crossview.` — the LoRA's trigger
1026
+ // word leads, the estate's own prose follows.
1027
+ const reshootChain = p.__reshoot
1028
+ ?? (reshootArmed(p) ? buildH3Reshoot(p, g, Number(p.length), runId) : undefined);
1029
+ const r2vPrompt = reshootChain !== undefined ? reshootPrompt(prompt) : prompt;
654
1030
  // card knob first (image), renderer alias second.
655
1031
  const guideImage = (p.image ?? p.image_name ?? '');
656
1032
  // ── the model chain (family-conditional defaults;
657
1033
  // absent = absent on wire) ──
658
- const stabilize = p.sla_stabilize_motion ?? (isT4r ? false : true);
1034
+
1035
+ // the spec's diagnostic matrix seats "SLA stabilize motion =
1036
+ // Enabled" as the flicker cure's own law — both arms get the true
1037
+ // fallback now (t4r rode false, the timeline's own reference lane
1038
+ // ran the flicker cure off); a doc's explicit false still wins.
1039
+ const stabilize = p.sla_stabilize_motion ?? true;
659
1040
  const unet = g.node('UNETLoader', { unet_name: facts.unet, weight_dtype: 'default' }).out();
660
1041
  const sla = g.node('H3SLAAttention', {
661
1042
  model: unet,
@@ -669,7 +1050,19 @@ function renderH3Window(p, g, facts, model) {
669
1050
  dense_backend: p.sla_dense_backend,
670
1051
  disable_fp16_accum: p.sla_disable_fp16_accum,
671
1052
  stabilize_motion: stabilize,
672
- reference_protection: p.sla_reference_protection,
1053
+
1054
+ // predicted drift, verified LIVE at the engine door): the
1055
+ // upstream input turned BOOLEAN (its own tooltip: 'ON (Light)
1056
+ // uses fixed 0.85 reference sparsity...') while our schema row
1057
+ // still served the three-string enum — every default compose
1058
+ // (the walk fills 'Heavy Enforcement') fed a STRING into the
1059
+ // boolean input: phase-1 refusal, card dead on lane, every
1060
+ // suite green (no wall fixture carried H3SLAAttention). The
1061
+ // UI vocabulary STAYS the richer enum (saved docs ride
1062
+ // verbatim); the compose translates at the node seat — the
1063
+ // engine's binary is the truth the wire must speak. Only 'Off'
1064
+ // is false; Light and Heavy Enforcement both protect.
1065
+ reference_protection: p.sla_reference_protection !== 'Off',
673
1066
  }).out();
674
1067
  const chunked = g.node('MiniMaxChunkFeedForward', {
675
1068
  model: g.node('MiniMaxLowVRAMAttention', { model: sla, head_chunks: 4 }).out(),
@@ -681,26 +1074,29 @@ function renderH3Window(p, g, facts, model) {
681
1074
  // writes the mod bag `loras` — [{id, strength}] rows the service
682
1075
  // resolves to {name, strength} filenames against the family's
683
1076
  // flavor catalog. Those rows build the upstream stack verbatim
684
- // ({on, lora, str, v:1, a:1, t:1}); an empty bag rides the
685
- // family catalog's turbo row (the mod plane's own default, built
1077
+ // ({on, lora, str, v:1, a:1, t:1}). THE EMPTY-BAG LAW (J1,
1078
+
1079
+ // operator's "no loras" — the wire carries an EMPTY stack and
1080
+ // nothing loads; only an ABSENT bag (unset) rides the family
1081
+ // catalog's default row (the mod plane's own default, built
686
1082
  // from the catalog so the value has one owner). ONE surface, one
687
- // owner.
688
- const loraStack = Array.isArray(p.loras) && p.loras.length > 0
689
- ? JSON.stringify(p.loras.map((r) => ({
690
- // the service resolves every row against the family catalog
691
- // (unknown ids refuse LOUD upstream) — {name, strength} is
692
- // the guaranteed wire shape, read directly
693
- on: true,
694
- lora: r.name,
695
- str: r.strength,
696
- v: 1, a: 1, t: 1,
697
- })))
698
- : loraStackDefault();
1083
+ // owner, two honest poles — and since the swap build the stack
1084
+ // string comes from h3LoraStackOf (the plane's ONE owner, shared
1085
+ // with swap.ts; never restated here).
1086
+ const loraStack = h3LoraStackOf(p);
699
1087
  // t4r templates carry shift_video 8.0; the t4 family carries the INT
700
1088
  // NO SILENT RESOLUTION LAW: the walked shift_video IS the value
701
1089
  // (declared default 8; the family literals retired with the
702
1090
  // nulling that fed them — 8.0 and 8 serialize identically anyway)
703
- const shiftVideo = p.shift_video;
1091
+ // THE MARRIED SHIFT (SOTA limb 2, the steps marriage's heir):
1092
+ // while a distill rides, the row's own sigma-shift grid wins over
1093
+ // the no-distill default (the 8-step turbos run 12, the 4-step
1094
+ // 6, native rows declare none and keep 8) — UNLESS the doc stated
1095
+ // its own shift (the __shift_pinned stamp: an explicit value is
1096
+ // the user's word, the marriage applies only to the unstated).
1097
+ // One owner since the swap build: h3ShiftVideoOf (shared with
1098
+ // swap.ts).
1099
+ const shiftVideo = h3ShiftVideoOf(p);
704
1100
  const clip = g.node('CLIPLoader', {
705
1101
  clip_name: facts.clip, type: 'minimax',
706
1102
  ...(isT4r ? { device: 'default' } : {}), // t4 templates OMIT it
@@ -710,7 +1106,21 @@ function renderH3Window(p, g, facts, model) {
710
1106
  let cond;
711
1107
  let latent;
712
1108
  let sigmaModel;
713
- let fpsInput;
1109
+
1110
+ // picked UNET+switch output BEFORE the primary LTX_lora_loader —
1111
+ // the un-distilled base pass 2's Stage-3 law rides (assigned in
1112
+ // both t4 arms; consumed only when a distill rides pass 2 at a
1113
+ // sub-1 window, so the plain pass stays byte-stable).
1114
+ let preLoraModel;
1115
+
1116
+ // non-reference seat was a DEAD STORE: the only fpsInput read sat
1117
+ // inside if (isT4r), so the else-arm's CreateVideo kept its
1118
+ // hardcoded 24 while the cure line sat two blocks above it). The
1119
+ // initializer puts the DOC's clock under every arm; the t4r branch
1120
+ // upgrades it to the walk-first PrimitiveFloat node, and the
1121
+ // else-arm container reads it directly. p.fps is a declared row
1122
+ // (default 24, the walk fills it on every real door).
1123
+ let fpsInput = p.fps;
714
1124
  if (isT4r) {
715
1125
  // opener: switch(SLABool) picks SLA-direct vs chunked; lora rides
716
1126
  // the switch; preview override wired to the in-graph step count.
@@ -719,19 +1129,31 @@ function renderH3Window(p, g, facts, model) {
719
1129
  // scalar straight when sla_switch is set. sla_enabled=false
720
1130
  // forces the chunked (SLA-off) path; otherwise the legacy
721
1131
  // sla_switch spelling rides untouched.
722
- const fpsNode = g.node('PrimitiveFloat', { value: 24.0 }).out(); // id .0 — CreateVideo.fps walks first
1132
+
1133
+ // clock rides the DOC's fps — the same clock the bar books — so
1134
+ // the clip's seconds equal the bar's seconds. The old hardcoded
1135
+ // 24 generated a 90-frame window that PLAYED 3.75s under a
1136
+ // 5.6s bar (frames right, seconds stolen by a third). p.fps is
1137
+ // a declared row (default 24, the walk fills it) — never a ??
1138
+ // fallback, never undefined on the wire.
1139
+ const fpsNode = g.node('PrimitiveFloat', { value: p.fps }).out(); // id .0 — CreateVideo.fps walks first
723
1140
  let slaSel = p.sla_enabled === false
724
1141
  ? true
725
1142
  : (p.sla_switch ?? null);
726
1143
  if (slaSel === null)
727
1144
  slaSel = g.node('PrimitiveBoolean', { value: false }).out();
728
1145
  const picked = g.node('ComfySwitchNode', { switch: slaSel, on_true: chunked, on_false: sla }).out();
1146
+ preLoraModel = picked;
729
1147
  const loraModel = g.node('LTX_lora_loader', {
730
1148
  model: picked, mode: 'minimax', stack_data: loraStack, lora_ui: '',
731
1149
  }).out();
732
1150
  const seconds = g.node('PrimitiveFloat', { value: p.fps_seconds }).out(); // id .1
1151
+ // ONE CLOCK (AUDIO-2): the seconds→frames inverse rides the doc
1152
+ // clock — fps_seconds was BOOKED at fpsClock (:length/fps), so a
1153
+ // hardcoded *24 here scaled a 16fps window's length by 1.5x. The
1154
+ // grid snap itself is clock-independent (frames are frames).
733
1155
  const lengthNode = g.node('ComfyMathExpression', {
734
- expression: MATH_STEPS_GOLD, 'values.a': seconds,
1156
+ expression: mathStepsGold(fpsClock), 'values.a': seconds,
735
1157
  }).out(1);
736
1158
  const previewed = g.node('ModelPreviewOverrideKJ', {
737
1159
  max_resolution: 512, jpeg_quality: 80,
@@ -814,6 +1236,18 @@ function renderH3Window(p, g, facts, model) {
814
1236
  throw new Error(`ref_video_trims: entry ${i} duration must be a number — got ${JSON.stringify(dur).slice(0, 40)}`);
815
1237
  return { start_time: start ?? 0, duration: dur ?? 0 };
816
1238
  });
1239
+
1240
+ // trims index-pair with the EFFECTIVE video lane — the call's
1241
+ // replaced bag when it states one, else the declared lane. A doc
1242
+ // authored against a longer declared list ([A,B,C] + [tA,tB,tC])
1243
+
1244
+ // for A) sliced X, tB/tC fell off — the wrong video's trim, never
1245
+ // a word. A trim row with no video to pair is the mis-slice's
1246
+ // signature; the compose refuses it LOUD, naming both counts.
1247
+ if (videoTrims.length > refVideos.length) {
1248
+ const lane = bagVideos.length > 0 ? 'the call replaced the lane' : 'the declared lane';
1249
+ throw new Error(`ref_video_trims: ${String(videoTrims.length)} trim rows pair with ${String(refVideos.length)} effective videos (${lane}) — a trim row with no video is the silent mis-slice; re-trim against the lane's videos`);
1250
+ }
817
1251
  const bagAudios = wireList(refBag.audios);
818
1252
  const refAudios = (bagAudios.length > 0 ? bagAudios : declaredAudios).slice(0, REF_CAPS.audios);
819
1253
  const bundleInputs = {};
@@ -919,7 +1353,7 @@ function renderH3Window(p, g, facts, model) {
919
1353
 
920
1354
  const refSize = p.ref_image_size;
921
1355
  const r2vInputs = {
922
- prompt, width: p.width, height: p.height,
1356
+ prompt: r2vPrompt, width: headW, height: headH,
923
1357
  length: lengthNode, ref_image_size: refSize,
924
1358
  clip, vae: vaeVideo, audio_vae: vaeAudio,
925
1359
  };
@@ -930,6 +1364,20 @@ function renderH3Window(p, g, facts, model) {
930
1364
  r2vInputs[`ref_video_audios.ref_video_audio_${i}`] = bout.out(10 + 2 * i);
931
1365
  r2vInputs[`ref_audios.ref_audio_${i}`] = bout.out(15 + i);
932
1366
  }
1367
+ // THE RE-SHOOT REF OVERRIDE (the official chain's appearance
1368
+
1369
+ // the identity/appearance reference the moved view re-renders
1370
+ // from (the official graph wires exactly this lane, exactly
1371
+ // here). Its audio lane is DELETED, not muted: the official
1372
+ // chain wires NO ref video audio at all, and the bundle's
1373
+ // slot-0 audio would pin sound from a DIFFERENT clip against
1374
+ // the reshoot's own source — an absent lane, never a mismatched
1375
+ // one. The bundle's video slots 1–2 and every ref_audio stay
1376
+ // theirs: the reshoot overrides the APPEARANCE seat only.
1377
+ if (reshootChain !== undefined) {
1378
+ r2vInputs['ref_videos.ref_video_0'] = reshootChain.refFrames;
1379
+ delete r2vInputs['ref_video_audios.ref_video_audio_0'];
1380
+ }
933
1381
 
934
1382
  // their natural lanes above — no slice, no shift, no fourth
935
1383
  // anything.)
@@ -956,6 +1404,16 @@ function renderH3Window(p, g, facts, model) {
956
1404
  // longer consumes a ref lane: bed + user audios keep the full
957
1405
  // 3-lane budget, and the guide is the dialogue's one owner.
958
1406
  {
1407
+
1408
+ // same slice law, the same pin law, three prompt fields. The
1409
+ // dialogue stamp keeps the measured shape (walls ride it);
1410
+ // sfx/music stamps are the same machinery on their lanes.
1411
+ // ONE CLOCK (AUDIO-2): the delay's seconds→frame reconverts
1412
+ // speak the doc clock — the stamps were booked at it in the
1413
+ // film loop; a /24 literal here pins a 16fps film's guide rows
1414
+ // late by 1.5x (lip-sync drift at the very pin the model
1415
+ // hears).
1416
+ const pinFps = typeof p.fps === 'number' && p.fps > 0 ? p.fps : DOC_FPS_DEFAULT;
959
1417
  const read = (key) => (p[key] ?? null);
960
1418
  const stamp = read('dialogue_slice');
961
1419
  if (stamp !== null) {
@@ -964,7 +1422,7 @@ function renderH3Window(p, g, facts, model) {
964
1422
  start_seconds: stamp.slice_start_seconds,
965
1423
  duration_seconds: stamp.slice_duration_seconds,
966
1424
  }).out(0);
967
- dialogueFrameIdx = Math.round(stamp.delay_seconds * 24);
1425
+ dialogueFrameIdx = Math.round(stamp.delay_seconds * pinFps);
968
1426
  }
969
1427
  const sfxStamp = read('sfx_slice');
970
1428
  if (sfxStamp !== null) {
@@ -973,7 +1431,7 @@ function renderH3Window(p, g, facts, model) {
973
1431
  start_seconds: sfxStamp.slice_start_seconds,
974
1432
  duration_seconds: sfxStamp.slice_duration_seconds,
975
1433
  }).out(0);
976
- sfxFrameIdx = Math.round(sfxStamp.delay_seconds * 24);
1434
+ sfxFrameIdx = Math.round(sfxStamp.delay_seconds * pinFps);
977
1435
  }
978
1436
  const musicStamp = read('music_slice');
979
1437
  if (musicStamp !== null) {
@@ -982,7 +1440,7 @@ function renderH3Window(p, g, facts, model) {
982
1440
  start_seconds: musicStamp.slice_start_seconds,
983
1441
  duration_seconds: musicStamp.slice_duration_seconds,
984
1442
  }).out(0);
985
- musicFrameIdx = Math.round(musicStamp.delay_seconds * 24);
1443
+ musicFrameIdx = Math.round(musicStamp.delay_seconds * pinFps);
986
1444
  }
987
1445
  }
988
1446
  const r2v = g.node('MiniMaxH3ReferenceToVideo', r2vInputs);
@@ -1035,6 +1493,28 @@ function renderH3Window(p, g, facts, model) {
1035
1493
  audio_vae: vaeAudio, audio: musicAudio,
1036
1494
  }).out(0);
1037
1495
  }
1496
+
1497
+ // this window's interior pins chain AFTER the audio pins — the
1498
+ // dialogue-measured order (audio first, image guides after; the
1499
+ // chain is positive-flows-through, so order is wiring, visible in
1500
+ // the graph). THE 17K+5 LEGALITY: a single-frame image guide is
1501
+ // lawful at EVERY row of the window's own grid (the engine's
1502
+ // 1-or-17k+5 batch rule — MiniMaxH3AddGuide treats a sub-5-frame
1503
+ // batch as one frame; the latent renders exactly p.length frames,
1504
+ // the 22+17k length law), so the only unlawful row is PAST the
1505
+ // generated tail — reachable only through a knob-pinned length
1506
+ // shorter than the authored span — and that pin SNAPS to the
1507
+ // nearest lawful row (loud comment, silent snap — the length
1508
+ // law's own idiom). The image rides the spell law's own helper:
1509
+ // a $spell rides its tensor slot verbatim, a path keeps the
1510
+ // LoadImage disk handoff (the anchor seat's exact grammar).
1511
+ for (const pin of pinsHere) {
1512
+ cond = g.node('MiniMaxH3AddGuide', {
1513
+ positive: cond, latent,
1514
+ frame_idx: Math.min(pin.frame_idx, p.length - 1),
1515
+ vae: vaeVideo, image: imageRef(pin.image),
1516
+ }).out(0);
1517
+ }
1038
1518
  }
1039
1519
  else {
1040
1520
  // t4 families: the SLA/attention switch rides ABOVE the LoRA
@@ -1069,6 +1549,7 @@ function renderH3Window(p, g, facts, model) {
1069
1549
  // the fallback arms were unreachable lies.
1070
1550
  switch: p.sla_enabled, on_true: sla, on_false: mab,
1071
1551
  }).out();
1552
+ preLoraModel = picked;
1072
1553
  const loraModel = g.node('LTX_lora_loader', {
1073
1554
  model: picked, mode: 'minimax', stack_data: loraStack,
1074
1555
  }).out();
@@ -1095,42 +1576,96 @@ function renderH3Window(p, g, facts, model) {
1095
1576
  // film total; fresh: the walked default; the 90/56 family budgets
1096
1577
  // retired with the nulling that fed them)
1097
1578
  const length = p.length;
1098
- const r2v = g.node('MiniMaxH3ReferenceToVideo', {
1099
- prompt, width: p.width,
1100
- height: p.height, length: length,
1579
+
1580
+ // trigger-led prompt + the prepared source clip as ref_video_0
1581
+ // (the official chain wires the appearance lane even on the
1582
+ // prompt-only arm — a reshoot without its source as reference
1583
+ // is the old low-quality posture). No ref video audio, the
1584
+ // official graph's own absence.
1585
+ const r2vInputs2 = {
1586
+ prompt: r2vPrompt, width: headW,
1587
+ height: headH, length: length,
1101
1588
  ref_image_size: p.ref_image_size,
1102
1589
  clip, vae: vaeVideo, audio_vae: vaeAudio,
1103
- });
1590
+ };
1591
+ if (reshootChain !== undefined) {
1592
+ r2vInputs2['ref_videos.ref_video_0'] = reshootChain.refFrames;
1593
+ // F5 (round-6 audit): node 20 takes its width/height from the
1594
+ // PREPARE node's own outputs — the prepared clip's shape is the
1595
+ // render shape, so a source aspect that differs from the doc's
1596
+ // literals cannot feed aspect-faithful refs into a differently
1597
+ // shaped latent. `length` deliberately stays the window's own
1598
+ // (one guide is shared across windows of different lengths:
1599
+ // prep.out(3) would shorten the longer ones — documented
1600
+ // divergence beside duration, F28).
1601
+ r2vInputs2['width'] = reshootChain.prepWidth;
1602
+ r2vInputs2['height'] = reshootChain.prepHeight;
1603
+ }
1604
+ const r2v = g.node('MiniMaxH3ReferenceToVideo', r2vInputs2);
1104
1605
  cond = r2v.out(0);
1105
1606
  latent = r2v.out(1);
1106
- fpsInput = 24;
1607
+ // FPS IS LAYER A, this arm too: the non-reference arm's container
1608
+ // clock rides the doc's declared fps — same law as the t4r arm's
1609
+ // fpsNode, no arm may hardcode a clock the bar disagrees with.
1610
+ fpsInput = p.fps;
1611
+ }
1612
+ // THE RE-SHOOT GUIDE PIN (the official chain's conditioning seat,
1613
+
1614
+ // own AV latent at row 0 — the H3-native image-guide lane (the
1615
+ // same node the keyframe pins ride), pinned LAST so the camera
1616
+ // geometry closes the guide chain (audio first, keyframes next,
1617
+ // the moved view's spine on top). The official graph's node 21,
1618
+ // verbatim shape; one pin per window, the shared warp handle.
1619
+ if (reshootChain !== undefined) {
1620
+ cond = applyH3ReshootCond(g, cond, latent, vaeVideo, reshootChain);
1107
1621
  }
1108
1622
 
1109
- // mods — .safetensors packs extracted under the engine's
1110
- // models/refmods/ — appended to the conditioning's reference
1111
- // tokens through ALL DiT blocks (the pack rides the model's
1112
- // native ref2va path; it spends conditioning-side tokens, never a
1113
- // bundle-bus slot, so the refs-imply-r2v law does not fire on a
1114
- // mod and BOTH arms share this one seam — Apply accepts the core
1115
- // CONDITIONING either r2v arm emits and returns the same type).
1116
- // Paths in, stems out: the loader's combo enumerates
1117
- // models/refmods/ stems, so a path arrives as its basename minus
1118
- // .safetensors — anything the engine cannot resolve refuses HERE,
1119
- // loud, instead of dying server-side as a combo miss (the I2V
1120
- // census-alignment law).
1623
+ // mods appended to the conditioning's reference tokens through ALL
1624
+ // DiT blocks (the pack rides the model's native ref2va path; it
1625
+ // spends conditioning-side tokens, never a bundle-bus slot, so the
1626
+ // refs-imply-r2v law does not fire on a mod and BOTH arms share
1627
+ // this one seam — Apply accepts the core CONDITIONING either r2v
1628
+ // arm emits and returns the same type).
1629
+
1630
+ // media kind — stills, videos, audio — and THE SYSTEM HANDLES THE
1631
+ // CONVERSION: the pack's own creator node (Create H3 RefMod /
1632
+ // MiniMaxH3RefModExtract) bakes the media into a mod at run time
1633
+ // (refs_image.ref_image_N stills ≤16, refs_video.ref_video_N frame
1634
+ // batches ≤8 — dotted autogrow addressing; audio
1635
+ // rides MiniMaxH3RefModAudioExtract). Forcing operators to
1636
+ // hand-place .safetensors packs was the regression (4f2342f46 →
1637
+ // ce79f052a), not the law. Pre-baked .safetensors stems under
1638
+ // models/refmods/ stay legal currency through the loader (the
1639
+ // listing door's rows) — a REUSE arm, never the only door.
1121
1640
 
1122
- // the run-level list — the canon's refs-lane arm (a stated call
1123
- // lane rides INSTEAD of the declared lane; absent inherits).
1124
- // Comma strings (the UI wire form) and arrays (the agent form)
1125
- // both resolve through wireList; the cap check below guards the
1126
- // EFFECTIVE list.
1641
+ // its own concept — identity/style/voice packs riding the ref2va
1642
+ // conditioning of every DiT block — never a fourth reference lane.
1643
+
1644
+ // G7: the old either/or REPLACED the declared list whenever a
1645
+ // window stated its own — a stated seat silently dropped, the
1646
+ // purge's kill class): the two spellings of the seat — the
1647
+ // run-level `ref_mods` (declared, rides EVERY window) and the
1648
+ // window's `refs.mods` (the per-call bag) — MERGE: declared
1649
+ // entries first, then the window's own not already present
1650
+ // (deduped by trimmed value), so a stated pack never drops and a
1651
+ // double-stated pack never double-spends a loader slot. Comma
1652
+ // strings (the UI wire form) and arrays (the agent form) both
1653
+ // resolve through wireList; the cap check below guards the UNION.
1654
+ // (The refs-lane REPLACE canon governs the image/video/audio BUS
1655
+ // lanes only — REFMOD IS NOT REFERENCE.)
1127
1656
  const bagMods = wireList(rb0.mods);
1128
- const refModsAll = bagMods.length > 0 ? bagMods : wireList(p.ref_mods);
1657
+ const declaredMods = wireList(p.ref_mods);
1658
+ const seenMods = new Set(declaredMods.map((m) => m.trim()));
1659
+ const refModsAll = [...declaredMods, ...bagMods.filter((m) => !seenMods.has(m.trim()))];
1129
1660
  if (refModsAll.length > 0) {
1130
1661
  if (refModsAll.length > REF_CAPS.refmods) {
1131
1662
  throw new Error(`[h3-timeline] ref_mods exceeds the loader's ${String(REF_CAPS.refmods)} slots (saw ${String(refModsAll.length)})`);
1132
1663
  }
1133
- const modStem = (src) => {
1664
+ const modStems = [];
1665
+ const modImages = [];
1666
+ const modVideos = [];
1667
+ const modAudios = [];
1668
+ for (const src of refModsAll) {
1134
1669
  // Trim, then query-strip (the estate precedent:
1135
1670
  // timelineContract's _kindOfFile splits '?' first), then split
1136
1671
  // on BOTH separators — a backslash-prefixed or padded entry
@@ -1138,26 +1673,135 @@ function renderH3Window(p, g, facts, model) {
1138
1673
  // the stem and die server-side as a combo miss. The two `as`
1139
1674
  // casts are total (split always yields a non-empty array), so
1140
1675
  // this adds no defensive branches to the coverage face.
1141
- const query = src.trim().split('?')[0];
1676
+ // A data: URL rides VERBATIM past the split (the studio's
1677
+ // upload chips commit data URLs; the run's staging walk
1678
+ // uploads them into the engine's input tree and rewrites the
1679
+ // load nodes' slots — the family reads off the MIME here).
1680
+ const raw = src.trim();
1681
+ const query = raw.split('?')[0];
1142
1682
  const base = query.split(/[\\/]/).pop();
1143
- if (!base.endsWith('.safetensors')) {
1144
- throw new Error(`[h3-timeline] ref_mods entries are .safetensors mods under models/refmods/ (saw '${src}')`);
1683
+ if (raw.startsWith('data:')) {
1684
+ const mime = /^data:([^;,]+)[;,]/.exec(raw)?.[1] ?? '';
1685
+ if (mime.startsWith('image/'))
1686
+ modImages.push(raw);
1687
+ else if (mime.startsWith('video/'))
1688
+ modVideos.push(raw);
1689
+ else if (mime.startsWith('audio/'))
1690
+ modAudios.push(raw);
1691
+ else {
1692
+ throw new Error(`[h3-timeline] ref_mods entries are ANY media (image/video/audio — the system bakes the pack) or pre-baked .safetensors stems under models/refmods/ (saw '${src.slice(0, 60)}')`);
1693
+ }
1694
+ continue;
1695
+ }
1696
+ if (base.endsWith('.safetensors')) {
1697
+ modStems.push(base.slice(0, -'.safetensors'.length));
1698
+ continue;
1145
1699
  }
1146
- return base.slice(0, -'.safetensors'.length);
1700
+ // ANY media kind boards (mediaKindOf — the contracts SSOT):
1701
+ // image → the creator's refs_image.ref_image_N, video →
1702
+ // refs_video.ref_video_N via the component split, audio → the
1703
+ // audio extractor. Anything
1704
+ // the estate does not recognize as media refuses HERE, loud,
1705
+ // instead of dying server-side (the I2V census-alignment law).
1706
+ const kind = mediaKindOf(base);
1707
+ if (kind === 'image')
1708
+ modImages.push(query);
1709
+ else if (kind === 'video')
1710
+ modVideos.push(query);
1711
+ else if (kind === 'audio')
1712
+ modAudios.push(query);
1713
+ else {
1714
+ throw new Error(`[h3-timeline] ref_mods entries are ANY media (image/video/audio — the system bakes the pack) or pre-baked .safetensors stems under models/refmods/ (saw '${src}')`);
1715
+ }
1716
+ }
1717
+ // The chain's law: each mods source appends through its own
1718
+ // Apply (Apply passes conditioning through, one mods input), in
1719
+ // fixed order — pre-baked stems, the baked visual pack, then
1720
+ // each baked audio pack.
1721
+ const applyMods = (mods) => {
1722
+ cond = g.node('MiniMaxH3RefModApply', {
1723
+ conditioning: cond, mods, override: false, retention: 1,
1724
+ curve_direction: 'constant', scramble_seed: -1,
1725
+ curve_shape: 'linear', curve_value: 1,
1726
+ }).out(0);
1147
1727
  };
1148
- const loaderInputs = { show_info: false };
1149
- for (let i = 0; i < REF_CAPS.refmods; i++) {
1150
- const src = refModsAll[i];
1151
- loaderInputs[`mod_${i + 1}`] = src === undefined ? '(none)' : modStem(src);
1152
- loaderInputs[`strength_${i + 1}`] = 1;
1153
- loaderInputs[`copies_${i + 1}`] = 1;
1728
+ if (modStems.length > 0) {
1729
+ const loaderInputs = { show_info: false };
1730
+ for (let i = 0; i < REF_CAPS.refmods; i++) {
1731
+ const stem = modStems[i];
1732
+ loaderInputs[`mod_${i + 1}`] = stem === undefined ? '(none)' : stem;
1733
+ loaderInputs[`strength_${i + 1}`] = 1;
1734
+ loaderInputs[`copies_${i + 1}`] = 1;
1735
+ }
1736
+ applyMods(g.node('MiniMaxH3RefModsLoader', loaderInputs).out(0));
1737
+ }
1738
+ if (modImages.length > 0 || modVideos.length > 0) {
1739
+ // One creator node stacks every visual ref of the seat into a
1740
+ // single video-kind mod (the node's own grammar: stills into
1741
+ // the refs_image autogrow container's grown slots, frame
1742
+ // batches into refs_video's — DOTTED container.slot addressing,
1743
+ // the r2v ref_images.ref_image_0 receipt; a BARE ref_image_1
1744
+ // key is an undeclared input and phase 1 refuses it, the
1745
+
1746
+ // ref's basename, sanitized node-side — a data: upload chip
1747
+ // has no basename, so a data-only seat names the generic
1748
+ // 'mod'. save rides the node default (true) so the baked pack
1749
+ // lands in the loader's dropdown for later reuse.
1750
+ const firstVisual = (modImages[0] ?? modVideos[0]);
1751
+ const nameBase = firstVisual.startsWith('data:') ? 'mod' : firstVisual.split(/[\\/]/).pop()?.replace(/\.[^.]+$/, '') ?? 'mod';
1752
+ // THE STATED BAKE (study §5/§7.2; value-arms ARMs 13/14): the
1753
+ // fidelity dials are DECLARED params (schema.ts, the refmod
1754
+ // group) and ride the node verbatim. Before this, pool and
1755
+ // identity were SILENT engine defaults (nothing named them)
1756
+ // and mode/save were pinned constants — the dials did not
1757
+ // exist on this lane. The fallbacks are the declared defaults
1758
+ // verbatim — one owner, the schema.
1759
+ const bakeMode = typeof p.refmod_mode === 'string' ? p.refmod_mode : 'Compressed Reference';
1760
+ const bakePool = typeof p.refmod_pool === 'number' && Number.isFinite(p.refmod_pool) ? p.refmod_pool : 16;
1761
+ const bakeIdentity = typeof p.refmod_identity === 'number' && Number.isFinite(p.refmod_identity) ? p.refmod_identity : 500;
1762
+ const extractInputs = {
1763
+ name: nameBase,
1764
+ mode: bakeMode, concept_type: 'generic',
1765
+ save: p.refmod_save !== false,
1766
+ pool_h: bakePool, pool_w: bakePool, identity: bakeIdentity,
1767
+
1768
+ // (MiniMax-H3 VAE loader) or a standard VAE' — the engine
1769
+ // refuses the extract at run time without one; both inputs
1770
+ // are schema-optional, so no phase-1 judge can catch it).
1771
+ // The family's own optimized H3 VAE rides (the int8-convrot
1772
+ // video VAE, the same handle the film lane loads); no
1773
+ // MINIMAX_H3_AV_ENCODER loader node exists in this engine's
1774
+ // /object_info, so the standard-VAE input is THE wire.
1775
+ vae: vaeVideo,
1776
+ };
1777
+ modImages.forEach((img, i) => {
1778
+ extractInputs[`refs_image.ref_image_${i}`] = g.node('LoadImage', { image: img, upload: 'image' }).out(0);
1779
+ });
1780
+ modVideos.forEach((vid, i) => {
1781
+ extractInputs[`refs_video.ref_video_${i}`] = g.node('GetVideoComponents', {
1782
+ video: g.node('LoadVideo', { file: vid }).out(),
1783
+ }).out(0);
1784
+ });
1785
+ applyMods(g.node('MiniMaxH3RefModExtract', extractInputs).out(0));
1786
+ }
1787
+ for (const src of modAudios) {
1788
+ // Audio mods are their own extractor (AUDIO in, one mod out);
1789
+ // one node per entry, voice-grade defaults, saved for reuse
1790
+ // (a data: upload chip names the generic 'audio_mod').
1791
+ // budget_policy + concept_type are REQUIRED bare combos in the
1792
+ // engine's /object_info — no declared default, so no primed
1793
+ // builder autofills them (the B7 wall refuses at compose) — the
1794
+ // graph states the pack's own signature defaults
1795
+ // (vendor/ComfyUI-MiniMaxH3Mod/nodes.py:2143: budget_policy
1796
+ // 'error', concept_type 'voice').
1797
+ applyMods(g.node('MiniMaxH3RefModAudioExtract', {
1798
+ audio: g.node('LoadAudio', { audio: src }).out(),
1799
+ audio_vae: vaeAudio,
1800
+ name: src.startsWith('data:') ? 'audio_mod' : src.split(/[\\/]/).pop()?.replace(/\.[^.]+$/, '') ?? 'audio_mod',
1801
+ budget_policy: 'error', concept_type: 'voice',
1802
+ save: true,
1803
+ }).out(0));
1154
1804
  }
1155
- const mods = g.node('MiniMaxH3RefModsLoader', loaderInputs).out(0);
1156
- cond = g.node('MiniMaxH3RefModApply', {
1157
- conditioning: cond, mods, override: false, retention: 1,
1158
- curve_direction: 'constant', scramble_seed: -1,
1159
- curve_shape: 'linear', curve_value: 1,
1160
- }).out(0);
1161
1805
  }
1162
1806
  // ── sampler stack ──────────────────────────────────────────────────
1163
1807
  // card knob first (seed), renderer alias second.
@@ -1183,6 +1827,15 @@ function renderH3Window(p, g, facts, model) {
1183
1827
  // boarding gate — the rows are the operator's BENCH row, 002 H1)
1184
1828
  // and every row fact (schedule capability, strength ceiling, the
1185
1829
  // clip/mask channels) arrived stamped by the service resolution.
1830
+
1831
+ // just ahead of it: the CrossView LoRA on the post-shift model —
1832
+ // the official order (distill lora → shift → attention → the
1833
+ // CrossView LoRA LAST) so the camera-trained adapters win, with
1834
+ // any file-based picks refining on top. The hoisted reshootChain
1835
+ // (the window head) is the one build — the film loop's stamped
1836
+ // handles or the single-window's own.
1837
+ if (reshootChain !== undefined)
1838
+ sigmaModel = applyH3ReshootModel(g, sigmaModel, p);
1186
1839
  sigmaModel = applyH3FunControlNets(g, sigmaModel, vaeVideo, fireControlNets(model, p));
1187
1840
  const schedName = p.sched_name;
1188
1841
  const denoiseVal = p.denoise;
@@ -1244,8 +1897,10 @@ function renderH3Window(p, g, facts, model) {
1244
1897
  // primary stack above NEVER changes), full-denoise short
1245
1898
  // schedule from the same noise seed, riding the doc's own
1246
1899
  // sampler/scheduler (the rider owns NO solver of its own — one
1247
- // owner per knob). Mounted ONLY when the service resolved a
1248
- // refine row; absent = the graph renders exactly as before.
1900
+ // owner per knob). Mounted ONLY when resolveRefineSeat above
1901
+ // assembles the rider (the door's single owner — the engine
1902
+ // service carries no refine assembly of its own); absent = the
1903
+ // graph renders exactly as before.
1249
1904
  // The TaoMate refiner thread's mechanics: pass A full, pass B
1250
1905
  // closes. The rider sits UPSTREAM of decode AND of the film's
1251
1906
  // seam handles — the chained texture is the refined one.
@@ -1254,16 +1909,99 @@ function renderH3Window(p, g, facts, model) {
1254
1909
  // refine each AND it with their own switch (legacy docs with
1255
1910
  // leaves set but no master render the plain pass, byte-stable).
1256
1911
  const secondPassOn = p.second_pass_enabled === true;
1257
- const refine = secondPassOn ? p.refine : undefined;
1912
+ const refine = resolveRefineSeat(p);
1913
+ // ── THE P2 LATENT-UPSCALE HANDOFF (SOTA plan Phase P2 — mounts
1914
+ // BEFORE the rider: the rider goes in-band on the UPSCALED
1915
+ // latent, ARM 43): the handoff's latent edge names the pass-1
1916
+ // sampler's output (the sampled joint AV — 24 video ch, ARM 38),
1917
+ // lock_audio true preserves pass-1 audio exactly, and the decode
1918
+ // below rides latOut so it decodes the upscaled latent (ARM 39).
1919
+
1920
+ // spec's diagnostic matrix names the mechanism — "Distilled LoRAs
1921
+ // at low denoise predict invalid noise fields" (the plastic/waxy
1922
+ // skin face); its cure row seats "Un-distilled b30-49 Base
1923
+ // Checkpoint" for pass 2. So whenever the primary bag carries a
1924
+ // counting distill AND the pass-2 window is sub-1 (the handoff's
1925
+ // window is ALWAYS sub-1 — its sigmas law below refuses 1.0), the
1926
+ // refine rider and the latent handoff mount on the PRE-LORA chain
1927
+ // instead of sigmaModel: the picked UNET+switch edge + the AdaLN
1928
+ // fix + the doc's own shift grid + the same fun-controlnet wrap —
1929
+ // every conditioning a pass needs, minus the distill. At denoise
1930
+ // 1.0 the rider keeps the primary stack (the TaoMate full mechanic
1931
+ // — pass A full, pass B closes — unchanged); with no counting row
1932
+ // the primary stack already IS the un-distilled base.
1933
+ // the bag's own truth: absent p.loras = the default
1934
+ // H3_DEFAULT_LORA_ID row (h3_lightx2v_turbo) rides via
1935
+ // loraStackDefault — a counting distill; a stated bag
1936
+ // rides a counting row iff the marriage sees one.
1937
+ const distillRides = Array.isArray(p.loras) ? marriedBagKnob(p, 'steps') !== null : true;
1938
+ const riderSubOne = refine !== undefined && refine.denoise < 1;
1939
+ let pass2Model = sigmaModel;
1940
+ if (distillRides && (upscaleOn || riderSubOne)) {
1941
+ const pass2Adaln = g.node('H3AdaLNLoRAFix', { model: preLoraModel, mode: 'port' }).out();
1942
+ const pass2Shift = g.node('MiniMaxH3SigmaShift', {
1943
+ model: pass2Adaln, shift_video: shiftVideo, shift_audio: p.shift_audio,
1944
+ }).out();
1945
+ pass2Model = applyH3FunControlNets(g, pass2Shift, vaeVideo, fireControlNets(model, p));
1946
+ }
1947
+ if (upscaleOn) {
1948
+ // THE STAGE-2 SCHEDULE: the married steps AT THIS SEAT — the
1949
+ // rider's own count when it mounts (the in-band marriage), else
1950
+ // the doc steps (a riderless stated refine_steps is a cross-gate
1951
+ // leaf, ARM 45's ARM-5 heir — it never reaches this schedule);
1952
+ // the denoise is the shared Stage-2 seat (resolveStage2Denoise
1953
+ // above — rides with or without the rider, the P2 verdict's
1954
+ // core). THE PARTIAL-DENOISE LAW (the vendored sequence node's
1955
+ // own contract — nodes/minimax_h3_refine.py run_h3_refinement:
1956
+ // sigmas must be 1-dim, ≥2 finite entries, and
1957
+ // 0 <= sigmas[0] < 1 STRICT; a full-noise sigma discards the
1958
+ // learned upscaled latent and the node throws at the engine).
1959
+ // A BasicScheduler full schedule (denoise 1.0) opens AT sigma_max
1960
+ // — so denoise 1.0 is ILLEGAL on this arm and refuses HERE, in
1961
+ // the handoff's own voice naming the sigmas law (ARM 46 fires
1962
+ // it). Off-arm 1.0 stays legal (the rider's taomate full-denoise
1963
+ // mechanic never crosses this node).
1964
+ const stage2Denoise = resolveStage2Denoise(p);
1965
+ if (stage2Denoise >= 1) {
1966
+ throw new Error(`h3 action: refine_denoise 1 composes no partial-denoise window — the latent-upscale handoff requires 0 <= sigmas[0] < 1 (vendored MinimaxH3LatentUpscaler3DRefineHandoff, run_h3_refinement: a full-noise sigma discards the upscaled latent); state a window below 1 (the researched 0.30–0.35) or turn upscale_route off for the taomate full-denoise mechanic`);
1967
+ }
1968
+ const stage2Sched = g.node('BasicScheduler', {
1969
+ model: pass2Model, scheduler: schedName,
1970
+ steps: refine !== undefined ? refine.steps : p.steps,
1971
+ denoise: stage2Denoise,
1972
+ }).out();
1973
+ const upscaled = g.node('MinimaxH3LatentUpscaler3DRefineHandoff', {
1974
+ model: pass2Model, noise, sampler: samplerSel, positive: cond,
1975
+ sigmas: stage2Sched, latent: latOut,
1976
+ model_name: p.upscale_model,
1977
+ mode: "scale by multiplier", scale: 2.0,
1978
+ lock_audio: true, precision: "bf16", device: "cuda", cfg: 1.0,
1979
+
1980
+ // the corpus stage-2+3 member's wiring pass reds — the node
1981
+ // composed estate-side without the engine's declared-required
1982
+ // inputs, and the engine refuses the prompt on any of them).
1983
+ // Multiplier mode ignores width/height/megapixels/keep_proportion
1984
+ // — they ride the pass-2 target (full size, aspect kept) and the
1985
+ // engine's own defaults; align is the kernel's latent-alignment
1986
+ // grain (32 = its default, every 3D-conv frame boundary).
1987
+ width: p.width, height: p.height,
1988
+ keep_proportion: true, megapixels: 1,
1989
+ align: 32, offload_after_upscale: false,
1990
+ });
1991
+ latOut = upscaled.out(0);
1992
+ }
1258
1993
  if (refine !== undefined) {
1259
1994
  const refineModel = g.node('LTX_lora_loader', {
1260
- model: sigmaModel, mode: 'minimax',
1995
+ model: pass2Model, mode: 'minimax',
1261
1996
  stack_data: JSON.stringify([{ on: true, lora: refine.name, str: refine.strength, v: 1, a: 1, t: 1 }]),
1262
1997
  lora_ui: '',
1263
1998
  }).out();
1264
1999
  const refineSched = g.node('BasicScheduler', {
1265
2000
  model: refineModel, scheduler: schedName,
1266
- steps: refine.steps, denoise: 1.0,
2001
+ // THE REFINE WINDOW (SOTA limb 1): 1.0 = the full-denoise
2002
+ // TaoMate mechanic (unstated, byte-stable); a stated window
2003
+ // (0.30–0.35) keeps pass 1's structure and polishes texture.
2004
+ steps: refine.steps, denoise: refine.denoise,
1267
2005
  }).out();
1268
2006
  const refineGuider = g.node('BasicGuider', { model: refineModel, conditioning: cond }).out();
1269
2007
  const refined = g.node('SamplerCustomAdvanced', {
@@ -1300,16 +2038,24 @@ function renderH3Window(p, g, facts, model) {
1300
2038
  }
1301
2039
  if (isT4r) {
1302
2040
  const created = g.node('CreateVideo', {
1303
- images: vdec, audio: vadec, fps: fpsInput, bit_depth: FILM_BIT_DEPTH,
2041
+
2042
+ // as every join leg — the sound VAE's 32 kHz never muxes raw, so
2043
+ // one press and one join emit one standard (48 kHz), equal-rate
2044
+ // legs paying only the stated law.
2045
+ images: vdec, audio: filmJoinAudio(g, vadec), fps: fpsInput, bit_depth: FILM_BIT_DEPTH,
1304
2046
  // color_space: pin autofill "sRGB"
1305
2047
  });
1306
2048
 
1307
- // every window saves under h3_t4_w<k> — the t4r arm's legacy
2049
+
2050
+ // under `<runId>/h3_t4_w<k>` — the t4r arm's legacy
1308
2051
  // 'video/ComfyUI' prefix died (multi-window anchored films were
1309
- // unaddressable: every window collided on one prefix, and the
1310
- // file tail's loader could not name them).
2052
+ // unaddressable), then the flat `h3_t4_w<k>` died too (the
2053
+ // harvest outlier: the swap chain's `${runId}/…` prefixes
2054
+ // harvest run-scoped, the film's flat prefixes stranded at the
2055
+ // engine output root). The subfolder is the same run-scope
2056
+ // spelling every chain save rides.
1311
2057
  const saved = g.node('SaveVideo', {
1312
- video: created.out(), filename_prefix: `h3_t4_w${k}`,
2058
+ video: created.out(), filename_prefix: `${runId}/h3_t4_w${k}`,
1313
2059
  format: 'auto', codec: 'h264',
1314
2060
  'codec.encoding': 're-encode', 'codec.encoding.crf': 10.0,
1315
2061
  });
@@ -1337,62 +2083,74 @@ function renderH3Window(p, g, facts, model) {
1337
2083
  // (V7/ours sharpened FIRST — before the upscaler could soften the
1338
2084
  // detail away). Sharpen rcas 0.3 after upscale "looks natural"
1339
2085
  // (his V9 notes). The switches stay ours; the ORDER is his.
1340
- const film = g.node('FrameInterpolationModelLoader', {
1341
- model_name: p.interp_model,
1342
- }).out();
1343
- const interpMultVal = p.interp_multiplier;
1344
- const interp = g.node('FrameInterpolate', {
1345
- interp_model: film, images: vdec, multiplier: interpMultVal,
1346
- }).out();
2086
+ //
1347
2087
 
1348
- // (declared default false). The legacy interp_switch alias is
1349
- // retired — post-declaration the walk materializes the primary,
1350
- // so the alias arm was unreachable dead law.
1351
- const interpSwOn = secondPassOn && p.interpolate_enabled;
1352
- const interpSw = g.node('ComfySwitchNode', {
1353
- switch: interpSwOn, on_true: interp, on_false: vdec,
1354
- }).out();
1355
- const srRes = p.sr_resolution;
1356
- const sr = g.node('SeedVR2VideoUpscaler', {
1357
- image: interpSw,
1358
- dit: g.node('SeedVR2LoadDiTModel', {
1359
- model: p.sr_model, device: 'cuda:0',
1360
- }).out(),
1361
- vae: g.node('SeedVR2LoadVAEModel', {
1362
- model: LANE_FILES.sr_vae, device: 'cuda:0',
1363
- }).out(),
1364
- seed: 42, resolution: srRes,
1365
- max_resolution: 0, batch_size: 5, uniform_batch_size: false,
1366
- color_correction: 'lab',
1367
- }).out();
2088
+ // VIDEO UI LIE… IT WILL ALWAYS UPSCALE") ── each limb mounts
2089
+ // IFF its own doc gate is on; an off limb composes NO node at
2090
+ // all. The pre-burn shape built every limb unconditionally and
2091
+ // routed a lazy ComfySwitchNode around each — the serialized
2092
+ // graph (a face the operator and the engine queue both read)
2093
+ // carried SeedVR2 + interp + sharpen on EVERY doc, switches or
2094
+ // not: the graph itself said "always upscale". The TS build now
2095
+ // picks the wire at compose time — the same mount-behind-the-
2096
+ // gate law the latent-upscale handoff and the refine rider
2097
+ // already ride — and the V9 ORDER is preserved by threading one
2098
+ // `postImage` handle down the chain.
2099
+ let postImage = vdec;
2100
+ const interpOn = secondPassOn && p.interpolate_enabled;
2101
+ if (interpOn) {
2102
+ const film = g.node('FrameInterpolationModelLoader', {
2103
+ model_name: p.interp_model,
2104
+ }).out();
2105
+ const interpMultVal = p.interp_multiplier;
2106
+ const interp = g.node('FrameInterpolate', {
2107
+ interp_model: film, images: postImage, multiplier: interpMultVal,
2108
+ }).out();
2109
+ postImage = interp;
2110
+ }
1368
2111
  const srSwOn = secondPassOn && p.sr_switch;
1369
- const srSw = g.node('ComfySwitchNode', {
1370
- switch: srSwOn, on_true: sr, on_false: interpSw,
1371
- }).out();
2112
+ if (srSwOn) {
2113
+ const srRes = p.sr_resolution;
2114
+ const sr = g.node('SeedVR2VideoUpscaler', {
2115
+ image: postImage,
2116
+ dit: g.node('SeedVR2LoadDiTModel', {
2117
+ model: p.sr_model, device: 'cuda:0',
2118
+ }).out(),
2119
+ vae: g.node('SeedVR2LoadVAEModel', {
2120
+ model: LANE_FILES.sr_vae, device: 'cuda:0',
2121
+ }).out(),
2122
+ seed: 42, resolution: srRes,
2123
+ max_resolution: 0, batch_size: 5, uniform_batch_size: false,
2124
+ color_correction: 'lab',
2125
+ }).out();
2126
+ postImage = sr;
2127
+ }
1372
2128
  // sharpen LAST (V9): the upscaler softens; rcas after it restores.
1373
2129
  // Renderer alias second (sharpen_* leaves above build the method).
1374
- const sharpened = g.node('ImageSharpenKJ', { image: srSw, method }).out();
1375
- const sharpSw = g.node('ComfySwitchNode', {
1376
- switch: secondPassOn && p.sharpen_enabled, on_true: sharpened, on_false: srSw,
1377
- }).out();
2130
+ if (secondPassOn && p.sharpen_enabled) {
2131
+ const sharpened = g.node('ImageSharpenKJ', { image: postImage, method }).out();
2132
+ postImage = sharpened;
2133
+ }
1378
2134
 
1379
2135
  // CreateVideo.fps = base × interp multiplier (his Enhancements:
1380
2136
  // PrimitiveFloat 24 → ComfyMathExpression "a * 2" → fps). Without
1381
2137
  // it every interp-on window plays at HALF speed — the frames
1382
- // double, the fps doesn't. Byte-stable at defaults (interp off →
1383
- // the served literal 24).
1384
- const interpOn = secondPassOn && p.interpolate_enabled;
1385
- const interpMult = p.interp_multiplier;
2138
+ // double, the fps doesn't. THE BASE IS THE DOC'S CLOCK, never a
2139
+ // hardcoded 24 (audit f1cc1197: this seat rode a literal while
2140
+ // the fpsInput "cure" above sat dead — the exact dead-store
2141
+ // class: a line that looks like a fix and never fires).
1386
2142
  const created = g.node('CreateVideo', {
1387
- images: sharpSw, audio: vadec, fps: interpOn ? 24 * interpMult : 24, bit_depth: FILM_BIT_DEPTH,
2143
+ // F25: the same join-rate door — the film standard is ONE rate
2144
+ // on every mux seat (t4r above, this window arm, every join).
2145
+ images: postImage, audio: filmJoinAudio(g, vadec), fps: interpOn ? fpsInput * p.interp_multiplier : fpsInput, bit_depth: FILM_BIT_DEPTH,
1388
2146
  // color_space: pin autofill "sRGB"
1389
2147
  });
1390
2148
  const saved = g.node('SaveVideo', {
1391
- video: created.out(), filename_prefix: `h3_t4_w${k}`,
2149
+ video: created.out(), filename_prefix: `${runId}/h3_t4_w${k}`,
1392
2150
  format: 'mp4', codec: 'h264',
1393
2151
  });
1394
2152
  rawHandles.savePassthrough = saved.out(0);
1395
- delivered = { images: sharpSw, audio: vadec };
2153
+ delivered = { images: postImage, audio: vadec };
1396
2154
  }
1397
2155
  // (every family path delivers — both arms save the window's clip;
1398
2156
  // no null arm: the family dispatch is exhaustive over FAMILIES.
@@ -1417,6 +2175,103 @@ function renderH3Window(p, g, facts, model) {
1417
2175
  * schema's own filter law — a retyped list would be a second
1418
2176
  * SSOT). */
1419
2177
  const H3_SAMPLER_OPTIONS = SAMPLER_OPTIONS.filter((n) => H3_RECOMMENDED_SAMPLERS.includes(n));
2178
+
2179
+
2180
+
2181
+
2182
+
2183
+
2184
+
2185
+
2186
+
2187
+
2188
+
2189
+
2190
+
2191
+
2192
+
2193
+
2194
+
2195
+
2196
+ function applyKeyframeCompose(p) {
2197
+ const kfRows = Array.isArray(p.keyframes) ? p.keyframes : [];
2198
+ if (kfRows.length === 0)
2199
+ return;
2200
+ const calls = Array.isArray(p.calls) ? p.calls : [];
2201
+ const str = (v) => (typeof v === 'string' ? v.trim() : '');
2202
+ const num = (v) => (typeof v === 'number' && Number.isFinite(v) ? v : null);
2203
+ const wins = calls.map((row, i) => {
2204
+ const sf = num(row.start_frame);
2205
+ const ef = num(row.end_frame);
2206
+ if (sf === null || ef === null || ef <= sf)
2207
+ return null;
2208
+ const carry = i > 0 ? transitionOverlap(typeof row.transition === 'string' ? row.transition : undefined) : 0;
2209
+ return { sf, ef, genStart: sf - carry, rides: { pins: [] }, row, forked: false };
2210
+ });
2211
+ const ridesByK = new Map();
2212
+ const fork = (w) => {
2213
+ if (!w.forked) {
2214
+ w.row = { ...w.row };
2215
+ w.forked = true;
2216
+ }
2217
+ return w.row;
2218
+ };
2219
+ for (const kf of kfRows) {
2220
+ // (the gate above guarantees a finite frame and a covering window)
2221
+ const f = kf.frame;
2222
+ const image = str(kf.image);
2223
+ const w = wins.find((win) => win !== null && f >= win.sf && f <= win.ef - 1);
2224
+ if (w === undefined)
2225
+ continue; // unreachable post-gate; the gate owns the refusal
2226
+ if (f === w.sf && w.rides.anchor === undefined && !isSeatStated(w, 'anchor')) {
2227
+ fork(w).image = image;
2228
+ w.rides.anchor = image;
2229
+ continue;
2230
+ }
2231
+ if (f === w.ef - 1 && w.rides.endAnchor === undefined && !isSeatStated(w, 'end')) {
2232
+ fork(w).last_frame = image;
2233
+ w.rides.endAnchor = image;
2234
+ continue;
2235
+ }
2236
+ // strictly interior — or a boundary seat already claimed (the first
2237
+ // pin won it): the interior arm, so the image still reaches the graph
2238
+ w.rides.pins.push({ image, frame_idx: f - w.genStart });
2239
+ }
2240
+ for (const [i, w] of wins.entries()) {
2241
+ if (w === null)
2242
+ continue;
2243
+ if (w.forked)
2244
+ calls[i] = w.row;
2245
+ if (w.rides.pins.length > 0) {
2246
+ w.rides.pins.sort((a, b) => a.frame_idx - b.frame_idx);
2247
+ ridesByK.set(i + 1, w.rides);
2248
+ }
2249
+ }
2250
+ if (ridesByK.size > 0) {
2251
+ const channel = {};
2252
+ for (const [k, rides] of ridesByK)
2253
+ channel[String(k)] = rides.pins;
2254
+ p.__keyframe_pins = channel;
2255
+ }
2256
+ /** A window's own stated seat (the canon's Layer B claim): the row's
2257
+ * guide spellings (the film loop's exact union) or its end anchor;
2258
+ * on the single-window shape the DOC-level seat is the same seat —
2259
+ * a stated one wins over the pin there too. */
2260
+ function isSeatStated(w, seat) {
2261
+ if (seat === 'anchor') {
2262
+ if (str(w.row.image) !== '' || str(w.row.ref_image) !== '' || str(w.row.image_name) !== '')
2263
+ return true;
2264
+ if (calls.length === 1 && str(p.image) !== '')
2265
+ return true;
2266
+ return false;
2267
+ }
2268
+ if (str(w.row.last_frame) !== '')
2269
+ return true;
2270
+ if (calls.length === 1 && str(p.last_frame) !== '')
2271
+ return true;
2272
+ return false;
2273
+ }
2274
+ }
1420
2275
  export const film = {
1421
2276
  id: 'film',
1422
2277
  inputs: [],
@@ -1439,9 +2294,23 @@ export const film = {
1439
2294
  // fps_seconds) are internal. ref_image_size is the schema's
1440
2295
  // const-or-WxH pattern tier — typed as its string spine.
1441
2296
  params: [
1442
- { name: "prompt", type: "string" },
1443
- { name: "image", type: "string" },
1444
- { name: "last_frame", type: "string" },
2297
+
2298
+ // ui-truth-gap #5): this face advertised a key the card's door
2299
+ // REFUSES — `prompt` rides neither the h3-timeline rider list nor
2300
+ // its admits, and the single-call LIFT writes p.prompt from the
2301
+ // call's own text (card.ts, "if (typeof single.text === ...)").
2302
+ // An agent that trusted this row got 'unknown-param' at the door.
2303
+ // The compose still reads p.prompt (the lift's write); the
2304
+ // ADVERTISED surface is what changed.
2305
+ // THE SCALAR MEDIA SEATS (the NO-DROP law's write half, D8 /
2306
+ // CONTRACTS §4 debt 16 — run-899a8448's burn: the seats declared
2307
+ // plain "string", so the declared plane offered freehand text for
2308
+ // a media seat and the UI wrote a stage name into one). They are
2309
+ // IMAGE seats: a media path at the wire, the form's picker +
2310
+ // upload face — the carrier schema's own `wtype: 'image'` rows
2311
+ // (schema.ts) are the same truth on the serve plane.
2312
+ { name: "image", type: "image" },
2313
+ { name: "last_frame", type: "image" },
1445
2314
  { name: "ref_images", type: "image_list" },
1446
2315
  { name: "ref_videos", type: "image_list" },
1447
2316
  { name: "ref_audios", type: "image_list" },
@@ -1449,7 +2318,7 @@ export const film = {
1449
2318
  { name: "duck_depth_db", type: "number", bounds: [-48, 0] },
1450
2319
  { name: "seed", type: "number", rule: "seed-sentinel" },
1451
2320
  { name: "width", type: "number", bounds: [448, 1344] },
1452
- { name: "height", type: "number", bounds: [448, 768] },
2321
+ { name: "height", type: "number", bounds: [448, 1344] },
1453
2322
  { name: "length", type: "number", bounds: [22, 362] },
1454
2323
  { name: "steps", type: "number", bounds: [4, 30] },
1455
2324
  { name: "second_pass_enabled", type: "boolean" },
@@ -1468,6 +2337,23 @@ export const film = {
1468
2337
  { name: "refine_lora", type: "string" },
1469
2338
  { name: "refine_strength", type: "number", bounds: [0, 2] },
1470
2339
  { name: "refine_steps", type: "number", bounds: [1, 10] },
2340
+ // THE REFINE WINDOW (SOTA limb 1): [0.05, 1] — ONE domain with
2341
+ // the schema row and the resolver above (parity walled by ARM
2342
+ // 4f); 1 is the full-denoise taomate mechanic (the default)
2343
+ { name: "refine_denoise", type: "number", bounds: [0.05, 1] },
2344
+ // THE LATENT-UPSCALE ROUTE (SOTA plan Phase P2 — the P2 verdict's
2345
+ // own seats on the family door): the sub-gate + its closed file
2346
+ // surface ride the door like every knob — h3-window-parity's
2347
+ // undeclaredServed arm names them, the census witnesses them at
2348
+ // ARM 37. The route is the OFF-latched union (off default,
2349
+ // byte-stable); the model is the on-disk LBH v1 3D-conv bf16
2350
+ // checkpoint (single-member vocabulary, the sr_model precedent).
2351
+ { name: "upscale_route", type: "enum", options: ["off", "latent_2x"] },
2352
+ { name: "upscale_model", type: "enum", options: ["minimax_h3_latent_upscaler_3d_bf16.safetensors"] },
2353
+ // THE RE-SHOOT SURFACE (feature 024): the commission rides the
2354
+ // card's RESHOOT_MOD bag now (the fourth-mod-bag unification,
2355
+ // §8) — the door's flat rows died with the schema group; the
2356
+ // bag's own field rows are the served truth.
1471
2357
  { name: "attention_backend", type: "enum", options: ["comfy kitchen attention", "pytorch attention"] },
1472
2358
  { name: "sr_switch", type: "boolean" },
1473
2359
  { name: "sr_resolution", type: "number", bounds: [720, 2160] },
@@ -1489,12 +2375,68 @@ export const film = {
1489
2375
  { name: "interp_switch", type: "boolean" },
1490
2376
  { name: "sharpen_switch", type: "boolean" },
1491
2377
  { name: "sla_switch", type: "boolean" },
2378
+ // THE BAKE'S STATED DIALS (study §5/§7.2; value-arms ARMs 13/14):
2379
+ // the RefMod extract's fidelity dials, declared on the serve plane
2380
+ // (schema.ts, the refmod group) and stated at the node (the
2381
+ // extract inputs). The family door judges them like every knob.
2382
+ { name: "refmod_mode", type: "enum", options: ["Compressed Reference", "Full Reference"] },
2383
+ { name: "refmod_pool", type: "number", bounds: [2, 64] },
2384
+ { name: "refmod_identity", type: "number", bounds: [0, 2000] },
2385
+ { name: "refmod_save", type: "boolean" },
1492
2386
  { name: "image_name", type: "string" },
1493
2387
  ],
1494
2388
  facts: parseH3Facts,
1495
- build({ p: docIn, facts, g, model }) {
2389
+ build({ p: docIn, facts, g, model, runId }) {
1496
2390
  const p = { ...docIn };
1497
2391
 
2392
+ // a pin's frame is FILM-absolute and must fall INSIDE some call's
2393
+ // [start_frame, end_frame) span; a pin in a gap has no window to
2394
+ // ride (the lane's whole truth is per-window compose), so it
2395
+ // refuses HERE — the same plan door that refuses a textless call —
2396
+ // never a silent unplaced pin (the no-drop law). Both window
2397
+ // shapes pass through this door (the film plan and the frozen
2398
+ // single-window doc), so one gate owns both. Slice 2 adds the pin
2399
+ // SHAPE arms — a pin must CARRY an image that names media (a
2400
+ // frameless or stage-named row anchors nothing and would silently
2401
+ // vanish or die at the engine door) — and then the pin→seat/
2402
+ // pin-node MAPPING lands below: an endpoint pin rides the window's
2403
+ // existing anchor/end-anchor seats, an interior pin rides the
2404
+ // AddGuide image chain.
2405
+ const kfRows = Array.isArray(p.keyframes) ? p.keyframes : [];
2406
+ if (kfRows.length > 0) {
2407
+ const windows = (Array.isArray(p.calls) ? p.calls : [])
2408
+ .map((c) => ({ start: c.start_frame, end: c.end_frame }))
2409
+ .filter((w) => typeof w.start === 'number' && Number.isFinite(w.start)
2410
+ && typeof w.end === 'number' && Number.isFinite(w.end));
2411
+ // Row SHAPE is the walk's literal too (assertKeyframeRowShape) —
2412
+ // called here so a doc that skipped the walk (a raw run body)
2413
+ // still speaks the same vocabulary; placement/media stay below.
2414
+ assertKeyframeRowShape(kfRows);
2415
+ for (let ki = 0; ki < kfRows.length; ki++) {
2416
+ const kf = (kfRows[ki] ?? {});
2417
+ const f = kf.frame;
2418
+ const image = kf.image.trim();
2419
+ if (!isMediaRef(image)) {
2420
+ throw new Error(`keyframes[${ki}]: "${image}" names no media — a stage/card name is not an image ` +
2421
+ '(pick the artifact: a file path, URL, or $spell rides; a label never does)');
2422
+ }
2423
+ const covered = windows.some((w) => f >= w.start && f <= w.end - 1);
2424
+ if (!covered) {
2425
+ const plan = windows.length > 0
2426
+ ? `[${windows[0].start}, ${windows[windows.length - 1].end})`
2427
+ : 'no windows at all (the doc names no calls)';
2428
+ throw new Error(`keyframes[${ki}]: frame ${f} falls outside every window — the plan covers ${plan}; ` +
2429
+ 'a keyframe in a gap has no window to ride (move the pin inside a window)');
2430
+ }
2431
+ }
2432
+ // THE KEYFRAME→SEAT MAPPING (slice 2): endpoint pins ride the
2433
+ // windows' existing anchor/end-anchor seats (rewritten call rows —
2434
+ // the byte-identical probe: a boundary-pin doc composes the graph
2435
+ // of the same doc stating the seats directly), interior pins ride
2436
+ // the `__keyframe_pins` channel into the AddGuide image chain.
2437
+ applyKeyframeCompose(p);
2438
+ }
2439
+
1498
2440
  // single-call doc rides the frozen single-window arm below —
1499
2441
  // which renders the DOC surface, never the row. Without this
1500
2442
  // unpack the sole call's Layer B seats (refs bag, anchor image,
@@ -1502,12 +2444,42 @@ export const film = {
1502
2444
  // the split-brain twin of the film loop's bag gate. One stanza
1503
2445
  // law, both arms: the row REPLACES the refs bag / anchor / text
1504
2446
  // seats it states (per-lane, per-seat); knobs replace per key;
1505
- // unstated seats inherit the doc.
1506
- {
1507
- const row = Array.isArray(p.calls) && p.calls.length === 1
1508
- ? p.calls[0]
2447
+ // unstated seats inherit the doc. (Runs AFTER the keyframe
2448
+ // mapping so the lift carries the mapped anchor/end-anchor seats
2449
+ // onto the doc surface — the single-window shape's byte-identical
2450
+ // endpoint probe rides this order.)
2451
+ // ONE STANZA LAW, ALL ARMS (journey audit 72b1d88a finding 1,
2452
+
2453
+ // shape (p.k set, calls > 1) renders window k on the DOC surface
2454
+ // — its row is calls[p.k - 1] (1-based, the film loop's own
2455
+ // window${k} naming). Before this arm the row's span, text,
2456
+ // refs and knobs died unread on every frozen multi-window doc,
2457
+ // and the lora bag stomped a knob-pinned steps: the split-brain
2458
+ // twin of the sole-call lift, unwalled only because no studio
2459
+ // gesture authors it — the agent plane and hand-built docs do.
2460
+ const stanzaRow = Array.isArray(p.calls) && p.calls.length === 1
2461
+ ? p.calls[0]
2462
+ : Array.isArray(p.calls) && p.calls.length > 1
2463
+ && typeof p.k === 'number' && Number.isInteger(p.k) && p.k >= 1 && p.k <= p.calls.length
2464
+ ? p.calls[p.k - 1]
1509
2465
  : null;
2466
+ {
2467
+ const row = stanzaRow;
1510
2468
  if (row !== null) {
2469
+
2470
+ // IS ALWAYS LAYER B"): the single call's span OWNS the window
2471
+ // length — lifted here through the same snap the film loop's
2472
+ // span rider uses, BEFORE the knobs assign (a deliberate
2473
+ // knob pin still wins; the walk's declared default and any
2474
+ // stale doc-level length NEVER do). Before this lift the
2475
+ // frozen arm rendered the doc's Layer-A length — a knob tied
2476
+ // to nothing the bar updates — and a 90-frame call generated
2477
+ // whatever the stale row said.
2478
+ const rowSf = typeof row.start_frame === 'number' && Number.isFinite(row.start_frame) ? row.start_frame : null;
2479
+ const rowEf = typeof row.end_frame === 'number' && Number.isFinite(row.end_frame) ? row.end_frame : null;
2480
+ if (rowSf !== null && rowEf !== null && rowEf > rowSf) {
2481
+ p.length = spanStanzaFrames({ start: rowSf, end: rowEf }, 0);
2482
+ }
1511
2483
  const rowText = typeof row.text === 'string' ? row.text.trim() : '';
1512
2484
  if (rowText !== '')
1513
2485
  p.prompt = row.text;
@@ -1543,15 +2515,42 @@ export const film = {
1543
2515
  // guide owns the reference lane.
1544
2516
  const statedFamily = typeof p.variant === 'string' && FAMILIES.includes(p.variant)
1545
2517
  ? p.variant : undefined;
1546
- if (guideImage !== '' && statedFamily !== undefined && statedFamily !== 't4r') {
2518
+ // THE KEYFRAME PIN CHANNEL CARRIES THE LANE (slice 2): a doc with
2519
+ // pins claims the reference lane wherever its pins land — an
2520
+ // endpoint pin maps onto the anchor/end-anchor seats below, an
2521
+ // interior pin composes the AddGuide image arm. Both guards below
2522
+ // count it: the conflict guard refuses a stated non-t4r family
2523
+ // over a pin-carrying doc exactly as over an anchor (the explicit
2524
+ // contract conflict is named, never silently overridden), and the
2525
+ // inverse guard admits a t4r doc whose guides ride the pin channel
2526
+ // alone (an interior pin is an image guide — the window is not
2527
+ // anchorless). (The conflict arm rides the SINGLE-WINDOW shape
2528
+ // only: a film doc's walked variant is t4_chain — the DERIVED film
2529
+ // family, never a stated conflict — and the film loop derives each
2530
+ // window's own family from its seats.)
2531
+ const kfLane = kfRows.length > 0 && Array.isArray(p.calls) && p.calls.length === 1;
2532
+ // THE SINGLE-WINDOW SHAPE ONLY (the lying-cure cure): a film's
2533
+ // doc-level guide is its opener anchor (the film loop seats it on
2534
+ // window 1, above) and each window derives its own family from its
2535
+ // own seats — the doc's walked variant is the DERIVED film family
2536
+ // (t4_chain), never a stated conflict. Refusing here told a
2537
+ // two-clip image-to-video write to "state no variant" when it had
2538
+ // stated none: the transcript's steps 5-7 loop.
2539
+ const callsRaw = p.calls;
2540
+ const isFilmDoc = Array.isArray(callsRaw) && callsRaw.length > 1;
2541
+ if ((guideImage !== '' || kfLane) && !isFilmDoc && statedFamily !== undefined && statedFamily !== 't4r') {
1547
2542
  const rbRef = (p.refs ?? {});
1548
2543
  const refsCarry = wireList(rbRef.images).length + wireList(rbRef.videos).length + wireList(rbRef.audios).length
1549
2544
  + wireList(p.ref_images).length + wireList(p.ref_videos).length + wireList(p.ref_audios).length > 0
1550
2545
  || (typeof p.last_frame === 'string' && p.last_frame.trim() !== '');
1551
2546
  if (!refsCarry) {
1552
- throw new Error(`h3_window: a guide image ("${guideImage.trim()}") rides only the t4r reference lane — ` +
1553
- `this doc's variant is '${String(p.variant)}'. State no variant (the walk derives t4r from ` +
1554
- 'the guide) or clear the guide; never a silent text-only render of a reference shot');
2547
+ throw new Error(guideImage !== ''
2548
+ ? `h3_window: a guide image ("${guideImage.trim()}") rides only the t4r reference lane — ` +
2549
+ `this doc's variant is '${String(p.variant)}'. State no variant (the walk derives t4r from ` +
2550
+ 'the guide) or clear the guide; never a silent text-only render of a reference shot'
2551
+ : `h3_window: keyframe pins ride only the t4r reference lane — this doc's variant is ` +
2552
+ `'${String(p.variant)}'. State no variant (the walk derives t4r from the pins) or clear ` +
2553
+ 'the keyframes; never a silent text-only render of a pinned shot');
1555
2554
  }
1556
2555
  }
1557
2556
 
@@ -1567,11 +2566,14 @@ export const film = {
1567
2566
  // (refs-implied t4r windows carry no anchor — the bundle IS
1568
2567
  // the r2v input; the guard admits them via the refs law — the
1569
2568
  // legacy stanza bag AND the declared input surface (the rail's
1570
- // fields) count; the bed rides the audio lane guideless too)
2569
+ // fields) count; the bed rides the audio lane guideless too;
2570
+ // slice 2: so do keyframe pins — an interior pin is an image
2571
+ // guide on the window's conditioning chain)
1571
2572
  const rbRef = (p.refs ?? {});
1572
2573
  const refsCarry = wireList(rbRef.images).length + wireList(rbRef.videos).length + wireList(rbRef.audios).length
1573
2574
  + wireList(p.ref_images).length + wireList(p.ref_videos).length + wireList(p.ref_audios).length > 0
1574
- || (typeof p.last_frame === 'string' && p.last_frame.trim() !== '');
2575
+ || (typeof p.last_frame === 'string' && p.last_frame.trim() !== '')
2576
+ || kfLane;
1575
2577
  if (!refsCarry) {
1576
2578
  throw new Error('h3_window(t4r): image-anchored window without a staged guide image — ' +
1577
2579
  'compose always injects LoadImage.0.image on this family');
@@ -1588,7 +2590,7 @@ export const film = {
1588
2590
  const docCalls = Array.isArray(p.calls) ? p.calls : null;
1589
2591
  const isFilm = docCalls !== null && docCalls.length > 1 && p.k === undefined;
1590
2592
  if (isFilm)
1591
- return renderH3Film(p, g, facts, model);
2593
+ return renderH3Film(p, g, facts, model, runId);
1592
2594
 
1593
2595
  // FILM-path consumer (it rides the accumulated film audio).
1594
2596
  // On the frozen single-window shape it would be a silent
@@ -1612,15 +2614,38 @@ export const film = {
1612
2614
  // never overwrites it.
1613
2615
  if (Array.isArray(p.loras)) {
1614
2616
  const rows = p.loras;
1615
- const applied = rows.map((r) => r.steps).filter((v) => typeof v === 'number' && Number.isFinite(v));
1616
- const singleKnobs = docCalls !== null && docCalls.length === 1
1617
- ? (docCalls[0].knobs ?? {})
2617
+ const married = marriedBagKnob(p, 'steps');
2618
+ // THE MARRIAGE'S ROW FACE: the sole call's knobs — and, since
2619
+ // the k-marked cure (journey audit 72b1d88a), the FROZEN
2620
+ // window's own row knobs too. One consult, both shapes: the
2621
+ // row the window renders is the row whose steps are the
2622
+ // user's word. The consult rides the shared helper — the
2623
+ // catalog fallback (a row's unstated count by filename) is
2624
+ // the same math here as on the film loop.
2625
+ const singleKnobs = stanzaRow !== null
2626
+ ? (stanzaRow.knobs ?? {})
1618
2627
  : {};
1619
- if (applied.length > 0 && p.__steps_pinned !== true && singleKnobs.steps === undefined) {
1620
- p.steps = Math.max(...applied);
2628
+ if (married !== null && p.__steps_pinned !== true && singleKnobs.steps === undefined) {
2629
+ p.steps = married;
1621
2630
  }
1622
2631
  }
1623
- return renderH3Window(p, g, facts, model).savePassthrough;
2632
+ // THE POST-MARRIAGE RE-WALK (the single-window face's arm of the
2633
+ // film loop's per-window walk — ERROR d, the ~100 burn): the
2634
+ // marriage lands the bag's stated count AFTER the card's one
2635
+ // walk, and without this judgment the mutated count rode into
2636
+ // the returned graph unjudged (the G6 TOCTOU — the estate's
2637
+ // faces let 100 in, the served bound packs.ts:34 is
2638
+ // min(1).max(100), the recipe row declares no steps domain). It
2639
+ // sits AFTER the render's own hand-checked seats so their pinned
2640
+ // voices fire first (the loader cap, the trim-entry shape); the
2641
+ // marriage's mutation is the only delta this re-check can add —
2642
+ // card.ts walked the same doc pre-marriage, so every other
2643
+ // refusal here was already refused upstream. The film loop
2644
+ // judges its stanza post-marriage; this face closes the same
2645
+ // TOCTOU — one schema, one voice.
2646
+ const handles = renderH3Window(p, g, facts, model, runId);
2647
+ assertOverlayGated(p, 'h3-timeline single-window knobs');
2648
+ return handles.savePassthrough;
1624
2649
  },
1625
2650
  };
1626
2651
  //# sourceMappingURL=actions.js.map