@melite/models-h3 0.1.4-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,28 +1,199 @@
1
+ import { fireControlNets } from '@melite/comfyui-card-kit/guard';
1
2
  import { saveAudio } from '@melite/comfyui-card-kit';
2
- 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';
3
5
  import { H3_LORA_ROWS } from '@melite/models-h3/mods/loras';
4
6
  import { SAMPLER_OPTIONS, SCHEDULER_OPTIONS } from '@melite/comfyui-card-kit/vocab';
5
- import { computeFilmMix, parseFilmMixClips, stanzaSecs } from "./filmMix.js";
6
- import { GRID_REMAINDER, GRID_STEP_FRAMES, IMAGE_BUS_SLOTS, REF_CAPS, assertGridLength, assertSpanGrid, imageReferenceCap, mergeDeclaredRefs, spanStanzaFrames, transitionOverlap, } from "./timelineContract.js";
7
-
8
- // built from the family lora CATALOG (mods/loras.ts — the one owner
9
- // of every lora filename and default strength; the value was
10
- // restated as a literal here, which is how a catalog edit would
11
- // have silently missed the default). The wire shape matches a
12
- // resolved bag row: on, lora (filename), str (default_strength),
13
- // plus the four fixed mode flags. A missing catalog row refuses at
14
- // 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
+ };
15
44
  const loraStackDefault = () => {
16
- const row = H3_LORA_ROWS.find((r) => r.id === 'h3_lightx2v_turbo');
45
+ const row = H3_LORA_ROWS.find((r) => r.id === H3_DEFAULT_LORA_ID);
17
46
  if (row === undefined) {
18
- throw new Error("h3 action: the lora catalog has no 'h3_lightx2v_turbo' 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`);
19
48
  }
20
49
  return JSON.stringify([{ on: true, lora: row.filename, str: row.default_strength, v: 1, a: 1, t: 1 }]);
21
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
+ }
22
191
  // His 17k+5 grid, in-graph (ComfyMathExpression): snap latent steps to 2 mod 5
23
192
  // (the card's own principles row: "Length snaps to the 17k+5 frame grid
24
- // at 24fps" — the principles).
25
- 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}`;
26
197
 
27
198
  // finding #4): MiniMaxH3ImageToVideo exists in the serialized graph
28
199
  // ONLY as the t4r family marker (finalizeH3 keys on it to skip the
@@ -49,7 +220,7 @@ const SHARPEN_DEFAULTS = { method: 'rcas', strength: 0.3, radius: 1.0, threshold
49
220
 
50
221
 
51
222
 
52
- const LANE_FILES = {
223
+ export const LANE_FILES = {
53
224
  clip: 'qwen3vl_32b_minimax_h3_int8_convrot.safetensors',
54
225
  vae_video: 'minimax_h3_video_vae_int8_convrot.safetensors',
55
226
  vae_audio: 'minimax_h3_audio_vae_fp32.safetensors',
@@ -62,6 +233,25 @@ const LANE_FILES = {
62
233
 
63
234
 
64
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
+ }
65
255
  export function parseH3Facts(raw) {
66
256
  const lane = (raw ?? {});
67
257
  const unet = lane.unet;
@@ -86,6 +276,63 @@ export const assertOverlayGated = (doc, where) => {
86
276
  throw new Error(`${where}: ${String(e)}`);
87
277
  }
88
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
+ }
89
336
  /** THE MERGED FILM: ONE prompt, N windows under `window${k}_`
90
337
  * scopes (GraphBuilder.scoped), with real seam edges between scopes
91
338
  * (the executor orders windows off the graph) and per-window
@@ -97,7 +344,7 @@ export const assertOverlayGated = (doc, where) => {
97
344
  * (the node's context_frames arm). prev_sec scales the carry:
98
345
  * picture snapped to the node's legal context lengths (5/22/39/56
99
346
  * frames — only whole latent steps), audio at 24 frames/second. */
100
- function renderH3Film(p, g, facts) {
347
+ function renderH3Film(p, g, facts, model, runId) {
101
348
  // (the compose dispatch guarantees calls is a non-empty array here)
102
349
  const calls = p.calls;
103
350
  const str = (v) => (typeof v === 'string' ? v : '');
@@ -148,6 +395,13 @@ function renderH3Film(p, g, facts) {
148
395
  // (the words law), a textless row is music (the historical
149
396
  // Music-row behavior, byte-identical for existing docs).
150
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.
151
405
  // THE FILM DOC'S SPANS — the clock's own rows, one per call, doc
152
406
  // frames with the seam word (filmMix.ts owns the law). The stanza
153
407
  // snap rides these (spanStanzaFrames): the render loop below and
@@ -163,6 +417,37 @@ function renderH3Film(p, g, facts) {
163
417
  // including absent IS extend); no card-side re-encoding
164
418
  transition: str(c.transition),
165
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;
166
451
  // (the clip text law lives where the text is consumed: THE
167
452
  // TRANSCRIPT — dialogue words ride the <d> prompt tag, sfx text
168
453
  // the soundscape field, music text non_diegetic_music. In every
@@ -175,13 +460,26 @@ function renderH3Film(p, g, facts) {
175
460
  // default; a user-stacked pair runs at the HIGHER count — 8 steps
176
461
  // on a 4-step distill is fine, 4 on an 8-step is undercooked).
177
462
  const loraRows = Array.isArray(p.loras) ? p.loras : [];
178
- const loraStepsList = loraRows
179
- .map((r) => r.steps)
180
- .filter((v) => typeof v === 'number' && Number.isFinite(v));
181
- 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');
182
468
  calls.forEach((call, i) => {
183
469
  const k = i + 1;
184
- 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) : '');
185
483
  // A CALL OWNS ITS TEXT (the operator's no-fallbacks law, enforced
186
484
 
187
485
  // a source substitution, the exact crime class the law bans). The
@@ -227,7 +525,13 @@ function renderH3Film(p, g, facts) {
227
525
  const hi = Math.min(clip.start + clip.dur, ef);
228
526
  if (hi - lo < 2.4)
229
527
  continue; // below the slice node's 0.1s floor
230
- 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;
231
535
  stamps[clip.cls] = {
232
536
  src: clip.src,
233
537
  slice_start_seconds: ms(Math.max(0, genStart - clip.start)),
@@ -307,10 +611,41 @@ function renderH3Film(p, g, facts) {
307
611
  '\n\noverall_soundscape:\nNo speech or dialogue in this shot — ambient and effects only; nobody speaks on screen and there is no voice-over.';
308
612
  }
309
613
  const stanza = { ...p, ...knobs, prompt: text, k };
614
+
615
+ // its media lanes DIRECTLY — last_frame / ref_images /
616
+ // ref_videos / ref_audios on the call row — and the schema
617
+ // admits them (the media gate walks them), so the compose MUST
618
+ // read them or they die schema-green and engine-blind. A stated
619
+ // lane REPLACES the declared (film) lane, an absent one
620
+ // inherits — the same per-seat canon the refs bag rides.
621
+ if (typeof call.last_frame === 'string' && call.last_frame.trim() !== '')
622
+ stanza.last_frame = call.last_frame;
623
+ if (wireList(call.ref_images).length > 0)
624
+ stanza.ref_images = call.ref_images;
625
+ if (wireList(call.ref_videos).length > 0)
626
+ stanza.ref_videos = call.ref_videos;
627
+ if (wireList(call.ref_audios).length > 0)
628
+ stanza.ref_audios = call.ref_audios;
629
+ const hasDirectRefs = wireList(call.ref_images).length + wireList(call.ref_videos).length + wireList(call.ref_audios).length > 0
630
+ || (typeof call.last_frame === 'string' && call.last_frame.trim() !== '');
310
631
  const anyStamp = stamps.dialogue !== undefined || stamps.sfx !== undefined || stamps.music !== undefined;
311
- stanza.variant = (guide !== '' || hasRefs || 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';
312
640
  // the distill's steps apply unless this call's knobs pinned steps
313
- 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)
314
649
  stanza.steps = loraStepsApplied;
315
650
  // THE DOOR GUARD, voice arm: a dialogue/sfx-pinned window mutes
316
651
  // the user ref audios (film-level and per-call) — the pins own
@@ -319,7 +654,15 @@ function renderH3Film(p, g, facts) {
319
654
  const voicePinned = stamps.dialogue !== undefined || stamps.sfx !== undefined;
320
655
  if (voicePinned)
321
656
  delete stanza.ref_audios;
322
- if (hasRefs)
657
+
658
+ // ANY lane rides it — refs (bundle bus) OR mods (conditioning
659
+ // tokens). The operator caught the hole live: a mods-only call
660
+ // lost its whole bag (hasRefs counted only the bus lanes, so the
661
+ // reference packs silently died). Mods never flip the arm (the
662
+ // refmod seam's own law below), so the gate widened here is the
663
+ // one behavior change — a mods-only call stays FL2VA.
664
+ const callMods = wireList(rb.mods);
665
+ if (hasRefs || callMods.length > 0)
323
666
  stanza.refs = voicePinned && Array.isArray(call.refs?.audios)
324
667
  ? { ...call.refs, audios: undefined }
325
668
  : call.refs;
@@ -327,6 +670,19 @@ function renderH3Film(p, g, facts) {
327
670
  stanza.image = guide;
328
671
  else
329
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
+ }
330
686
  if (sf !== null && ef !== null && ef > sf) {
331
687
  // THE UNIFORM SPAN GATE, second door: a stale or hand-built
332
688
  // document re-rides the same law the walk admitted under, so
@@ -353,10 +709,18 @@ function renderH3Film(p, g, facts) {
353
709
  // (The snap itself is filmMix's spanStanzaFrames — the ONE
354
710
  // law the render loop and the film manifest share; the old
355
711
  // inline 22+17k twin died here.)
356
- if (knobs.fps_seconds === undefined) {
357
- stanza.fps_seconds = Math.round((stanza.length / 24) * 1000) / 1000;
358
- }
359
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.
360
724
  // THE GRID GATE (§26): a knob-pinned length bypassed the snap
361
725
  // above — validate, never trust. Refuses at compose (zero GPU)
362
726
  // with the span, the nearest legal length, and the proven
@@ -368,6 +732,8 @@ function renderH3Film(p, g, facts) {
368
732
  }
369
733
  if (prev !== undefined)
370
734
  stanza.__prev = prev;
735
+ if (reshootChain !== undefined)
736
+ stanza.__reshoot = reshootChain;
371
737
 
372
738
  // bed arm retired with the bed the same day): a pinned window
373
739
  // owns its audio conditioning — the normal inputs stand down for
@@ -389,7 +755,7 @@ function renderH3Film(p, g, facts) {
389
755
  stanza.sfx_slice = stamps.sfx;
390
756
  if (stamps.music !== undefined)
391
757
  stanza.music_slice = stamps.music;
392
- const h = g.scoped(`window${k}_`, (w) => renderH3Window(stanza, w, facts));
758
+ const h = g.scoped(`window${k}_`, (w) => renderH3Window(stanza, w, facts, model, runId));
393
759
  prev = h;
394
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 */
395
761
  if (h.savePassthrough !== undefined)
@@ -447,10 +813,16 @@ function renderH3Film(p, g, facts) {
447
813
  if (windowSaves.length === 0) {
448
814
  throw new Error('[h3-timeline] a family arm saved no clip to pass the film boundary — the film tail cannot order its loads');
449
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;
450
821
  const manifest = computeFilmMix({
451
822
  spans,
452
823
  clips,
453
- windowSecs: stanzaSecs(spans),
824
+ windowSecs: stanzaSecs(spans, docFps),
825
+ fps: docFps,
454
826
  // the knob's declared default (−14) walks through the schema
455
827
  // door; computeFilmMix owns the fallback for the absent key
456
828
  duckDb: p.duck_depth_db,
@@ -460,23 +832,22 @@ function renderH3Film(p, g, facts) {
460
832
  // stitch: 960×576 leftovers globbed as windows) and
461
833
  // run-18ea8c810104 (loud no-match refusal on h3_t4_w2): cut
462
834
  // windows chain NOTHING and even chained windows' SAVE nodes are
463
- // not downstream of one another, so the old single boundary on
464
- // the LAST save rode a scheduler tie-break — window 2's save was
465
- // an unordered island the loader could beat). Every window's
466
- // SaveVideo passthrough feeds its OWN boundary; each boundary's
467
- // optional 'after' wires the prior boundary's token, so the final
468
- // token (the concat's 'after') transitively depends on EVERY
469
- // save — and each window's passthrough tensor still dies at its
470
- // own boundary (the §20 law; the flush is idempotent, weights
471
- // stay resident).
472
- let boundaryAfter;
473
- for (const save of windowSaves) {
474
- boundaryAfter = g.node('MeliteUnload', {
475
- video: save, unload_models: false,
476
- ...(boundaryAfter !== undefined ? { after: boundaryAfter } : {}),
477
- }).out(0);
478
- }
479
- 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);
480
851
  if (clips.length > 0) {
481
852
 
482
853
 
@@ -493,7 +864,7 @@ function renderH3Film(p, g, facts) {
493
864
  // the mix, not the raw concat audio. Early return: the
494
865
  // clips-free arm below stays byte-frozen.
495
866
  const mix = g.node('MeliteFilmAudioMix', {
496
- videos: calls.map((_c, i) => `h3_t4_w${i + 1}`).join(','),
867
+ videos: windowPrefixes.join(','),
497
868
  after,
498
869
  // the manifest rendered verbatim: every placement's source,
499
870
  // film seat, duration, and class — doc order kept (the node's
@@ -516,36 +887,54 @@ function renderH3Film(p, g, facts) {
516
887
  // calibrated against ffmpeg's ebur128 to within 0.1 LU on tones,
517
888
  // noise, gating, and mono.
518
889
  const meter = g.node('MeliteLoudness', { audio: mix.out(0) });
519
- saveAudio(g, meter.out(0), 'h3_t4_film_audio');
890
+ saveAudio(g, meter.out(0), `${runId}/h3_t4_film_audio`);
520
891
  // THE FILM MP4 (GAP 1): the same file-tail video join the
521
892
  // clips-free arm rides — container mux only (CreateVideo +
522
893
  // SaveVideo h264/mp4 on the decoded window files), never the
523
894
  // mix. The mix rides it: audio carries the node's output.
524
- const join = g.node('MeliteConcatVideos', {
525
- videos: calls.map((_c, i) => `h3_t4_w${i + 1}`).join(','),
526
- after,
895
+ return concatSavedFilms(g, windowPrefixes, after, `${runId}/h3_t4_film`, {
896
+ audio: meter.out(0),
527
897
  });
528
- const filmCreated = g.node('CreateVideo', {
529
- images: join.out(0), audio: meter.out(0), fps: join.out(2), bit_depth: FILM_BIT_DEPTH,
530
- });
531
- return g.node('SaveVideo', {
532
- video: filmCreated.out(), filename_prefix: 'h3_t4_film',
533
- format: 'mp4', codec: 'h264',
898
+ }
899
+ return concatSavedFilms(g, windowPrefixes, after, `${runId}/h3_t4_film`);
900
+ }
901
+ /** THE FUN-CONTROLNET CHAIN (002 H2/H4 + 007 L7): family-owned,
902
+ * the LTX_lora_loader precedent — the node pair is the family's
903
+ * own (ModelPatchLoader + MiniMaxH3FunControlNetApply, the
904
+ * engine's model-patch spelling), spelled HERE, never swapped
905
+ * into the kit's still-image stackControlNets (whose node pair
906
+ * stays z-image's). One link per fired pick, array order = apply
907
+ * order, empty picks → the bare model (byte-stable). The control
908
+ * source rides the pick's clip channel (a staged video artifact —
909
+ * LoadVideo → GetVideoComponents' image stream) or its still
910
+ * image; the mask channel rides LoadImageMask (alpha; the node
911
+ * reads it with source_video unset — no presumption about the
912
+ * video behind the mask). The schedule window stamps verbatim:
913
+ * the row declares 'ranged' and the node carries the dials (the
914
+ * kit's schedule law already refused what the row forbids). */
915
+ function applyH3FunControlNets(g, model, vae, picks) {
916
+ let cur = model;
917
+ for (const pick of picks) {
918
+ const hasClip = pick.clip !== undefined && pick.clip !== '';
919
+ const control = hasClip
920
+ ? g.node('GetVideoComponents', { video: g.node('LoadVideo', { file: pick.clip }).out() }).out(0)
921
+ : pick.image !== ''
922
+ ? g.node('LoadImage', { image: pick.image, upload: 'image' }).out(0)
923
+ : undefined;
924
+ const hasMask = pick.mask !== undefined && pick.mask !== '';
925
+ const patch = g.node('ModelPatchLoader', { name: pick.model }).out();
926
+ cur = g.node('MiniMaxH3FunControlNetApply', {
927
+ model: cur, model_patch: patch, vae,
928
+ strength: pick.strength,
929
+ start_percent: pick.start_percent ?? 0,
930
+ end_percent: pick.end_percent ?? 1,
931
+ ...(control === undefined ? {} : { control_video: control }),
932
+ ...(hasMask ? { mask: g.node('LoadImageMask', { image: pick.mask, channel: 'alpha' }).out(0) } : {}),
534
933
  }).out();
535
934
  }
536
- const concat = g.node('MeliteConcatVideos', {
537
- videos: calls.map((_c, i) => `h3_t4_w${i + 1}`).join(','),
538
- after,
539
- });
540
- const filmCreated = g.node('CreateVideo', {
541
- images: concat.out(0), audio: concat.out(1), fps: concat.out(2), bit_depth: FILM_BIT_DEPTH,
542
- });
543
- return g.node('SaveVideo', {
544
- video: filmCreated.out(), filename_prefix: 'h3_t4_film',
545
- format: 'mp4', codec: 'h264',
546
- }).out();
935
+ return cur;
547
936
  }
548
- function renderH3Window(p, g, facts) {
937
+ function renderH3Window(p, g, facts, model, runId) {
549
938
  // REFS IMPLY THE R2V LANE (the bundle IS the r2v input): a
550
939
  // refs-carrying window is t4r even without a guide still — the
551
940
  // same law the film renderer applies per call. The DECLARED input
@@ -554,20 +943,69 @@ function renderH3Window(p, g, facts) {
554
943
  const rb0 = (p.refs ?? {});
555
944
  const declaredCount = wireList(p.ref_images).length + wireList(p.ref_videos).length + wireList(p.ref_audios).length;
556
945
  const hasRefs = declaredCount + wireList(rb0.images).length + wireList(rb0.videos).length + wireList(rb0.audios).length > 0;
557
- if (hasRefs && p.variant !== 't4r')
558
- p = { ...p, variant: 't4r' };
559
- const family = p.variant;
560
- if (!FAMILIES.includes(family)) {
561
- throw new Error(`unknown window family '${String(p.variant)}' (known: ${[...FAMILIES].sort().join(', ')})`);
562
- }
946
+
947
+ // variant:'timeline' break): the window family is DERIVED from
948
+ // the window's own seats — a guide still or a reference bus makes
949
+ // the reference lane; everything else is text. SEATS BEAT STATED:
950
+ // refs coerce the lane even over a stated lawful family (the old
951
+ // refs-imply-r2v coercion — a refs-carrying window is t4r even
952
+ // without a guide still). A stated LAWFUL family rides only when
953
+ // the seats are silent (the film loop derives per stanza before
954
+ // calling here; the schema walk derives from the same seats); an
955
+ // axis-seeded string ('timeline' — the model axis the add door
956
+ // stamps onto every fresh stage) is not a family and never was:
957
+ // the seats own the lane, model metadata never picks one.
958
+ const statedFamily = typeof p.variant === 'string' && FAMILIES.includes(p.variant)
959
+ ? p.variant : undefined;
960
+ const guide0 = [p.image, p.image_name, p.ref_image].some((v) => typeof v === 'string' && v.trim() !== '');
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.
563
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');
564
969
  // THE GRID GATE (§26, defense in depth): no window renders
565
970
  // off-grid — the film loop's pin check voices the call span, this
566
971
  // one catches the single-call path and any direct caller.
567
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;
568
991
  const isT4r = family === 't4r';
569
992
  const isChain = family === 't4_chain';
570
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
+
571
1009
  // is the fresh-card admission, not a fallback crime. The window
572
1010
  // shape's text face is p.prompt (declared required=True, "optional
573
1011
 
@@ -578,11 +1016,27 @@ function renderH3Window(p, g, facts) {
578
1016
  // lawfully write p.prompt from call text because in the one-window
579
1017
  // shape p.prompt IS the text owner — never a substitute.)
580
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;
581
1030
  // card knob first (image), renderer alias second.
582
1031
  const guideImage = (p.image ?? p.image_name ?? '');
583
1032
  // ── the model chain (family-conditional defaults;
584
1033
  // absent = absent on wire) ──
585
- 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;
586
1040
  const unet = g.node('UNETLoader', { unet_name: facts.unet, weight_dtype: 'default' }).out();
587
1041
  const sla = g.node('H3SLAAttention', {
588
1042
  model: unet,
@@ -596,7 +1050,19 @@ function renderH3Window(p, g, facts) {
596
1050
  dense_backend: p.sla_dense_backend,
597
1051
  disable_fp16_accum: p.sla_disable_fp16_accum,
598
1052
  stabilize_motion: stabilize,
599
- 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',
600
1066
  }).out();
601
1067
  const chunked = g.node('MiniMaxChunkFeedForward', {
602
1068
  model: g.node('MiniMaxLowVRAMAttention', { model: sla, head_chunks: 4 }).out(),
@@ -608,26 +1074,29 @@ function renderH3Window(p, g, facts) {
608
1074
  // writes the mod bag `loras` — [{id, strength}] rows the service
609
1075
  // resolves to {name, strength} filenames against the family's
610
1076
  // flavor catalog. Those rows build the upstream stack verbatim
611
- // ({on, lora, str, v:1, a:1, t:1}); an empty bag rides the
612
- // 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
613
1082
  // from the catalog so the value has one owner). ONE surface, one
614
- // owner.
615
- const loraStack = Array.isArray(p.loras) && p.loras.length > 0
616
- ? JSON.stringify(p.loras.map((r) => ({
617
- // the service resolves every row against the family catalog
618
- // (unknown ids refuse LOUD upstream) — {name, strength} is
619
- // the guaranteed wire shape, read directly
620
- on: true,
621
- lora: r.name,
622
- str: r.strength,
623
- v: 1, a: 1, t: 1,
624
- })))
625
- : 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);
626
1087
  // t4r templates carry shift_video 8.0; the t4 family carries the INT
627
1088
  // NO SILENT RESOLUTION LAW: the walked shift_video IS the value
628
1089
  // (declared default 8; the family literals retired with the
629
1090
  // nulling that fed them — 8.0 and 8 serialize identically anyway)
630
- 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);
631
1100
  const clip = g.node('CLIPLoader', {
632
1101
  clip_name: facts.clip, type: 'minimax',
633
1102
  ...(isT4r ? { device: 'default' } : {}), // t4 templates OMIT it
@@ -637,7 +1106,21 @@ function renderH3Window(p, g, facts) {
637
1106
  let cond;
638
1107
  let latent;
639
1108
  let sigmaModel;
640
- 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;
641
1124
  if (isT4r) {
642
1125
  // opener: switch(SLABool) picks SLA-direct vs chunked; lora rides
643
1126
  // the switch; preview override wired to the in-graph step count.
@@ -646,19 +1129,31 @@ function renderH3Window(p, g, facts) {
646
1129
  // scalar straight when sla_switch is set. sla_enabled=false
647
1130
  // forces the chunked (SLA-off) path; otherwise the legacy
648
1131
  // sla_switch spelling rides untouched.
649
- 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
650
1140
  let slaSel = p.sla_enabled === false
651
1141
  ? true
652
1142
  : (p.sla_switch ?? null);
653
1143
  if (slaSel === null)
654
1144
  slaSel = g.node('PrimitiveBoolean', { value: false }).out();
655
1145
  const picked = g.node('ComfySwitchNode', { switch: slaSel, on_true: chunked, on_false: sla }).out();
1146
+ preLoraModel = picked;
656
1147
  const loraModel = g.node('LTX_lora_loader', {
657
1148
  model: picked, mode: 'minimax', stack_data: loraStack, lora_ui: '',
658
1149
  }).out();
659
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).
660
1155
  const lengthNode = g.node('ComfyMathExpression', {
661
- expression: MATH_STEPS_GOLD, 'values.a': seconds,
1156
+ expression: mathStepsGold(fpsClock), 'values.a': seconds,
662
1157
  }).out(1);
663
1158
  const previewed = g.node('ModelPreviewOverrideKJ', {
664
1159
  max_resolution: 512, jpeg_quality: 80,
@@ -671,7 +1166,11 @@ function renderH3Window(p, g, facts) {
671
1166
  }).out();
672
1167
  // THE ANCHOR + THE REFERENCE BUNDLE (the operator's distinction,
673
1168
 
674
- // the frozen served shape); `refs` is the call's REFERENCE bundle
1169
+ // the frozen served shape — ref_image_0 on the r2v node, the
1170
+ // strongest identity pull; the window's literal first frame
1171
+ // GENERATES under its guidance, it is never pinned — the i2v
1172
+ // first-frame input is the orphaned marker below); `refs` is the
1173
+ // call's REFERENCE bundle
675
1174
  // — the upstream "Extra References" subgraph's own vocabulary
676
1175
  // (LoadImage → the ref resizer; LoadVideo → GetVideoComponents →
677
1176
  // the image+audio component pair; LoadAudio). Bundle layout (the
@@ -681,10 +1180,17 @@ function renderH3Window(p, g, facts) {
681
1180
  // the reference resizer (bundle → r2v refs) before the geometry
682
1181
  // resizer (i2v) — creation mirrors the walk.
683
1182
  const refBag = (p.refs ?? {});
684
- // THE DECLARED-SURFACE MERGE (the input rail's law): the typed
685
- // fields (ref_images/ref_videos/ref_audios — Layer A, stamped
686
- // onto every stanza) are PRIMARY; the legacy stanza bag's
687
- // entries append, deduped. One wire form, one reader.
1183
+
1184
+ // is the card's DEFAULTS; a call (Layer B) REPLACES a refs lane
1185
+ // it states — per lane, never per bag — and inherits the
1186
+ // declared lane when it states none. The pre-canon merge
1187
+ // (declared PRIMARY + bag appended, deduped) made a call unable
1188
+ // to override the run's references: the exact harm the operator
1189
+ // named. LoRAs own the opposite pole — CALL_KEYS admits no
1190
+ // loras key, so a call cannot even state one (film-level model
1191
+ // configuration is Layer A's alone). One canon, per seat:
1192
+ // replace (refs lanes), per-key replace (CALL_KNOB_KEYS), or
1193
+ // none (loras, geometry, the bed).
688
1194
  const declaredImages = wireList(p.ref_images);
689
1195
  const declaredVideos = wireList(p.ref_videos);
690
1196
  const declaredAudios = wireList(p.ref_audios);
@@ -697,14 +1203,53 @@ function renderH3Window(p, g, facts) {
697
1203
  // image stream — and be silently clobbered; the law refuses
698
1204
  // LOUD instead.
699
1205
  const lastFrame = (p.last_frame ?? '');
700
- const refImagesAll = mergeDeclaredRefs(declaredImages, wireList(refBag.images));
1206
+ // THE CANON'S REPLACE ARM (per lane): a stated call lane rides
1207
+ // INSTEAD of the declared lane; an absent call lane inherits it.
1208
+ const bagImages = wireList(refBag.images);
1209
+ const refImagesAll = bagImages.length > 0 ? bagImages : declaredImages;
701
1210
  const imageCap = imageReferenceCap(lastFrame !== '');
702
1211
  if (lastFrame !== '' && refImagesAll.length > imageCap) {
703
1212
  throw new Error(`[h3-timeline] the image bus is full: a last frame (input 2) + ${String(refImagesAll.length)} references exceeds the ${IMAGE_BUS_SLOTS}-slot bus — keep references ≤ ${imageCap} with an end anchor (≤ ${REF_CAPS.images} without)`);
704
1213
  }
705
1214
  const refImages = refImagesAll.slice(0, imageCap);
706
- const refVideos = mergeDeclaredRefs(declaredVideos, wireList(refBag.videos)).slice(0, REF_CAPS.videos);
707
- const refAudios = mergeDeclaredRefs(declaredAudios, wireList(refBag.audios)).slice(0, REF_CAPS.audios);
1215
+ const bagVideos = wireList(refBag.videos);
1216
+ const refVideos = (bagVideos.length > 0 ? bagVideos : declaredVideos).slice(0, REF_CAPS.videos);
1217
+ // THE TRIM SEAT'S READER (audit 003/V4): index-paired with
1218
+ // ref_videos — schema resolve fills each entry's start_time/
1219
+ // duration defaults, so a wire `{item:…}` or partial entry
1220
+ // normalizes before it reaches the slice. A non-object entry
1221
+ // refuses LOUD (the probe-proven law), never rides silent.
1222
+ const rawTrims = Array.isArray(p.ref_video_trims) ? p.ref_video_trims : [];
1223
+ if (rawTrims.length > REF_CAPS.videos) {
1224
+ throw new Error(`ref_video_trims: expected at most ${REF_CAPS.videos} entries (the video lane's cap) — got ${rawTrims.length}`);
1225
+ }
1226
+ const videoTrims = rawTrims.map((e, i) => {
1227
+ if (typeof e !== 'object' || e === null || Array.isArray(e)) {
1228
+ throw new Error(`ref_video_trims: entry ${i} must be an object { start_time, duration } — got ${JSON.stringify(e).slice(0, 40)}`);
1229
+ }
1230
+ const row = e;
1231
+ const start = row.start_time;
1232
+ const dur = row.duration;
1233
+ if (start !== undefined && typeof start !== 'number')
1234
+ throw new Error(`ref_video_trims: entry ${i} start_time must be a number — got ${JSON.stringify(start).slice(0, 40)}`);
1235
+ if (dur !== undefined && typeof dur !== 'number')
1236
+ throw new Error(`ref_video_trims: entry ${i} duration must be a number — got ${JSON.stringify(dur).slice(0, 40)}`);
1237
+ return { start_time: start ?? 0, duration: dur ?? 0 };
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
+ }
1251
+ const bagAudios = wireList(refBag.audios);
1252
+ const refAudios = (bagAudios.length > 0 ? bagAudios : declaredAudios).slice(0, REF_CAPS.audios);
708
1253
  const bundleInputs = {};
709
1254
 
710
1255
  // it all"): a '$name' value names a WIRED STAGE INPUT, never a
@@ -758,7 +1303,20 @@ function renderH3Window(p, g, facts) {
758
1303
  // the spelled motion guide rides GetVideoComponents' tensor
759
1304
  // input directly (the producer's pre-save video tensor); a
760
1305
  // path keeps the LoadVideo disk handoff.
761
- const vid = isSpell(src) ? src : g.node('LoadVideo', { file: src }).out();
1306
+ let vid = isSpell(src) ? src : g.node('LoadVideo', { file: src }).out();
1307
+ // THE TRIM THREAD (audit 003/V4): entry i slices guide i
1308
+ // through the engine's own Video Slice BEFORE conditioning —
1309
+ // both arms (spelled tensor and disk path) trim the same,
1310
+ // because the slice rides the VIDEO tensor either way. A
1311
+ // zero/zero or absent entry builds no node: the whole clip
1312
+ // stays the guide, byte-stable with the pre-trim graph.
1313
+ const trim = videoTrims[i];
1314
+ if (trim !== undefined && (trim.start_time > 0 || trim.duration > 0)) {
1315
+ vid = g.node('Video Slice', {
1316
+ video: vid, start_time: trim.start_time,
1317
+ duration: trim.duration, strict_duration: false,
1318
+ }).out();
1319
+ }
762
1320
  const comp = g.node('GetVideoComponents', { video: vid });
763
1321
  bundleInputs[`input_${10 + 2 * i}`] = comp.out(0);
764
1322
  bundleInputs[`input_${11 + 2 * i}`] = comp.out(1);
@@ -795,7 +1353,7 @@ function renderH3Window(p, g, facts) {
795
1353
 
796
1354
  const refSize = p.ref_image_size;
797
1355
  const r2vInputs = {
798
- prompt, width: p.width, height: p.height,
1356
+ prompt: r2vPrompt, width: headW, height: headH,
799
1357
  length: lengthNode, ref_image_size: refSize,
800
1358
  clip, vae: vaeVideo, audio_vae: vaeAudio,
801
1359
  };
@@ -806,6 +1364,20 @@ function renderH3Window(p, g, facts) {
806
1364
  r2vInputs[`ref_video_audios.ref_video_audio_${i}`] = bout.out(10 + 2 * i);
807
1365
  r2vInputs[`ref_audios.ref_audio_${i}`] = bout.out(15 + i);
808
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
+ }
809
1381
 
810
1382
  // their natural lanes above — no slice, no shift, no fourth
811
1383
  // anything.)
@@ -832,6 +1404,16 @@ function renderH3Window(p, g, facts) {
832
1404
  // longer consumes a ref lane: bed + user audios keep the full
833
1405
  // 3-lane budget, and the guide is the dialogue's one owner.
834
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;
835
1417
  const read = (key) => (p[key] ?? null);
836
1418
  const stamp = read('dialogue_slice');
837
1419
  if (stamp !== null) {
@@ -840,7 +1422,7 @@ function renderH3Window(p, g, facts) {
840
1422
  start_seconds: stamp.slice_start_seconds,
841
1423
  duration_seconds: stamp.slice_duration_seconds,
842
1424
  }).out(0);
843
- dialogueFrameIdx = Math.round(stamp.delay_seconds * 24);
1425
+ dialogueFrameIdx = Math.round(stamp.delay_seconds * pinFps);
844
1426
  }
845
1427
  const sfxStamp = read('sfx_slice');
846
1428
  if (sfxStamp !== null) {
@@ -849,7 +1431,7 @@ function renderH3Window(p, g, facts) {
849
1431
  start_seconds: sfxStamp.slice_start_seconds,
850
1432
  duration_seconds: sfxStamp.slice_duration_seconds,
851
1433
  }).out(0);
852
- sfxFrameIdx = Math.round(sfxStamp.delay_seconds * 24);
1434
+ sfxFrameIdx = Math.round(sfxStamp.delay_seconds * pinFps);
853
1435
  }
854
1436
  const musicStamp = read('music_slice');
855
1437
  if (musicStamp !== null) {
@@ -858,7 +1440,7 @@ function renderH3Window(p, g, facts) {
858
1440
  start_seconds: musicStamp.slice_start_seconds,
859
1441
  duration_seconds: musicStamp.slice_duration_seconds,
860
1442
  }).out(0);
861
- musicFrameIdx = Math.round(musicStamp.delay_seconds * 24);
1443
+ musicFrameIdx = Math.round(musicStamp.delay_seconds * pinFps);
862
1444
  }
863
1445
  }
