@melite/estate-queue 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.
Files changed (106) hide show
  1. package/LICENSE +561 -457
  2. package/README.md +55 -0
  3. package/lib/bench.d.ts +19 -11
  4. package/lib/bench.js +47 -57
  5. package/lib/cardsArmError.d.ts +94 -2
  6. package/lib/cardsArmError.js +34 -4
  7. package/lib/cardsCompose.d.ts +13 -1
  8. package/lib/cardsCompose.js +151 -67
  9. package/lib/cardsDangling.d.ts +2 -2
  10. package/lib/cardsDangling.js +82 -37
  11. package/lib/cardsFacts.d.ts +32 -3
  12. package/lib/cardsFacts.js +39 -1
  13. package/lib/cardsLanes.d.ts +62 -4
  14. package/lib/cardsLanes.js +407 -20
  15. package/lib/cardsLanesCopy.d.ts +21 -0
  16. package/lib/cardsLanesCopy.js +22 -0
  17. package/lib/cardsRegistry.d.ts +195 -10
  18. package/lib/cardsRegistry.js +959 -67
  19. package/lib/cardsVariant.d.ts +22 -8
  20. package/lib/cardsVariant.js +243 -52
  21. package/lib/discloseRegistry.d.ts +42 -11
  22. package/lib/discloseRegistry.js +163 -23
  23. package/lib/filmLead.js +5 -3
  24. package/lib/flowsData.d.ts +68 -13
  25. package/lib/flowsData.js +236 -107
  26. package/lib/flowsFamilyCompose.d.ts +5 -8
  27. package/lib/flowsFamilyCompose.js +25 -14
  28. package/lib/flowsParamsOverlay.d.ts +55 -0
  29. package/lib/flowsParamsOverlay.js +197 -0
  30. package/lib/flowsRegistryRows.d.ts +4 -1
  31. package/lib/flowsRegistryRows.js +325 -25
  32. package/lib/index.d.ts +1 -3
  33. package/lib/index.js +20 -5
  34. package/lib/lifecycleLatch.d.ts +16 -0
  35. package/lib/lifecycleLatch.js +42 -0
  36. package/lib/loadPlane.d.ts +3 -2
  37. package/lib/loadPlane.js +34 -8
  38. package/lib/loadRegistry.js +1 -1
  39. package/lib/manageOps.d.ts +8 -2
  40. package/lib/manageOps.js +28 -7
  41. package/lib/managePlane.d.ts +42 -1
  42. package/lib/managePlane.js +911 -101
  43. package/lib/managePreflight.d.ts +26 -0
  44. package/lib/managePreflight.js +179 -0
  45. package/lib/manageProbe.d.ts +15 -7
  46. package/lib/manageProbe.js +79 -8
  47. package/lib/manageRegistry.d.ts +42 -4
  48. package/lib/manageRegistry.js +45 -7
  49. package/lib/mediaKinds.d.ts +1 -1
  50. package/lib/mediaKinds.js +1 -1
  51. package/lib/queue.js +14 -10
  52. package/lib/queueCore.d.ts +21 -5
  53. package/lib/queueCore.js +22 -5
  54. package/lib/queueLifecycle.d.ts +0 -24
  55. package/lib/queueLifecycle.js +9 -63
  56. package/lib/queueLock.d.ts +8 -2
  57. package/lib/queueLock.js +9 -6
  58. package/lib/queueResurrect.d.ts +7 -2
  59. package/lib/queueResurrect.js +25 -6
  60. package/lib/queueSidecar.d.ts +114 -1
  61. package/lib/queueSidecar.js +178 -7
  62. package/lib/queueSubmit.d.ts +124 -10
  63. package/lib/queueSubmit.js +251 -48
  64. package/lib/queueSweep.js +13 -2
  65. package/lib/runsChange.d.ts +8 -0
  66. package/lib/runsChange.js +21 -5
  67. package/lib/runsErrorCodes.d.ts +1 -1
  68. package/lib/runsErrorCodes.js +35 -0
  69. package/lib/runsExecute.d.ts +26 -0
  70. package/lib/runsExecute.js +184 -6
  71. package/lib/runsGates.d.ts +5 -1
  72. package/lib/runsGates.js +10 -5
  73. package/lib/runsList.d.ts +43 -3
  74. package/lib/runsList.js +172 -58
  75. package/lib/runsRefusalVoices.js +101 -0
  76. package/lib/runsRegistry.d.ts +188 -12
  77. package/lib/runsRegistry.js +1233 -179
  78. package/lib/runsSourceEcho.d.ts +27 -0
  79. package/lib/runsSourceEcho.js +84 -18
  80. package/lib/runsStart.d.ts +80 -17
  81. package/lib/runsStart.js +303 -49
  82. package/lib/runsTypes.d.ts +62 -2
  83. package/lib/runsTypes.js +30 -6
  84. package/lib/runsValidateArms.js +61 -7
  85. package/lib/runsValidateServe.d.ts +2 -2
  86. package/lib/runsValidateServe.js +46 -14
  87. package/lib/runsValidateShared.d.ts +10 -1
  88. package/lib/runsValidateShared.js +14 -0
  89. package/lib/runsValidateStages.d.ts +10 -3
  90. package/lib/runsValidateStages.js +44 -12
  91. package/lib/runtimeProvision.d.ts +119 -0
  92. package/lib/runtimeProvision.js +243 -0
  93. package/lib/service.d.ts +24 -6
  94. package/lib/service.js +19 -11
  95. package/lib/skillFs.d.ts +9 -4
  96. package/lib/skillFs.js +12 -14
  97. package/lib/skillPlane.d.ts +3 -2
  98. package/lib/skillPlane.js +12 -6
  99. package/lib/skillRegistry.js +1 -1
  100. package/lib/skillRows.d.ts +4 -3
  101. package/lib/skillRows.js +21 -14
  102. package/lib/toolProjection.d.ts +1 -1
  103. package/lib/toolProjection.js +1 -1
  104. package/package.json +18 -17
  105. package/lib/runStatus.d.ts +0 -7
  106. package/lib/runStatus.js +0 -21
@@ -68,6 +68,7 @@
68
68
  // Erasable-syntax TS only (node --experimental-strip-types): no
69
69
  // enums, import type for types, .ts specifiers for relative imports.
70
70
  import { Service } from "@deepseek-ai/cordis";
71
+ import { readFileSync, statSync } from "node:fs";
71
72
  // CROSS-COPY LAW (the estate's documented topology): the engine
72
73
  // package resolves the REGISTRY cordis instance; this package's
73
74
  // "@deepseek-ai/cordis" is the vendor instance. The service TYPE
@@ -78,14 +79,15 @@ import { Service } from "@deepseek-ai/cordis";
78
79
  * package (the registry-keyed instance ComfyUIService mounts on),
79
80
  * imported through the engine's public surface like every other
80
81
  * engine dep. No deep path, no runtime-only dodge. */
81
- import { bootModels, cardDefsNow, ComposeRefusal, getModel, liveScanOrder, loadCardDefs, loadFacts, registryIds, registryModel, resolveCardFlowOutputs, theService } from "@melite/comfyui-cordis";
82
+ import { bootModels, cardDefsNow, ComposeRefusal, getModel, liveScanOrder, loadCardDefs, loadFacts, owningAtom, registryIds, registryModel, resolveCardFlowOutputs, resolveRepoRoot, theService } from "@melite/comfyui-cordis";
83
+ import { probeMedia } from '@melite/contracts/media-probe';
82
84
  import { DOOR_KEYS } from "./runsGates.js";
83
- import { getRegistryFlow } from "./flowsData.js";
84
- import { CardArmError, EnvelopeRefusal, phaseRefusal } from "./cardsArmError.js";
85
+ import { CardArmError, EnvelopeRefusal, phaseRefusalCode } from "./cardsArmError.js";
85
86
  export { CardArmError } from "./cardsArmError.js";
86
- import { factsPath, deriveDecls } from "./cardsFacts.js";
87
+ import { cardAdmits, factsPath, deriveDecls, familyLanesOf } from "./cardsFacts.js";
87
88
  import { WIRE_STAGE_KEYS } from "@melite/contracts/benchStage";
88
- import { judgeLaneBounds, judgeLaneRelations, judgeLaneSurface, laneBoundsOf, laneSurfaceOf, RELATION_WORDS } from "@melite/contracts/laneRelations";
89
+ import { reseatDeadKeys } from "@melite/contracts/familyLane";
90
+ import { dropAuthoringIncomplete, isUnstatedRequiredVoice, judgeDeliverableSize, judgeLaneBounds, judgeLaneRelations, judgeLaneSurface, laneBoundsOf, laneStaleCarry, laneSurfaceOf, laneTogetherClosure, RELATION_WORDS } from "@melite/contracts/laneRelations";
89
91
  import { lanePresenceRefusal } from "./cardsLanes.js";
90
92
  import { selectCardVariant, liftCardParams } from "./cardsVariant.js";
91
93
  // the extracted planes re-export through the registry's public
