@melite/estate-queue 0.1.5-pre-alpha → 0.2.0-alpha

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/LICENSE +561 -457
  2. package/lib/cardsArmError.d.ts +52 -3
  3. package/lib/cardsArmError.js +7 -1
  4. package/lib/cardsCompose.js +43 -7
  5. package/lib/cardsFacts.d.ts +16 -0
  6. package/lib/cardsFacts.js +25 -1
  7. package/lib/cardsLanes.d.ts +51 -3
  8. package/lib/cardsLanes.js +337 -13
  9. package/lib/cardsLanesCopy.d.ts +21 -0
  10. package/lib/cardsLanesCopy.js +22 -0
  11. package/lib/cardsRegistry.d.ts +102 -5
  12. package/lib/cardsRegistry.js +668 -45
  13. package/lib/cardsVariant.d.ts +12 -7
  14. package/lib/cardsVariant.js +196 -58
  15. package/lib/discloseRegistry.d.ts +36 -6
  16. package/lib/discloseRegistry.js +153 -15
  17. package/lib/filmLead.js +5 -3
  18. package/lib/flowsData.d.ts +1 -1
  19. package/lib/flowsData.js +7 -4
  20. package/lib/flowsFamilyCompose.js +12 -1
  21. package/lib/flowsRegistryRows.d.ts +1 -0
  22. package/lib/flowsRegistryRows.js +193 -35
  23. package/lib/index.d.ts +1 -0
  24. package/lib/index.js +6 -0
  25. package/lib/loadPlane.js +9 -0
  26. package/lib/manageOps.js +2 -1
  27. package/lib/managePlane.d.ts +11 -1
  28. package/lib/managePlane.js +559 -24
  29. package/lib/managePreflight.d.ts +26 -0
  30. package/lib/managePreflight.js +179 -0
  31. package/lib/manageProbe.d.ts +17 -0
  32. package/lib/manageProbe.js +61 -1
  33. package/lib/queueCore.d.ts +14 -1
  34. package/lib/queueCore.js +13 -0
  35. package/lib/queueResurrect.d.ts +7 -2
  36. package/lib/queueResurrect.js +25 -6
  37. package/lib/queueSidecar.d.ts +110 -1
  38. package/lib/queueSidecar.js +177 -7
  39. package/lib/queueSubmit.d.ts +67 -4
  40. package/lib/queueSubmit.js +133 -4
  41. package/lib/runsErrorCodes.js +5 -3
  42. package/lib/runsExecute.js +44 -4
  43. package/lib/runsGates.d.ts +5 -1
  44. package/lib/runsGates.js +6 -2
  45. package/lib/runsList.d.ts +43 -3
  46. package/lib/runsList.js +159 -39
  47. package/lib/runsRefusalVoices.js +50 -1
  48. package/lib/runsRegistry.d.ts +84 -6
  49. package/lib/runsRegistry.js +515 -105
  50. package/lib/runsStart.d.ts +24 -3
  51. package/lib/runsStart.js +128 -13
  52. package/lib/runsTypes.d.ts +27 -2
  53. package/lib/runsTypes.js +23 -6
  54. package/lib/runsValidateServe.js +20 -10
  55. package/lib/runsValidateShared.d.ts +9 -0
  56. package/lib/runsValidateShared.js +14 -0
  57. package/lib/runsValidateStages.js +21 -9
  58. package/lib/runtimeProvision.d.ts +119 -0
  59. package/lib/runtimeProvision.js +243 -0
  60. package/lib/skillRows.js +7 -2
  61. package/package.json +18 -18
@@ -21,13 +21,18 @@ export interface VariantSelection {
21
21
  * distilled lane's marriage is not agency territory. */
22
22
  readonly samplerEnvelope: Readonly<Record<"steps" | "cfg", EnvelopeBound | undefined>> | null;
23
23
  }
24
- /** Select the matrix cell (R1 wire contract): explicit body
25
- * variant/quant keys win when stated (matched against facts
26
- * variant id/route + cell quant); unstated coordinates fall to
27
- * the FIRST non-Recipe variant / first cell (Model.resolve —
28
- * the family default). Unknown coordinates refuse LOUD (never a
29
- * silent neighbor cell). */
30
- export declare function selectCardVariant(mid: string, famRow: ModelFactsRow, body: Record<string, unknown>, phase: string): VariantSelection;
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
+
33
+
34
+
35
+ export declare function selectCardVariant(mid: string, famRow: ModelFactsRow, body: Record<string, unknown>, phase: string, familyLanes?: readonly string[], familyId?: string): VariantSelection;
31
36
  export declare function stampCardOverlay(body: Record<string, unknown>, famRow: ModelFactsRow, decl: CardDeclRow, sel: VariantSelection, phase: string, fam: string): Record<string, unknown>;