864
1446
  const r2v = g.node('MiniMaxH3ReferenceToVideo', r2vInputs);
@@ -911,6 +1493,28 @@ function renderH3Window(p, g, facts) {
911
1493
  audio_vae: vaeAudio, audio: musicAudio,
912
1494
  }).out(0);
913
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
+ }
914
1518
  }
915
1519
  else {
916
1520
  // t4 families: the SLA/attention switch rides ABOVE the LoRA
@@ -945,6 +1549,7 @@ function renderH3Window(p, g, facts) {
945
1549
  // the fallback arms were unreachable lies.
946
1550
  switch: p.sla_enabled, on_true: sla, on_false: mab,
947
1551
  }).out();
1552
+ preLoraModel = picked;
948
1553
  const loraModel = g.node('LTX_lora_loader', {
949
1554
  model: picked, mode: 'minimax', stack_data: loraStack,
950
1555
  }).out();
@@ -971,15 +1576,232 @@ function renderH3Window(p, g, facts) {
971
1576
  // film total; fresh: the walked default; the 90/56 family budgets
972
1577
  // retired with the nulling that fed them)
973
1578
  const length = p.length;
974
- const r2v = g.node('MiniMaxH3ReferenceToVideo', {
975
- prompt, width: p.width,
976
- 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,
977
1588
  ref_image_size: p.ref_image_size,
978
1589
  clip, vae: vaeVideo, audio_vae: vaeAudio,
979
- });
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);
980
1605
  cond = r2v.out(0);
