@melite/estate-queue 0.0.0-stage → 0.1.5-pre-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 (131) hide show
  1. package/LICENSE +557 -0
  2. package/README.md +54 -2
  3. package/lib/bakeParams.d.ts +17 -0
  4. package/lib/bakeParams.js +182 -0
  5. package/lib/bench.d.ts +32 -0
  6. package/lib/bench.js +111 -0
  7. package/lib/cardsArmError.d.ts +61 -0
  8. package/lib/cardsArmError.js +57 -0
  9. package/lib/cardsCompose.d.ts +53 -0
  10. package/lib/cardsCompose.js +295 -0
  11. package/lib/cardsDangling.d.ts +16 -0
  12. package/lib/cardsDangling.js +213 -0
  13. package/lib/cardsFacts.d.ts +87 -0
  14. package/lib/cardsFacts.js +78 -0
  15. package/lib/cardsLanes.d.ts +43 -0
  16. package/lib/cardsLanes.js +178 -0
  17. package/lib/cardsRegistry.d.ts +404 -0
  18. package/lib/cardsRegistry.js +1543 -0
  19. package/lib/cardsVariant.d.ts +37 -0
  20. package/lib/cardsVariant.js +243 -0
  21. package/lib/discloseRegistry.d.ts +95 -0
  22. package/lib/discloseRegistry.js +156 -0
  23. package/lib/filmLead.d.ts +4 -0
  24. package/lib/filmLead.js +17 -0
  25. package/lib/filmMemoryWarn.d.ts +27 -0
  26. package/lib/filmMemoryWarn.js +99 -0
  27. package/lib/flowsData.d.ts +234 -0
  28. package/lib/flowsData.js +673 -0
  29. package/lib/flowsFamilyCompose.d.ts +45 -0
  30. package/lib/flowsFamilyCompose.js +191 -0
  31. package/lib/flowsParamsOverlay.d.ts +55 -0
  32. package/lib/flowsParamsOverlay.js +197 -0
  33. package/lib/flowsRegistryRows.d.ts +12 -0
  34. package/lib/flowsRegistryRows.js +520 -0
  35. package/lib/index.d.ts +47 -0
  36. package/lib/index.js +75 -0
  37. package/lib/ledgerTail.d.ts +20 -0
  38. package/lib/ledgerTail.js +123 -0
  39. package/lib/lifecycleLatch.d.ts +16 -0
  40. package/lib/lifecycleLatch.js +42 -0
  41. package/lib/loadPlane.d.ts +94 -0
  42. package/lib/loadPlane.js +570 -0
  43. package/lib/loadRegistry.d.ts +22 -0
  44. package/lib/loadRegistry.js +55 -0
  45. package/lib/manageOps.d.ts +27 -0
  46. package/lib/manageOps.js +162 -0
  47. package/lib/managePlane.d.ts +151 -0
  48. package/lib/managePlane.js +1790 -0
  49. package/lib/manageProbe.d.ts +48 -0
  50. package/lib/manageProbe.js +165 -0
  51. package/lib/manageRegistry.d.ts +66 -0
  52. package/lib/manageRegistry.js +113 -0
  53. package/lib/managerRail.d.ts +33 -0
  54. package/lib/managerRail.js +91 -0
  55. package/lib/mediaKinds.d.ts +3 -0
  56. package/lib/mediaKinds.js +2 -0
  57. package/lib/queue.d.ts +9 -0
  58. package/lib/queue.js +80 -0
  59. package/lib/queueCore.d.ts +72 -0
  60. package/lib/queueCore.js +128 -0
  61. package/lib/queueLifecycle.d.ts +2 -0
  62. package/lib/queueLifecycle.js +11 -0
  63. package/lib/queueLock.d.ts +60 -0
  64. package/lib/queueLock.js +198 -0
  65. package/lib/queueResurrect.d.ts +59 -0
  66. package/lib/queueResurrect.js +249 -0
  67. package/lib/queueRetry.d.ts +36 -0
  68. package/lib/queueRetry.js +24 -0
  69. package/lib/queueSidecar.d.ts +149 -0
  70. package/lib/queueSidecar.js +183 -0
  71. package/lib/queueSubmit.d.ts +82 -0
  72. package/lib/queueSubmit.js +191 -0
  73. package/lib/queueSweep.d.ts +30 -0
  74. package/lib/queueSweep.js +132 -0
  75. package/lib/resurrect.d.ts +6 -0
  76. package/lib/resurrect.js +18 -0
  77. package/lib/rootsManifest.d.ts +11 -0
  78. package/lib/rootsManifest.js +11 -0
  79. package/lib/runsChange.d.ts +61 -0
  80. package/lib/runsChange.js +79 -0
  81. package/lib/runsErrorCodes.d.ts +2 -0
  82. package/lib/runsErrorCodes.js +48 -0
  83. package/lib/runsExecute.d.ts +52 -0
  84. package/lib/runsExecute.js +494 -0
  85. package/lib/runsGates.d.ts +161 -0
  86. package/lib/runsGates.js +307 -0
  87. package/lib/runsList.d.ts +78 -0
  88. package/lib/runsList.js +574 -0
  89. package/lib/runsRefusalVoices.d.ts +9 -0
  90. package/lib/runsRefusalVoices.js +96 -0
  91. package/lib/runsRegistry.d.ts +351 -0
  92. package/lib/runsRegistry.js +2394 -0
  93. package/lib/runsSourceEcho.d.ts +81 -0
  94. package/lib/runsSourceEcho.js +341 -0
  95. package/lib/runsStart.d.ts +163 -0
  96. package/lib/runsStart.js +667 -0
  97. package/lib/runsTypes.d.ts +218 -0
  98. package/lib/runsTypes.js +289 -0
  99. package/lib/runsValidate.d.ts +5 -0
  100. package/lib/runsValidate.js +31 -0
  101. package/lib/runsValidateArms.d.ts +7 -0
  102. package/lib/runsValidateArms.js +339 -0
  103. package/lib/runsValidateInline.d.ts +6 -0
  104. package/lib/runsValidateInline.js +82 -0
  105. package/lib/runsValidateRefusals.d.ts +7 -0
  106. package/lib/runsValidateRefusals.js +18 -0
  107. package/lib/runsValidateServe.d.ts +15 -0
  108. package/lib/runsValidateServe.js +276 -0
  109. package/lib/runsValidateShared.d.ts +84 -0
  110. package/lib/runsValidateShared.js +88 -0
  111. package/lib/runsValidateStages.d.ts +32 -0
  112. package/lib/runsValidateStages.js +511 -0
  113. package/lib/runsValidateSweeps.d.ts +6 -0
  114. package/lib/runsValidateSweeps.js +143 -0
  115. package/lib/service.d.ts +63 -0
  116. package/lib/service.js +89 -0
  117. package/lib/skillFrontmatter.d.ts +11 -0
  118. package/lib/skillFrontmatter.js +46 -0
  119. package/lib/skillFs.d.ts +24 -0
  120. package/lib/skillFs.js +78 -0
  121. package/lib/skillPlane.d.ts +99 -0
  122. package/lib/skillPlane.js +269 -0
  123. package/lib/skillRegistry.d.ts +23 -0
  124. package/lib/skillRegistry.js +55 -0
  125. package/lib/skillRows.d.ts +127 -0
  126. package/lib/skillRows.js +468 -0
  127. package/lib/toolProjection.d.ts +30 -0
  128. package/lib/toolProjection.js +142 -0
  129. package/lib/vocab.d.ts +6 -0
  130. package/lib/vocab.js +18 -0
  131. package/package.json +48 -4
