@melite/estate-queue 0.0.0-stage → 0.1.4-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 (129) hide show
  1. package/LICENSE +557 -0
  2. package/lib/bakeParams.d.ts +17 -0
  3. package/lib/bakeParams.js +182 -0
  4. package/lib/bench.d.ts +24 -0
  5. package/lib/bench.js +121 -0
  6. package/lib/cardsArmError.d.ts +18 -0
  7. package/lib/cardsArmError.js +33 -0
  8. package/lib/cardsCompose.d.ts +41 -0
  9. package/lib/cardsCompose.js +247 -0
  10. package/lib/cardsDangling.d.ts +16 -0
  11. package/lib/cardsDangling.js +168 -0
  12. package/lib/cardsFacts.d.ts +74 -0
  13. package/lib/cardsFacts.js +64 -0
  14. package/lib/cardsLanes.d.ts +33 -0
  15. package/lib/cardsLanes.js +115 -0
  16. package/lib/cardsRegistry.d.ts +316 -0
  17. package/lib/cardsRegistry.js +1274 -0
  18. package/lib/cardsVariant.d.ts +28 -0
  19. package/lib/cardsVariant.js +190 -0
  20. package/lib/discloseRegistry.d.ts +94 -0
  21. package/lib/discloseRegistry.js +154 -0
  22. package/lib/filmLead.d.ts +4 -0
  23. package/lib/filmLead.js +17 -0
  24. package/lib/filmMemoryWarn.d.ts +27 -0
  25. package/lib/filmMemoryWarn.js +99 -0
  26. package/lib/flowsData.d.ts +179 -0
  27. package/lib/flowsData.js +547 -0
  28. package/lib/flowsFamilyCompose.d.ts +48 -0
  29. package/lib/flowsFamilyCompose.js +191 -0
  30. package/lib/flowsRegistryRows.d.ts +10 -0
  31. package/lib/flowsRegistryRows.js +378 -0
  32. package/lib/index.d.ts +50 -0
  33. package/lib/index.js +66 -0
  34. package/lib/ledgerTail.d.ts +20 -0
  35. package/lib/ledgerTail.js +123 -0
  36. package/lib/loadPlane.d.ts +93 -0
  37. package/lib/loadPlane.js +553 -0
  38. package/lib/loadRegistry.d.ts +22 -0
  39. package/lib/loadRegistry.js +55 -0
  40. package/lib/manageOps.d.ts +21 -0
  41. package/lib/manageOps.js +142 -0
  42. package/lib/managePlane.d.ts +120 -0
  43. package/lib/managePlane.js +1515 -0
  44. package/lib/manageProbe.d.ts +57 -0
  45. package/lib/manageProbe.js +154 -0
  46. package/lib/manageRegistry.d.ts +28 -0
  47. package/lib/manageRegistry.js +75 -0
  48. package/lib/managerRail.d.ts +33 -0
  49. package/lib/managerRail.js +91 -0
  50. package/lib/mediaKinds.d.ts +3 -0
  51. package/lib/mediaKinds.js +2 -0
  52. package/lib/queue.d.ts +9 -0
  53. package/lib/queue.js +76 -0
  54. package/lib/queueCore.d.ts +69 -0
  55. package/lib/queueCore.js +124 -0
  56. package/lib/queueLifecycle.d.ts +26 -0
  57. package/lib/queueLifecycle.js +65 -0
  58. package/lib/queueLock.d.ts +54 -0
  59. package/lib/queueLock.js +195 -0
  60. package/lib/queueResurrect.d.ts +59 -0
  61. package/lib/queueResurrect.js +249 -0
  62. package/lib/queueRetry.d.ts +36 -0
  63. package/lib/queueRetry.js +24 -0
  64. package/lib/queueSidecar.d.ts +145 -0
  65. package/lib/queueSidecar.js +182 -0
  66. package/lib/queueSubmit.d.ts +31 -0
  67. package/lib/queueSubmit.js +117 -0
  68. package/lib/queueSweep.d.ts +30 -0
  69. package/lib/queueSweep.js +121 -0
  70. package/lib/resurrect.d.ts +6 -0
  71. package/lib/resurrect.js +18 -0
  72. package/lib/rootsManifest.d.ts +11 -0
  73. package/lib/rootsManifest.js +11 -0
  74. package/lib/runStatus.d.ts +7 -0
  75. package/lib/runStatus.js +21 -0
  76. package/lib/runsChange.d.ts +53 -0
  77. package/lib/runsChange.js +63 -0
  78. package/lib/runsErrorCodes.d.ts +2 -0
  79. package/lib/runsErrorCodes.js +15 -0
  80. package/lib/runsExecute.d.ts +26 -0
  81. package/lib/runsExecute.js +356 -0
  82. package/lib/runsGates.d.ts +161 -0
  83. package/lib/runsGates.js +306 -0
  84. package/lib/runsList.d.ts +78 -0
  85. package/lib/runsList.js +580 -0
  86. package/lib/runsRefusalVoices.d.ts +9 -0
  87. package/lib/runsRefusalVoices.js +44 -0
  88. package/lib/runsRegistry.d.ts +253 -0
  89. package/lib/runsRegistry.js +1750 -0
  90. package/lib/runsSourceEcho.d.ts +54 -0
  91. package/lib/runsSourceEcho.js +275 -0
  92. package/lib/runsStart.d.ts +121 -0
  93. package/lib/runsStart.js +528 -0
  94. package/lib/runsTypes.d.ts +183 -0
  95. package/lib/runsTypes.js +282 -0
  96. package/lib/runsValidate.d.ts +5 -0
  97. package/lib/runsValidate.js +31 -0
  98. package/lib/runsValidateArms.d.ts +7 -0
  99. package/lib/runsValidateArms.js +285 -0
  100. package/lib/runsValidateInline.d.ts +6 -0
  101. package/lib/runsValidateInline.js +82 -0
  102. package/lib/runsValidateRefusals.d.ts +7 -0
  103. package/lib/runsValidateRefusals.js +18 -0
  104. package/lib/runsValidateServe.d.ts +15 -0
  105. package/lib/runsValidateServe.js +254 -0
  106. package/lib/runsValidateShared.d.ts +84 -0
  107. package/lib/runsValidateShared.js +88 -0
  108. package/lib/runsValidateStages.d.ts +25 -0
  109. package/lib/runsValidateStages.js +491 -0
  110. package/lib/runsValidateSweeps.d.ts +6 -0
  111. package/lib/runsValidateSweeps.js +143 -0
  112. package/lib/service.d.ts +45 -0
  113. package/lib/service.js +81 -0
  114. package/lib/skillFrontmatter.d.ts +11 -0
  115. package/lib/skillFrontmatter.js +46 -0
  116. package/lib/skillFs.d.ts +19 -0
  117. package/lib/skillFs.js +80 -0
  118. package/lib/skillPlane.d.ts +98 -0
  119. package/lib/skillPlane.js +263 -0
  120. package/lib/skillRegistry.d.ts +23 -0
  121. package/lib/skillRegistry.js +55 -0
  122. package/lib/skillRows.d.ts +126 -0
  123. package/lib/skillRows.js +466 -0
  124. package/lib/toolProjection.d.ts +30 -0
  125. package/lib/toolProjection.js +142 -0
  126. package/lib/vocab.d.ts +6 -0
  127. package/lib/vocab.js +18 -0
  128. package/package.json +47 -4
  129. package/README.md +0 -3