981
1606
  latent = r2v.out(1);
982
- 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);
1621
+ }
1622
+
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.
1640
+
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.)
1656
+ const bagMods = wireList(rb0.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()))];
1660
+ if (refModsAll.length > 0) {
1661
+ if (refModsAll.length > REF_CAPS.refmods) {
1662
+ throw new Error(`[h3-timeline] ref_mods exceeds the loader's ${String(REF_CAPS.refmods)} slots (saw ${String(refModsAll.length)})`);
1663
+ }
1664
+ const modStems = [];
1665
+ const modImages = [];
1666
+ const modVideos = [];
1667
+ const modAudios = [];
1668
+ for (const src of refModsAll) {
1669
+ // Trim, then query-strip (the estate precedent:
1670
+ // timelineContract's _kindOfFile splits '?' first), then split
1671
+ // on BOTH separators — a backslash-prefixed or padded entry
1672
+ // would otherwise pass the suffix check with junk baked into
1673
+ // the stem and die server-side as a combo miss. The two `as`
1674
+ // casts are total (split always yields a non-empty array), so
1675
+ // this adds no defensive branches to the coverage face.
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];
1682
+ const base = query.split(/[\\/]/).pop();
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;
1699
+ }
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);
1727
+ };
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));
1804
+ }
983
1805
  }