@@ -0,0 +1,570 @@
1
+
2
+ // the dead gateway's disclose.ts loader span (killed with the
3
+ // gateway app) ports here — load opens ONE card or flow (agents
4
+ // md + tool-call signature + tier-1 skill lines; bodies stay
5
+ // behind melite_skill_read). Division of enhance unchanged (operator law
6
+
7
+ // melite_skill_read, writes the prompt itself.
8
+ //
9
+ // Erasable-syntax TS only (node --experimental-strip-types).
10
+ import { createHash } from "node:crypto";
11
+ import { existsSync, readdirSync, readFileSync } from "node:fs";
12
+ import { join } from "node:path";
13
+ import { cardPackages, emitModifierKinds, emitParamsSchema, getModel, modelsService, theService } from "@melite/comfyui-cordis";
14
+ import { semanticModelEntries } from "@melite/comfyui-card-kit/semanticModelKnob";
15
+ import { laneContractsFor } from "@melite/contracts/laneRelations";
16
+ import { seedFlowsSeat } from "./flowsData.js";
17
+ import { toolBaseRows } from "./toolProjection.js";
18
+ import { modelRows, cardRows, engineDirs, wireSkill, findSkill } from "./skillPlane.js";
19
+ import { laneFilesStatus } from "./cardsLanes.js";
20
+ /** A card id → its package dir. The cardPackages rows are package
21
+ * NAMES ('@melite/<genre>-<card>'); the id is the row's tail past
22
+ * the genre prefix, which is NOT reparseable from the string alone
23
+ * (ids carry dashes) — so match rows ending in '-' + id, split the
24
+ * genre against the LIVE domain tier (readdir packages/), and keep
25
+ * the ones whose dir carries src/card.ts (the cardUnitDirs guard).
26
+ * Node resolution is the WRONG tool (pnpm links only dependents —
27
+ * require.resolve starves); the repo tree is the truth.
28
+ * Zero hits = unknown id; two = a data bug — both refuse LOUD at
29
+ * the door, never a silent pick. */
30
+ export function resolveCardPackageDir(repo, cardId) {
31
+ let domains = [];
32
+ try {
33
+ domains = readdirSync(join(repo, "packages"), { withFileTypes: true })
34
+ .filter((e) => e.isDirectory())
35
+ .map((e) => e.name);
36
+ }
37
+ catch {
38
+ throw new Error(`disclose: no packages tier under '${repo}'`);
39
+ }
40
+ const hits = [];
41
+ let named = 0;
42
+ for (const row of cardPackages) {
43
+ // (every cardPackages row carries the @melite/ prefix — the bare arm never fires;
44
+ // studio cards' rows point at the CARD subpath ('.../card') — strip it: the
45
+ // resolver wants the package name, and the dir guard below does the rest)
46
+ const tail = (row.startsWith("@melite/") ? row.slice("@melite/".length) : /* v8 ignore next */ row).replace(/\/card$/, "");
47
+ if (!tail.endsWith("-" + cardId))
48
+ continue;
49
+ named++;
50
+ for (const dom of domains) {
51
+ if (!tail.startsWith(dom + "-"))
52
+ continue;
53
+ const dir = join(repo, "packages", dom, tail.slice(dom.length + 1));
54
+
55
+
56
+
57
+ if (!existsSync(join(dir, "src", "card.ts")))
58
+ continue;
59
+ hits.push(dir);
60
+ }
61
+ }
62
+ if (hits.length === 0) {
63
+ if (named === 0)
64
+ throw new Error(`disclose: unknown card '${cardId}'`);
65
+
66
+
67
+
68
+
69
+
70
+
71
+
72
+
73
+
74
+
75
+ throw new Error(`disclose: card '${cardId}' is registered but no source dir serves under '${repo}' ` +
76
+ `(the load door reads packages/<genre>/<card>/src/card.ts from the repo tree; ` +
77
+ `an install tree ships no card sources — pin MELITE_REPO_ROOT to the estate checkout)`);
78
+ }
79
+
80
+
81
+ if (hits.length > 1)
82
+ throw new Error(`disclose: card '${cardId}' is ambiguous (${hits.length} packages)`);
83
+ return hits[0];
84
+ }
85
+ /** The card's agents md (src/agents/**, AGENT.md first, sorted,
86
+ * capped — the cap is the contract: lines route, bodies stay
87
+ * bounded). */
88
+ export function cardSkillDocs(pkgDir) {
89
+ const MAX_FILES = 8;
90
+ const MAX_BYTES = 32768;
91
+ const agents = join(pkgDir, "src", "agents");
92
+ let files = [];
93
+ try {
94
+ files = readdirSync(agents).filter((f) => f.endsWith(".md"));
95
+ }
96
+ catch (e) {
97
+
98
+ // most cards ship none. Any OTHER read failure is a real defect
99
+ // and is NAMED (the bundle must not silently narrow the agent's
100
+ // constraints); the bundle still serves (a disclose read never
101
+ // refuses the door), but the degrade is visible in the log.
102
+ if (e.code !== "ENOENT") {
103
+ console.error(`disclose: card agents dir unreadable (${agents}): ${String(e)}`);
104
+ }
105
+ return [];
106
+ }
107
+ files.sort((a, b) => {
108
+ const ra = a === "AGENT.md" ? 0 : 1;
109
+ const rb = b === "AGENT.md" ? 0 : 1;
110
+ // (byte-sorted readdir + V8's (current, earlier) insertion order
111
+ // never evaluate the less-than tiebreak here: the sort RESULT is
112
+ // pinned by the AGENT-first assertions below)
113
+ return ra - rb || (a < b ? /* v8 ignore next */ -1 : 1);
114
+ });
115
+ const out = [];
116
+ let budget = MAX_BYTES;
117
+ for (const f of files.slice(0, MAX_FILES)) {
118
+ if (budget <= 0)
119
+ break;
120
+ try {
121
+ const text = readFileSync(join(agents, f), "utf8").slice(0, budget);
122
+ budget -= text.length;
123
+ out.push({ path: "src/agents/" + f, text });
124
+ }
125
+ catch (e) {
126
+
127
+ // the agent's constraints must not narrow invisibly.
128
+ console.error(`disclose: card skill doc unreadable (${join(agents, f)}): ${String(e)}`);
129
+ }
130
+ }
131
+ return out;
132
+ }
133
+ /** The card's tool-call signature — the /v1/tools row
134
+ * envelope (ROW_KEYS mirror toolsEmit — one projection, the
135
+ * emitter imported, the envelope shared by construction). */
136
+ export function toolRowFor(id, def, rows) {
137
+ const base = rows.get(id);
138
+ if (base === undefined)
139
+ throw new Error(`disclose: no tool row for card '${id}'`);
140
+ // The model knob serves the same style entries as the base row.
141
+ // An unresolvable boarded id keeps the bare boarded enum.
142
+ let semantic;
143
+ try {
144
+ const decls = [];
145
+ for (const fam of def.boarded)
146
+ decls.push(getModel(fam));
147
+ const entries = semanticModelEntries(decls);
148
+ if (entries.length > 0)
149
+ semantic = entries;
150
+ }
151
+ catch {
152
+ // A missing DECL keeps the bare fallback.
153
+ // The compose door refuses it loud with its own voice.
154
+ semantic = undefined;
155
+ }
156
+ const paramsSchema = emitParamsSchema((def.schemaCarrier ?? def.schema), def.boarded, semantic);
157
+ // THE MODS PROJECTION (stroke 79): one emitter (emitModifierKinds
158
+ // — the same SSOT the /v1/tools manifest row serves), so the load
159
+ // bundle's signature and the manifest never drift. leaf_face never
160
+ // rides (the agent composes VALUES, never faces).
161
+ const modifiers = emitModifierKinds(def.mods);
162
+ // THE LANE CONTRACT RIDES THE BUNDLE (the DECL audit's gap 1,
163
+
164
+ // served no `lanes` key at all — so the agent's primary face said
165
+ // nothing about a lane's surface, its relation words, its bounds,
166
+ // or its sampler domain, and the agent learned every law by
167
+ // hitting the bench's refusal. /v1/card-tools served the same
168
+ // projection; this is ONE construction (laneContractsFor, contracts
169
+ // floor) so the two faces cannot drift.
170
+ const lanes = laneContractsFor(def.boarded, (fam) => {
171
+ try {
172
+ return getModel(fam);
173
+ }
174
+ catch {
175
+ // a boarded id that is not a declared family (a retired
176
+ // address) contributes nothing — the stand-down, never a throw
177
+ return undefined;
178
+ }
179
+ });
180
+ return {
181
+ ...(modifiers.length > 0 ? { modifiers } : {}),
182
+ ...(Object.keys(lanes).length > 0 ? { lanes } : {}),
183
+ name: base.name,
184
+ version: base.version,
185
+ kind: base.kind,
186
+ card: base.card,
187
+ model: base.model,
188
+ stage_title: base.stageTitle,
189
+ description: base.description,
190
+ params_schema: {
191
+ type: paramsSchema.type,
192
+ properties: paramsSchema.properties,
193
+ ...(paramsSchema.required !== undefined ? { required: paramsSchema.required } : {}),
194
+ },
195
+ };
196
+ }
197
+ /** The bundle digest (the DSH session-catalog half we CAN own:
198
+ * their catalog is digest-diffed "stable, never duplicated" — we
199
+ * don't own the loop so we can't clear the agent's context, but a
200
+ * stable content hash lets the agent dedupe its own reloads: quote
201
+ * the digests you hold, skip reload on a match). sha16 of the
202
+ * canonical bundle JSON (the asset pipeline's sha16 convention). */
203
+ export function bundleDigest(bundle) {
204
+ return createHash("sha256").update(JSON.stringify(bundle)).digest("hex").slice(0, 16);
205
+ }
206
+ // ── end moved pures ──
207
+ /** Tier-1 skill LINES for one card id (the melite_skill_index truth —
208
+ * wireSkill rows over the planes buckets, card-skill scope only;
209
+ * the card's AGENT.md rides full under agents, never as a line).
210
+ * Merged across engines, id-deduped; unknown cards line nothing
211
+ * (the walk is the truth — never a refusal). */
212
+ export function skillLinesForCard(repo, cardId) {
213
+ const out = [];
214
+ const seen = new Set();
215
+ let engines;
216
+ try {
217
+ engines = engineDirs(join(repo, "packages", "engines"));
218
+ }
219
+ catch {
220
+
221
+
222
+ return out;
223
+ }
224
+ for (const engine of engines) {
225
+ let bucket;
226
+ try {
227
+ bucket = cardRows(engine, repo).buckets.get(cardId);
228
+ }
229
+ catch {
230
+
231
+
232
+ continue;
233
+ }
234
+ if (bucket === undefined)
235
+ continue;
236
+ for (const doc of bucket.rows) {
237
+ if (doc.row.scope !== "card-skill")
238
+ continue;
239
+
240
+
241
+
242
+ if (seen.has(doc.row.id))
243
+ continue;
244
+ seen.add(doc.row.id);
245
+ out.push(wireSkill(doc.row));
246
+ }
247
+ }
248
+ return out;
249
+ }
250
+
251
+
252
+
253
+
254
+
255
+
256
+
257
+
258
+
259
+
260
+ export function skillLinesForFamilies(repo, fams) {
261
+ const out = [];
262
+ const seen = new Set();
263
+
264
+ // old try/catch here was a dead arm; removed. If it ever DOES
265
+ // throw, the error propagates loud: fail-closed is the law.)
266
+ const engines = engineDirs(join(repo, "packages", "engines"));
267
+ // walk once, bucket per family — the bundle emits boarded order
268
+ const perFam = new Map();
269
+ for (const engine of engines) {
270
+ let rows;
271
+ try {
272
+ rows = modelRows(engine);
273
+ }
274
+ catch (e) {
275
+
276
+ // the skill walk — that degrade is NAMED, never silent.
277
+ console.error(`disclose: model rows unreadable (${engine}): ${String(e)}`);
278
+ continue;
279
+ }
280
+ for (const doc of rows) {
281
+ if (doc.row.model === null || !fams.includes(doc.row.model))
282
+ continue;
283
+ if (doc.row.scope !== "model" && doc.row.scope !== "model-skill")
284
+ continue;
285
+ if (seen.has(doc.row.id))
286
+ continue;
287
+ seen.add(doc.row.id);
288
+ const cell = perFam.get(doc.row.model) ?? [];
289
+ cell.push({ id: doc.row.id, line: wireSkill(doc.row), entrance: doc.row.scope === "model" });
290
+ perFam.set(doc.row.model, cell);
291
+ }
292
+ }
293
+ for (const fam of fams) {
294
+ const cell = perFam.get(fam) ?? [];
295
+ // entrance first, then skills in walk order
296
+ cell.sort((a, b) => Number(b.entrance) - Number(a.entrance));
297
+ for (const r of cell)
298
+ out.push(r.line);
299
+ }
300
+ return out;
301
+ }
302
+ export function flowLeafDocs(repo, flowName) {
303
+ const MAX_FILES = 8;
304
+ const MAX_BYTES = 32768;
305
+ const leaf = join(repo, "flows", flowName);
306
+ const files = [];
307
+ const walk = (dir, rel) => {
308
+
309
+
310
+ if (files.length >= MAX_FILES)
311
+ return;
312
+ let entries;
313
+ try {
314
+ entries = readdirSync(dir, { withFileTypes: true });
315
+ }
316
+ catch {
317
+ return;
318
+ }
319
+ const names = entries.map((e) => e.name);
320
+ const isDir = new Map(entries.map((e) => [e.name, e.isDirectory()]));
321
+ names.sort((a, b) => {
322
+ const rank = (f) => f === "AGENT.md" || f === "AGENTS.md" || f === "SKILL.md" ? 0 : 1;
323
+ // (same byte-order law as cardSkillDocs above: the less-than
324
+ // tiebreak never evaluates; the order assertions pin the result)
325
+ return rank(a) - rank(b) || (a < b ? /* v8 ignore next */ -1 : 1);
326
+ });
327
+ for (const f of names) {
328
+ if (files.length >= MAX_FILES)
329
+ break;
330
+ if (isDir.get(f) === true) {
331
+ walk(join(dir, f), rel + f + "/");
332
+ }
333
+ else if (f.endsWith(".md")) {
334
+ files.push(rel + f);
335
+ }
336
+ }
337
+ };
338
+ walk(leaf, "");
339
+ const out = [];
340
+ let budget = MAX_BYTES;
341
+ for (const f of files) {
342
+ if (budget <= 0)
343
+ break;
344
+ try {
345
+ const text = readFileSync(join(leaf, f), "utf8").slice(0, budget);
346
+ budget -= text.length;
347
+ out.push({ path: "flows/" + flowName + "/" + f, text });
348
+ }
349
+ catch {
350
+ // unreadable — skip, never refuse the bundle
351
+ }
352
+ }
353
+ return out;
354
+ }
355
+ /** Resolve one skill ref (a card:/model:/flow: sid) to its tier-1
356
+ * line through the planes registry (the melite_skill_index truth).
357
+ * Dangling refs line null — visible drift, never a refusal. */
358
+ /** @param modelsSeat the context's models service when mounted (the
359
+ * same seat-threading law the runs doors ride) */
360
+ export function skillLineForRef(repo, ref, modelsSeat, flowsSeat) {
361
+ try {
362
+ const found = findSkill(repo, ref, modelsSeat, flowsSeat);
363
+ if (found !== null)
364
+ return { ref, line: wireSkill(found.row) };
365
+ }
366
+ catch {
367
+ // registry walk threw — line null below
368
+ }
369
+ return { ref, line: null };
370
+ }
371
+ /** Melite load for a CARD: agents md + tool-call signature +
372
+ * tier-1 skill lines (the card's own AND every boarded family's
373
+ * model skills — ONE load hands the agent the whole craft: loading
374
+ * image-gen serves model:anima:prompt-enhance beside the card
375
+ * lines, so the prompt guide is read before compose, never hunted
376
+ * after) + model hints (the boarded families' DECL identity —
377
+ * presence-marked, never a run-time surprise; LLM-powered enhance
378
+ * stays the user's ✦ door, never served here). Throws LOUD
379
+ * on unknown ids (the door maps to 404). */
380
+ export function loadCard(repo, cards, modelsSeat, cardId) {
381
+ // ADMISSION BEFORE THE DEPENDENCY (the flow arm's own order at
382
+ // loadFlow: the referent first, the seat that serves it second).
383
+ // Reading the models seat first made an unknown card answer in the
384
+ // engine's bootstrap voice ("models service not booted") instead of
385
+ // the load door's own "disclose: unknown card 'x'".
386
+ const defs = cards.defsSync();
387
+ const def = defs.get(cardId);
388
+ if (def === undefined)
389
+ throw new Error(`disclose: unknown card '${cardId}'`);
390
+ // The lane's seat when mounted (the lane-seat law — the same read
391
+ // the flow arm threads), the booted singleton otherwise; an
392
+ // unmounted seat degrades exactly like the flow arm.
393
+ const models = modelsSeat ?? modelsService();
394
+ const rows = toolBaseRows(defs);
395
+ const pkgDir = resolveCardPackageDir(repo, cardId);
396
+ const decls = new Map(models.allDecls().map((d) => [d.id, { id: d.id, label: d.label, description: d.description ?? "", ...(d.lane_inputs === undefined ? {} : { lane_inputs: d.lane_inputs }) }]));
397
+ const hints = [];
398
+ for (const fam of def.boarded) {
399
+ const d = decls.get(fam);
400
+ if (d === undefined)
401
+ continue;
402
+ let present = false;
403
+ const lanePath = typeof d.lane_inputs?.["model_path"] === "string"
404
+ ? String(d.lane_inputs?.["model_path"]).trim()
405
+ : "";
406
+ const filesPresent = typeof models.checkModelPresent === "function"
407
+ ? laneFilesStatus(d, (folder, name) => models.checkModelPresent("models/" + folder, name, repo))
408
+ : null;
409
+ if ((lanePath !== "" && typeof models.checkModelPathPresent === "function" && models.checkModelPathPresent(lanePath, repo) !== null) || filesPresent === true) {
410
+ present = true;
411
+ }
412
+ else {
413
+ try {
414
+ const rows = models.resolveCatalogArtifact(fam, "", "", repo);
415
+ present = rows.length > 0 && rows.every((row) => models.checkModelPresent(row.relative_path, row.name, repo) !== null);
416
+ }
417
+ catch {
418
+ present = false;
419
+ }
420
+ }
421
+ // The served hint carries presence only.
422
+ // Labels live in the semantic knob now.
423
+ hints.push({ description: d.description, present });
424
+ }
425
+ // THE PACK HINTS (the no-silent-drop law's extension half,
426
+ // stroke 18): the card's declared extension packs (flat requires +
427
+ // every per-family slice), presence-marked by the EXTENSION-LAW
428
+ // gate's own read via the engine service. The LLM sees a missing
429
+ // pack at LOAD time — install via comfy_manage install_extension
430
+ // before running, never a run-time surprise.
431
+ const extDef = def;
432
+ const packIds = [...(extDef.requires ?? [])];
433
+ for (const slice of Object.values(extDef.requiresByFamily ?? {})) {
434
+ for (const p of slice)
435
+ if (!packIds.includes(p))
436
+ packIds.push(p);
437
+ }
438
+ let pack_hints = [];
439
+ try {
440
+ const svc = theService();
441
+ pack_hints = svc.packPresence(packIds).map((r) => ({ id: r.id, present: r.present }));
442
+ }
443
+ catch {
444
+ // engine service unavailable at load time — the ids still serve
445
+ // (present: null — unknown, never a silent drop)
446
+ pack_hints = packIds.map((id) => ({ id, present: null }));
447
+ }
448
+ const bundle = {
449
+ name: cardId,
450
+ kind: "card",
451
+ signature: toolRowFor(cardId, def, rows),
452
+ agents: cardSkillDocs(pkgDir),
453
+ skills: [
454
+ ...skillLinesForCard(repo, cardId),
455
+
456
+ // the boarded families' model skills ride the same bundle —
457
+ // no second hunt before compose.
458
+ ...skillLinesForFamilies(repo, def.boarded),
459
+ ],
460
+ model_hints: hints,
461
+ pack_hints,
462
+ };
463
+ bundle["digest"] = bundleDigest(bundle);
464
+ return bundle;
465
+ }
466
+ /** Melite load for a FLOW: the leaf agents md + the registry
467
+ * signature (the tool overlay verbatim — ONE spelling, the same
468
+ * object validate/start enforce; null when the row declares
469
+ * none) + slim stages + the author's skill refs (verbatim) with
470
+ * their tier-1 lines. Throws LOUD on unknown flows. */
471
+ /** @param modelsSeat the context's models service when mounted — the
472
+ * flow's skill lines resolve through the seat the runs doors
473
+ * thread (the lane-seat law); the booted singleton otherwise */
474
+ export function loadFlow(repo, flowName, modelsSeat, flowsSeat) {
475
+ const row = (flowsSeat ?? seedFlowsSeat()).get(flowName);
476
+ if (row === undefined)
477
+ throw new Error(`disclose: unknown flow '${flowName}'`);
478
+ const stages = row.stages.map((s) => ({
479
+ id: s.id,
480
+ // A family stage discloses its verb (family.action) — the card
481
+ // key stays "" and the family keys ride alongside (stroke 4's
482
+ // compose-at-expansion: the graph derives from the action).
483
+ ...(s.family !== "" ? { family: s.family, action: s.action } : {}),
484
+ card: s.card,
485
+ description: s.description,
486
+ // fromFlow links resolve at COMPILE time (expandRegistryFlow) —
487
+ // disclosure serves the link verbatim, never a silent copy.
488
+ ...(s.fromFlow !== null ? { fromFlow: { flow: s.fromFlow.flow, stage: s.fromFlow.stage } } : {}),
489
+ }));
490
+ const seen = new Set();
491
+ const skills = [];
492
+ const pushLines = (cardId) => {
493
+ for (const line of skillLinesForCard(repo, cardId)) {
494
+ // wireSkill always emits id (skillPlane.ts) — the String reads it.
495
+ const id = String(line.id);
496
+
497
+
498
+
499
+ if (id === "")
500
+ continue;
501
+
502
+
503
+
504
+ if (seen.has(id))
505
+ continue;
506
+ seen.add(id);
507
+ skills.push(line);
508
+ }
509
+ };
510
+ const pushFamilyLines = (fam) => {
511
+ for (const line of skillLinesForFamilies(repo, [fam])) {
512
+ const id = String(line.id);
513
+ if (id === "" || seen.has(id))
514
+ continue;
515
+ seen.add(id);
516
+ skills.push(line);
517
+ }
518
+ };
519
+ // Card stages ride the card's skill lines; family stages ride
520
+ // the FAMILY's (the boarded-craft law: no second hunt before
521
+ // compose — a census flow's stages are all family-side).
522
+ for (const s of row.stages) {
523
+ if (s.family !== "")
524
+ pushFamilyLines(s.family);
525
+ else
526
+ pushLines(s.card);
527
+ }
528
+ const refs = [];
529
+ for (const ref of row.skillRefs) {
530
+ const r = skillLineForRef(repo, ref, modelsSeat);
531
+ refs.push(r);
532
+ const line = r["line"];
533
+
534
+
535
+ if (line === null)
536
+ continue;
537
+ // wireSkill always emits id (skillPlane.ts) — the String reads it.
538
+ const id = String(line.id);
539
+
540
+
541
+ if (id === "")
542
+ continue;
543
+
544
+
545
+
546
+ if (seen.has(id))
547
+ continue;
548
+ seen.add(id);
549
+ skills.push(line);
550
+ }
551
+ const bundle = {
552
+ name: flowName,
553
+ kind: "flow",
554
+ signature: row.tool === null ? null : {
555
+ name: row.tool.name,
556
+ description: row.tool.description,
557
+ properties: row.tool.properties,
558
+ required: row.tool.required,
559
+ overlays: row.tool.overlays,
560
+ },
561
+ agents: flowLeafDocs(repo, flowName),
562
+ stages,
563
+ refs: row.skillRefs.slice(),
564
+ skills,
565
+ };
566
+ bundle["digest"] = bundleDigest(bundle);
567
+ return bundle;
568
+ }
569
+ /** First-non-blank query value (the catalogs qFirst shape). */
570
+ //# sourceMappingURL=loadPlane.js.map
@@ -0,0 +1,22 @@
1
+ import { Service } from "@deepseek-ai/cordis";
2
+ import type { Context } from "@deepseek-ai/cordis";
3
+ export declare class LoadResolverService extends Service {
4
+ static inject: string[];
5
+ constructor(ctx: Context);
6
+ /** GET /v1/load?inference_type=card|flow&name=<n> — the bundle.
7
+ * The door's parameter law rides verbatim: inference_type must
8
+ * be card|flow (nothing else executes), name is required. */
9
+ load(inferenceType: string, name: string): Record<string, unknown>;
10
+ }
11
+ /** The load row: gates on the card registry seat. */
12
+ export declare const loadProvider: {
13
+ name: string;
14
+ inject: readonly ["cardRegistry"];
15
+ apply(ctx: Context): void;
16
+ };
17
+ declare module "@deepseek-ai/cordis" {
18
+ interface Context {
19
+ load: LoadResolverService;
20
+ }
21
+ }
22
+ //# sourceMappingURL=loadRegistry.d.ts.map
@@ -0,0 +1,55 @@
1
+
2
+ // load opens ONE card or flow over the loadPlane pures. The seat
3
+ // assembles the two service deps (card registry + models) from
4
+ // the estate's own seams; unknown names answer the door's voice.
5
+ //
6
+ // Erasable-syntax TS only (node --experimental-strip-types).
7
+ import { Service } from "@deepseek-ai/cordis";
8
+ import { resolveRepoRoot } from "@melite/comfyui-cordis";
9
+ import { loadCard, loadFlow } from "./loadPlane.js";
10
+ // ROLE (cookbook adding-a-package role table): Resolver: computes/locates one named answer (the bundle) without owning it. Key "load" unchanged.
11
+ export class LoadResolverService extends Service {
12
+ static inject = ["cardRegistry"];
13
+ constructor(ctx) {
14
+ super(ctx, "load");
15
+ }
16
+ /** GET /v1/load?inference_type=card|flow&name=<n> — the bundle.
17
+ * The door's parameter law rides verbatim: inference_type must
18
+ * be card|flow (nothing else executes), name is required. */
19
+ load(inferenceType, name) {
20
+ if (inferenceType !== "card" && inferenceType !== "flow") {
21
+ throw new Error("load needs inference_type=card|flow (a card or a flow tool call — nothing else executes)");
22
+ }
23
+ if (name === "") {
24
+ throw new Error("load needs name (discover it first)");
25
+ }
26
+ const repo = resolveRepoRoot();
27
+ if (inferenceType === "flow") {
28
+ // The flow bundle composes from the LANES seat (the lane-seat
29
+ // law, audit finding 4): the same read the runs doors thread, so
30
+ // the disclosed body and the composed graph never diverge. ctx.get
31
+ // is the injector API (an unmounted seat reads undefined and the
32
+ // plane degrades to the booted singleton).
33
+ return {
34
+ bundle: loadFlow(repo, name, this.ctx.get("models"), this.ctx.get("meliteFlows")),
35
+ };
36
+ }
37
+ // The card arm reads the LANE's seat for the same reason the flow
38
+ // arm above does (the lane-seat law): the disclosed presence hints
39
+ // must come from the lane that serves the run, not the import-side
40
+ // singleton — on a cold boot the singleton's own read can refuse
41
+ // "models service not booted" while this lane is fully seated.
42
+ return {
43
+ bundle: loadCard(repo, this.ctx.cardRegistry, this.ctx.get("models"), name),
44
+ };
45
+ }
46
+ }
47
+ /** The load row: gates on the card registry seat. */
48
+ export const loadProvider = {
49
+ name: "estate-load",
50
+ inject: ["cardRegistry"],
51
+ apply(ctx) {
52
+ new LoadResolverService(ctx);
53
+ },
54
+ };
55
+ //# sourceMappingURL=loadRegistry.js.map
@@ -0,0 +1,27 @@
1
+ import { ManagerApiError } from "./managerRail.js";
2
+ import { Refused } from "./managePlane.js";
3
+ import type { ManageCtx, ManageEnvelope, Req } from "./managePlane.js";
4
+ export declare function base(ctx: ManageCtx): string;
5
+ /** Map a manager refusal to the estate envelope (the vendor's own
6
+ * security texts ride verbatim — this door never reinterprets a
7
+ * security answer). */
8
+ export declare function mapManagerRefused(e: ManagerApiError, action: string): Refused;
9
+ /** Map a rail failure to its refusal: the rail throws ManagerApiError
10
+ * by contract (refusals verbatim, transports as the 503 template),
11
+ * so the fallthrough only guards the type, never a live error. */
12
+ export declare function mapRail(e: unknown, action: string): Refused;
13
+ export declare function railMs(req: Req): number;
14
+ export declare function awaitQueueDrained(ctx: ManageCtx, req: Req): Promise<Record<string, unknown>>;
15
+ /** BYO guard: estate-orchestration legs (systemd, workspace reads)
16
+ * never touch a user-owned ComfyUI. */
17
+ export declare function estateOnly(req: Req, cfg: Record<string, unknown>): void;
18
+ /** Run systemctl for the estate's engine unit.
19
+ * @param req - the manage request (envelope rows).
20
+ * @param verb - the systemctl verb to run.
21
+ * @param unit - the estate deployment's systemd unit (config-pinned).
22
+ * @param signal - aborts the child and maps to the abort reason.
23
+ * @returns [status, envelope] as the manage lane's answer.
24
+ */
25
+ export declare function systemctl(req: Req, verb: "start" | "stop", unit: string, signal?: AbortSignal): Promise<[number, ManageEnvelope]>;
26
+ export declare function guardLifecycle(req: Req, ctx: ManageCtx): void;
27
+ //# sourceMappingURL=manageOps.d.ts.map