@@ -0,0 +1,547 @@
1
+ // flowsData.ts — the TS flow-authoring plane, RE-HOMED (REBUILD-13,
2
+
3
+ // gateway package (doors/flowsRegistry.ts, killed with the gateway
4
+ // app — KILL commit 40b57f94) live HERE as data, beside their
5
+ // serving owners (the runs registry {flow:} arms). Port verbatim:
6
+ // the eight declarations, the live from_flow expansion, and the
7
+ // inline shim (registryFlowToInline) — validate and start resolve
8
+ // stages LIVE through expandRegistryFlow, no snapshot drift.
9
+ //
10
+ // THE COMPILE-TIME INITIAL GATE (REBUILD-21, the deferral closed):
11
+ // registryInitialsError + checkFileInitial + InitialsRoots port
12
+ // verbatim (photo/glb file-initial checks + bake_params via the
13
+ // re-homed belt); the runs registry's {flow:} arms run it BEFORE
14
+ // any run registers — start can never queue what validate refuses.
15
+ //
16
+ // QUEUE LANE LAW unchanged: no legacy (no flow.py read — existence
17
+ // rides this registry), no fallbacks, no hardcodes.
18
+ //
19
+ // Erasable-syntax TS only (node --experimental-strip-types).
20
+ import { CARD_PLANE_ENGINE, LEGACY_RUN_MEDIA_PREFIX, RUN_MEDIA_PREFIX } from "@melite/contracts/benchStage";
21
+ import { statSync } from "node:fs";
22
+ import { join, resolve } from "node:path";
23
+ import { mediaVocab } from "./mediaKinds.js";
24
+ import { validateBakeParams } from "./bakeParams.js";
25
+ function isFile(p) {
26
+ try {
27
+ return statSync(p).isFile();
28
+ }
29
+ catch {
30
+ return false;
31
+ }
32
+ }
33
+ // ── shared builders ─────────────────────────────────────────────
34
+ export function initial(key) {
35
+ return { initial: key };
36
+ }
37
+ export function fromStage(stage, output) {
38
+ return { stage, output };
39
+ }
40
+ export function plainStage(row) {
41
+ return {
42
+ id: row.id,
43
+ engine: row.engine,
44
+ card: row.card ?? "",
45
+ family: row.family ?? "",
46
+ action: row.action ?? "",
47
+ description: row.description,
48
+ inputs: row.inputs,
49
+ expected: row.expected ?? {},
50
+ outputs: row.outputs ?? {},
51
+ cardIo: row.cardIo ?? {},
52
+ params: row.params,
53
+ skipWhen: row.skipWhen ?? null,
54
+ fromFlow: null,
55
+ };
56
+ }
57
+ export function linkedStage(flow, stage, id, inputs) {
58
+ return {
59
+ id,
60
+ engine: "",
61
+ card: "",
62
+ family: "",
63
+ action: "",
64
+ description: "",
65
+ inputs,
66
+ expected: {},
67
+ outputs: {},
68
+ cardIo: {},
69
+ params: {},
70
+ skipWhen: null,
71
+ fromFlow: { flow, stage },
72
+ };
73
+ }
74
+
75
+ /** The craft loop (stroke 55, plan §2.3): ONE engine stage on
76
+ * 'craft' — act (a nested engine command) → capture (run-dir
77
+ * artifacts) → critique (the image-capable route, the capture
78
+ * attached) → decide (done | refine-with-next-command), bounded
79
+ * by max_iterations (default unlimited, hard cap 1000). The
80
+ * operator's card sketch verbatim: model dropdown, inputs
81
+ * (generic), prompt for the agent, optional max iterations. The
82
+ * stage params carry those four fields at DRIVE time (the agent
83
+ * composes them into the start doc; the registry row is the
84
+ * template + the agent leaf). */
85
+ /** The agent spawner (stroke 61, plan §5): ONE engine stage on
86
+ * 'agent' — a general tool-calling loop with the task as its brief
87
+ * (packages/engines/agent). The operator's card sketch verbatim:
88
+ * MCPs (blender, unity, custom), skills (dreamshot…), max turns
89
+ * (default unlimited), inputs (the plus-box list). The stage
90
+ * params carry those fields at DRIVE time; the registry row is
91
+ * the template + the agent leaf. */
92
+ import { BODY_TO_SOMAX, ANNY_HMR_COMMERCIAL, ANNY_PARAMS, AUDIO_NATIVE_TTS, FIT_SEAT, IMAGE_UPSCALE, MUSIC_NATIVE, CRAFT_LOOP } from "./flowsRegistryRows.js";
93
+ const REGISTRY = {
94
+ "craft-loop": CRAFT_LOOP,
95
+ "anny-hmr-commercial": ANNY_HMR_COMMERCIAL,
96
+ "body-to-somax": BODY_TO_SOMAX,
97
+ "anny-params": ANNY_PARAMS,
98
+ "audio-native-tts": AUDIO_NATIVE_TTS,
99
+ "fit-seat": FIT_SEAT,
100
+ "image-upscale": IMAGE_UPSCALE,
101
+ "music-native": MUSIC_NATIVE,
102
+ };
103
+
104
+ // asymmetry, closed): the REGISTRY literal above is the BOOT SEED,
105
+ // never the registry itself. Registrations ride a fiber-owned
106
+ // disposer (ctx.effect at the plugin seam) exactly like cards and
107
+ // families — a drop-in can add a flow to a running host; disposing
108
+ // the fiber removes it. No filesystem discovery: the door stays a
109
+ // drop-in naming a seam, never a sweep.
110
+ const LIVE_FLOWS = new Map(Object.entries(REGISTRY));
111
+ /** Register one flow into the live seat. LOUD: a duplicate id
112
+ * refuses (one owner per flow id — the same interlock as cards and
113
+ * model families). Returns the disposer; call it and the flow is
114
+ * gone from every read below. */
115
+ export function registerRegistryFlow(flow) {
116
+ if (LIVE_FLOWS.has(flow.id)) {
117
+ throw new Error(`flow '${flow.id}' registered twice — one owner per flow id (the interlock)`);
118
+ }
119
+ if (!Array.isArray(flow.stages) || flow.stages.length === 0) {
120
+ throw new Error(`flow '${String(flow.id)}' has no stages — a flow is a pipeline, an empty one is authoring noise`);
121
+ }
122
+ // THE SEAM'S TWO HALVES MUST AGREE (registration, not first use):
123
+ // a required initial the flow does not also VALIDATE gets no shape
124
+ // check, and the extractor — which walks initialValidators — never
125
+ // lifts it, so the value would reach the merge unlinked and die
126
+ // there as an unresolvable token. Refuse the row at its one
127
+ // registration instead of at the door, sixty seconds later.
128
+ for (const key of flow.requiredInitials ?? []) {
129
+ if (flow.initialValidators[key] === undefined) {
130
+ throw new Error(`flow '${String(flow.id)}' requires initial '${key}' but declares no validator for it — ` +
131
+ "a required initial needs its kind (the gate shapes it; the extractor lifts it)");
132
+ }
133
+ }
134
+ LIVE_FLOWS.set(flow.id, flow);
135
+ return () => {
136
+ // only OUR row dies — a later registration under the same id
137
+ // (impossible today, the interlock above) would not be reverted
138
+ if (LIVE_FLOWS.get(flow.id) === flow)
139
+ LIVE_FLOWS.delete(flow.id);
140
+ };
141
+ }
142
+ /** All registered flow names (the flow.scan_flow_ids order — sorted;
143
+ * the live seat, so a hot registration is visible at once). */
144
+ export function registryFlowNames() {
145
+ return [...LIVE_FLOWS.keys()].sort();
146
+ }
147
+ /** The raw (unexpanded) declaration, or undefined for unknown names. */
148
+ export function getRegistryFlow(name) {
149
+ return LIVE_FLOWS.get(name);
150
+ }
151
+ /** Resolve every fromFlow row against its source flow (Stage.from_flow
152
+ * verbatim: the source row's engine/card/description/expected/
153
+ * outputs/card_io/params ride; the link's id + inputs win). Throws
154
+ * LOUD on a dangling link (authoring bug — never a silent row). */
155
+ export function expandRegistryFlow(flow) {
156
+ const stages = flow.stages.map((st) => {
157
+ if (st.fromFlow === null) {
158
+ // THE RAW-WORKFLOW REFUSAL (the strictness audit's fix 8,
159
+ // corrected against the dispatch truth): a stage is composed
160
+ // by exactly one of three planes — the card plane (card),
161
+ // the family plane (family AND action), or an engine verb
162
+ // (any engine but the card-plane one — craft/agent stages
163
+ // ride the runs door directly). A card-plane-engine stage
164
+ // naming no card and no family action is the retired
165
+
166
+ // to the engine and die there ("carries no inline
167
+ // workflow"); it refuses LOUD here, named, never serves.
168
+ if (st.family !== "" && st.action === "") {
169
+ throw new Error("[flows_registry] flow " + flow.id + " stage " + st.id +
170
+ " declares family " + st.family + " with no action — the family plane needs both (refused at expansion)");
171
+ }
172
+ if (st.card === "" && st.family === "" && st.action === "") {
173
+ if (st.engine !== CARD_PLANE_ENGINE)
174
+ return st; // engine-verb stage — legal
175
+ throw new Error("[flows_registry] flow " + flow.id + " stage " + st.id +
176
+ " names neither card nor family+action on engine " + st.engine +
177
+ " — the raw-workflow authoring shape is retired (refused at expansion, never served)");
178
+ }
179
+ return st;
180
+ }
181
+ const link = st.fromFlow;
182
+
183
+
184
+ // flow registered live could never be a from_flow TARGET — the
185
+ // seat was write-only for expansion, and no wall could see it
186
+ // (the seed flow the walls clone has no links). A drop-in that
187
+ // registers a flow another flow links to is exactly the
188
+ // composition the door exists for.
189
+ const src = LIVE_FLOWS.get(link.flow);
190
+ if (src === undefined) {
191
+ throw new Error("[flows_registry] flow " + flow.id + " stage " + st.id +
192
+ " links unknown flow " + link.flow);
193
+ }
194
+ const base = src.stages.find((s) => s.id === link.stage);
195
+ if (base === undefined) {
196
+ throw new Error("[flows_registry] flow " + flow.id + " stage " + st.id +
197
+ " links unknown stage " + link.flow + "/" +
198
+ link.stage);
199
+ }
200
+ if (base.fromFlow !== null) {
201
+ throw new Error("[flows_registry] flow " + flow.id + " stage " + st.id +
202
+ " links a linked stage (single-hop only): " +
203
+ link.flow + "/" + link.stage);
204
+ }
205
+ return { ...base, id: st.id, inputs: st.inputs };
206
+ });
207
+ return { ...flow, stages };
208
+ }
209
+
210
+
211
+
212
+
213
+ export function inlineStagesNameCards(doc) {
214
+ const rows = doc["stages"];
215
+ if (!Array.isArray(rows))
216
+ return false;
217
+ return rows.some((r) => typeof r === "object" && r !== null &&
218
+ typeof r["card"] === "string" &&
219
+ r["card"] !== "");
220
+ }
221
+ /** The registry flow as a flow_from_body-shaped inline doc (the
222
+ * validate compile + start shim both ride the EXISTING inline
223
+ * pipelines — no second validator). Card rows ride card/card_io;
224
+ * skip_when rides verbatim. */
225
+ export function registryFlowToInline(flow) {
226
+ return {
227
+ id: flow.id,
228
+ description: flow.description,
229
+ stages: flow.stages.map((st) => {
230
+ const inputs = {};
231
+ for (const [name, edge] of Object.entries(st.inputs)) {
232
+ if ("initial" in edge)
233
+ inputs[name] = { initial: edge.initial };
234
+ else {
235
+ inputs[name] = {
236
+ stage: edge.stage,
237
+ output: edge.output,
238
+ };
239
+ }
240
+ }
241
+ const row = {
242
+ id: st.id,
243
+ engine: st.engine,
244
+ description: st.description,
245
+ inputs,
246
+ outputs: { ...st.outputs },
247
+ expected: { ...st.expected },
248
+ params: st.params,
249
+ };
250
+ if (st.card !== "")
251
+ row["card"] = st.card;
252
+ if (Object.keys(st.cardIo).length > 0)
253
+ row["card_io"] = { ...st.cardIo };
254
+ if (st.skipWhen !== null) {
255
+ row["skip_when"] = {
256
+ initial: st.skipWhen.initial,
257
+ when: st.skipWhen.when,
258
+ };
259
+ }
260
+ return row;
261
+ }),
262
+ };
263
+ }
264
+ /** Check one photo/glb initial value. Null = passes. */
265
+ function checkFileInitial(key, kind, value, roots) {
266
+ let ref;
267
+ if (typeof value === "string")
268
+ ref = value;
269
+ else if (typeof value === "object" && value !== null && !Array.isArray(value) &&
270
+ typeof value["path"] === "string") {
271
+ ref = value["path"];
272
+ }
273
+ else {
274
+ return ("initial " + JSON.stringify(key) + " must be a file path string or " +
275
+ "{path: ...} (got " + (typeof value) + ")");
276
+ }
277
+ const raw = ref.trim();
278
+ if (raw.startsWith("data:") || raw.startsWith("blob:")) {
279
+ return ("initial " + JSON.stringify(key) +
280
+ " is browser-local (nothing to stage) — upload the file first: " +
281
+ "POST /v1/uploads, then pass its staged path");
282
+ }
283
+ // (split never yields [] — [0] is always a string here)
284
+ const dot = raw.split(/[?#]/)[0].lastIndexOf(".");
285
+ const ext = dot >= 0
286
+ ? raw.split(/[?#]/)[0].slice(dot + 1).toLowerCase()
287
+ : "";
288
+ // The vocab is TYPED DATA now (mediaKinds.ts, REBUILD-7) — no
289
+ // repo-anchored kindsPath read survives the re-home.
290
+ const kinds = mediaVocab();
291
+ const allowed = kind === "photo" ? kinds.image : kinds.model;
292
+ if (!allowed.includes(ext)) {
293
+ return ("initial " + JSON.stringify(key) + " is not a stageable " +
294
+ (kind === "photo" ? "image" : "mesh") + " (got extension " +
295
+ JSON.stringify(ext) + ")");
296
+ }
297
+ if (raw.includes("..")) {
298
+ return "initial " + JSON.stringify(key) + " refuses traversal";
299
+ }
300
+ const cands = [];
301
+
302
+ // ever): the live /melite-media/runs/ and the legacy
303
+ // /v1/assets/runs/ that stored benches, archives and run rows
304
+ // still name. The media route serves both, so a chained input
305
+ // resolves whichever spelling it carries.
306
+ // the contract's two names (benchStage.ts) — the same pair the
307
+ // media route mounts and the bench heals
308
+ const ASSET_RUNS_PREFIX = LEGACY_RUN_MEDIA_PREFIX + "/";
309
+ const MEDIA_RUNS_PREFIX = RUN_MEDIA_PREFIX + "/";
310
+ const runPrefix = raw.startsWith(MEDIA_RUNS_PREFIX)
311
+ ? MEDIA_RUNS_PREFIX
312
+ : raw.startsWith(ASSET_RUNS_PREFIX) ? ASSET_RUNS_PREFIX : "";
313
+ if (runPrefix !== "") {
314
+ const rel = raw.slice(runPrefix.length);
315
+ if (rel === "" || rel.endsWith("/") || !rel.includes("/")) {
316
+ return ("initial " + JSON.stringify(key) +
317
+ " is a malformed artifact URL (want " + RUN_MEDIA_PREFIX + "/<run_id>/<file>)");
318
+ }
319
+ for (const root of [
320
+ join(roots.stateRoot, "output"),
321
+ join(roots.stateRoot, "test-output"),
322
+ join(roots.repoRoot, "data", "runs", "output"),
323
+ join(roots.repoRoot, "data", "runs", "test-output"),
324
+ ]) {
325
+ cands.push(join(root, rel));
326
+ }
327
+ }
328
+ else if (raw.startsWith("/")) {
329
+ cands.push(raw);
330
+ }
331
+ else {
332
+ cands.push(resolve(roots.repoRoot, raw));
333
+ cands.push(resolve(process.cwd(), raw));
334
+ }
335
+ for (const cand of cands) {
336
+ if (isFile(cand))
337
+ return null;
338
+ }
339
+ return "initial " + JSON.stringify(key) + " is not on disk (" + raw + ")";
340
+ }
341
+ /** The compile-time gate over a registry flow's initial_validators:
342
+ * the first refusal text, or null when every PRESENT initial
343
+ * passes (absent initials ride — the $channel/branch arms own
344
+ * them). Runs BEFORE any run registers, on both doors. */
345
+ export function registryInitialsError(flow, body, roots) {
346
+ for (const [key, kind] of Object.entries(flow.initialValidators)) {
347
+ const value = body[key];
348
+ if (value === undefined || value === null)
349
+ continue;
350
+ if (kind === "bake_params") {
351
+ const s = typeof value === "string"
352
+ ? value
353
+ : JSON.stringify(value);
354
+ if (s === undefined) {
355
+ return ("initial " + JSON.stringify(key) +
356
+ " must be a params_json string or object (got " +
357
+ (typeof value) + ")");
358
+ }
359
+ const err = validateBakeParams(s);
360
+ if (err !== null) {
361
+ return "initial " + JSON.stringify(key) + " refuses the preset dialect: " + err;
362
+ }
363
+ continue;
364
+ }
365
+ // A TEXT initial is a bare name, not a file: a bone, a rig slot.
366
+ // The engine's own gate is on emptiness; the door's is on shape,
367
+ // so a path can never arrive where a name belongs.
368
+ if (kind === "text") {
369
+ const text = typeof value === "string" ? value : "";
370
+ if (text.trim() === "") {
371
+ return "initial " + JSON.stringify(key) + " must be a non-empty name";
372
+ }
373
+ if (text.includes("..") || text.includes("/") || text.includes("\\")) {
374
+ return "initial " + JSON.stringify(key) +
375
+ " is a bare name (no path separators, no traversal)";
376
+ }
377
+ continue;
378
+ }
379
+ const err = checkFileInitial(key, kind, value, roots);
380
+ if (err !== null)
381
+ return err;
382
+ }
383
+ // A REQUIRED INITIAL refuses here, before a run registers (an
384
+ // optional one rides absent — the $channel/branch arms own it), and
385
+ // AFTER the present-value checks so a request carrying a bad value
386
+ // hears about THAT value first. The fit verb's bone is the case: the
387
+ // vendor's row gate refuses an empty one, so a request that omits it
388
+ // must learn that at the door, not sixty seconds into a render.
389
+ for (const key of flow.requiredInitials ?? []) {
390
+ const value = body[key];
391
+ if (value === undefined || value === null || value === "") {
392
+ return "initial " + JSON.stringify(key) +
393
+ " is REQUIRED by the " + JSON.stringify(flow.id) + " flow — " +
394
+ "this verb cannot run without it (name it in the request; the " +
395
+ "door refuses here rather than the engine refusing later)";
396
+ }
397
+ }
398
+ return null;
399
+ }
400
+ /** The initial VALUE one gate-blessed body entry carries, in the
401
+ * string form the engine merge links a $spell against: file
402
+ * initials give their path ({path: …} unwraps — the two spellings
403
+ * the gate blesses), bake_params gives its params_json string
404
+ * (objects stringify — the dialect the belt validates). Null
405
+ * refuses a shape the gate would have refused, so a mangled
406
+ * durable body fails loud at the door instead of shipping an
407
+ * "[object Object]" literal to the engine.
408
+ * @param key the initial's declared name, for the refusal voice
409
+ * @param kind the declared validator kind
410
+ * @param value the raw body entry
411
+ * @returns the normalized string, or null when the shape is neither */
412
+ export function normalizedInitialValue(key, kind, value) {
413
+ // A TEXT initial is a BARE NAME: nothing unwraps it and nothing
414
+ // path-shaped reaches it, so the {path: …} arm below never runs
415
+
416
+ // name, reachable only because every call site runs the gate
417
+ // first — this arm makes the extractor honest on its own.)
418
+ if (kind === "text")
419
+ return typeof value === "string" ? value : null;
420
+ if (typeof value === "string")
421
+ return value;
422
+ if (kind === "bake_params") {
423
+ // JSON.stringify(undefined) is undefined — the null-ish check
424
+ // in the caller skips absent entries before this arm.
425
+ const s = JSON.stringify(value);
426
+ return s === undefined ? null : s;
427
+ }
428
+ if (typeof value === "object" && value !== null && !Array.isArray(value) &&
429
+ typeof value["path"] === "string") {
430
+ return value["path"];
431
+ }
432
+ return null;
433
+ }
434
+ /** The request initials a body carries for a flow's declared
435
+ * validators, normalized per {@link normalizedInitialValue}:
436
+ * declared keys, present values only; absent stays absent (the
437
+ * $channel/branch arms own those). First refusal text, or null
438
+ * when every present value normalizes. Both start doors (the
439
+ * flow arm and the flow_inline replay arm, which recovers the
440
+ * declaration from the inline doc's registry id) call this —
441
+ * the replayed durable body re-extracts the same values the
442
+ * original start extracted, so a queued run that reboots mid-
443
+ * queue keeps its $spells linkable at the engine merge.
444
+ * @param flow the declaration whose initialValidators own the keys
445
+ * @param body the request body
446
+ * @returns the normalized initials record, or a refusal string */
447
+ export function extractRequestInitials(flow, body) {
448
+ const initials = {};
449
+ for (const [key, kind] of Object.entries(flow.initialValidators)) {
450
+ const value = body[key];
451
+ if (value === undefined || value === null)
452
+ continue;
453
+ const normalized = normalizedInitialValue(key, kind, value);
454
+ if (normalized === null) {
455
+ return {
456
+ refusal: "initial " + JSON.stringify(key) +
457
+ (kind === "bake_params"
458
+ ? " must be a params_json string or object (got " +
459
+ (typeof value) + ")"
460
+ : kind === "text"
461
+ ? " must be a bare name (got " + (typeof value) + ")"
462
+ : " must be a file path string or {path: ...} (got " +
463
+ (typeof value) + ")"),
464
+ };
465
+ }
466
+ initials[key] = normalized;
467
+ }
468
+ return { initials };
469
+ }
470
+ // ── the skill-body render (REBUILD-16; the tail beyond the
471
+ // REBUILD-13 cut) ──
472
+ function edgeText(edge, flow) {
473
+ // A REQUIRED INITIAL SAYS SO (the door refuses a request without
474
+ // it; the served body is where a caller learns that before they
475
+ // try). The flow's own requiredInitials list is the one truth.
476
+ if ("initial" in edge) {
477
+ return "initial '" + edge.initial + "'" +
478
+ ((flow.requiredInitials ?? []).includes(edge.initial) ? " (REQUIRED)" : "");
479
+ }
480
+ const src = edge.stage + "." + edge.output;
481
+ let kind = "";
482
+ for (const st of flow.stages) {
483
+ const base = st.fromFlow !== null ? resolveLink(st) : st;
484
+ if (base.id === edge.stage) {
485
+ kind = base.outputs[edge.output] ?? base.cardIo[edge.output] ?? "";
486
+ }
487
+ }
488
+ return "stage " + src + (kind !== "" ? " (" + kind + ")" : "");
489
+ }
490
+
491
+
492
+
493
+
494
+
495
+
496
+
497
+ function resolveLink(st) {
498
+
499
+
500
+
501
+
502
+ if (st.fromFlow === null) {
503
+ throw new Error("resolveLink: stage '" + st.id + "' carries no fromFlow link (caller guard missing)");
504
+ }
505
+ const link = st.fromFlow;
506
+ // the LIVE SEAT, same law as expandRegistryFlow above
507
+ const src = LIVE_FLOWS.get(link.flow);
508
+ if (src === undefined) {
509
+ throw new Error("registry: stage '" + st.id + "' links from unknown flow '" + link.flow +
510
+ "' (known flows: " + registryFlowNames().join(", ") + ")");
511
+ }
512
+ const base = src.stages.find((s) => s.id === link.stage);
513
+ if (base === undefined) {
514
+ throw new Error("registry: stage '" + st.id + "' links from unknown stage '" + link.flow + "/" + link.stage +
515
+ "' (known stages: " + src.stages.map((s) => s.id).sort().join(", ") + ")");
516
+ }
517
+ return base;
518
+ }
519
+ /** Render one registry flow as its skill-body text. */
520
+ export function registrySkillBody(flow) {
521
+ const lines = ["# flow " + flow.id, "", flow.description, "", "## stages"];
522
+ for (const st of flow.stages) {
523
+ const base = st.fromFlow !== null ? resolveLink(st) : st;
524
+ let head = "- " + st.id + " (";
525
+ head += st.fromFlow !== null
526
+ ? "from " + st.fromFlow.flow + "/" + st.fromFlow.stage
527
+ : base.engine + (base.card !== "" ? ", card " + base.card : "");
528
+ head += ")";
529
+ if (base.description !== "")
530
+ head += ": " + base.description;
531
+ lines.push(head);
532
+ for (const [name, edge] of Object.entries(st.inputs)) {
533
+ lines.push(" input " + name + ": " + edgeText(edge, flow));
534
+ }
535
+ for (const [name, kind] of Object.entries(base.outputs)) {
536
+ lines.push(" output " + name + ": " + kind);
537
+ }
538
+ for (const [name, kind] of Object.entries(base.cardIo)) {
539
+ lines.push(" card_io " + name + ": " + kind);
540
+ }
541
+ if (st.skipWhen !== null) {
542
+ lines.push(" skip when initial '" + st.skipWhen.initial + "' is " + st.skipWhen.when);
543
+ }
544
+ }
545
+ return lines.join("\n") + "\n";
546
+ }
547
+ //# sourceMappingURL=flowsData.js.map
@@ -0,0 +1,48 @@
1
+ import type { RegistryFlow } from "./flowsData.js";
2
+ /** The families seat's read shape (structural — the models
3
+ * service's allDecls() rows, action arrays intact). */
4
+ export type FamilyDeclRow = {
5
+ readonly id: string;
6
+ };
7
+ export type FamilyModelsSeat = {
8
+ allDecls(): readonly FamilyDeclRow[];
9
+ };
10
+ /** How the family seat answered, which is three different facts:
11
+ * `seated` (the table holds families), `bare` (the owner is mounted
12
+ * and the table holds none — a lane that mounted the catalog
13
+ * provider without the family plugins), and `absent` (no seat at
14
+ * all: an unmounted context whose singleton never booted). The
15
+ * refusal must name which one it is — a family that is merely
16
+ * unregistered is a different defect from a lane with no table.
17
+ * A flow with NO family stage never reads this. */
18
+ export type FamilySeatState = "seated" | "bare" | "absent";
19
+ /** The live family declarations, and how the seat answered. A flow
20
+ * WITH a family stage refuses LOUD on an unanswering seat inside
21
+ * composeOne, in the seat's own voice.
22
+ * @param modelsSeat the context's models service when mounted
23
+ * (the injectable read); the booted singleton otherwise
24
+ * @returns the declarations (empty on an unanswering seat) and the
25
+ * state that produced them */
26
+ export declare function liveFamilySeat(modelsSeat?: FamilyModelsSeat | null): {
27
+ readonly decls: readonly FamilyDeclRow[];
28
+ readonly state: FamilySeatState;
29
+ };
30
+ /** The live family declarations, for the callers that only need the
31
+ * rows. A refusal composed from these alone cannot tell an absent
32
+ * seat from an unregistered family — use {@link liveFamilySeat}.
33
+ * @param modelsSeat the context's models service when mounted
34
+ * @returns the family declarations, or [] when no seat answers */
35
+ export declare function liveFamilyDecls(modelsSeat?: FamilyModelsSeat | null): readonly FamilyDeclRow[];
36
+ /** Compose every family-action stage of an expanded flow into its
37
+ * workflow envelope. Flows with no family stage pass through
38
+ * byte-identical (zero lookups, zero overhead).
39
+ * @param flow the EXPANDED registry flow (fromFlow links resolved)
40
+ * @param decls the families seat's declarations (allDecls())
41
+ * @param seatState how the seat answered, so a refusal names the
42
+ * condition it found (see {@link liveFamilySeat})
43
+ * @returns the flow with every family stage composed
44
+ * @throws when the seat cannot answer, a family is unregistered, an
45
+ * action undeclared, a param unadmitted, or a hand-written output
46
+ * contradicts the action's declaration */
47
+ export declare function composeFamilyStages(flow: RegistryFlow, decls: readonly FamilyDeclRow[], seatState?: FamilySeatState): RegistryFlow;
48
+ //# sourceMappingURL=flowsFamilyCompose.d.ts.map