984
1806
  // ── sampler stack ──────────────────────────────────────────────────
985
1807
  // card knob first (seed), renderer alias second.
@@ -996,6 +1818,25 @@ function renderH3Window(p, g, facts) {
996
1818
  // template carries switch=false as a LITERAL, not a bool node
997
1819
  sampler = g.node('ComfySwitchNode', { switch: false, on_true: ersde, on_false: samplerSel }).out();
998
1820
  }
1821
+ // THE FUN-CONTROLNET SEAT (007 L7): one insertion past the sigma
1822
+ // shift, BOTH t4 arms by construction (each arm assigns sigmaModel
1823
+ // above; every downstream consumer — BasicScheduler, BasicGuider,
1824
+ // the continuation seam, the soft-AV release — rides the chain's
1825
+ // tail). Empty picks → sigmaModel verbatim (byte-stable); entries
1826
+ // fire only when the family boards the controlnet pack (the kit's
1827
+ // boarding gate — the rows are the operator's BENCH row, 002 H1)
1828
+ // and every row fact (schedule capability, strength ceiling, the
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);
1839
+ sigmaModel = applyH3FunControlNets(g, sigmaModel, vaeVideo, fireControlNets(model, p));
999
1840
  const schedName = p.sched_name;
1000
1841
  const denoiseVal = p.denoise;
