@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
@@ -3,6 +3,8 @@
3
3
  // 2-6) and the in-process compose (steps 7-9). Explicit seat
4
4
  // deps; no Service state beyond the accessors the seat passes.
5
5
  import { ComfyUIService, resolveEngineBaseUrl, composeCards, ComposeRefusal, checkModelPresent, owningAtom } from "@melite/comfyui-cordis";
6
+ import { cardAdmits, familyLanesOf } from "./cardsFacts.js";
7
+ export { cardAdmits };
6
8
  import { EngineContext, composeModPlane, loadFacts, theService } from "@melite/comfyui-cordis";
7
9
  import { CardArmError, phaseRefusal } from "./cardsArmError.js";
8
10
  import { findCardDangling } from "./cardsDangling.js";
@@ -18,9 +20,15 @@ import { FLOW_ID_RE } from "./runsGates.js";
18
20
  export function liftStanza(params) {
19
21
  const inner = params["params"];
20
22
  if (typeof inner === "object" && inner !== null && !Array.isArray(inner)) {
23
+
24
+ // reads as absent — the same verdict JSON persistence would hand
25
+ // the in-memory row — so declared default overlays apply
26
+ // uniformly on both faces.
21
27
  return {
22
- ...inner,
23
- ...Object.fromEntries(Object.entries(params).filter(([k]) => k !== "params")),
28
+ ...Object.fromEntries(Object.entries(inner)
29
+ .filter(([, v]) => v !== undefined)),
30
+ ...Object.fromEntries(Object.entries(params)
31
+ .filter(([k, v]) => k !== "params" && v !== undefined)),
24
32
  };
25
33
  }
26
34
  return params;
@@ -38,66 +46,94 @@ export async function composeOnce(deps, card, fam, params, runId, phase) {
38
46
  throw phaseRefusal(phase, "comfyui live object_info primed empty — refusing closed (EXTENSION LAW: never compose unauthenticated)");
39
47
  }
40
48
  const ctx = new EngineContext();
41
- await ctx.plugin({
42
- apply(c) {
43
- new ComfyUIService(c);
44
- },
45
- });
46
-
47
- // boot rides the SAME composition table as loadCardDefs —
48
- // composeCards (exported from @melite/comfyui; the engine
49
- // src/cards readdir glob died with the sweep). A card lands by
50
- // adding its package + one table row; no shared-file edit.
51
- await composeCards(ctx);
52
-
53
- // service composed cards ONLY, so flavor rows were absent and
54
- // every mod id refused at compose. Same composeModPlane as
55
- // loadCardDefs — one composition, two riders.
56
- await composeModPlane(ctx);
57
- ctx.comfyui.setFacts(loadFacts(factsPath(), deps.readsSync()));
58
- ctx.comfyui.setObjectInfo(oi);
59
-
60
- // the compose door checks the run's touched provision rows
61
- // against the models tree BEFORE composing — the module-level
62
- // presence read (runtime tree + the endpoint mount leg, the
63
- // manage door's own spelling). An absent weight refuses loud
64
- // with its fetch URL, never a silent downstream death.
65
- ctx.comfyui.setWeightPresent((relativePath, name) => checkModelPresent(relativePath, name) !== null);
66
- // THE NESTED STANZA UNWRAP (cli.ts:82-91): a `params` dict key in
67
- // the incoming params IS the stanza; siblings merge over it.
68
- const lifted = liftStanza(params);
69
- // THE ADMISSION CONTRACT GATE (cli.ts admission verbatim voice):
70
- // every param key must be a declared knob or ride the admits row.
71
-
72
- // question — phase1Card runs this gate BEFORE the lane-presence
73
- // ENVIRONMENT gate, so the voice is box-independent; composeOnce
74
- // re-runs the same function, never a divergent copy.)
75
- admissionRefusal(deps, card, fam, lifted, phase);
76
49
  try {
77
- return ctx.comfyui.compose(card, fam, lifted, runId);
78
- }
79
- catch (e) {
80
- if (e instanceof ComposeRefusal) {
81
- throw phaseRefusal(phase, e.code + ": " + e.message);
50
+ await ctx.plugin({
51
+ apply(c) {
52
+ new ComfyUIService(c);
53
+ },
54
+ });
55
+
56
+ // boot rides the SAME composition table as loadCardDefs —
57
+ // composeCards (exported from @melite/comfyui; the engine
58
+ // src/cards readdir glob died with the sweep). A card lands by
59
+ // adding its package + one table row; no shared-file edit.
60
+ await composeCards(ctx);
61
+
62
+ // service composed cards ONLY, so flavor rows were absent and
63
+ // every mod id refused at compose. Same composeModPlane as
64
+ // loadCardDefs — one composition, two riders.
65
+ await composeModPlane(ctx);
66
+ ctx.comfyui.setFacts(loadFacts(factsPath(), deps.readsSync()));
67
+ ctx.comfyui.setObjectInfo(oi);
68
+
69
+ // the compose door checks the run's touched provision rows
70
+ // against the models tree BEFORE composing — the module-level
71
+ // presence read (runtime tree + the endpoint mount leg, the
72
+ // manage door's own spelling). An absent weight refuses loud
73
+ // with its fetch URL, never a silent downstream death.
74
+ ctx.comfyui.setWeightPresent((relativePath, name) => checkModelPresent(relativePath, name) !== null);
75
+ // THE NESTED STANZA UNWRAP (cli.ts:82-91): a `params` dict key in
76
+ // the incoming params IS the stanza; siblings merge over it.
77
+ const lifted = liftStanza(params);
78
+ // THE ADMISSION CONTRACT GATE (cli.ts admission verbatim voice):
79
+ // every param key must be a declared knob or ride the admits row.
80
+
81
+ // question — phase1Card runs this gate BEFORE the lane-presence
82
+ // ENVIRONMENT gate, so the voice is box-independent; composeOnce
83
+ // re-runs the same function, never a divergent copy.)
84
+ admissionRefusal(deps, card, fam, lifted, phase);
85
+ try {
86
+ // J12: the estate's state-root manifest rides the compose as
87
+ // call data (the queue seat's config-named trees — the
88
+ // linked-input rewrite names its trees, never an env read)
89
+ return ctx.comfyui.compose(card, fam, lifted, runId, { stateRoots: deps.stateRoots() });
82
90
  }
83
- throw phaseRefusal(phase, e instanceof Error
84
- ? e.message
85
- :
91
+ catch (e) {
92
+ if (e instanceof ComposeRefusal) {
93
+ throw phaseRefusal(phase, e.code + ": " + e.message);
94
+ }
95
+ throw phaseRefusal(phase, e instanceof Error
96
+ ? e.message
97
+ :
86
98
 
87
- String(e));
99
+ String(e));
100
+ }
101
+ }
102
+ finally {
103
+ // PER-REQUEST CONTEXTS DISPOSE (the fiber lifetime law —
104
+ // cordis-api/fiber.md: `fiber.dispose` unloads the plugin tree
105
+ // and settles once cleanup finished; the root fiber, uid 0,
106
+ // owns every row mounted below it). The effects here touch
107
+ // only the context's own service maps today, but any future
108
+ // effect with an external resource (timer, listener, file
109
+ // handle) must not leak per request. The compose result is
110
+ // already evaluated when this runs — dispose never races it.
111
+ await ctx.fiber.dispose();
88
112
  }
89
113
  }
90
114
 
91
115
 
92
116
 
93
117
 
94
- export function admissionRefusal(deps, card, fam, lifted, phase) {
95
- const decls = deps.cardDecls();
96
- // (prepareCardParams guarantees a registered card — its
97
- // unknown-card arm refuses first — so the lookup never misses.)
118
+
119
+
120
+
121
+
122
+
123
+
124
+
125
+ export function admissionRefusal(deps, card, fam, lifted, phase, facts) {
126
+ const decls = deps.cardDecls(facts);
127
+ // (prepareCardParams's own arm refuses unknown cards on the
128
+ // {model:} path — this gate runs first on the raw card, so it
129
+ // carries the named voice itself; the old shape crashed here on
130
+ // the undefined cast, an accidental rejection the finally-law
131
+ // wall mistook for a refusal, audit J-E2's sweep.)
98
132
  const decl = decls[card];
99
- const knobs = new Set(decl.schemaNames);
100
- const admits = decl.admits;
133
+ if (decl === undefined) {
134
+ throw phaseRefusal(phase, "compose-door: unknown card " + JSON.stringify(card) +
135
+ " (no registered card definition — register the card or address a known one)");
136
+ }
101
137
 
102
138
  // admission is the declared surface — and the mod fields a
103
139
  // family ABSORBS are part of that surface (registerMod through
@@ -110,6 +146,7 @@ export function admissionRefusal(deps, card, fam, lifted, phase) {
110
146
  // turn on `qvoice_save` — the pack rides fields, never its own
111
147
  // key). Pack → its family-scoped field names, same fold.
112
148
  const packFields = new Map();
149
+ const fieldOwners = new Map();
113
150
 
114
151
 
115
152
 
@@ -132,23 +169,57 @@ export function admissionRefusal(deps, card, fam, lifted, phase) {
132
169
  if (!packFields.has(a.pack))
133
170
  packFields.set(a.pack, names);
134
171
  }
172
+ // THE MOD-FIELD OWNERSHIP ROSTER (the tts dossier's B4 cure,
173
+
174
+ // shared door): the fold above scopes mod fields to THIS run's
175
+ // atom, so a key that is a REGISTERED mod field of a DIFFERENT
176
+ // family refused as bare 'unknown' — an agent holding the
177
+ // field burned a probe turn learning which family owns it.
178
+ // Collect every row's ownership UNFILTERED; the refusal below
179
+ // names the owning family and the params.model cure for
180
+ // exactly the keys the envelope-scoped fold did not admit.
181
+ for (const a of theService().cardModFields(card)) {
182
+ const fams = a.families.filter((f) => f !== envelopeAtom);
183
+ if (fams.length === 0)
184
+ continue;
185
+ for (const n of Object.keys(a.fields.dict ?? {})) {
186
+ const row = fieldOwners.get(n);
187
+ if (row === undefined)
188
+ fieldOwners.set(n, { pack: a.pack, families: [...fams] });
189
+ else
190
+ for (const f of fams)
191
+ if (!row.families.includes(f))
192
+ row.families.push(f);
193
+ }
194
+ }
135
195
  /* v8 ignore stop */
136
196
  }
137
- catch {
138
- // card defs not booted in this fiber — the mod surface is
139
- // empty here; the knobs+admits rows still gate.
197
+ catch (modFoldError) {
198
+ // modFoldError: card defs not booted in this fiber — the mod
199
+ // surface is empty here; the knobs+admits rows still gate
200
+ // (compose's own admission gate re-judges with the fold).
140
201
  }
141
- const admitted = (key) => knobs.has(key) ||
142
- modNames.has(key) ||
143
- admits.some((a) => a === key || (a.endsWith("*") && key.startsWith(a.slice(0, -1))));
202
+ const admitted = (key) => cardAdmits(decl, modNames, key);
144
203
  const unknown = Object.keys(lifted).filter((k) => !admitted(k)).sort();
145
204
  if (unknown.length > 0) {
146
205
  const hints = unknown
147
206
  .filter((k) => packFields.has(k))
148
207
  .map((k) => " '" + k + "' is the '" + k + "' mod pack — it takes no key of its own; its fields ride flat top-level: " + packFields.get(k).join(", "));
208
+ // THE MOD-FIELD FAMILY HINT (B4): a refused key owned by
209
+ // ANOTHER family's mod pack names that family and the one
210
+ // write that reaches it — never a bare 'unknown'.
211
+ const fieldHints = unknown
212
+ .filter((k) => !packFields.has(k) && fieldOwners.has(k))
213
+ .map((k) => {
214
+ const o = fieldOwners.get(k);
215
+ return " '" + k + "' is the '" + o.pack + "' mod field of " +
216
+ o.families.map((f) => "family '" + f + "'").join(" / ") +
217
+ " — state params.model on that family's lane to ride it";
218
+ });
149
219
  throw phaseRefusal(phase, "compose-door: unknown param(s) on the " + card + " card: " + unknown.join(", ") +
150
220
  " (admission is the declared surface — knobs + contract admits; see the card's TS definition)" +
151
- (hints.length > 0 ? " Mod-pack keys:" + hints.join(";") : ""));
221
+ (hints.length > 0 ? " Mod-pack keys:" + hints.join(";") : "") +
222
+ (fieldHints.length > 0 ? " Mod-field families:" + fieldHints.join(";") : ""));
152
223
  }
153
224
  }
154
225
  /** Resolve + sweep + select + overlay + lift (steps 2-6):
@@ -166,8 +237,13 @@ export function admissionRefusal(deps, card, fam, lifted, phase) {
166
237
  * seat, which takes the strict read here (`deps.modelFacts()`).
167
238
  */
168
239
  export function prepareCardParams(deps, body, mid, phase, factsArg) {
240
+
241
+ // reads ONLY /v1/assets/-prefixed refs (estate-owned URLs); a
242
+ // runs-relative or absolute path is outside its contract and dies
243
+ // engine-side if wrong — named here so the asymmetry with the
244
+ // resolver's wider classifier is a decision, not an oversight.
169
245
  const facts = factsArg ?? deps.modelFacts();
170
- const dangling = findCardDangling(body);
246
+ const dangling = findCardDangling(body, deps.stateRoots());
171
247
  if (dangling !== null) {
172
248
  const [location, ref, why] = dangling;
173
249
  throw new CardArmError(400, "dangling artifact ref at " + JSON.stringify(location) + ": " + ref + " (" + why + ")", "invalid_request");
@@ -178,10 +254,10 @@ export function prepareCardParams(deps, body, mid, phase, factsArg) {
178
254
  const resolves = mid in facts || deps.resolveCardFamily(mid, facts) in facts || deps.modelMids().has(mid);
179
255
  if (!resolves) {
180
256
 
181
- // Run-press law, the operator's wall): the bench's Run press
182
- // addresses a family-less card by its OWN id — runCardStage's
183
- // documented fallback, defaultFamilyForCard returning the
184
- // card id when no family stands behind the card. The {model:}
257
+
258
+ // the bench's Run press addresses a family-less card by its OWN
259
+ // id — stage-run maps defaultFamilyForCard's null to the card
260
+ // id explicitly (never a writer `?? cardId` mint). The {model:}
185
261
  // door therefore COMPOSES the card the press names (the GUI's
186
262
  // shape is the contract), params verbatim: no family row, so
187
263
  // no variant selection and no model-defaults overlay — the
@@ -226,8 +302,8 @@ export function prepareCardParams(deps, body, mid, phase, factsArg) {
226
302
  throw new CardArmError(400, "card_compose phase " + phase + ": unknown card " + JSON.stringify(famRow.card) +
227
303
  " (no registered card definition for the card model " + JSON.stringify(mid) + " names)", "card_compose");
228
304
  }
229
- const sel = selectCardVariant(mid, famRow, body, phase);
230
- const stamped = stampCardOverlay(body, famRow, decl, sel, phase);
305
+ const sel = selectCardVariant(mid, famRow, body, phase, familyLanesOf(decl.boarded), fam);
306
+ const stamped = stampCardOverlay(body, famRow, decl, sel, phase, fam);
231
307
  return {
232
308
  mid,
233
309
  fam,
@@ -237,7 +313,15 @@ export function prepareCardParams(deps, body, mid, phase, factsArg) {
237
313
  // route composes the CLONE lane rather than the head's — the
238
314
  // difference between a lawful bench state that runs and one
239
315
  // that refuses at the door.
240
- modelId: sel.variantRoute !== "" ? sel.variantRoute : mid,
316
+ // THE CELL'S ROUTE WINS (the size-at-quant reshape, operator
317
+
318
+ // cell re-keys the lane its weights load — the same
319
+ // cell-before-variant order the engine's own resolve() reads,
320
+ // so the estate's compose and the engine's route never
321
+ // disagree about which tree a run loads.
322
+ modelId: sel.cellRoute !== ""
323
+ ? sel.cellRoute
324
+ : sel.variantRoute !== "" ? sel.variantRoute : mid,
241
325
  card: famRow.card,
242
326
  skeleton: decl.skeleton !== "" ? decl.skeleton : mid,
243
327
  decl,
@@ -1,7 +1,7 @@
1
1
  /** THE SWEEP ROOTS (§23): every manifest root's output/ and
2
2
  * test-output/ trees, own state root first, deduped. A test:true
3
3
  * run may wire a test artifact — the test trees sweep too. */
4
- export declare function sweepOutputRoots(): string[];
4
+ export declare function sweepOutputRoots(stateRoots: readonly string[]): string[];
5
5
  export declare function resolveArtifactFile(ref: string, outRoot: string): string;
6
6
  export declare function refLocations(body: unknown): Array<{
7
7
  location: string;
@@ -12,5 +12,5 @@ export declare function refLocations(body: unknown): Array<{
12
12
  * live under ANY swept tree (§23 — the manifest walk, own root
13
13
  * first; a miss names every searched tree so a two-roots box
14
14
  * stays debuggable). */
15
- export declare function findCardDangling(body: Record<string, unknown>): [string, string, string] | null;
15
+ export declare function findCardDangling(body: Record<string, unknown>, stateRoots: readonly string[]): [string, string, string] | null;
16
16
  //# sourceMappingURL=cardsDangling.d.ts.map
@@ -11,34 +11,40 @@
11
11
  // MELITE_STATE_ROOT/output; the maker paid a refusal + ~8 forensic
12
12
  // calls to diagnose OUR two-roots lie): every run-resolving door
13
13
  // searches the roots MANIFEST in order — own state root first,
14
- // then the MELITE_STATE_ROOTS extras — the same walk the
14
+ // then the stateRoots config extras — the same walk the
15
15
  // source-echo resolver (runsSourceEcho) and the run doors use.
16
16
  // One law, one spelling: refs may carry EITHER estate prefix
17
17
  // (/v1/assets/runs/ or /melite-media/runs/ — both are first-class
18
- // run sources; the h3 card's own docs teach the assets spelling).
19
- import { statSync } from "node:fs";
18
+ // run sources; the h3 card's own docs teach the assets spelling)
19
+ // or the gallery's artifact face (/infer-gallery/artifact?path=
20
+ // — the same tail the guard and the engine stage).
21
+ import { isFile } from "./skillFs.js";
20
22
  import { join, relative, resolve, sep } from "node:path";
21
- import { resolveRepoRoot } from "@melite/comfyui-cordis";
22
- import { rootsManifest, searchedVoice } from "./rootsManifest.js";
23
- import { resolveStateRoot } from "./queueLock.js";
24
- import { ASSET_RUNS_PREFIX, MEDIA_RUNS_PREFIX } from "./runsSourceEcho.js";
23
+ import { ASSET_RUNS_PREFIX, MEDIA_RUNS_PREFIX, galleryTail } from "./runsSourceEcho.js";
24
+ import { segmentConfined } from "@melite/contracts/mediaKinds";
25
+ import { searchedVoice } from "./rootsManifest.js";
25
26
  // ── artifact-ref sweep (find_dangling_refs
26
27
  // semantics — the validate-door mirror, same roots) ──────────
27
28
  /** The one-prefix question: which estate route (if any) does this
28
29
  * string carry? Both spellings are the same trees (the media
29
- * route is the newer first-class face — runsSourceEcho's law). */
30
+ * route is the newer first-class face — runsSourceEcho's law).
31
+ * Case-insensitive like the guard's detectFace and the engine's
32
+ * estate arm (round-23 gallery audit F5): the slice rides the
33
+ * constant's LENGTH (the prefixes are ASCII), so the tail keeps
34
+ * its case for the disk walk. */
30
35
  function artifactPrefixOf(raw) {
31
- if (raw.startsWith(ASSET_RUNS_PREFIX))
36
+ const lower = raw.toLowerCase();
37
+ if (lower.startsWith(ASSET_RUNS_PREFIX.toLowerCase()))
32
38
  return ASSET_RUNS_PREFIX;
33
- if (raw.startsWith(MEDIA_RUNS_PREFIX))
39
+ if (lower.startsWith(MEDIA_RUNS_PREFIX.toLowerCase()))
34
40
  return MEDIA_RUNS_PREFIX;
35
41
  return null;
36
42
  }
37
43
  /** THE SWEEP ROOTS (§23): every manifest root's output/ and
38
44
  * test-output/ trees, own state root first, deduped. A test:true
39
45
  * run may wire a test artifact — the test trees sweep too. */
40
- export function sweepOutputRoots() {
41
- const roots = rootsManifest(resolveStateRoot(resolveRepoRoot()));
46
+ export function sweepOutputRoots(stateRoots) {
47
+ const roots = [...stateRoots];
42
48
  const out = [];
43
49
  const seen = new Set();
44
50
  for (const root of roots) {
@@ -57,17 +63,54 @@ export function resolveArtifactFile(ref, outRoot) {
57
63
  const raw = String(ref).trim();
58
64
  if (raw === "")
59
65
  throw new Error("empty artifact ref (nothing to resolve)");
60
- if (raw.includes(".."))
61
- throw new Error("artifact ref refuses traversal: " + JSON.stringify(raw));
62
66
  const prefix = artifactPrefixOf(raw);
67
+ // THE GALLERY FACE (round-23 gallery audit F5): the compose gate
68
+ // never learned the gallery's artifact URLs — a dead gallery ref
69
+ // passed the sweep and refused only at the start door. The tail
70
+ // rides the guard's own parse (runsSourceEcho's galleryTail — one
71
+ // decode, route boundary, twinning the server), never a retype.
72
+ const gallery = prefix === null ? galleryTail(raw) : null;
63
73
  let cand;
64
- if (prefix !== null) {
65
- const rel = raw.slice(prefix.length);
66
- if (rel === "" || rel.endsWith("/") || !rel.includes("/")) {
74
+ if (prefix !== null || gallery !== null) {
75
+ const encoded = prefix !== null ? raw.slice(prefix.length) : gallery;
76
+ const segs = encoded.split("/");
77
+ // the shape law (the old malformed voices, kept verbatim): too
78
+ // few segments, a leading empty (a ?path=/run/x tail), or a
79
+ // trailing slash. A MIDDLE empty rides to the segment law
80
+ // below — the guard refuses it as traversal, and the sweep
81
+ // twins the verdict (it once join-normalized it away).
82
+ if (segs.length < 2 || segs[0] === "" || segs[segs.length - 1] === "") {
67
83
  throw new Error("malformed artifact URL (want <prefix><run_id>/<file> with prefix " +
68
- ASSET_RUNS_PREFIX + " or " + MEDIA_RUNS_PREFIX + "): " + JSON.stringify(raw));
84
+ ASSET_RUNS_PREFIX + " or " + MEDIA_RUNS_PREFIX + " or " +
85
+ "the gallery face /infer-gallery/artifact?path=<run_id>/<file>): " + JSON.stringify(raw));
69
86
  }
70
- cand = join(outRoot, rel);
87
+ const rel = [];
88
+ for (const seg of segs) {
89
+ // PER-SEGMENT DECODE (round-23 gallery audit F3's sweep twin):
90
+ // the media route mints per-segment escapes — resolving the
91
+ // literal `out%201.png` looked up a file that never exists
92
+ // and dangled a LIVE ref at compose. The gallery tail arrives
93
+ // decoded exactly once already (the URL parser's doing) —
94
+ // decoding again corrupts a legal `%` in a filename, so the
95
+ // segment walk confines it but never decodes it again.
96
+ // THE SEGMENT LAW (round-23 gallery audit F2/F4's sweep twin):
97
+ // traversal is a property of SEGMENTS — the old whole-string
98
+ // `..` ban refused the engine's legal `still..frame.png`.
99
+ let dec = seg;
100
+ if (prefix !== null) {
101
+ try {
102
+ dec = decodeURIComponent(seg);
103
+ }
104
+ catch {
105
+ throw new Error("malformed artifact URL (bad percent-escape): " + JSON.stringify(raw));
106
+ }
107
+ }
108
+ if (!segmentConfined(dec)) {
109
+ throw new Error("artifact ref refuses traversal: " + JSON.stringify(raw));
110
+ }
111
+ rel.push(dec);
112
+ }
113
+ cand = join(outRoot, rel.join("/"));
71
114
  }
72
115
  else if (raw.includes("/") && !raw.startsWith("/")) {
73
116
  cand = join(outRoot, raw);
@@ -90,19 +133,12 @@ export function resolveArtifactFile(ref, outRoot) {
90
133
  if (relToRoot === ".." || relToRoot.startsWith(".." + sep)) {
91
134
  throw new Error("artifact ref escapes the output root: " + JSON.stringify(raw));
92
135
  }
93
- let isFile = false;
94
- try {
95
- isFile = statSync(absCand).isFile();
96
- }
97
- catch {
98
- isFile = false;
99
- }
100
- if (!isFile) {
136
+ if (!isFile(absCand)) {
101
137
  // The run id rides the ref's own first segment for every
102
- // prefix-URL and runs-relative shape; an absolute path carries
103
- // no run, so "?" names that absence.
104
- const run = prefix !== null || (raw.includes("/") && !raw.startsWith("/"))
105
- ? raw.slice(prefix !== null ? prefix.length : 0).split("/", 2)[0] // split yields >= 1
138
+ // prefix-URL, gallery-URL and runs-relative shape; an absolute
139
+ // path carries no run, so "?" names that absence.
140
+ const run = prefix !== null || gallery !== null || (raw.includes("/") && !raw.startsWith("/"))
141
+ ? (prefix !== null ? raw.slice(prefix.length) : gallery !== null ? gallery : raw).split("/", 2)[0] // split yields >= 1
106
142
  : "?";
107
143
  throw new Error("artifact not found on disk: " + JSON.stringify(raw) + " (looked up " + absCand + ") — the " +
108
144
  "upstream run may have been pruned, or the ref was never an output of run " + run);
@@ -126,7 +162,7 @@ export function refLocations(body) {
126
162
  stack.push({ node: node[i], path: path + "[" + i + "]" });
127
163
  }
128
164
  }
129
- else if (typeof node === "string" && artifactPrefixOf(node) !== null) {
165
+ else if (typeof node === "string" && (artifactPrefixOf(node) !== null || galleryTail(node) !== null)) {
130
166
  out.push({ location: path, ref: node });
131
167
  }
132
168
  }
@@ -134,8 +170,8 @@ export function refLocations(body) {
134
170
  }
135
171
  /** The shared sweep body: every dangling (location, ref, why) in refLocations' DFS order, each miss quoting the PRIMARY root lookup (resolveArtifactFile above) + every searched tree (the NAME-THE-ROOT law, §23). */
136
172
  /** Receipt transcript-034 step 18: the old voice named ONE tree and read like a pruned run. */
137
- function scanRefs(body) {
138
- const roots = sweepOutputRoots();
173
+ function scanRefs(body, stateRoots) {
174
+ const roots = sweepOutputRoots(stateRoots);
139
175
  const dangling = [];
140
176
  for (const { location, ref } of refLocations(body)) {
141
177
  let live = false;
@@ -152,7 +188,16 @@ function scanRefs(body) {
152
188
  }
153
189
  }
154
190
  if (!live) {
155
- dangling.push([location, ref, primaryErr.message + " " + searchedVoice(roots)]);
191
+
192
+ // here as a raw TypeError — the sweep fails closed with a
193
+ // named reason instead of 500ing the door.
194
+ dangling.push([
195
+ location,
196
+ ref,
197
+ primaryErr !== null
198
+ ? primaryErr.message + " " + searchedVoice(roots)
199
+ : "no sweep roots configured" + " " + searchedVoice(roots),
200
+ ]);
156
201
  }
157
202
  }
158
203
  return dangling;
@@ -162,7 +207,7 @@ function scanRefs(body) {
162
207
  * live under ANY swept tree (§23 — the manifest walk, own root
163
208
  * first; a miss names every searched tree so a two-roots box
164
209
  * stays debuggable). */
165
- export function findCardDangling(body) {
166
- return scanRefs(body)[0] ?? null;
210
+ export function findCardDangling(body, stateRoots) {
211
+ return scanRefs(body, stateRoots)[0] ?? null;
167
212
  }
168
213
  //# sourceMappingURL=cardsDangling.js.map
@@ -1,11 +1,16 @@
1
- import type { CardDefinition } from "@melite/comfyui-cordis";
1
+ import type { CardDefinition } from "@melite/comfyui-card-kit/card-definition";
2
2
  import type { LaneRelations, SamplerEnvelope } from "@melite/contracts/laneRelations";
3
3
  export interface VariantCellRow {
4
4
  readonly quant: string;
5
5
  readonly route: string;
6
6
  readonly hide_from_dropdown?: boolean;
7
+
8
+
9
+
10
+
11
+ readonly params?: readonly string[];
7
12
  }
8
- export interface VariantRow {
13
+ export interface ResolvedVariantRow {
9
14
  readonly id: string;
10
15
  readonly group: string;
11
16
  readonly hide_from_dropdown?: boolean;
@@ -40,7 +45,7 @@ export interface VariantRow {
40
45
  export interface ModelFactsRow {
41
46
  readonly card: string;
42
47
  readonly defaults: Record<string, unknown>;
43
- readonly variants: VariantRow[];
48
+ readonly variants: ResolvedVariantRow[];
44
49
 
45
50
 
46
51
 
@@ -56,6 +61,13 @@ export interface ModelFactsRow {
56
61
  min?: number;
57
62
  max?: number;
58
63
  }>>;
64
+
65
+
66
+
67
+ readonly required_defaults?: readonly {
68
+ readonly name: string;
69
+ readonly class: "user" | "variant" | "mod";
70
+ }[];
59
71
  /** The assembly-studio declaration (hand-owned model-facts.json
60
72
  * carries it; the projection unions its writes into admits). */
61
73
  readonly studio?: {
@@ -69,6 +81,23 @@ export interface CardDeclRow {
69
81
  readonly admits: readonly string[];
70
82
  readonly spells: readonly string[];
71
83
  }
84
+ /** The window-family lanes a card's boarded families derive — the
85
+ * vocabulary an agent confuses for a variant (the transcript's
86
+ * step-8 burn: variant 't4r' read "unknown variant"). Reads the
87
+ * DECLs' served familyLaw, never a copy; undefined when no boarded
88
+ * family declares a law (legacy families get the plain voice).
89
+ *
90
+ * @param boarded the card's boarded family ids.
91
+ * @returns the union of their declared lane ids, or undefined. */
92
+ export declare function familyLanesOf(boarded: readonly string[] | undefined): readonly string[] | undefined;
72
93
  export declare function factsPath(): string;
73
94
  export declare function deriveDecls(defs: Map<string, CardDefinition>, facts: Record<string, ModelFactsRow>): Record<string, CardDeclRow>;
95
+ /** THE SHARED ADMISSION PREDICATE (audit J-E2): knobs ∪ absorbed
96
+ * mod fields ∪ contract admits (a `prefix*` admit row admits every
97
+ * key under the prefix). ONE surface for the admission seats —
98
+ * compose's admission gate, start's params-override door, and the
99
+ * variant stamp gate (audit Y-S2) — or the seats disagree about
100
+ * what a card admits. Lives on the leaf: every consumer already
101
+ * imports these row types, no seat-to-seat cycle. */
102
+ export declare function cardAdmits(decl: CardDeclRow | undefined, modNames: ReadonlySet<string>, key: string): boolean;
74
103
  //# sourceMappingURL=cardsFacts.d.ts.map
package/lib/cardsFacts.js CHANGED
@@ -3,7 +3,31 @@
3
3
  // facts/decl plane owns model-facts.json reads and the pure
4
4
  // defs+facts->rows derivation. No Service state — module truth.
5
5
  import { join } from "node:path";
6
- import { resolveRepoRoot } from "@melite/comfyui-cordis";
6
+ import { getModel, resolveRepoRoot } from "@melite/comfyui-cordis";
7
+ /** The window-family lanes a card's boarded families derive — the
8
+ * vocabulary an agent confuses for a variant (the transcript's
9
+ * step-8 burn: variant 't4r' read "unknown variant"). Reads the
10
+ * DECLs' served familyLaw, never a copy; undefined when no boarded
11
+ * family declares a law (legacy families get the plain voice).
12
+ *
13
+ * @param boarded the card's boarded family ids.
14
+ * @returns the union of their declared lane ids, or undefined. */
15
+ export function familyLanesOf(boarded) {
16
+ const lanes = [];
17
+ for (const fam of boarded ?? []) {
18
+ let law;
19
+ try {
20
+ law = getModel(fam).familyLaw;
21
+ }
22
+ catch {
23
+ continue;
24
+ }
25
+ for (const row of law?.lanes ?? [])
26
+ if (!lanes.includes(row.lane))
27
+ lanes.push(row.lane);
28
+ }
29
+ return lanes.length > 0 ? lanes : undefined;
30
+ }
7
31
  export function factsPath() {
8
32
 
9
33
  // cordis package): the compose plane lives in
@@ -61,4 +85,18 @@ export function deriveDecls(defs, facts) {
61
85
  }
62
86
  return out;
63
87
  }
88
+ /** THE SHARED ADMISSION PREDICATE (audit J-E2): knobs ∪ absorbed
89
+ * mod fields ∪ contract admits (a `prefix*` admit row admits every
90
+ * key under the prefix). ONE surface for the admission seats —
91
+ * compose's admission gate, start's params-override door, and the
92
+ * variant stamp gate (audit Y-S2) — or the seats disagree about
93
+ * what a card admits. Lives on the leaf: every consumer already
94
+ * imports these row types, no seat-to-seat cycle. */
95
+ export function cardAdmits(decl, modNames, key) {
96
+ if (decl === undefined)
97
+ return false;
98
+ return (decl.schemaNames.includes(key) ||
99
+ modNames.has(key) ||
100
+ decl.admits.some((a) => a === key || (a.endsWith("*") && key.startsWith(a.slice(0, -1)))));
101
+ }
64
102
  //# sourceMappingURL=cardsFacts.js.map