32
37
  /** The card-compose lift (card_compose_body 363-372): the run body
33
38
  * minus the gateway envelope, restaged as the ONE params stanza.
@@ -1,6 +1,6 @@
1
1
  import { samplerEnvelopeCure } from "@melite/contracts/laneRelations";
2
2
  import { EnvelopeRefusal, phaseRefusal } from "./cardsArmError.js";
3
- import { judgeSamplerEnvelope, unknownQuantVoice, unknownVariantVoice } from "@melite/contracts/laneRelations";
3
+ import { judgeSamplerEnvelope, offeredPool, resolveCellRow, resolveVariantRow, unknownQuantVoice, unknownVariantVoice, } from "@melite/contracts/laneRelations";
4
4
  import { CARD_ENVELOPE_KEYS } from "./cardsRegistry.js";
5
5
  import { cardAdmits } from "./cardsFacts.js";
6
6
  import { theService, owningAtom } from "@melite/comfyui-cordis";
@@ -21,60 +21,67 @@ function normalizeEnvelope(raw) {
21
21
  const cfg = bound(r.cfg);
22
22
  return steps === undefined && cfg === undefined ? null : { steps, cfg };
23
23
  }
24
- function knownVariantIds(row) {
25
- return (row.variants ?? []).map((v) => v.id);
26
- }
27
- /** Select the matrix cell (R1 wire contract): explicit body
28
- * variant/quant keys win when stated (matched against facts
29
- * variant id/route + cell quant); unstated coordinates fall to
30
- * the FIRST non-Recipe variant / first cell (Model.resolve —
31
- * the family default). Unknown coordinates refuse LOUD (never a
32
- * silent neighbor cell). */
33
- export function selectCardVariant(mid, famRow, body, phase) {
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
+
33
+
34
+
35
+ export function selectCardVariant(mid, famRow, body, phase, familyLanes, familyId) {
34
36
  const variants = famRow.variants ?? [];
35
- const offered = variants.filter((v) => v.hide_from_dropdown !== true);
36
37
  const hiddenRoute = variants.find((v) => v.hide_from_dropdown === true && (v.route === mid || v.id === mid || (v.cells ?? []).some((c) => c.route === mid)));
37
38
  const hiddenCellRoute = variants.some((v) => (v.cells ?? []).some((c) => c.hide_from_dropdown === true && c.route === mid));
38
39
  if (hiddenRoute !== undefined || hiddenCellRoute) {
39
40
  throw phaseRefusal(phase, "model " + JSON.stringify(mid) +
40
41
  " is not offered (the variant route is hidden from the dropdown)");
41
42
  }
42
- const configured = offered.filter((v) => v.group !== "Recipe");
43
- const pool = configured.length > 0 ? configured : offered;
44
- if (pool.length === 0 && variants.length > 0) {
43
+ // THE DOOR'S EARLY ALL-HIDDEN REFUSAL (order-pinned by its suite:
44
+ // before the stated search — an all-hidden family refuses its
45
+ // address, never its stated coordinate). The pool itself is the
46
+ // resolver's one spelling (offeredPool).
47
+ if (offeredPool(variants).length === 0 && variants.length > 0) {
45
48
  throw phaseRefusal(phase, "model " + JSON.stringify(mid) + " has no offered variants");
46
49
  }
47
50
  const rawVariant = body["variant"];
48
51
  const rawQuant = body["quant"];
49
- let variant;
50
- if (rawVariant === undefined || rawVariant === null) {
51
-
52
- // offered-cells wall's first firing): a doc pinned to a route
53
- // that names a VARIANT-level lane ('krea-2-raw',
54
- // 'z-image-base-int8') must compose THAT lane, never pool[0]'s
55
- // silent neighbor. The address's cell claim below only searches
56
- // the chosen variant's cells — without this claim a
57
- // route-addressed draft landed pool[0] + cells[0] and composed
58
- // the wrong weights while every surface stayed green (variant
59
- // switching "not working" under an all-green suite).
60
- variant = pool.find((v) => v.route === mid
61
- || (v.cells ?? []).some((c) => c.hide_from_dropdown !== true && c.route !== "" && c.route === mid)) ?? pool[0];
52
+ if (rawVariant !== undefined && rawVariant !== null && typeof rawVariant !== "string") {
53
+ throw phaseRefusal(phase, "variant must be a string (got " +
54
+ (Array.isArray(rawVariant) ? "list" : typeof rawVariant) + ")");
62
55
  }
63
- else {
64
- if (typeof rawVariant !== "string") {
65
- throw phaseRefusal(phase, "variant must be a string (got " +
66
- (Array.isArray(rawVariant) ? "list" : typeof rawVariant) + ")");
67
- }
68
- const requested = variants.find((v) => v.id === rawVariant || v.route === rawVariant);
69
- if (requested?.hide_from_dropdown === true) {
70
- throw phaseRefusal(phase, "variant " + JSON.stringify(rawVariant) +
71
- " is not offered for model " + JSON.stringify(mid));
72
- }
73
- variant = offered.find((v) => v.id === rawVariant || v.route === rawVariant);
74
- if (variant === undefined) {
75
- throw phaseRefusal(phase, unknownVariantVoice(rawVariant, mid, knownVariantIds(famRow)));
76
- }
56
+ // THE STATED/UNSTATED VARIANT ARM (the resolver's offered face):
57
+ // the stated search runs over the whole handed matrix (a hidden hit
58
+ // is the door's not-offered refusal, a miss speaks the matrix's own
59
+ // ids); the unstated coordinate is the address claim, else pool[0].
60
+ //
61
+
62
+ // audit 013 — the edit-steps burn): the address claim exists for
63
+ // ROUTE pins (a draft naming a variant-level lane like
64
+ // 'krea-2-raw'). When the door's address IS the family's own head
65
+ // id, the doc states the FAMILY, not a pin — and the claim captured
66
+ // the BASE row for every family whose base route equals the family
67
+ // id (qwen-img-edit-21: door resolved base/25 while the client
68
+ // mirror's '' spelling fell to pool[0]/turbo — one resolver, two
69
+ // spellings, the UI banner over a base-composed run). The head
70
+ // spelling narrows to '' so the door and the mirror read pool[0] —
71
+ // the DECL-walk law: first declared = the default.
72
+ const address = familyId !== undefined && mid === familyId ? "" : mid;
73
+ const vres = resolveVariantRow(variants, rawVariant, address, "offered");
74
+ if (vres.status === "missing") {
75
+ throw phaseRefusal(phase, unknownVariantVoice(vres.stated, mid, vres.known, familyLanes));
76
+ }
77
+ if (vres.status === "hidden") {
78
+ throw phaseRefusal(phase, "variant " + JSON.stringify(rawVariant) +
79
+ " is not offered for model " + JSON.stringify(mid));
77
80
  }
81
+ // 'pool-empty' is only reachable on an EMPTY matrix here (the
82
+ // early all-hidden throw guarded the non-empty one) — the
83
+ // variant-less family resolves empty coordinates.
84
+ const variant = vres.status === "resolved" ? vres.variant : undefined;
78
85
  let quant = "";
79
86
  let cell;
80
87
  // THE LEGACY COORDINATE (the size-at-quant fold, operator
@@ -91,26 +98,29 @@ export function selectCardVariant(mid, famRow, body, phase) {
91
98
  throw phaseRefusal(phase, "quant must be a string (got " +
92
99
  (Array.isArray(rawQuant) ? "list" : typeof rawQuant) + ")");
93
100
  }
94
- const cells = variant !== undefined
95
- ? (variant.cells ?? []).filter((c) => c.hide_from_dropdown !== true)
96
- : [];
97
- const hit = cells.find((c) => c.quant === rawQuant);
98
- if (hit === undefined) {
99
- throw phaseRefusal(phase, unknownQuantVoice(rawQuant, mid, variant !== undefined ? variant.id : "", cells.map((c) => c.quant)));
101
+ const qres = resolveCellRow(variant, rawQuant, mid, "offered");
102
+ if (qres.status === "missing") {
103
+ throw phaseRefusal(phase, unknownQuantVoice(qres.stated, mid, variant !== undefined ? variant.id : "", qres.known));
100
104
  }
101
- cell = hit;
102
- quant = hit.quant;
105
+ cell = qres.cell ?? undefined;
106
+ quant = qres.quant;
103
107
  }
104
108
  else if (variant !== undefined) {
105
- const cells = (variant.cells ?? []).filter((c) => c.hide_from_dropdown !== true);
106
109
  // Unstated quant: the ADDRESS'S OWN CELL CLAIM wins (the
107
110
  // fold's coverage law — a draft pinned to 'qwen3-tts-base'
108
111
  // means the 0.6B clone; one pinned to 'qwen3-tts-voicedesign'
109
112
  // means the 1.7B persona), else the FIRST cell (Model.resolve's
110
- // family default — the large rung leads every ladder).
111
- cell = cells.find((c) => c.route !== "" && c.route === mid) ?? cells[0];
112
- if (cell !== undefined)
113
- quant = String(cell.quant ?? "");
113
+ // family default — the large rung leads every ladder). The
114
+ // claim rides the NARROWED address (the B3 address trap,
115
+
116
+ // 0.6B cell for the family head 'qwen3-tts' — whose id IS that
117
+ // cell's route — so every family-stated compose stole the small
118
+ // model while the agent doc promised "ALWAYS the 1.7B cell".
119
+ // The head spelling narrows to '' (line 128), the claim goes
120
+ // unstated, and pool[0] (the declared 1.7B first cell) serves.
121
+ const qres = resolveCellRow(variant, null, address, "offered");
122
+ cell = qres.status === "resolved" ? (qres.cell ?? undefined) : undefined;
123
+ quant = qres.status === "resolved" ? qres.quant : "";
114
124
  }
115
125
  return {
116
126
  variantId: variant !== undefined ? variant.id : "",
@@ -156,6 +166,64 @@ function envelopeRefusal(body, sel, phase) {
156
166
  ". " + samplerEnvelopeCure() +
157
167
  " (Read the family lane: melite_skill_read model:<family>.)", "card_compose");
158
168
  }
169
+ /** THE ONE-SWITCH LAW, BAG HALF — the variant voice for a carried
170
+ * mod row the arrival family does not serve. One shape with
171
+ * unknownQuantVoice (the shared lane voices): the stated row, the
172
+ * lane it landed on, the rows the lane serves; the tail names the
173
+ * law, not a silent fix. The client half of this law nulls the bag
174
+ * at the gesture (card-base spec.ts modelSwitchPatch's cross-model
175
+ * arm); this voice is the door's half for re-points no gesture
176
+ * covers. */
177
+ function unknownBagRowVoice(pack, id, fam, sel, known) {
178
+ return "unknown " + pack + " row " + JSON.stringify(id) +
179
+ " for model " + JSON.stringify(fam) +
180
+ " variant " + JSON.stringify(sel.variantId) +
181
+ (known.length > 0
182
+ ? " (known: " + known.join(", ") + ")"
183
+ : " (the family serves no rows)") +
184
+ " — mods are per model: the bag was picked for another model's weights and refuses here rather than ride to the engine" +
185
+ " (Read the family lane: melite_skill_read model:" + fam + ".)";
186
+ }
187
+ /** THE CROSS-MODEL CARRY JUDGE, BAG HALF (journey-closure §D3 — the
188
+ * axis-unification audit's estate-lane residue, 071f8c7a1's
189
+ * recorded finding): a doc whose model key was re-pointed without a
190
+ * gesture (the card's semantic-model knob, a tool face patch, an
191
+ * agent write, a stage copy) arrives here with bag values still
192
+ * stamped under the departed family. Every absorbed pack's array
193
+ * field the body carries is mod currency picked for SOME model's
194
+ * weights; each option-mode entry ({id,…}) must name a row of the
195
+ * arrival atom's OWN catalog, else it refuses loud — foreign values
196
+ * never reach the engine. Reads the arrival family's DIRECT catalog
197
+ * (modCatalog on the route→atom fold, the same fold the stamp
198
+ * surface scopes) — never the compose walk's boarded-family
199
+ * fallback (service.ts modCatalogForCompose), whose fallback serves
200
+ * another boarded family's rows when the arrival family serves
201
+ * none: exactly the cross-model absorption this judge refuses.
202
+ * Filename entries ({name,…}) ride untouched — the card-authoring
203
+ * lane, the service door's own boundary. @param bags the absorbed
204
+ * packs' array-typed field names, collected in the fold below;
205
+ * empty when the fold degraded (card defs not booted in this
206
+ * fiber) — the judge degrades with it, the pre-judge shape. */
207
+ function bagRefusal(body, bags, atom, sel, phase, fam) {
208
+ for (const bag of bags) {
209
+ const carried = body[bag.key];
210
+ if (!Array.isArray(carried))
211
+ continue;
212
+ const known = theService().modCatalog(bag.pack, atom).rows.map((r) => r.id);
213
+ for (const entry of carried) {
214
+ if (entry === null || typeof entry !== "object")
215
+ continue;
216
+ const row = entry;
217
+ if (typeof row.name === "string" && row.name !== "")
218
+ continue;
219
+ if (typeof row.id !== "string" || row.id === "")
220
+ continue;
221
+ if (known.includes(row.id))
222
+ continue;
223
+ throw phaseRefusal(phase, unknownBagRowVoice(bag.pack, row.id, fam, sel, known));
224
+ }
225
+ }
226
+ }
159
227
  export function stampCardOverlay(body, famRow, decl, sel, phase, fam) {
160
228
  envelopeRefusal(body, sel, phase);
161
229
  const stamps = { ...(famRow.defaults ?? {}) };
@@ -168,24 +236,92 @@ export function stampCardOverlay(body, famRow, decl, sel, phase, fam) {
168
236
  // three seats; the atom rides in (owningAtom(fam), the same fold
169
237
  // admissionRefusal judges).
170
238
  const modNames = new Set();
239
+ // THE BAG FIELDS (the carry judge's walk, one fold two products):
240
+ // each absorbed pack's array-typed field is mod currency (the bag
241
+ // law) — collected beside the knob names so the judge reads the
242
+ // SAME route→atom fold the stamp surface scopes.
243
+ const bagFields = [];
244
+ let envelopeAtom = "";
171
245
  try {
172
246
  // THE ROUTE→ATOM FOLD (same fold admissionRefusal judges): the
173
247
  // owning atom scopes the absorbed surface; a not-booted models
174
248
  // service degrades the whole fold to knobs+admits.
175
- const envelopeAtom = owningAtom(fam);
249
+ envelopeAtom = owningAtom(fam);
176
250
  for (const a of theService().cardModFields(famRow.card)) {
177
251
  if (!a.families.includes(envelopeAtom))
178
252
  continue;
179
- for (const n of Object.keys(a.fields.dict ?? {}))
253
+ for (const [n, node] of Object.entries(a.fields.dict ?? {})) {
180
254
  modNames.add(n);
255
+ if (node?.type === "array") {
256
+ bagFields.push({ pack: a.pack, key: n });
257
+ }
258
+ }
181
259
  }
182
260
  }
183
261
  catch (modFoldError) {
184
262
  // modFoldError: card defs not booted in this fiber — the stamp
185
- // gate degrades to knobs+admits, the pre-Y-S2 surface.
263
+ // gate degrades to knobs+admits, the pre-Y-S2 surface (and the
264
+ // carry judge degrades with it: bagFields stays empty).
186
265
  }
266
+ // THE CARRY JUDGE, BAG HALF — before the stamps walk and the
267
+ // compose walk: the departure-blind door judges the carry against
268
+ // the arrival family's own catalog (bagRefusal's contract).
269
+ bagRefusal(body, bagFields, envelopeAtom, sel, phase, fam);
187
270
  const onSurface = (k) => cardAdmits(decl, modNames, k);
188
271
  const out = { ...body };
272
+ // THE QVOICE-STATED PRESET SKIP (the tts dossier's B7 cure,
273
+
274
+ // a body carrying a non-empty qvoice (the saved-persona bag:
275
+ // string or rows) NEVER takes the 'voice' preset stamp. The
276
+ // engine's qvoice branch has no speaker at all (upstream
277
+ // generate_voice_clone carries none), so the stamped preset was
278
+ // inert currency the receipts lied about; with the stamp skipped,
279
+ // an EXPLICIT both-stated run refuses loud at the card's own
280
+ // compose (card.ts's B2 refusal), never silently drops one.
281
+ // THE STANZA SEAT (the B7 residue, the second rebuild's live
282
+ // refusal): the bench-save shape carries the bag INSIDE the
283
+ // params stanza ({model, params:{…qvoice…}}) — a top-level-only
284
+ // look missed it, stamped 'ryan' at the top level, and the lift
285
+ // merged stamp + stanza into a both-stated body the card refused
286
+ // verbatim (card-mode qvoice compose, no voice stated anywhere).
287
+ // The skip reads BOTH seats: the flat agent body AND the stanza.
288
+ const stanzaRow = typeof body["params"] === "object" && body["params"] !== null && !Array.isArray(body["params"])
289
+ ? body["params"]
290
+ : null;
291
+ const qvoiceSeats = [body["qvoice"]];
292
+ if (stanzaRow !== null)
293
+ qvoiceSeats.push(stanzaRow["qvoice"]);
294
+ const qvoiceStated = qvoiceSeats.some((q) => (typeof q === "string" && q !== "") ||
295
+ (Array.isArray(q) && q.length > 0));
296
+
297
+ // burn): the 'voice' stamp above is DERIVED currency, never the
298
+ // author's word — but once a compile has written it into the doc, a
299
+ // later add-stage that states a qvoice meets it as a both-stated
300
+ // body and the card's B2 gate refuses. Patching {voice: null} could
301
+ // not hold: JSON-merge-patch deletes the key and the next compile
302
+ // re-stamps it, so the saved doc could never reach a legal
303
+ // qvoice-only stage. Release the derived seat instead: while a
304
+ // persona is stated, a preset equal to THIS lane's own stamp value
305
+ // is the overlay's residue, so it is dropped at both seats. A
306
+ // preset the author states beside the persona stays — the card's
307
+ // own B2 refusal (ONE voice performs) is the loud door for that.
308
+ if (qvoiceStated) {
309
+ const derived = new Set();
310
+ for (const v of [stamps["voice"], (famRow.defaults ?? {})["voice"], sel.resolverDefaults["voice"]]) {
311
+ if (typeof v === "string" && v !== "")
312
+ derived.add(v);
313
+ }
314
+ if (derived.size > 0) {
315
+ if (derived.has(out["voice"]))
316
+ delete out["voice"];
317
+ const held = out["params"];
318
+ if (held !== null && typeof held === "object" && !Array.isArray(held) && derived.has(held["voice"])) {
319
+ const next = { ...held };
320
+ delete next["voice"];
321
+ out["params"] = next;
322
+ }
323
+ }
324
+ }
189
325
  for (const [k, v] of Object.entries(stamps)) {
190
326
  if (v === null || v === undefined || v === "")
191
327
  continue;
@@ -195,6 +331,8 @@ export function stampCardOverlay(body, famRow, decl, sel, phase, fam) {
195
331
  continue;
196
332
  if (CARD_ENVELOPE_KEYS.includes(k))
197
333
  continue;
334
+ if (k === "voice" && qvoiceStated)
335
+ continue;
198
336
  out[k] = v;
199
337
  }
200
338
  return out;
@@ -8,6 +8,15 @@ export interface DiscoveredCard {
8
8
  readonly description: string;
9
9
  readonly genre: string;
10
10
  readonly tags: readonly string[];
11
+ /** WHY this row surfaced (the ranked-answer law, slice 3): the
12
+ * facets that matched, strongest first — `tags=image` for a facet
13
+ * filter, `tag:sky`, `word:beta`, `modality:image`, or
14
+ * `fuzzy:seas~sea(0.67)`. Never a bare row the agent must guess
15
+ * the reason for. */
16
+ readonly matched_by: string;
17
+ /** The ranking score (sum of facet weights) — the sort key, served
18
+ * so a caller can see the distance between rows. */
19
+ readonly score: number;
11
20
  }
12
21
  /** One flow summary (the routing layer). */
13
22
  export interface FlowSummary {
@@ -18,7 +27,10 @@ export interface FlowSummary {
18
27
  readonly skillRefs: readonly string[];
19
28
  }
20
29
  /** The search surface a card def offers (the def itself satisfies
21
- * this — structural, no import of the engine service). */
30
+ * this — structural, no import of the engine service). boarded is
31
+ * the card's family roster — a model name in q must route, so the
32
+ * corpus carries the family ids, never just the card's own words
33
+ * (friction-report #5: q ignored model names). */
22
34
  export interface SearchableCard {
23
35
  readonly identity?: {
24
36
  readonly label?: string;
@@ -26,11 +38,20 @@ export interface SearchableCard {
26
38
  readonly genre?: string;
27
39
  };
28
40
  readonly tags?: readonly string[];
41
+ readonly boarded?: readonly string[];
29
42
  }
30
- /** Search the card defs: the q tokens (whitespace-split,
31
- * case-folded) ALL match (id + label + description + tags); the
32
- * tags param (comma list) ALL match def.tags. Empty q + tags =
33
- * all. */
43
+
44
+
45
+
46
+ export declare function diceTrigrams(a: string, b: string): number;
47
+ /** Search the card defs (slice 3, the intent door): the tags param
48
+ * (comma list) is a HARD facet — a card must carry every tag. q is
49
+ * RANKED, never an AND: every non-stopword token scores its best
50
+ * facet (exact tag 3, exact word 2, modality 2, trigram fuzzy
51
+ * 0.42–1), rows sort by score then id, and every row carries the
52
+ * WHY it surfaced. With tags stated the facet alone keeps a row
53
+ * (score 0 is a lawful tag hit); without tags a row needs at least
54
+ * one scoring token. Empty q + tags = every tag-matched card. */
34
55
  export declare function searchCards(defs: ReadonlyMap<string, SearchableCard>, q: string, tags: string): DiscoveredCard[];
35
56
  /** Search the flow rows (PURE over the merged rows). */
36
57
  export declare function searchFlows(rows: ReadonlyArray<FlowSummary>, q: string): FlowSummary[];
@@ -74,10 +95,19 @@ export declare class DiscloseDirectoryService extends Service {
74
95
  };
75
96
  /** GET /v1/discover: unknown
76
97
  * lookup refuses with the door's own voice; the body carries the
77
- * requested planes only. */
98
+ * requested planes only. totals is the UNFILTERED estate size
99
+ * (friction-report #5: a filtered answer must say "N cards, M
100
+ * matched" — never present the match as the catalog); missed_tags
101
+ * is the tag vocabulary of cards the filter removed, so a miss is
102
+ * discoverable in one hop. */
78
103
  discover(lookup: string, q: string, tags: string): {
79
104
  flows?: FlowSummary[];
80
105
  cards?: DiscoveredCard[];
106
+ totals: {
107
+ flows: number;
108
+ cards: number;
109
+ };
110
+ missed_tags?: string[];
81
111
  };
82
112
  }
83
113
  /** The disclose row: mounts after the card-registry provider (its
@@ -21,12 +21,103 @@ import { join } from "node:path";
21
21
  import { Service } from "@deepseek-ai/cordis";
22
22
  import { resolveRepoRoot } from "@melite/comfyui-cordis";
23
23
  import { seedFlowsSeat } from "./flowsData.js";
24
- /** Search the card defs: the q tokens (whitespace-split,
25
- * case-folded) ALL match (id + label + description + tags); the
26
- * tags param (comma list) ALL match def.tags. Empty q + tags =
27
- * all. */
24
+ /** The words a user sentence carries but no card owns — articles,
25
+ * pronouns, auxiliaries and request verbs. Ignored for scoring (the
26
+ * full-sentence miss was the transcript's first call: "Make an image
27
+ * of an anime girl." carries four stopwords around one real word). */
28
+ const STOPWORDS = new Set([
29
+ "a", "an", "the", "of", "to", "with", "for", "and", "or", "in", "on", "at", "by",
30
+ "from", "into", "me", "my", "i", "we", "you", "it", "this", "that", "these", "those",
31
+ "turn", "want", "need", "please", "can", "could", "would", "should",
32
+ "do", "does", "is", "are", "be", "as", "so", "if", "then", "than", "using", "use",
33
+ ]);
34
+ /** The modality vocabulary: a query word names a modality, and a card
35
+ * whose tags/genre carry that modality answers it (the transcript's
36
+ * `tags=image` facet, scored instead of required). */
37
+ const MODALITY_WORDS = {
38
+ image: "image", images: "image", photo: "image", photos: "image", picture: "image",
39
+ pictures: "image", still: "image", illustration: "image",
40
+ video: "video", videos: "video", clip: "video", clips: "video", movie: "video",
41
+ animation: "video", animate: "video", film: "video",
42
+ audio: "audio", sound: "audio", sounds: "audio", music: "audio", voice: "audio",
43
+ speech: "audio", talk: "audio", talking: "audio",
44
+ mesh: "mesh", "3d": "mesh", blender: "mesh",
45
+ };
46
+ /** Request verbs → the OPERATION tag they mean. A card declares its
47
+ * operations in tags (generate/edit/upscale); the user's verb is the
48
+ * same intent in another spelling, so it scores like a modality word
49
+ * ("make an image" must rank the GENERATE card above the EDIT card —
50
+ * the transcript's request was to generate, not to edit). */
51
+ const OPERATION_WORDS = {
52
+ make: "generate", create: "generate", generate: "generate", render: "generate",
53
+ draw: "generate", imagine: "generate", produce: "generate", design: "generate",
54
+ edit: "edit", modify: "edit", change: "edit", adjust: "edit", retouch: "edit",
55
+ upscale: "upscale", enlarge: "upscale", upres: "upscale", enhance: "upscale",
56
+ animate: "animate", motion: "animate",
57
+ };
58
+
59
+
60
+
61
+ export function diceTrigrams(a, b) {
62
+ if (a === b)
63
+ return 1;
64
+ if (a.length < 3 || b.length < 3)
65
+ return 0;
66
+ const grams = (w) => {
67
+ const m = new Map();
68
+ for (let i = 0; i + 3 <= w.length; i++) {
69
+ const g = w.slice(i, i + 3);
70
+ m.set(g, (m.get(g) ?? 0) + 1);
71
+ }
72
+ return m;
73
+ };
74
+ const ga = grams(a);
75
+ const gb = grams(b);
76
+ let overlap = 0;
77
+ for (const [g, n] of ga)
78
+ overlap += Math.min(n, gb.get(g) ?? 0);
79
+ return (2 * overlap) / (a.length - 2 + b.length - 2);
80
+ }
81
+ /** Score one query token against one card; returns the weight and
82
+ * the WHY line, or null. Order: exact tag, exact word, modality,
83
+ * fuzzy (the strongest facet wins — one reason per token). */
84
+ function scoreToken(tok, words, dtags, genre) {
85
+ if (dtags.includes(tok))
86
+ return { weight: 3, why: "tag:" + tok };
87
+ if (words.includes(tok))
88
+ return { weight: 2, why: "word:" + tok };
89
+ const modality = MODALITY_WORDS[tok];
90
+ if (modality !== undefined && (dtags.includes(modality) || genre.toLowerCase() === modality)) {
91
+ return { weight: 2, why: "modality:" + tok };
92
+ }
93
+ const operation = OPERATION_WORDS[tok];
94
+ if (operation !== undefined && dtags.includes(operation)) {
95
+ return { weight: 2, why: "operation:" + tok + "->" + operation };
96
+ }
97
+ let best = 0;
98
+ let bestWord = "";
99
+ for (const w of words) {
100
+ const d = diceTrigrams(tok, w);
101
+ if (d > best) {
102
+ best = d;
103
+ bestWord = w;
104
+ }
105
+ }
106
+ if (best >= 0.42) {
107
+ return { weight: Math.round(best * 100) / 100, why: "fuzzy:" + tok + "~" + bestWord + "(" + best.toFixed(2) + ")" };
108
+ }
109
+ return null;
110
+ }
111
+ /** Search the card defs (slice 3, the intent door): the tags param
112
+ * (comma list) is a HARD facet — a card must carry every tag. q is
113
+ * RANKED, never an AND: every non-stopword token scores its best
114
+ * facet (exact tag 3, exact word 2, modality 2, trigram fuzzy
115
+ * 0.42–1), rows sort by score then id, and every row carries the
116
+ * WHY it surfaced. With tags stated the facet alone keeps a row
117
+ * (score 0 is a lawful tag hit); without tags a row needs at least
118
+ * one scoring token. Empty q + tags = every tag-matched card. */
28
119
  export function searchCards(defs, q, tags) {
29
- const toks = q.toLowerCase().split(/\s+/).filter((t) => t !== "");
120
+ const toks = q.toLowerCase().split(/[^a-z0-9]+/).filter((t) => t !== "" && !STOPWORDS.has(t));
30
121
  const want = tags.toLowerCase().split(",").map((t) => t.trim()).filter((t) => t !== "");
31
122
  const out = [];
32
123
  for (const [id, def] of defs) {
@@ -36,13 +127,30 @@ export function searchCards(defs, q, tags) {
36
127
  continue;
37
128
  const label = def.identity?.label ?? id;
38
129
  const description = def.identity?.description ?? "";
39
- const hay = (id + " " + label + " " + description + " " + dtags.join(" ")).toLowerCase();
40
- if (!toks.every((t) => hay.includes(t)))
130
+ const genre = def.identity?.genre ?? "";
131
+ // THE FAMILY CORPUS (friction-report #5): the boarded family ids
132
+ // ride the corpus split on separators, so `krea` routes to the
133
+ // card boarding krea-2 (fuzzy on the whole id already caught the
134
+ // full spelling — the splits catch the bare name).
135
+ const fams = def.boarded ?? [];
136
+ const famWords = fams.flatMap((f) => [f, ...f.split(/[-_]+/)]).join(" ");
137
+ const words = (id + " " + label + " " + description + " " + low.join(" ") + " " + famWords).toLowerCase().split(/[^a-z0-9]+/).filter((w) => w !== "");
138
+ const why = want.length > 0 ? ["tags=" + want.join(",")] : [];
139
+ let score = 0;
140
+ for (const tok of toks) {
141
+ const hit = scoreToken(tok, words, low, genre);
142
+ if (hit !== null) {
143
+ score += hit.weight;
144
+ why.push(hit.why);
145
+ }
146
+ }
147
+ // the facet law: tags stated => the tag match is the row; tags
148
+ // silent => a row needs a scoring token (never the whole corpus)
149
+ if (want.length === 0 && toks.length > 0 && score === 0)
41
150
  continue;
42
- out.push({ id, label, description, genre: def.identity?.genre ?? "", tags: dtags });
151
+ out.push({ id, label, description, genre, tags: dtags, matched_by: why.length > 0 ? why.join("; ") : "all", score });
43
152
  }
44
- // (map keys are unique — the equal arm never fires)
45
- out.sort((a, b) => (a.id < b.id ? -1 : a.id > b.id ? 1 : /* v8 ignore next */ 0));
153
+ out.sort((a, b) => (b.score - a.score) || (a.id < b.id ? -1 : a.id > b.id ? 1 : /* v8 ignore next */ 0));
46
154
  return out;
47
155
  }
48
156
  /** Search the flow rows (PURE over the merged rows). */
@@ -126,20 +234,50 @@ export class DiscloseDirectoryService extends Service {
126
234
  }
127
235
  /** GET /v1/discover: unknown
128
236
  * lookup refuses with the door's own voice; the body carries the
129
- * requested planes only. */
237
+ * requested planes only. totals is the UNFILTERED estate size
238
+ * (friction-report #5: a filtered answer must say "N cards, M
239
+ * matched" — never present the match as the catalog); missed_tags
240
+ * is the tag vocabulary of cards the filter removed, so a miss is
241
+ * discoverable in one hop. */
130
242
  discover(lookup, q, tags) {
131
243
  if (lookup !== "all" && lookup !== "cards" && lookup !== "flows") {
132
244
  throw new Error("unknown lookup '" + lookup + "' (all | cards | flows)");
133
245
  }
134
- const body = {};
246
+ const allFlows = flowSummaryRows(resolveRepoRoot(), this.ctx.get("meliteFlows"));
247
+ const cards = this.ctx.cardRegistry;
248
+ const defs = cards.defsSync();
249
+ const filtering = q !== "" || tags !== "";
250
+ const body = {
251
+ totals: { flows: allFlows.length, cards: defs.size },
252
+ };
135
253
  if (lookup === "all" || lookup === "flows") {
136
- body.flows = searchFlows(flowSummaryRows(resolveRepoRoot(), this.ctx.get("meliteFlows")), q);
254
+ body.flows = searchFlows(allFlows, q);
137
255
  }
138
256
  if (lookup === "all" || lookup === "cards") {
139
257
  // property read: the hard inject (above) is the fiber's
140
258
  // contract — the legal spelling under the tutorial's law.
141
- const cards = this.ctx.cardRegistry;
142
- body.cards = searchCards(cards.defsSync(), q, tags);
259
+ body.cards = searchCards(defs, q, tags);
260
+ if (filtering) {
261
+ // THE MISS VOCABULARY (friction-report #5): tags carried by
262
+ // NO matched card — the rows the filter removed, so a miss is
263
+ // discoverable in one hop (a second q/tags off this list).
264
+ const matchedIds = new Set((body.cards ?? []).map((c) => c.id));
265
+ const matchedTags = new Set();
266
+ for (const c of body.cards ?? []) {
267
+ for (const t of defs.get(c.id)?.tags ?? [])
268
+ matchedTags.add(t);
269
+ }
270
+ const missed = new Set();
271
+ for (const [id, def] of defs) {
272
+ if (matchedIds.has(id))
273
+ continue;
274
+ for (const t of def.tags ?? []) {
275
+ if (!matchedTags.has(t))
276
+ missed.add(t);
277
+ }
278
+ }
279
+ body.missed_tags = [...missed].sort().slice(0, 40);
280
+ }
143
281
  }
144
282
  return body;
145
283
  }
package/lib/filmLead.js CHANGED
@@ -6,9 +6,11 @@
6
6
  // is the one pure, filesystem-free decision the gallery needs:
7
7
  // when the engine composed the film itself, the film leads the
8
8
  // names.
9
- /** The ENGINE FILM artifact — the in-graph assembly's output
10
- * (SaveVideo prefix h3_t4_film + ComfyUI's counter suffix). */
11
- const ENGINE_FILM_RE = /(?:^|\/)h3_t4_film_\d+_\.mp4$/;
9
+
10
+
11
+
12
+
13
+ const ENGINE_FILM_RE = /(?:^|[/_])h3_t4_film_\d+_\.mp4$/;
12
14
  /** The engine-composed film's name among a stage's artifacts, if
13
15
  * any — presentation order only, never composition. */
14
16
  export function engineFilmName(names) {