1001
1842
  const sched = g.node('BasicScheduler', {
@@ -1056,8 +1897,10 @@ function renderH3Window(p, g, facts) {
1056
1897
  // primary stack above NEVER changes), full-denoise short
1057
1898
  // schedule from the same noise seed, riding the doc's own
1058
1899
  // sampler/scheduler (the rider owns NO solver of its own — one
1059
- // owner per knob). Mounted ONLY when the service resolved a
1060
- // 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.
1061
1904
  // The TaoMate refiner thread's mechanics: pass A full, pass B
1062
1905
  // closes. The rider sits UPSTREAM of decode AND of the film's
1063
1906
  // seam handles — the chained texture is the refined one.
@@ -1066,16 +1909,99 @@ function renderH3Window(p, g, facts) {
1066
1909
  // refine each AND it with their own switch (legacy docs with
1067
1910
  // leaves set but no master render the plain pass, byte-stable).
1068
1911
  const secondPassOn = p.second_pass_enabled === true;
1069
- 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
+ }
1070
1993
  if (refine !== undefined) {
1071
1994
  const refineModel = g.node('LTX_lora_loader', {
1072
- model: sigmaModel, mode: 'minimax',
1995
+ model: pass2Model, mode: 'minimax',
1073
1996
  stack_data: JSON.stringify([{ on: true, lora: refine.name, str: refine.strength, v: 1, a: 1, t: 1 }]),
1074
1997
  lora_ui: '',
1075
1998
  }).out();
1076
1999
  const refineSched = g.node('BasicScheduler', {
1077
2000
  model: refineModel, scheduler: schedName,
1078
- 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,
1079
2005
  }).out();
1080
2006
  const refineGuider = g.node('BasicGuider', { model: refineModel, conditioning: cond }).out();
1081
2007
  const refined = g.node('SamplerCustomAdvanced', {
@@ -1112,16 +2038,24 @@ function renderH3Window(p, g, facts) {
1112
2038
  }
1113
2039
  if (isT4r) {
1114
2040
  const created = g.node('CreateVideo', {
1115
- 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,
1116
2046
  // color_space: pin autofill "sRGB"
1117
2047
  });
1118
2048
 
1119
- // 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
1120
2051
  // 'video/ComfyUI' prefix died (multi-window anchored films were
1121
- // unaddressable: every window collided on one prefix, and the
1122
- // 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.
1123
2057
  const saved = g.node('SaveVideo', {
1124
- video: created.out(), filename_prefix: `h3_t4_w${k}`,
2058
+ video: created.out(), filename_prefix: `${runId}/h3_t4_w${k}`,
1125
2059
  format: 'auto', codec: 'h264',
1126
2060
  'codec.encoding': 're-encode', 'codec.encoding.crf': 10.0,
1127
2061
  });
@@ -1149,62 +2083,74 @@ function renderH3Window(p, g, facts) {
1149
2083
  // (V7/ours sharpened FIRST — before the upscaler could soften the
1150
2084
  // detail away). Sharpen rcas 0.3 after upscale "looks natural"
1151
2085
  // (his V9 notes). The switches stay ours; the ORDER is his.
1152
- const film = g.node('FrameInterpolationModelLoader', {
1153
- model_name: p.interp_model,
1154
- }).out();
1155
- const interpMultVal = p.interp_multiplier;
1156
- const interp = g.node('FrameInterpolate', {
1157
- interp_model: film, images: vdec, multiplier: interpMultVal,
1158
- }).out();
2086
+ //
1159
2087
 
1160
- // (declared default false). The legacy interp_switch alias is
1161
- // retired — post-declaration the walk materializes the primary,
1162
- // so the alias arm was unreachable dead law.
1163
- const interpSwOn = secondPassOn && p.interpolate_enabled;
1164
- const interpSw = g.node('ComfySwitchNode', {
1165
- switch: interpSwOn, on_true: interp, on_false: vdec,
1166
- }).out();
1167
- const srRes = p.sr_resolution;
1168
- const sr = g.node('SeedVR2VideoUpscaler', {
1169
- image: interpSw,
1170
- dit: g.node('SeedVR2LoadDiTModel', {
1171
- model: p.sr_model, device: 'cuda:0',
1172
- }).out(),
1173
- vae: g.node('SeedVR2LoadVAEModel', {
1174
- model: LANE_FILES.sr_vae, device: 'cuda:0',
1175
- }).out(),
1176
- seed: 42, resolution: srRes,
1177
- max_resolution: 0, batch_size: 5, uniform_batch_size: false,
1178
- color_correction: 'lab',
1179
- }).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
+ }
1180
2111
  const srSwOn = secondPassOn && p.sr_switch;
1181
- const srSw = g.node('ComfySwitchNode', {
1182
- switch: srSwOn, on_true: sr, on_false: interpSw,
1183
- }).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
+ }
1184
2128
  // sharpen LAST (V9): the upscaler softens; rcas after it restores.
1185
2129
  // Renderer alias second (sharpen_* leaves above build the method).
1186
- const sharpened = g.node('ImageSharpenKJ', { image: srSw, method }).out();
1187
- const sharpSw = g.node('ComfySwitchNode', {
1188
- switch: secondPassOn && p.sharpen_enabled, on_true: sharpened, on_false: srSw,
1189
- }).out();
2130
+ if (secondPassOn && p.sharpen_enabled) {
2131
+ const sharpened = g.node('ImageSharpenKJ', { image: postImage, method }).out();
2132
+ postImage = sharpened;
2133
+ }
1190
2134
 
1191
2135
  // CreateVideo.fps = base × interp multiplier (his Enhancements:
1192
2136
  // PrimitiveFloat 24 → ComfyMathExpression "a * 2" → fps). Without
1193
2137
  // it every interp-on window plays at HALF speed — the frames
1194
- // double, the fps doesn't. Byte-stable at defaults (interp off →
1195
- // the served literal 24).
1196
- const interpOn = secondPassOn && p.interpolate_enabled;
1197
- 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).
1198
2142
  const created = g.node('CreateVideo', {
1199
- 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,
1200
2146
  // color_space: pin autofill "sRGB"
1201
2147
  });
1202
2148
  const saved = g.node('SaveVideo', {
1203
- video: created.out(), filename_prefix: `h3_t4_w${k}`,
2149
+ video: created.out(), filename_prefix: `${runId}/h3_t4_w${k}`,
1204
2150
  format: 'mp4', codec: 'h264',
1205
2151
  });
1206
2152
  rawHandles.savePassthrough = saved.out(0);
1207
- delivered = { images: sharpSw, audio: vadec };
2153
+ delivered = { images: postImage, audio: vadec };
1208
2154
  }
1209
2155
  // (every family path delivers — both arms save the window's clip;
1210
2156
  // no null arm: the family dispatch is exhaustive over FAMILIES.
@@ -1229,6 +2175,103 @@ function renderH3Window(p, g, facts) {
1229
2175
  * schema's own filter law — a retyped list would be a second
1230
2176
  * SSOT). */
1231
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
+ }
1232
2275
  export const film = {
1233
2276
  id: 'film',
1234
2277
  inputs: [],
@@ -1251,16 +2294,31 @@ export const film = {
1251
2294
  // fps_seconds) are internal. ref_image_size is the schema's
1252
2295
  // const-or-WxH pattern tier — typed as its string spine.
1253
2296
  params: [
1254
- { name: "prompt", type: "string" },
1255
- { name: "image", type: "string" },
1256
- { 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" },
1257
2314
  { name: "ref_images", type: "image_list" },
1258
2315
  { name: "ref_videos", type: "image_list" },
1259
2316
  { name: "ref_audios", type: "image_list" },
2317
+ { name: "ref_mods", type: "image_list" },
1260
2318
  { name: "duck_depth_db", type: "number", bounds: [-48, 0] },
1261
2319
  { name: "seed", type: "number", rule: "seed-sentinel" },
1262
2320
  { name: "width", type: "number", bounds: [448, 1344] },
1263
- { name: "height", type: "number", bounds: [448, 768] },
2321
+ { name: "height", type: "number", bounds: [448, 1344] },
1264
2322
  { name: "length", type: "number", bounds: [22, 362] },
1265
2323
  { name: "steps", type: "number", bounds: [4, 30] },
1266
2324
  { name: "second_pass_enabled", type: "boolean" },
@@ -1279,6 +2337,23 @@ export const film = {
1279
2337
  { name: "refine_lora", type: "string" },
1280
2338
  { name: "refine_strength", type: "number", bounds: [0, 2] },
1281
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.
1282
2357
  { name: "attention_backend", type: "enum", options: ["comfy kitchen attention", "pytorch attention"] },
1283
2358
  { name: "sr_switch", type: "boolean" },
1284
2359
  { name: "sr_resolution", type: "number", bounds: [720, 2160] },
@@ -1300,35 +2375,222 @@ export const film = {
1300
2375
  { name: "interp_switch", type: "boolean" },
1301
2376
  { name: "sharpen_switch", type: "boolean" },
1302
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" },
1303
2386
  { name: "image_name", type: "string" },
1304
2387
  ],
1305
2388
  facts: parseH3Facts,
1306
- build({ p: docIn, facts, g }) {
2389
+ build({ p: docIn, facts, g, model, runId }) {
1307
2390
  const p = { ...docIn };
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
+
2440
+ // single-call doc rides the frozen single-window arm below —
2441
+ // which renders the DOC surface, never the row. Without this
2442
+ // unpack the sole call's Layer B seats (refs bag, anchor image,
2443
+ // text, render knobs) died silently on every single-call doc:
2444
+ // the split-brain twin of the film loop's bag gate. One stanza
2445
+ // law, both arms: the row REPLACES the refs bag / anchor / text
2446
+ // seats it states (per-lane, per-seat); knobs replace per key;
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]
2465
+ : null;
2466
+ {
2467
+ const row = stanzaRow;
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
+ }
2483
+ const rowText = typeof row.text === 'string' ? row.text.trim() : '';
2484
+ if (rowText !== '')
2485
+ p.prompt = row.text;
2486
+ if (row.refs !== undefined && row.refs !== null)
2487
+ p.refs = row.refs;
2488
+ const rowImage = typeof row.image === 'string' ? row.image.trim() : '';
2489
+ if (rowImage !== '')
2490
+ p.image = row.image;
2491
+
2492
+ // law): the row's DIRECT media lanes ride onto p — the same
2493
+ // per-seat replace canon the stanza arm carries; before this
2494
+ // lift a single-window doc's row-level refs died unread.
2495
+ if (typeof row.last_frame === 'string' && row.last_frame.trim() !== '')
2496
+ p.last_frame = row.last_frame;
2497
+ if (wireList(row.ref_images).length > 0)
2498
+ p.ref_images = row.ref_images;
2499
+ if (wireList(row.ref_videos).length > 0)
2500
+ p.ref_videos = row.ref_videos;
2501
+ if (wireList(row.ref_audios).length > 0)
2502
+ p.ref_audios = row.ref_audios;
2503
+ const rowKnobs = (row.knobs ?? null);
2504
+ if (rowKnobs !== null)
2505
+ Object.assign(p, rowKnobs);
2506
+ }
2507
+ }
1308
2508
  const guideImage = (p.image ?? p.image_name ?? '');
1309
- if (p.variant === 't4r' && !guideImage) {
2509
+
2510
+ // LAWFUL stated family in conflict with a guide still refuses
2511
+ // loud — an explicit t4_open/t4_chain pin over an anchored doc
2512
+ // is a contract conflict, named at build. An axis-seeded string
2513
+ // ('timeline' — model metadata, not a family claim) never
2514
+ // reaches this guard: the seats derive the family and the
2515
+ // guide owns the reference lane.
2516
+ const statedFamily = typeof p.variant === 'string' && FAMILIES.includes(p.variant)
2517
+ ? p.variant : undefined;
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') {
2542
+ const rbRef = (p.refs ?? {});
2543
+ const refsCarry = wireList(rbRef.images).length + wireList(rbRef.videos).length + wireList(rbRef.audios).length
2544
+ + wireList(p.ref_images).length + wireList(p.ref_videos).length + wireList(p.ref_audios).length > 0
2545
+ || (typeof p.last_frame === 'string' && p.last_frame.trim() !== '');
2546
+ if (!refsCarry) {
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');
2554
+ }
2555
+ }
2556
+
2557
+ // the guard below polices "t4r without a guide" — but the
2558
+ // run-899a8448 rot was the INVERSE hole: a guide present while
2559
+ // variant derived t4_open (the schema derivation missed the
2560
+ // `image` spelling), so renderH3Window took the non-reference
2561
+ // arm, the anchor arm inside `if (isT4r)` never ran, and the
2562
+ // window rendered text-only with the user's reference silently
2563
+ // dead. A guide-bearing window that is not t4r and carries no
2564
+ // reference bus REFUSES here — one law, both directions.
2565
+ if (statedFamily === 't4r' && !guideImage) {
1310
2566
  // (refs-implied t4r windows carry no anchor — the bundle IS
1311
2567
  // the r2v input; the guard admits them via the refs law — the
1312
2568
  // legacy stanza bag AND the declared input surface (the rail's
1313
- // 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)
1314
2572
  const rbRef = (p.refs ?? {});
1315
2573
  const refsCarry = wireList(rbRef.images).length + wireList(rbRef.videos).length + wireList(rbRef.audios).length
1316
2574
  + wireList(p.ref_images).length + wireList(p.ref_videos).length + wireList(p.ref_audios).length > 0
1317
- || (typeof p.last_frame === 'string' && p.last_frame.trim() !== '');
2575
+ || (typeof p.last_frame === 'string' && p.last_frame.trim() !== '')
2576
+ || kfLane;
1318
2577
  if (!refsCarry) {
1319
2578
  throw new Error('h3_window(t4r): image-anchored window without a staged guide image — ' +
1320
2579
  'compose always injects LoadImage.0.image on this family');
1321
2580
  }
1322
2581
  }
1323
- // THE FILM DISPATCH: a multi-call chain doc with no per-window
1324
- // stanza markers (k absent — the stanza vocabulary) composes
1325
- // the MERGED film; everything else is the frozen single-window
1326
- // shape (served byte-identical).
2582
+
2583
+ // calls ARE the grammar — more than one call with no per-window
2584
+ // stanza markers (k absent) composes the MERGED film; everything
2585
+ // else is the frozen single-window shape. The variant string
2586
+ // NEVER gates this seat: it is axis metadata ('timeline') or a
2587
+ // schema stamp derived from these same calls — reading it here
2588
+ // demoted multi-window docs to one window and burned the
2589
+ // operator's timing (bench-session-2d6af763, variant:'timeline').
1327
2590
  const docCalls = Array.isArray(p.calls) ? p.calls : null;
1328
- const isFilm = docCalls !== null && docCalls.length > 1
1329
- && p.k === undefined && (p.variant === undefined || p.variant === 't4_chain');
2591
+ const isFilm = docCalls !== null && docCalls.length > 1 && p.k === undefined;
1330
2592
  if (isFilm)
1331
- return renderH3Film(p, g, facts);
2593
+ return renderH3Film(p, g, facts, model, runId);
1332
2594
 
1333
2595
  // FILM-path consumer (it rides the accumulated film audio).
1334
2596
  // On the frozen single-window shape it would be a silent
@@ -1352,15 +2614,38 @@ export const film = {
1352
2614
  // never overwrites it.
1353
2615
  if (Array.isArray(p.loras)) {
1354
2616
  const rows = p.loras;
1355
- const applied = rows.map((r) => r.steps).filter((v) => typeof v === 'number' && Number.isFinite(v));
1356
- const singleKnobs = docCalls !== null && docCalls.length === 1
1357
- ? (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 ?? {})
1358
2627
  : {};
1359
- if (applied.length > 0 && p.__steps_pinned !== true && singleKnobs.steps === undefined) {
1360
- p.steps = Math.max(...applied);
2628
+ if (married !== null && p.__steps_pinned !== true && singleKnobs.steps === undefined) {
2629
+ p.steps = married;
1361
2630
  }
1362
2631
  }
1363
- return renderH3Window(p, g, facts).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;
1364
2649
  },
1365
2650
  };
1366
2651
  //# sourceMappingURL=actions.js.map