@@ -124,6 +126,28 @@ export const CARD_ENVELOPE_KEYS = [
124
126
  "draft_id",
125
127
  "test",
126
128
  "service",
129
+ // press_key is the submit door's retry-dedup coordinate
130
+ // (queueSubmit names ONE press across retries) — door
131
+ // vocabulary, never a card knob. It rode unregistered and the
132
+ // live Run press refused "unknown param(s) … press_key" while
133
+ // the whole suite stayed green (the contract-depth red,
134
+
135
+ "press_key",
136
+ // bench_stage_id is the SINGLE-CARD press's bench identity (the
137
+
138
+ // vocabulary — the card never sees it as a knob, and the composed
139
+ // stage stamps it (runsRegistry's card arm) so the run sidecar's
140
+ // digest names the row the operator pressed, which is what the
141
+ // bench read's `last_run` binds to. Unregistered, it would land in
142
+ // every card's params as an unknown knob and refuse the press.
143
+ "bench_stage_id",
144
+ // seeds is the submit door's seed-sweep coordinate (friction #9,
145
+
146
+ // door vocabulary consumed before any card composes, never a card
147
+ // knob. The per-run body carries the SEAT's `seed` (a real knob,
148
+ // deliberately NOT on this list — liftCardParams must carry it
149
+ // into the card's params); the sweep key itself rides the envelope.
150
+ "seeds",
127
151
  // the bench row's own non-wire coordinates (benchStage's stage row
128
152
  // carries these beside the wire keys; they select, they never ride)
129
153
  "author",
@@ -205,14 +229,278 @@ export function familyFace(fam) {
205
229
 
206
230
 
207
231
 
232
+ /** The unstated-required-word class test: the contracts' judge owns
233
+ * the sentence stem (isUnstatedRequiredVoice — the one spelling).
234
+ * Named — the run seat's refusal code and the write door's filter
235
+ * spell the same class through it. */
236
+
237
+
238
+
239
+
240
+
241
+
242
+
243
+
244
+
245
+
246
+
247
+
248
+
249
+
250
+
251
+
252
+
253
+
254
+
255
+
256
+ function stampClipGeometry(body, admits) {
257
+ const clip = body["clip"];
258
+ if (typeof clip !== "string" || clip === "")
259
+ return;
260
+ // UNSTATED has two spellings: an ABSENT key (the GUI wire omits
261
+
262
+ // width/height at all, run-9e6585c227c8) and an explicit 0 (the
263
+ // form's stated default). Both mean "the user owns no geometry";
264
+ // either stamps. A stated non-zero number is the user's — never
265
+ // touched.
266
+ const w = body["width"];
267
+ const h = body["height"];
268
+ const unstated = (v) => v === undefined || v === 0;
269
+ if (typeof w !== "number" && w !== undefined)
270
+ return;
271
+ if (typeof h !== "number" && h !== undefined)
272
+ return;
273
+ if (!unstated(w) && !unstated(h))
274
+ return;
275
+ if (!admits("width") && !admits("height"))
276
+ return;
277
+ const abs = clip.startsWith("/")
278
+ ? clip
279
+ : resolveRepoRoot() + "/" + clip.replace(/^\/+/, "");
280
+ let bytes;
281
+ try {
282
+ const st = statSync(abs);
283
+ if (!st.isFile())
284
+ return;
285
+ bytes = new Uint8Array(readFileSync(abs));
286
+ }
287
+ catch {
288
+ return;
289
+ }
290
+ let probed;
291
+ try {
292
+ probed = probeMedia(bytes);
293
+ }
294
+ catch {
295
+ return;
296
+ }
297
+ const stream = probed.streams.find((s) => s.width !== undefined && s.height !== undefined);
298
+ if (stream === undefined)
299
+ return;
300
+ if (unstated(w) && admits("width"))
301
+ body["width"] = stream.width;
302
+ if (unstated(h) && admits("height"))
303
+ body["height"] = stream.height;
304
+ }
305
+ /** The h3 bags whose second pass CARRIES the source clip's
306
+ * soundtrack (each composes a VHS [frames, audio] load and feeds
307
+ * the sound VAE — replace swaps the cast, repair cleans it, extend
308
+ * continues it, refine upscales it; the reshoot bag is absent on
309
+ * purpose, its card states the soundtrack does not carry over). */
310
+ const H3_SOUND_CARRYING_BAGS = ["replace", "repair", "extend", "refine"];
311
+ /** Resolve a bag source to a readable file: absolute, repo-relative
312
+ * (the compose's own staged-leaf posture), else the estate input
313
+ * index by basename. */
314
+ function bagSourceBytes(leaf) {
315
+ const candidates = [];
316
+ if (leaf.startsWith("/"))
317
+ candidates.push(leaf);
318
+ candidates.push(resolveRepoRoot() + "/" + leaf.replace(/^\/+/, ""));
319
+ const base = leaf.split("/").pop() ?? "";
320
+ if (base !== "")
321
+ candidates.push(resolveRepoRoot() + "/data/input/" + base);
322
+ for (const abs of candidates) {
323
+ try {
324
+ const st = statSync(abs);
325
+ if (!st.isFile())
326
+ continue;
327
+ return new Uint8Array(readFileSync(abs));
328
+ }
329
+ catch {
330
+
331
+
332
+
333
+ }
334
+ }
335
+ return null;
336
+ }
337
+
338
+
339
+
340
+
341
+
342
+
343
+
344
+
345
+ function refuseSilentSource(card, params) {
346
+ if (card !== "h3-timeline")
347
+ return;
348
+ for (const lane of H3_SOUND_CARRYING_BAGS) {
349
+ const bag = params[lane];
350
+ if (!Array.isArray(bag) || bag.length === 0)
351
+ continue;
352
+ for (const entry of bag) {
353
+ if (entry === null || typeof entry !== "object" || Array.isArray(entry))
354
+ continue;
355
+ const leaf = entry["source_clip"];
356
+ if (typeof leaf !== "string" || leaf.trim() === "")
357
+ continue;
358
+ const bytes = bagSourceBytes(leaf.trim());
359
+ if (bytes === null)
360
+ continue;
361
+ let probed;
362
+ try {
363
+ probed = probeMedia(bytes);
364
+ }
365
+ catch {
366
+ continue;
367
+ }
368
+ if (probed.streams.some((stream) => stream.codec_type === "audio" || stream.sample_rate !== undefined))
369
+ continue;
370
+ throw new CardArmError(400, `the ${lane} pass carries the source clip's soundtrack, and "${leaf.trim()}" has no audio track ` +
371
+ `(probed ${probed.streams.length} stream(s), none audio) — add a track, or pick a source that has one; ` +
372
+ `a silent source dies mid-render inside the video loader`, "invalid_request");
373
+ }
374
+ }
375
+ }
376
+ /** The card-scope seat for the clip-geometry stamp: resolves the
377
+ * card the run addresses — the family route's famRow.card, or the
378
+ * familyless id itself — mirroring prepareCardParams's two arms,
379
+ * then answers admission's own predicate for a key. An
380
+ * unresolvable card admits nothing (the stamp no-ops; prepare's
381
+ * own refusal owns that voice). */
382
+ function clipGeometryAdmits(deps, mid) {
383
+ const facts = deps.modelFacts();
384
+ const resolves = mid in facts || deps.resolveCardFamily(mid, facts) in facts || deps.modelMids().has(mid);
385
+ const fam = deps.resolveCardFamily(mid, facts);
386
+ const famRow = facts[fam];
387
+ const card = resolves && famRow !== undefined ? famRow.card : mid;
388
+ const decls = deps.cardDecls(facts);
389
+ const decl = decls[card];
390
+ return (key) => cardAdmits(decl, new Set(), key);
391
+ }
392
+ function isUnstatedRequiredWord(message) {
393
+ return isUnstatedRequiredVoice(message);
394
+ }
208
395
  function incompleteDraftViolations(violations) {
209
- return violations.filter((v) => !v.message.startsWith("this lane requires"));
396
+
397
+ // drop itself is ONE spelling in the contracts judge
398
+ // (dropAuthoringIncomplete); the form's inline gate calls the same
399
+ // function, so the class can never drift between the two
400
+ // transports (attempt 12 was exactly that drift: the door
401
+ // filtered, the form's copy didn't, and the keystroke refused).
402
+ return dropAuthoringIncomplete(violations);
403
+ }
404
+ /** THE OUTPUT-RESOLUTION SEAM (round-22 compose audit Q4a,
405
+ * VALIDATE-RESOLVES-OUTPUTS): phase 2's def lookup + output
406
+ * resolution with the run seat's exact voices, shared by the run
407
+ * seat (phase2Card, thrown as CardArmError) and the validate seat
408
+ * (composeValidateCard, folded to its verdict). Validate composed
409
+ * the graph and discarded it, so every phase-2 output refusal
410
+ * answered validate-green/start-refuse on the binding cards; the
411
+ * seat resolves over its phase-1 graph now — same overlaid
412
+ * params, same graph, same refusal. Cards without bindings
413
+ * resolve vacuously (the resolver returns {}), so their seats
414
+ * answer exactly as before.
415
+ * @param defs the card definitions table
416
+ * @param card the card id (prepare already admitted it)
417
+ * @param params the prepared params (the overlaid truth both doors hold)
418
+ * @param graph the composed graph
419
+ */
420
+ export function resolveCardOutputsOrThrow(defs, card, params, graph) {
421
+ const def = defs.get(card);
422
+ if (def === undefined) {
423
+ throw new CardArmError(400, `unknown card ${card}`, "card_compose");
424
+ }
425
+ try {
426
+ return resolveCardFlowOutputs(def, params, graph);
427
+ }
428
+ catch (error) {
429
+ if (error instanceof ComposeRefusal) {
430
+ throw new CardArmError(400, `${error.code}: ${error.message}`, "card_compose");
431
+ }
432
+ // PHASE2-CATCH-ALL (round-22 compose audit Q5a): a non-refusal
433
+ // throw here — a flowKinds-less def, a binding `when` that
434
+ // throws — is this card's output resolution failing on the
435
+ // request, and it rides the same 400 envelope as the refusal
436
+ // arm: both doors catch CardArmError only, so a raw rethrow
437
+ // surfaced as a 500.
438
+ const why = error instanceof Error ? error.message : String(error);
439
+ throw new CardArmError(400, `flow-output: ${card}: ${why}`, "card_compose");
440
+ }
441
+ }
442
+
443
+
444
+
445
+
446
+
447
+
448
+
449
+
450
+
451
+
452
+
453
+ export const FAMILY_RESEAT_CARVE = [];
454
+
455
+
456
+
457
+
458
+
459
+
460
+
461
+
462
+
463
+
464
+ function familyLawOfCard(def) {
465
+ for (const family of def.boarded) {
466
+ const law = getModel(family).familyLaw;
467
+ if (law !== undefined)
468
+ return law;
469
+ }
470
+ return undefined;
471
+ }
472
+
473
+
474
+
475
+
476
+
477
+
478
+
479
+
480
+
481
+
482
+
483
+ export function familyLawDrift(laws) {
484
+ const drift = [];
485
+ for (const [family, law] of laws) {
486
+ const lanes = new Set(law.lanes.map((l) => l.lane));
487
+ if (law.lanes.length === 0)
488
+ drift.push(`${family}: no lanes declared`);
489
+ const orphan = Object.keys(law.deadKeys).filter((l) => !lanes.has(l));
490
+ if (orphan.length > 0)
491
+ drift.push(`${family}: deadKeys names undeclared lanes ${JSON.stringify(orphan)}`);
492
+ }
493
+ return drift;
210
494
  }
211
495
  export class CardRegistryService extends Service {
496
+ static inject = ["queue"];
212
497
  /** The primed card definitions (null until prime()). */
213
498
  defs = null;
214
499
  /** The frozen model facts (lazy — strict load, throws LOUD). */
215
500
  facts = null;
501
+ /** When the facts cache primed (HMR audit 009 F2 — the staleness
502
+ * signal's own clock; null until the first modelFacts()). */
503
+ factsPrimedAt = null;
216
504
  /** Route address → family owner from the registry-derived facts. */
217
505
  owners = {};
218
506
  /** Registry reads for the row derivation (primed with the models boot). */
@@ -224,11 +512,22 @@ export class CardRegistryService extends Service {
224
512
  * primeObjectInfo before any compose). null = not yet primed or
225
513
  * the engine is unreachable. */
226
514
  oi = null;
515
+ /** The doc the process singleton was last armed with (the re-arm
516
+ * guard — auditor G's row: a weight landing changes the doc
517
+ * identity, and the singleton must follow it; an unchanged doc
518
+ * re-arms nothing). null = never armed (or a boot re-prime). */
519
+ singletonArmedOi = null;
227
520
  /** The catalog existence set (lazy — strict load, throws LOUD). */
228
521
  mids = null;
229
522
  constructor(ctx) {
230
523
  super(ctx, "cardRegistry");
231
524
  }
525
+ /** The §23 manifest for the compose gate's dangling sweep (the
526
+ * ComposeSeat seam): one law from the queue seat — config-named
527
+ * roots, never the retired env seam (J12). */
528
+ stateRoots() {
529
+ return this.ctx.queue.stateRoots;
530
+ }
232
531
  /** Prime the registry (service init — replaces the retired
233
532
  * primeCardRegistry()): the registry loads async (dynamic
234
533
  * card-module imports) but the validate/disclosure rims are sync,
@@ -241,9 +540,58 @@ export class CardRegistryService extends Service {
241
540
  async prime() {
242
541
  this.defs = await loadCardDefs();
243
542
  this.decls = null;
543
+
544
+
545
+ // derived family rides the lane declaration (familyLaw data)
546
+ // and the registry's ONE seat settles the strand through the
547
+ // shared spelling. prime() reds on ANY card declaring the face:
548
+ // the carve can never silently refill. THE DECLARATION JUDGE:
549
+ // every familyLaw is validated at boot — deadKeys naming a lane
550
+ // the lanes array does not declare reds HERE, before any live
551
+ // write, so a mistyped lane id can never silently no-op the
552
+ // drop (a law nobody can hit is a lie the estate refuses to
553
+ // serve).
554
+ // the face is DELETED from the type — read the runtime extra
555
+ // property through the cast so the judge keeps its teeth on a
556
+ // def that silently grows one back (the wall's own spelling).
557
+ const carved = [...this.defs.entries()]
558
+ .filter(([, def]) => def.reseatFamily !== undefined)
559
+ .map(([id]) => id)
560
+ .sort();
561
+ if (carved.length > 0) {
562
+ throw new Error("family-reseat carve violated: cards declaring reseatFamily " +
563
+ JSON.stringify(carved) +
564
+ ". The per-card reseat face is DEAD (the one-seat migration, 2026-11-12): " +
565
+ "the derived family rides the MODEL DECL (ModelDecl.familyLaw) and " +
566
+ "the registry's ONE seat (reseatStageFamily) settles the strand through " +
567
+ "@melite/contracts familyLane.ts. Grow the declaration, never another face.");
568
+ }
244
569
  // the models boot feeds the row derivation (facts.ts renders
245
570
  // rows through these reads — one spelling, no frozen matrix).
571
+ // THE DECLARATION JUDGE rides AFTER the boot (getModel is
572
+ // strict without it): every declared familyLaw — a card's
573
+ // boarded families, deduped — must name at least one lane, and
574
+ // every deadKeys lane must be a lane the lanes array declares.
575
+ // A drop keyed to a lane nobody derives never fires — a law the
576
+ // estate refuses to serve, red HERE at boot, before any live
577
+ // write.
246
578
  await bootModels();
579
+ const laws = new Map();
580
+ for (const def of this.defs.values()) {
581
+ for (const family of def.boarded) {
582
+ if (laws.has(family))
583
+ continue;
584
+ const law = getModel(family).familyLaw;
585
+ if (law !== undefined)
586
+ laws.set(family, law);
587
+ }
588
+ }
589
+ const badLaw = familyLawDrift(laws);
590
+ if (badLaw.length > 0) {
591
+ throw new Error("family-law declaration violated: " + badLaw.join("; ") +
592
+ ". Every deadKeys lane must be a lane the lanes array declares — " +
593
+ "a drop keyed to a lane nobody derives never fires.");
594
+ }
247
595
  this.reads = { getModel, registryIds, registryModel };
248
596
  this.facts = null;
249
597
  this.owners = {};
@@ -255,15 +603,34 @@ export class CardRegistryService extends Service {
255
603
  // lane. Same live doc + same facts file the compose gate reads:
256
604
  // one truth, two seats, one spelling of the check.
257
605
  await this.primeObjectInfo();
606
+ // the boot arm rides the guard too: primeObjectInfo just armed
607
+ // the fresh doc (or skipped an unchanged one — a skip means the
608
+ // singleton already serves that exact doc)
609
+ this.armSingletonFromDoc(this.oi);
610
+ }
611
+
612
+
613
+
614
+
615
+
616
+
617
+
618
+
619
+
620
+
621
+ armSingletonFromDoc(doc) {
622
+ if (doc === this.singletonArmedOi)
623
+ return;
624
+ this.singletonArmedOi = doc;
258
625
  try {
259
626
  const svc = theService();
260
- svc.setObjectInfo(this.objectInfo());
627
+ svc.setObjectInfo(doc);
261
628
  svc.setFacts(loadFacts(factsPath(), this.readsSync()));
262
629
  }
263
630
  catch {
264
631
  // the singleton is not resolvable in this context — the
265
- // serving surfaces degrade to unknown marks (never a throw on
266
- // the prime path; compose still arms its own fresh service)
632
+ // serving surfaces degrade to unknown marks (compose still
633
+ // arms its own fresh service)
267
634
  }
268
635
  }
269
636
  /** Test seam: drop all registry state (walls boot fresh processes;
@@ -275,6 +642,7 @@ export class CardRegistryService extends Service {
275
642
  this.reads = null;
276
643
  this.decls = null;
277
644
  this.oi = null;
645
+ this.singletonArmedOi = null;
278
646
  this.mids = null;
279
647
  }
280
648
  /** Sync read of the primed registry (the disclosure projection
@@ -324,18 +692,49 @@ export class CardRegistryService extends Service {
324
692
  const doc = loadFacts(factsPath(), this.readsSync());
325
693
  this.facts = doc.models;
326
694
  this.owners = { ...doc.owners };
695
+ this.factsPrimedAt = new Date();
327
696
  return this.facts;
328
697
  }
698
+
699
+
700
+
701
+
702
+
703
+
704
+
705
+
706
+
707
+ factsStaleness() {
708
+ const path = factsPath();
709
+ const mtime = statSync(path).mtime;
710
+ const primed = this.factsPrimedAt;
711
+ return {
712
+ primed_at: primed?.toISOString() ?? null,
713
+ source: path,
714
+ source_mtime: mtime.toISOString(),
715
+ stale: primed !== null && mtime.getTime() > primed.getTime(),
716
+ };
717
+ }
329
718
  /** The decl projection — derived from defs + the strict facts, or
330
719
  * from defs + caller-supplied facts (the validate door's
331
720
  * degraded read; derived fresh, never cached over foreign facts). */
332
721
  cardDecls(facts) {
333
722
  if (facts !== undefined)
334
723
  return deriveDecls(this.defsSync(), facts);
335
- if (this.decls !== null)
336
- return this.decls;
337
- const derived = deriveDecls(this.defsSync(), this.modelFacts());
338
- this.decls = derived;
724
+
725
+ // cure): refreshCardDefs() swaps the defs module cache —
726
+
727
+ // and kept serving the boot snapshot (a hot card served in
728
+ // forms, then refused at validate/run). The cache re-derives
729
+ // once when the cache identity differs from the primed proof;
730
+ // facts/owners/mids stay untouched (disk/boot derived, not
731
+ // defs-derived).
732
+ const now = cardDefsNow() ?? this.defs;
733
+ if (this.decls === null || now !== this.defs) {
734
+ const derived = deriveDecls(this.defsSync(), this.modelFacts());
735
+ this.decls = derived;
736
+ this.defs = now;
737
+ }
339
738
  return this.decls;
340
739
  }
341
740
  /** The primed live doc (sync face for the sweeps/spec fakes).
@@ -343,19 +742,31 @@ export class CardRegistryService extends Service {
343
742
  objectInfo() {
344
743
  return this.oi;
345
744
  }
346
- /** Prime the live node-definitions doc off the engine (/object_info
347
- * via the SDK, cached per process). Never throws: false = the
348
- * engine is unreachable and the doc stays null (the compose gate
349
- * refuses CLOSED on that; the serving surfaces degrade). */
350
- async primeObjectInfo() {
745
+
746
+
747
+
748
+
749
+
750
+
751
+
752
+
753
+
754
+
755
+
756
+
757
+
758
+ async primeObjectInfo(boundMs = 60_000) {
351
759
  try {
352
- this.oi = await liveObjectInfo(resolveEngineBaseUrl());
760
+ this.oi = await liveObjectInfo(resolveEngineBaseUrl(), undefined, boundMs);
353
761
  this.armWiringFromDoc(this.oi);
762
+ this.armSingletonFromDoc(this.oi);
354
763
  return true;
355
764
  }
356
765
  catch {
357
766
  this.oi = null;
358
767
  this.armWiringFromDoc(null);
768
+ // the singleton keeps its last armed doc — an unreachable
769
+ // engine never degrades a healthy serving surface
359
770
  return false;
360
771
  }
361
772
  }
@@ -402,6 +813,18 @@ export class CardRegistryService extends Service {
402
813
  this.mids = new Set(ids);
403
814
  return this.mids;
404
815
  }
816
+ /** THE LANDING RE-ARM (the cards-plane batch's weight-landing row):
817
+ * every presence face (cardFamilies' present flags, admitModel's
818
+ * downloaded list) reads this.mids, and the cache froze at boot —
819
+ * a weight landed mid-process (provision_model, download_model,
820
+ * acquire_weight) served present:false until a reboot. This drops
821
+ * the cache; the NEXT read re-derives from the live scan order.
822
+ * The manage plane calls it on every model landing under a living
823
+ * process. No truth outside mids changes: facts/owners/defs are
824
+ * DECL-derived, and a landing moves files, not declarations. */
825
+ rearmWeights() {
826
+ this.mids = null;
827
+ }
405
828
  /** The owning family for mid: mid itself, or the facts model whose
406
829
  * variant/cell route owns mid (mirrors _route_family;
407
830
  * route-id-as-model is preserved — the graph is addressed by the
@@ -439,11 +862,14 @@ export class CardRegistryService extends Service {
439
862
  // mids — the lens arms never fire through this path.)
440
863
  for (const [fam, row] of Object.entries(table)) {
441
864
  for (const v of row.variants ?? []) {
442
- /* v8 ignore next */
865
+
866
+
867
+
443
868
  if (v.route === mid)
444
869
  return fam;
445
870
  for (const c of v.cells ?? []) {
446
- /* v8 ignore next */
871
+ /* v8 ignore next -- same census: a cell route is a route,
872
+ * and no route lives outside mids — never fires. */
447
873
  if (c.route === mid)
448
874
  return fam;
449
875
  }
@@ -534,7 +960,7 @@ export class CardRegistryService extends Service {
534
960
  }
535
961
  return { ok: true };
536
962
  }
537
- const flow = getRegistryFlow(card);
963
+ const flow = this.ctx.get("meliteFlows").get(card);
538
964
  if (flow !== undefined) {
539
965
  // The stage list names BOTH planes' riders: card stages by
540
966
  // card id, family stages by family.action (the five census
@@ -579,6 +1005,19 @@ export class CardRegistryService extends Service {
579
1005
  // (CardDefinition pins boarded: readonly string[] — required, and
580
1006
  // every live def carries it — so no undefined fallback here.)
581
1007
  const boarded = def.boarded;
1008
+ // THE CARD-UNIT ALIAS (the minted-model regression kill,
1009
+
1010
+ // NOTHING is its own routing key — the GUI's Run press names the
1011
+ // card id (stage-run maps defaultFamilyForCard's null to the card
1012
+ // id explicitly), the compose seam lanes it on
1013
+ // modelId==='' (cardsCompose's familyless arm), and this
1014
+
1015
+ // 'mask' is not offered by card 'mask'", boards: none) — every
1016
+ // model-less card's Run died HERE. The card's OWN id is the
1017
+ // card-unit arm, never a model offer; any other unboarded id
1018
+ // keeps refusing below (the address-must-be-the-offer law).
1019
+ if (boarded.length === 0 && model === card)
1020
+ return { ok: true };
582
1021
  const mids = this.modelMids();
583
1022
  const downloaded = boarded.filter((fam) => mids.has(fam));
584
1023
 
@@ -637,6 +1076,313 @@ export class CardRegistryService extends Service {
637
1076
 
638
1077
 
639
1078
 
1079
+
1080
+
1081
+
1082
+
1083
+
1084
+
1085
+
1086
+
1087
+ admitStageFamily(card, params) {
1088
+ const def = this.defsSync().get(card);
1089
+ if (def === undefined || def.admitFamily === undefined)
1090
+ return { ok: true };
1091
+ return def.admitFamily(params);
1092
+ }
1093
+
1094
+
1095
+
1096
+
1097
+
1098
+
1099
+
1100
+
1101
+
1102
+
1103
+
1104
+
1105
+
1106
+
1107
+
1108
+
1109
+
1110
+
1111
+ reseatStageFamily(card, params, priorParams) {
1112
+ const def = this.defsSync().get(card);
1113
+ if (def === undefined)
1114
+ return null;
1115
+ const law = familyLawOfCard(def);
1116
+ if (law === undefined)
1117
+ return null;
1118
+ return reseatDeadKeys(law, params, priorParams);
1119
+ }
1120
+
1121
+
1122
+
1123
+
1124
+
1125
+
1126
+
1127
+
1128
+
1129
+
1130
+
1131
+
1132
+
1133
+
1134
+
1135
+
1136
+
1137
+
1138
+
1139
+
1140
+
1141
+ laneMigrate(card, params, priorParams) {
1142
+ // one seat's tolerance on the NEXT view: a selection/prepare
1143
+ // fault there is the ADMISSION's voice, never this seat's — an
1144
+ // unresolvable next state passes through untouched and refuses
1145
+ // (or tolerates) exactly as it did before this seat existed.
1146
+ let prepNext;
1147
+ try {
1148
+ const midNext = params["model"];
1149
+ if (typeof midNext !== "string" || midNext === "")
1150
+ return params;
1151
+ prepNext = prepareCardParams(this, params, midNext, "admission");
1152
+ }
1153
+ catch {
1154
+ return params;
1155
+ }
1156
+ const facts = this.modelFacts();
1157
+
1158
+ // wedge): a stage whose family is spec-implied never states
1159
+ // `model`, so no prior lane resolves — the old seat returned
1160
+ // here and the write refused downstream (the variant's
1161
+ // declared surface names nothing the prior lane's words
1162
+ // explain). The carry is still identifiable without the prior
1163
+ // lane (any member SOME lane declares that the next lane does
1164
+ // not take), so the seat continues to the union fallback
1165
+ // below; a member NO lane declares stays authored and still
1166
+ // refuses.
1167
+ // THE KNOWN-BUT-HIDDEN PRIOR (the 2511 soft-retire,
1168
+
1169
+ // know but no dropdown offers throws the hidden-address
1170
+ // refusal out of prepareCardParams — standing aside would
1171
+ // strand the switch (stale 2511-only carry survives and
1172
+ // refuses downstream: the stuck-switch injury this seat
1173
+ // exists to prevent). The prior lane's words stay DECLARED,
1174
+ // so the seat falls through to the same union fallback: a
1175
+ // union member the next lane does not take drops, a member of
1176
+ // nothing stays authored and still refuses. A prior whose
1177
+ // family the facts do not know at all (a card-addressed
1178
+ // Run-press prior, a fully retired mid) is the tolerance
1179
+ // law's own shape — the seat stands aside exactly as before.
1180
+ let prepPrior = null;
1181
+ try {
1182
+ const midPrior = priorParams["model"];
1183
+ if (typeof midPrior === "string" && midPrior !== "") {
1184
+ prepPrior = prepareCardParams(this, priorParams, midPrior, "admission");
1185
+ }
1186
+ }
1187
+ catch {
1188
+ const midPrior = priorParams["model"];
1189
+ if (typeof midPrior !== "string" || midPrior === "" || facts[midPrior] === undefined)
1190
+ return params;
1191
+ }
1192
+ const famNext = facts[prepNext.fam];
1193
+ if (famNext === undefined)
1194
+ return params;
1195
+ const famPrior = prepPrior !== null ? facts[prepPrior.fam] : undefined;
1196
+ const cellOf = (fam, sel) =>
1197
+ // THE CELL IS PART OF THE LANE (the size-at-quant reshape,
1198
+
1199
+ // when the two cells' surfaces differ — a cell change with a
1200
+ // stale member is a MIGRATION, never a refusal.
1201
+ fam.variants.find((v) => v.id === sel.variantId)?.cells.find((c) => c.quant === sel.quant)?.params;
1202
+ // THE UNION PREV (the model-less prior's surface): every member
1203
+ // any lane declares (family ∪ variant ∪ cell, the same cascade
1204
+ // laneSurfaceOf reads). A member of the union that the next
1205
+ // lane does not take is stale carry from SOMEWHERE — the write
1206
+ // drops it and lands. A member of nothing is authored state and
1207
+ // survives to refuse.
1208
+ const unionPrevSurface = () => {
1209
+ const acc = new Set();
1210
+ for (const f of Object.values(facts)) {
1211
+ for (const n of f.params ?? [])
1212
+ acc.add(n);
1213
+ for (const v of f.variants) {
1214
+ for (const n of v.params ?? [])
1215
+ acc.add(n);
1216
+ for (const c of v.cells) {
1217
+ for (const n of c.params ?? [])
1218
+ acc.add(n);
1219
+ }
1220
+ }
1221
+ }
1222
+ return [...acc];
1223
+ };
1224
+ let selNext;
1225
+ let selPrior = null;
1226
+ let prevSurface;
1227
+ try {
1228
+ selNext = selectCardVariant(prepNext.mid, famNext, params, "admission", familyLanesOf(prepNext.decl.boarded), prepNext.fam);
1229
+ if (prepPrior === null) {
1230
+ prevSurface = unionPrevSurface();
1231
+ }
1232
+ else {
1233
+ // A resolved prior whose family the facts do not know is the
1234
+ // tolerance law's own shape (a card-addressed Run-press
1235
+ // prior, a retired mid): the union would misread its words
1236
+ // as some other lane's, so the seat stands aside exactly as
1237
+ // it always did.
1238
+ if (famPrior === undefined)
1239
+ return params;
1240
+ const priorSel = selectCardVariant(prepPrior.mid, famPrior, priorParams, "admission", familyLanesOf(prepPrior.decl.boarded), prepPrior.fam);
1241
+ selPrior = priorSel;
1242
+ prevSurface = laneSurfaceOf(famPrior.params, famPrior.variants.find((v) => v.id === priorSel.variantId)?.params, cellOf(famPrior, priorSel));
1243
+ }
1244
+ }
1245
+ catch {
1246
+ return params;
1247
+ }
1248
+ // same lane, no migration — a same-lane patch judges exactly as
1249
+ // it always did (an off-surface member stated ON the lane it
1250
+ // was authored on refuses; this seat never softens that). A
1251
+ // model-less prior is never the same lane: the next lane
1252
+ // resolves, the prior cannot equal it, so the seat always
1253
+ // continues to the union below.
1254
+ if (selPrior !== null &&
1255
+ prepPrior !== null &&
1256
+ prepNext.fam === prepPrior.fam &&
1257
+ selNext.variantId === selPrior.variantId &&
1258
+ selNext.quant === selPrior.quant) {
1259
+ return params;
1260
+ }
1261
+ const nextSurface = laneSurfaceOf(famNext.params, famNext.variants.find((v) => v.id === selNext.variantId)?.params, cellOf(famNext, selNext));
1262
+
1263
+ // the stale rule judges what each side TAKES — the lane surface
1264
+ // PLUS that side's absorbed mod fold. Deliberately NOT the
1265
+ // card's static words (schemaNames/admits): the lane door judges
1266
+ // the variant surface, so a static-carried member the next lane
1267
+ // does not take still refuses downstream (the 2511 pair ride the
1268
+ // image-edit schema AND the 2511 surface — on the 21 lane the
1269
+ // surface is what fires). A mod rider the prior fold absorbed
1270
+ // but the next does not take is stale carry exactly like a
1271
+ // departed surface member (the image-gen `loras` write refusal);
1272
+ // a rider neither fold absorbs is authored state and still
1273
+ // refuses downstream. The fold reads theService: it throws in
1274
+ // the test fiber (never booted there), so the fold bodies ride
1275
+ // the v8-ignored precedent of cardsCompose's own admission —
1276
+ // the rule itself stays wallable with literal sets at
1277
+ // laneStaleCarry, which takes the sets as plain arrays.
1278
+ const takenOf = (surface, atom) => {
1279
+ // No surfaceless model family ships in facts (the legacy
1280
+ // truth has no live rows) — the null arm is the lane judge's
1281
+ // own "declares nothing, judges nothing", exercised with
1282
+ // literal sets at laneStaleCarry's wall.
1283
+ /* v8 ignore next */
1284
+ if (surface === null)
1285
+ return null;
1286
+ const taken = new Set(surface);
1287
+
1288
+ // the old text claimed theService() never boots in the test
1289
+ // fiber — FALSE since loadCardDefs sets the globalThis cell at
1290
+ // prime(); the fold CONTRIBUTES here (voice_name et al). The
1291
+ // v8-ignore regions dropped with the lie: this code executes
1292
+ // under the booted registry and owes its coverage.)
1293
+ try {
1294
+ if (atom === null) {
1295
+ // model-less prior: the generous prev — every pack field
1296
+ // the card absorbs anywhere (a rider absorbed SOMEWHERE is
1297
+ // prior carry, never authored; the next side still judges).
1298
+ for (const pack of theService().cardModFields(card)) {
1299
+ for (const n of Object.keys(pack.fields.dict ?? {}))
1300
+ taken.add(n);
1301
+ }
1302
+ }
1303
+ else {
1304
+ for (const pack of theService().cardModFields(card)) {
1305
+ if (!pack.families.includes(atom))
1306
+ continue;
1307
+ for (const n of Object.keys(pack.fields.dict ?? {}))
1308
+ taken.add(n);
1309
+ }
1310
+ }
1311
+ }
1312
+ catch (modFoldFault) {
1313
+ // modFoldFault: card defs genuinely absent (a bare fiber
1314
+ // without prime()) — the absorbed surface is empty here;
1315
+ // surfaces + statics judge.
1316
+ }
1317
+ return [...taken];
1318
+ };
1319
+ const stale = laneStaleCarry(takenOf(prevSurface, prepPrior !== null ? owningAtom(prepPrior.fam) : null), takenOf(nextSurface, owningAtom(prepNext.fam)), params);
1320
+ // THE ORPHANED HALF (the export-pair wedge, voicedesign →
1321
+ // customvoice carrying a named export): a together-group is
1322
+ // all-or-none at the admission this seat migrates toward — one
1323
+ // member dropped as stale while a stated sibling survives (kept
1324
+ // because the next lane's absorbed fold takes it) GUARANTEES
1325
+ // the downstream refusal ("state all or none"). The relations'
1326
+ // own cure is "or drop both": a stale member takes its
1327
+ // together-group with it. Groups read from the TARGET lane's
1328
+ // judged relations (family + resolved variant — the same rows
1329
+ // the admission judges), never the prior's; a sibling already
1330
+ // blank is not carried state and stays put.
1331
+
1332
+ // fixpoint verb — a single pass strands transitively-dropped
1333
+ // siblings when overlapping groups declare in the wrong order;
1334
+ // the seat and the pure wall now share one spelling.
1335
+ const staleSet = laneTogetherClosure([famNext.relations, famNext.variants.find((v) => v.id === selNext.variantId)?.relations], new Set(stale), params);
1336
+
1337
+ // law's family-seam proof): stale carry is what the STORED ROW
1338
+ // held — the doc's own past, droppable on a lane it leaves. A
1339
+ // member the merged view holds ONLY because THIS patch states
1340
+ // it is AUTHORED — the writer's present act; this seat never
1341
+ // launders it. It stands and the admission judges it exactly as
1342
+ // the a priori law promises ("a member no prior lane declared
1343
+ // is authored state and still refuses"). Before this line the
1344
+ // union fallback read the merged view alone, so a freshly
1345
+ // authored off-lane key (h3's sr_switch on a t4r arrival over a
1346
+ // bare seeded stage) classified as "carry from SOMEWHERE" and
1347
+ // silently vanished — the write landed a state the author never
1348
+ // sent, and the family judge never saw the poison. Both patch
1349
+ // verbs ride this seat, so both doors answer identically.
1350
+ const carry = [];
1351
+ for (const name of staleSet) {
1352
+ if (Object.prototype.hasOwnProperty.call(priorParams, name))
1353
+ carry.push(name);
1354
+ }
1355
+ if (carry.length === 0)
1356
+ return params;
1357
+ const cleaned = { ...params };
1358
+ for (const name of carry)
1359
+ delete cleaned[name];
1360
+ return cleaned;
1361
+ }
1362
+
1363
+
1364
+
1365
+
1366
+
1367
+
1368
+
1369
+
1370
+
1371
+ /** The lane verdict as its sentence (the write door's and the
1372
+ * validate seat's currency — the class rides only where the run
1373
+ * seat needs it, via laneVerdictDetailed). */
1374
+ laneVerdict(card, params, admitIncomplete = false) {
1375
+ return this.laneVerdictCore(card, params, admitIncomplete)?.message ?? null;
1376
+ }
1377
+
1378
+
1379
+
1380
+
1381
+
1382
+
1383
+ laneVerdictDetailed(card, params, admitIncomplete = false, factsArg) {
1384
+ return this.laneVerdictCore(card, params, admitIncomplete, factsArg);
1385
+ }
640
1386
  /** The draft (model-less) row's verdict: the words EVERY boarded
641
1387
  * declaring family states, judged over the raw params — the
642
1388
  * intersection law (see the model-less branch above). Bounds
@@ -644,7 +1390,7 @@ export class CardRegistryService extends Service {
644
1390
  * holds); relation rows bind when every family states the row
645
1391
  * verbatim. A card with no declaring family stays null (the
646
1392
  * familyless tolerance). */
647
- modellessDraftVerdict(card, params, admitIncomplete) {
1393
+ modellessDraftVerdict(card, params, admitIncomplete, factsArg) {
648
1394
  const def = this.defsSync().get(card);
649
1395
  /* v8 ignore next -- laneVerdict's own defsSync-miss guard (the
650
1396
  * same lookup, earlier in the same request) already returned on
@@ -652,7 +1398,11 @@ export class CardRegistryService extends Service {
652
1398
  * two same-request reads, which the frozen cache forbids. */
653
1399
  if (def === undefined)
654
1400
  return null;
655
- const facts = this.modelFacts();
1401
+ // ONE-FACTS-READ (round-22 compose audit Q3b): the validate
1402
+ // door threads its one facts read through the whole arm, so the
1403
+ // draft verdict judges the same table the door's prepare did —
1404
+ // never a second strict read beside a degraded first.
1405
+ const facts = factsArg ?? this.modelFacts();
656
1406
  // (boarded is required on every live def — same reasoning as
657
1407
  // admitStageModel's read above; no undefined fallback.)
658
1408
  const boarded = def.boarded;
@@ -752,12 +1502,15 @@ export class CardRegistryService extends Service {
752
1502
  ? incompleteDraftViolations(judged)
753
1503
  : [...judged];
754
1504
  if (violations.length > 0) {
755
- return "lane (draft, model-less) refuses the state: " +
756
- violations.map((v) => v.message).join("; ");
1505
+ return {
1506
+ message: "lane (draft, model-less) refuses the state: " +
1507
+ violations.map((v) => v.message).join("; "),
1508
+ incomplete: violations.every((v) => isUnstatedRequiredWord(v.message)),
1509
+ };
757
1510
  }
758
1511
  return null;
759
1512
  }
760
- laneVerdict(card, params, admitIncomplete = false) {
1513
+ laneVerdictCore(card, params, admitIncomplete = false, factsArg) {
761
1514
  const def = this.defsSync().get(card);
762
1515
  if (def === undefined)
763
1516
  return null; // mcp/flow ids — not lane-admitted
@@ -771,7 +1524,7 @@ export class CardRegistryService extends Service {
771
1524
  // family and no lane: it is judged here, over the raw params
772
1525
  // minus the envelope, before any tolerance.
773
1526
  try {
774
- admissionRefusal(this, card, "", liftCardParams(params), "admission");
1527
+ admissionRefusal(this, card, "", liftCardParams(params), "admission", factsArg);
775
1528
  }
776
1529
  catch (e) {
777
1530
  // a CardArmError is this seat's own refusal; anything else —
@@ -779,7 +1532,7 @@ export class CardRegistryService extends Service {
779
1532
  // and keeps its identity instead of becoming a verdict string
780
1533
  if (!(e instanceof CardArmError))
781
1534
  throw e;
782
- return e.message;
1535
+ return { message: e.message, incomplete: false };
783
1536
  }
784
1537
  // THE MODEL-LESS ROW STILL MEETS THE WORDS EVERY FAMILY AGREES
785
1538
  // ON (the audit's GAP 7: the form judged a model-less tts
@@ -792,11 +1545,32 @@ export class CardRegistryService extends Service {
792
1545
  // word was already declared); a word only some families state
793
1546
  // stays the run door's voice. No union — a union would refuse
794
1547
  // states the composing family admits.
795
- return this.modellessDraftVerdict(card, params, admitIncomplete); // null when no family agrees on any word
1548
+ return this.modellessDraftVerdict(card, params, admitIncomplete, factsArg); // null when no family agrees on any word
1549
+ }
1550
+ // THE EMPTY-SELECTION LAW, FIRST-CLASS (the no-default-voice
1551
+
1552
+ // to no voice, instead of VIVIAN"): the stated-empty refusal used
1553
+ // to ride an incidental ghost — the family's vivian default
1554
+ // stamped onto a resolved recipe lane refused first, and the
1555
+ // catch clause below only converted that arm error. With the
1556
+ // default gone the ghost never rides, so the law states itself
1557
+ // HERE, in the run door's own voice, before prepare: a stated
1558
+ // EMPTY variant/quant/model is not a selection, it is an
1559
+ // authoring surface's unchosen control written as a value — the
1560
+ // parity law's false admit if this seat passed it to a run door
1561
+ // that refuses the same state. An ABSENT axis still passes
1562
+ // (compose defaults it).
1563
+ for (const axis of ["model", "variant", "quant"]) {
1564
+ if (params[axis] === "") {
1565
+ return {
1566
+ message: `unknown ${axis} "" for model ${JSON.stringify(mid)} — a stated empty selection is not a choice (pick one, or remove the key and let compose default it)`,
1567
+ incomplete: false,
1568
+ };
1569
+ }
796
1570
  }
797
1571
  let prep;
798
1572
  try {
799
- prep = prepareCardParams(this, params, mid, "admission");
1573
+ prep = prepareCardParams(this, params, mid, "admission", factsArg);
800
1574
  }
801
1575
  catch (e) {
802
1576
  // THE ENVELOPE IS A DECL-OWN WORD (the audit's GAP 1: this
@@ -807,7 +1581,7 @@ export class CardRegistryService extends Service {
807
1581
  // admit the parity law forbids). It refuses HERE, at the
808
1582
  // write seat, in the same voice the run door speaks.
809
1583
  if (e instanceof EnvelopeRefusal)
810
- return e.message;
1584
+ return { message: e.message, incomplete: false };
811
1585
 
812
1586
  // bench: 'bench stage "s_0": card_compose phase 1: unknown
813
1587
  // quant "" for model "z-image" variant "turbo" (known: int8)')
@@ -824,7 +1598,7 @@ export class CardRegistryService extends Service {
824
1598
  // authors the empty string in the first place.
825
1599
  if (e instanceof CardArmError &&
826
1600
  (params["variant"] === "" || params["quant"] === "" || params["model"] === "")) {
827
- return e.message;
1601
+ return { message: e.message, incomplete: false };
828
1602
  }
829
1603
  // selection/dangling failures keep the run door's voice —
830
1604
  // this seat judges only the DECL's own words
@@ -834,7 +1608,7 @@ export class CardRegistryService extends Service {
834
1608
  // needs no family — but with a family named, the same gate judges
835
1609
  // the LIFTED view the run seat composes).
836
1610
  try {
837
- admissionRefusal(this, prep.card, prep.fam, prep.params, "admission");
1611
+ admissionRefusal(this, prep.card, prep.fam, prep.params, "admission", factsArg);
838
1612
  }
839
1613
  catch (e) {
840
1614
  /* v8 ignore next -- admissionRefusal throws only
@@ -842,9 +1616,9 @@ export class CardRegistryService extends Service {
842
1616
  * never read as a verdict. */
843
1617
  if (!(e instanceof CardArmError))
844
1618
  throw e;
845
- return e.message;
1619
+ return { message: e.message, incomplete: false };
846
1620
  }
847
- const facts = this.modelFacts();
1621
+ const facts = factsArg ?? this.modelFacts();
848
1622
  const famRow = prep.fam === "" ? undefined : facts[prep.fam];
849
1623
  if (famRow === undefined)
850
1624
  return null; // familyless card unit — no lane
@@ -857,7 +1631,7 @@ export class CardRegistryService extends Service {
857
1631
  // legacy families exactly the nothing they had.
858
1632
  let sel;
859
1633
  try {
860
- sel = selectCardVariant(mid, famRow, params, "admission");
1634
+ sel = selectCardVariant(mid, famRow, params, "admission", familyLanesOf(prep.decl.boarded), prep.fam);
861
1635
  }
862
1636
  catch {
863
1637
  /* v8 ignore next -- prepareCardParams already ran the SAME
@@ -882,12 +1656,21 @@ export class CardRegistryService extends Service {
882
1656
  // false admit, the worse half of the two errors.
883
1657
  const laneVariantId = sel.variantId;
884
1658
  const variantRow = famRow.variants.find((v) => v.id === laneVariantId);
1659
+ // THE CELL SURFACE (the size-at-quant reshape, operator
1660
+
1661
+ // the selected (variant × quant) cell's additions ride the
1662
+ // judged surface — a size cell may take a member its sibling
1663
+ // size does not (style_instruction on the 1.7B customvoice cell
1664
+ // only). selectCardVariant already resolved the cell (stated or
1665
+ // first); an off-surface member stated on the sibling cell's
1666
+ // lane refuses HERE, at the write seat, in the run door's voice.
1667
+ const cellRow = variantRow?.cells.find((c) => c.quant === sel.quant);
885
1668
  const relations = [];
886
1669
  if (famRow.relations !== undefined)
887
1670
  relations.push(famRow.relations);
888
1671
  if (variantRow?.relations !== undefined)
889
1672
  relations.push(variantRow.relations);
890
- const surface = laneSurfaceOf(famRow.params, variantRow?.params);
1673
+ const surface = laneSurfaceOf(famRow.params, variantRow?.params, cellRow?.params);
891
1674
 
892
1675
  // own numeric domains ride the DECL beside the words — family
893
1676
  // rows, per-field REPLACED by a variant row that states the
@@ -901,8 +1684,33 @@ export class CardRegistryService extends Service {
901
1684
  // THE INCOMPLETE-DRAFT LAW rides the family arm too (see the
902
1685
  // helper): the unstated required word is the run door's voice —
903
1686
  // so the filter applies ONLY when the WRITE seat is asking.
1687
+ // THE DOCUMENT PLANE IS NOT A KNOB LANE (slice 1, the keyframe
1688
+ // bus): the card's own studio.writes rows (calls, audio_clips,
1689
+ // keyframes) are document state the timeline contract validators
1690
+ // own — they ride EVERY lane by design, so the lane-surface judge
1691
+ // must not read them as knobs that "fire nothing". The exemption
1692
+ // is the DECL's own writes list (never a literal), the same
1693
+ // derivable class the ONE SEAT wall reads.
1694
+ const documentPlane = new Set((famRow.studio?.writes ?? []).map(String));
1695
+ const knobFields = prep.decl.schemaNames.filter((n) => !documentPlane.has(n));
1696
+
1697
+ // the edit lanes SURFACE the deliverable pair (width/height
1698
+ // beside the card's match_input_resolution toggle — the pair
1699
+ // sizes the render: the lane derives the encoder budget from
1700
+ // w·h and mounts the exact w×h empty latent, no ImageScale
1701
+ // tail), so the surface judge sanctions the pair like any knob
1702
+ // — and the SHARED size law judges its VALUES
1703
+ // (judgeDeliverableSize — the same spelling the firing gate
1704
+ // throws and every build() throws, so the bench and the engine
1705
+ // can never disagree). ON + stated refuses with the flip in the
1706
+ // voice; OFF + neither passes (the flip-then-type identity);
1707
+ // OFF + half/non-integer/<16 refuses field-named. The toggle's
1708
+ // presence in the served schema IS the law's declaration
1709
+ // (today only the image-edit card serves it).
1710
+ const servesDeliverableSwitch = knobFields.includes("match_input_resolution");
904
1711
  const judgedFam = [
905
- ...judgeLaneSurface(surface, prep.decl.schemaNames, prep.params),
1712
+ ...judgeLaneSurface(surface, knobFields, prep.params),
1713
+ ...(servesDeliverableSwitch ? judgeDeliverableSize(prep.params) : []),
906
1714
  ...judgeLaneRelations(relations, prep.params),
907
1715
  ...judgeLaneBounds(bounds, prep.params),
908
1716
  ];
@@ -910,8 +1718,11 @@ export class CardRegistryService extends Service {
910
1718
  ? incompleteDraftViolations(judgedFam)
911
1719
  : [...judgedFam];
912
1720
  if (violations.length > 0) {
913
- return "lane '" + prep.fam + "/" + laneVariantId + "' refuses the state: " +
914
- violations.map((v) => v.message).join("; ");
1721
+ return {
1722
+ message: "lane '" + prep.fam + "/" + laneVariantId + "' refuses the state: " +
1723
+ violations.map((v) => v.message).join("; "),
1724
+ incomplete: violations.every((v) => isUnstatedRequiredWord(v.message)),
1725
+ };
915
1726
  }
916
1727
 
917
1728
  // behavioural audit's BROKEN-B: `params: {model, text,
@@ -922,7 +1733,7 @@ export class CardRegistryService extends Service {
922
1733
  // that voice, and it now runs on BOTH seats (the lane voice
923
1734
  // first, because it is the more specific law).
924
1735
  try {
925
- admissionRefusal(this, prep.card, prep.fam, prep.params, "admission");
1736
+ admissionRefusal(this, prep.card, prep.fam, prep.params, "admission", factsArg);
926
1737
  }
927
1738
  catch (e) {
928
1739
  // the gate speaks by THROWING on the run seat; this door's
@@ -938,7 +1749,7 @@ export class CardRegistryService extends Service {
938
1749
  if (!(e instanceof CardArmError))
939
1750
  throw e;
940
1751
  /* v8 ignore next -- the belt's verdict line. */
941
- return e.message;
1752
+ return { message: e.message, incomplete: false };
942
1753
  }
943
1754
  return null;
944
1755
  }
@@ -1032,6 +1843,7 @@ export class CardRegistryService extends Service {
1032
1843
 
1033
1844
 
1034
1845
 
1846
+
1035
1847
  async composeValidateCard(card, fam, params,
1036
1848
  // the body's OWN model address, when the caller still holds it: the
1037
1849
  // `params` this arm receives has been through the overlay, so
@@ -1045,7 +1857,13 @@ export class CardRegistryService extends Service {
1045
1857
  // a param), so the prepare must see the body to select the lane —
1046
1858
  // preparing from the overlay's product silently composed the head
1047
1859
  // and refused a lawful `variant: base` clone.
1048
- rawBody) {
1860
+ rawBody,
1861
+ // ONE-FACTS-READ (round-22 compose audit Q3b): the validate
1862
+ // door's one facts read (degraded-or-fresh), threaded through
1863
+ // the internal prepare and the lane verdict so the whole arm
1864
+ // judges a single table. Omitted by every other seat (start
1865
+ // keeps its strict reads).
1866
+ factsArg) {
1049
1867
 
1050
1868
  // question: "HOW DID THE VALIDATE RETURN SUCCESS WHEN THE INPUT
1051
1869
  // IMAGE DID NOT GO"): the {model:} door composes ONE stage and
@@ -1099,11 +1917,11 @@ export class CardRegistryService extends Service {
1099
1917
  return { message: boardCheck.error, code: "invalid_request" };
1100
1918
  let prep;
1101
1919
  try {
1102
- prep = prepareCardParams(this, rawBody ?? params, address, "1");
1920
+ prep = prepareCardParams(this, rawBody ?? params, address, "1", factsArg);
1103
1921
  }
1104
1922
  catch (e) {
1105
- // no factsArg is passed to composeValidateCard, so prepare's own
1106
- // strict facts load sits inside this try: a CardArmError is this
1923
+ // the threaded facts (or prepare's own strict load for seats
1924
+ // that omit it) sit inside this try: a CardArmError is this
1107
1925
  // seat's refusal, and every other throw keeps its identity
1108
1926
  if (!(e instanceof CardArmError))
1109
1927
  throw e;
@@ -1117,12 +1935,60 @@ export class CardRegistryService extends Service {
1117
1935
  // validate — an export conflict answered ok:true here while the
1118
1936
  // bench and the start door both refused it). The run seat already
1119
1937
  // judges `body`; the seats now judge the same thing.
1120
- const laneRefusal = this.laneVerdict(card, rawBody ?? params);
1938
+
1939
+ // seat once answered its own `lane_refusal` code — a spelling
1940
+ // RUNS_ERROR_CODES never tabled, so the runs validate door's
1941
+ // unmapped-code guard LOUD-threw and crashed the door on the
1942
+ // very refusal it existed to answer. The verdict now rides the
1943
+ // SAME incomplete-distinct codes the run seat's phaseRefusalCode
1944
+ // throws, so validate predicts start verbatim.
1945
+ const laneRefusal = this.laneVerdictDetailed(card, rawBody ?? params, false, factsArg);
1121
1946
  if (laneRefusal !== null) {
1122
- return { message: laneRefusal, code: "lane_refusal" };
1947
+ return {
1948
+ message: laneRefusal.message,
1949
+ code: laneRefusal.incomplete
1950
+ ? "card_compose_incomplete"
1951
+ : "card_compose",
1952
+ };
1953
+ }
1954
+
1955
+ // validate-green/start-red twin): phase 1 refuses a missing lane
1956
+ // file (lane_input_missing); this seat answered ok for the same
1957
+ // body. Same gate, same voice — validate predicts start on
1958
+ // weights, not just on shape.
1959
+ if (prep.familyless !== true) {
1960
+ // THE VARIANT-LANE PRESENCE LAW (h¹ remainder): the probe rides
1961
+ // the RESOLVED lane inputs — the body's stated variant over the
1962
+ // address's own row (the same derivation the compose stamps).
1963
+
1964
+ // lanePresenceRefusal THROWS its miss — phase1Card's pinned
1965
+ // contract ("the refusal is a THROW, never a value"), so the
1966
+ // `miss !== null` arm this seat wrote was dead code, and the
1967
+ // raw CardArmError escaped to the door's failEstate, which
1968
+ // mints 502 for every non-RemoteError throw: a missing weight
1969
+ // at /v1/flows/validate answered Bad Gateway (krea-2,
1970
+ // flux-klein — the combination sweep's live red) while the
1971
+ // same miss at phase1 answered its lawful 400. The fold
1972
+ // answers the miss as THIS seat's verdict, same voice, same
1973
+ // code — walled by lane-presence-validate-fold.spec.
1974
+ try {
1975
+ lanePresenceRefusal(prep.fam, prep.params, prep.modelId);
1976
+ }
1977
+ catch (e) {
1978
+ if (e instanceof CardArmError)
1979
+ return { message: e.message, code: e.code };
1980
+ throw e;
1981
+ }
1123
1982
  }
1124
1983
  try {
1125
- await composeOnce(this, prep.card, prep.modelId, prep.params, "", "1");
1984
+ const graph = await composeOnce(this, prep.card, prep.modelId, prep.params, "", "1");
1985
+ // VALIDATE-RESOLVES-OUTPUTS (round-22 compose audit Q4a): the
1986
+ // seat composed the graph and discarded it, so every phase-2
1987
+ // output refusal answered validate-green/start-refuse. The
1988
+ // phase-1 graph resolves through the shared seam — the
1989
+ // CardArmError fold below speaks the run seat's exact voice
1990
+ // as this seat's verdict.
1991
+ resolveCardOutputsOrThrow(this.defsSync(), prep.card, prep.params, graph);
1126
1992
  return null;
1127
1993
  }
1128
1994
  catch (e) {
@@ -1136,7 +2002,30 @@ export class CardRegistryService extends Service {
1136
2002
  * registration. The $spell branch composes NO graph (the pool
1137
2003
  * passes — the two-card-flow handoff). */
1138
2004
  async phase1Card(body, mid) {
2005
+
2006
+ // "width and height are defaulting to zero for viggle… it needs
2007
+ // to follow what image edit does and default to the input size
2008
+ // of the video"): a body carrying a `clip` param AND
2009
+ // width/height knobs riding the family's 0 default (the
2010
+ // follow-the-clip convention) gets the clip's OWN geometry
2011
+ // stamped into the body BEFORE any resolution or judge runs —
2012
+ // prepareCardParams, the lane verdict, the ledger and the graph
2013
+ // all read real numbers, never a zero that reads broken. Both
2014
+ // stated = the user owns the geometry; a probe miss (an
2015
+ // unreadable file or an unrecognized container, webm today)
2016
+ // leaves the 0s riding — the engine's own follow-the-clip
2017
+ // contract still renders (receipts run-be048a52385d mp4 →
2018
+ // 928×1344, run-9c267ef6c8fd webm → 928×1344). CARD-SCOPED
2019
+ // since the track-card burn (fix 7): a card that declares no
2020
+ // size knobs gets no stamped keys — the stamp may not invent
2021
+ // params admission will refuse.
2022
+ stampClipGeometry(body, clipGeometryAdmits(this, mid));
1139
2023
  const prep = prepareCardParams(this, body, mid, "1");
2024
+ // THE SILENT-SOURCE REFUSAL (F26): an armed sound-carrying bag's
2025
+ // source must carry audio — refused here, zero GPU, with the lane
2026
+ // and the file named (the run door's own envelope walk, so the
2027
+ // validate seat hears the same sentence).
2028
+ refuseSilentSource(prep.card, prep.params);
1140
2029
  // THE BOARD CHECK RIDES THE RUN SEAT TOO (the behavioural
1141
2030
  // re-check's BYPASS 1: the bench refused an unoffered model
1142
2031
  // address, but `validate` with the SAME address composed the
@@ -1177,9 +2066,16 @@ export class CardRegistryService extends Service {
1177
2066
  // resolution, the same one composeOnce gets) and reaches the same
1178
2067
  // verdict. (Confirmed by the door audit's receipt: judging
1179
2068
  // prep.params made every state admit.)
1180
- const laneRefusal = this.laneVerdict(prep.card, body);
2069
+ const laneRefusal = this.laneVerdictDetailed(prep.card, body);
1181
2070
  if (laneRefusal !== null) {
1182
- throw phaseRefusal("1", laneRefusal);
2071
+
2072
+ // replayed-refusal bug): an UNSTATED required word is bench
2073
+ // state under construction (the incomplete-draft law above) —
2074
+ // the client must not carry it onto the run face as a terminal
2075
+ // failure, or every later open replays a refusal the operator
2076
+ // cured by typing. The code names the class; a stated-wrong
2077
+ // verdict keeps the compose code and carries as a failure.
2078
+ throw phaseRefusalCode(laneRefusal.message, laneRefusal.incomplete ? "card_compose_incomplete" : "card_compose");
1183
2079
  }
1184
2080
  // THE LANE PRESENCE GATE (one pattern, every family): before any
1185
2081
  // graph composes, the family's declared lane files must stand on
@@ -1191,7 +2087,10 @@ export class CardRegistryService extends Service {
1191
2087
  // lanes, and the card's own pins gate loud at the engine's load
1192
2088
  // (the YOLO/SAM2 checkpoints refuse hard when absent).
1193
2089
  if (prep.familyless !== true) {
1194
- lanePresenceRefusal(prep.fam);
2090
+ // THE VARIANT-LANE PRESENCE LAW (h¹ remainder): same derivation
2091
+ // as validate's seat — the switch refuses LOUD at the gate, never
2092
+ // at the engine's validation.
2093
+ lanePresenceRefusal(prep.fam, prep.params, prep.modelId);
1195
2094
  }
1196
2095
  const spells = prep.decl.spells;
1197
2096
  const pool = {};
@@ -1220,20 +2119,10 @@ export class CardRegistryService extends Service {
1220
2119
  if (typeof graph !== "object" || graph === null || Array.isArray(graph)) {
1221
2120
  throw new CardArmError(400, "card_compose produced an empty graph for " + p1.mid, "invalid_request");
1222
2121
  }
1223
- const def = this.defsSync().get(p1.card);
1224
- if (def === undefined) {
1225
- throw new CardArmError(400, `unknown card ${p1.card}`, "card_compose");
1226
- }
1227
- let flow;
1228
- try {
1229
- flow = resolveCardFlowOutputs(def, p1.params, graph);
1230
- }
1231
- catch (error) {
1232
- if (error instanceof ComposeRefusal) {
1233
- throw new CardArmError(400, `${error.code}: ${error.message}`, "card_compose");
1234
- }
1235
- throw error;
1236
- }
2122
+ // VALIDATE-RESOLVES-OUTPUTS shares this mapping (round-22
2123
+ // compose audit Q4a): one seam, both seats, the run seat's
2124
+ // exact voices.
2125
+ const flow = resolveCardOutputsOrThrow(this.defsSync(), p1.card, p1.params, graph);
1237
2126
  return { graph, skeleton: p1.skeleton, spell: p1.spell, ...flow };
1238
2127
  }
1239
2128
  }
@@ -1248,6 +2137,9 @@ export class CardRegistryService extends Service {
1248
2137
  * the app; this is what the estate composition mounts). */
1249
2138
  export const cardRegistryProvider = {
1250
2139
  name: "estate-card-registry",
2140
+ // J12: the §23 manifest read (stateRoots) rides the queue seat's
2141
+ // config — the registry's own ctx must carry the inject to read it.
2142
+ inject: ["queue"],
1251
2143
  // NO comfyui inject: the compose rim property-reads ctx.comfyui on
1252
2144
  // its OWN throwaway EngineContext (which mounts ComfyUIService
1253
2145
  // itself at the rim head) — never on the host fiber, so no read