@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,99 @@
1
+ // filmMemoryWarn.ts — F-6(b): the film lane warns at admission.
2
+ //
3
+ // The OOM record (attempt002/003): a film admitted under memory
4
+ // pressure burns the render — kernel OOM on host contention (43G +
5
+ // swap, load-264) and VRAM at 23.7/24.5 GiB (96.8%), while the
6
+ // retry that lived ran with 8.7G VRAM free. The TOOL half of the
7
+ // pre-flight (F-6(a) briefs the agent; this warns the run): at film
8
+ // admission the door reads the engine's live VRAM and, under the
9
+ // pressure line, stamps a warning on the run — the warn rides
10
+ // run_status, never a refusal. Admission NEVER blocks on telemetry:
11
+ // an unreachable engine skips the warn (the run is unaffected; the
12
+ // §21 engine-loss arm owns dead engines).
13
+ //
14
+ // The line (20% of device VRAM) interpolates between the two
15
+ // measured points on this box (failure 3%, success 35%) —
16
+ // documented here, not derived: a byte predictor would need
17
+ // measured per-family weight minima that exist nowhere on record,
18
+ // and LAW 2 forbids fabricating them. The warn names the admitted
19
+ // LOAD (windows/frames/geometry — exact, off the doc) against live
20
+ // FREE, so the pressure comparison is real on both sides.
21
+ import { deadline } from "@deepseek-ai/dsh-timeout";
22
+ /** Read the film load off a card body (h3-timeline calls shape).
23
+ * Null when the body carries no computable spans — the warn never
24
+ * refuses on shape (validate owns that); nothing computable means
25
+ * nothing to warn about. */
26
+ export function filmLoadOf(body) {
27
+ const calls = body['calls'];
28
+ if (!Array.isArray(calls) || calls.length === 0)
29
+ return null;
30
+ let frames = 0;
31
+ let counted = 0;
32
+ for (const c of calls) {
33
+ if (typeof c !== 'object' || c === null)
34
+ continue;
35
+ const rec = c;
36
+ const s = rec['start_frame'];
37
+ const e = rec['end_frame'];
38
+ if (typeof s !== 'number' || typeof e !== 'number' ||
39
+ !Number.isInteger(s) || !Number.isInteger(e) || e <= s)
40
+ continue;
41
+ frames += e - s;
42
+ counted++;
43
+ }
44
+ if (counted === 0)
45
+ return null;
46
+ const w = body['width'];
47
+ const h = body['height'];
48
+ return {
49
+ windows: calls.length,
50
+ frames,
51
+ width: typeof w === 'number' && w > 0 ? w : 0,
52
+ height: typeof h === 'number' && h > 0 ? h : 0,
53
+ };
54
+ }
55
+ const GIB = 1024 ** 3;
56
+ const gib = (b) => (b / GIB).toFixed(1);
57
+ /** The pressure decision — null mem (telemetry down) or healthy
58
+ * pressure returns null: no warn. Only the pressured side speaks. */
59
+ export function filmMemoryWarn(load, mem) {
60
+ if (mem === null)
61
+ return null;
62
+ if (!(mem.vramTotal > 0) || !(mem.vramFree >= 0))
63
+ return null;
64
+ if (mem.vramFree >= mem.vramTotal / 5)
65
+ return null;
66
+ const pct = ((mem.vramFree / mem.vramTotal) * 100).toFixed(0);
67
+ const geo = load.width > 0 && load.height > 0 ? `, ${load.width}x${load.height}` : ', unstated geometry';
68
+ return (`film admission: engine VRAM pressured — ${gib(mem.vramFree)} of ${gib(mem.vramTotal)} GiB free ` +
69
+ `(${pct}%) below the 20% line for a ${load.windows}-window film (${load.frames} frames${geo}); ` +
70
+ `a ComfyUI restart before the big film is sanctioned — an identical params/seed rerun rides the node cache.`);
71
+ }
72
+ /** Live VRAM off the engine (primary device serves the film).
73
+ * Null on ANY failure (unreachable, unparseable, no devices) —
74
+ * the caller skips the warn, never fails admission. The fuse is
75
+ * dsh-timeout's deadline (no timer seat on this path — the manage
76
+ * plane's seat does not reach the start door). */
77
+ export async function fetchEngineMem(baseUrl, fetchFn = globalThis.fetch, timeoutMs = 5000) {
78
+ const dl = deadline(undefined, timeoutMs, "ENGINE_MEM");
79
+ try {
80
+ const r = await fetchFn(baseUrl.replace(/\/+$/, '') + '/system_stats', { signal: dl.signal });
81
+ const stats = (await r.json());
82
+ const devices = stats['devices'];
83
+ if (!Array.isArray(devices) || devices.length === 0)
84
+ return null;
85
+ const d = devices[0];
86
+ const free = d['vram_free'];
87
+ const total = d['vram_total'];
88
+ if (typeof free !== 'number' || typeof total !== 'number')
89
+ return null;
90
+ return { vramFree: free, vramTotal: total };
91
+ }
92
+ catch {
93
+ return null;
94
+ }
95
+ finally {
96
+ dl[Symbol.dispose]();
97
+ }
98
+ }
99
+ //# sourceMappingURL=filmMemoryWarn.js.map
@@ -0,0 +1,234 @@
1
+ /** One initial edge: {"initial": key} (the operator-supplied wire). */
2
+ export interface RegistryInitialEdge {
3
+ readonly initial: string;
4
+ }
5
+ /** One stage edge: {"stage": id, "output": name} (an earlier stage). */
6
+ export interface RegistryStageEdge {
7
+ readonly stage: string;
8
+ readonly output: string;
9
+ }
10
+ export type RegistryEdge = RegistryInitialEdge | RegistryStageEdge;
11
+ /** A from_flow row (Stage.from_flow — the live reference): the
12
+ * stage is COPIED from the named flow's stage at expansion time
13
+ * (id overridden, inputs overridden), so the source stays the
14
+ * single truth — never a snapshot. */
15
+ export interface RegistryFromFlow {
16
+ readonly flow: string;
17
+ readonly stage: string;
18
+ }
19
+ /** One authoring-stage row (the Stage(...) fields, JSON-shaped).
20
+ * A stage is composed by exactly one of three planes: a card
21
+ * (card ≠ "" — the card plane's dispatch), a family action
22
+ * (family + action ≠ "" — the family's DECL composes the nodes at
23
+ * expansion; flowsFamilyCompose owns that interpreter), or an
24
+ * engine verb (engine ≠ the card-plane engine — craft/agent
25
+ * stages the runs door drives directly). A card-plane-engine
26
+ * stage naming neither card nor family action is the retired
27
+ * raw-workflow shape: expandRegistryFlow refuses it, named. */
28
+ export interface RegistryStage {
29
+ readonly id: string;
30
+ readonly engine: string;
31
+ readonly card: string;
32
+ readonly family: string;
33
+ readonly action: string;
34
+ readonly description: string;
35
+ readonly inputs: Record<string, RegistryEdge>;
36
+ readonly expected: Record<string, string>;
37
+ readonly outputs: Record<string, string>;
38
+ readonly cardIo: Record<string, string>;
39
+ readonly params: Record<string, unknown>;
40
+ readonly skipWhen: {
41
+ readonly initial: string;
42
+ readonly when: string;
43
+ } | null;
44
+ readonly fromFlow: RegistryFromFlow | null;
45
+ }
46
+ /** The compile-time initial kinds (flow.initial_validators). */
47
+ export type RegistryInitialKind = "photo" | "glb" | "bake_params" | "text";
48
+ /** One headless-tool overlay (FlowToolOverlay: tool param -> the
49
+ * stage doc path it stamps, with the value choices map). */
50
+ export interface RegistryToolOverlay {
51
+ readonly param: string;
52
+ readonly stage: string;
53
+ readonly path: readonly string[];
54
+ readonly choices: Record<string, string> | null;
55
+ }
56
+ /** One headless-tool property (FlowToolProperty). */
57
+ export interface RegistryToolProperty {
58
+ readonly ptype: string;
59
+ readonly description: string;
60
+ readonly default: unknown;
61
+ readonly hasDefault: boolean;
62
+ readonly minimum: number | null;
63
+ readonly maximum: number | null;
64
+ readonly enum: readonly string[] | null;
65
+ }
66
+ /** The headless surface (FlowTool: name + version + schema +
67
+ * required + overlays). Absent (null) on flows with no tool=. */
68
+ export interface RegistryTool {
69
+ readonly name: string;
70
+ readonly version: number;
71
+ readonly description: string;
72
+ readonly properties: Record<string, RegistryToolProperty>;
73
+ readonly required: readonly string[];
74
+ readonly overlays: readonly RegistryToolOverlay[];
75
+ }
76
+ /** One named flow (the Flow(...) declaration, JSON-shaped). */
77
+ export interface RegistryFlow {
78
+ readonly id: string;
79
+ readonly description: string;
80
+ readonly stages: readonly RegistryStage[];
81
+ readonly initialValidators: Record<string, RegistryInitialKind>;
82
+ /** Initial names this flow cannot run without. An OPTIONAL initial
83
+ * rides absent (the $channel/branch arms own it); a REQUIRED one
84
+ * refuses at the door, before a run registers, so a verb whose
85
+ * graph needs the value (the fit verb's bone — the vendor's row
86
+ * gate refuses an empty one) never reaches the engine to fail
87
+ * there. */
88
+ readonly requiredInitials?: readonly string[];
89
+ readonly tool: RegistryTool | null;
90
+ readonly skillRefs: readonly string[];
91
+ }
92
+ export declare function initial(key: string): RegistryInitialEdge;
93
+ export declare function fromStage(stage: string, output: string): RegistryStageEdge;
94
+ export declare function plainStage(row: {
95
+ readonly id: string;
96
+ readonly engine: string;
97
+ readonly card?: string;
98
+ readonly family?: string;
99
+ readonly action?: string;
100
+ readonly description: string;
101
+ readonly inputs: Record<string, RegistryEdge>;
102
+ readonly expected?: Record<string, string>;
103
+ readonly outputs?: Record<string, string>;
104
+ readonly cardIo?: Record<string, string>;
105
+ readonly params: Record<string, unknown>;
106
+ readonly skipWhen?: {
107
+ readonly initial: string;
108
+ readonly when: string;
109
+ } | null;
110
+ }): RegistryStage;
111
+ export declare function linkedStage(flow: string, stage: string, id: string, inputs: Record<string, RegistryEdge>): RegistryStage;
112
+ import { Service } from "@deepseek-ai/cordis";
113
+ import type { Context } from "@deepseek-ai/cordis";
114
+ /** The read face pure registry code needs — the seat injected into
115
+ * the pure plane (link resolution + the known-flows voice). */
116
+ export interface FlowsSeat {
117
+ /** The raw (unexpanded) declaration, or undefined for unknown names. */
118
+ get(name: string): RegistryFlow | undefined;
119
+ /** All registered flow names, sorted (the flow.scan_flow_ids order
120
+ * — the live seat, so a hot registration is visible at once). */
121
+ names(): string[];
122
+ }
123
+ /** A pure read-only seat over the boot seed (REGISTRY verbatim, no
124
+ * registration surface): the door for callers with no host fiber —
125
+ * pure rigs and the walls. Service-owning callers read the live
126
+ * seat instead (ctx.get("meliteFlows")).
127
+ * @returns the seeded FlowsSeat. */
128
+ export declare function seedFlowsSeat(): FlowsSeat;
129
+ /** The live flow registry seat (J4 cure: the table is instance
130
+ * state, never a module global). */
131
+ export declare class FlowsSeatService extends Service implements FlowsSeat {
132
+ static readonly inject: readonly string[];
133
+ private flows;
134
+ constructor(ctx: Context);
135
+ /** The raw (unexpanded) declaration, or undefined for unknown
136
+ * names. */
137
+ get(name: string): RegistryFlow | undefined;
138
+ /** All registered flow names, sorted. */
139
+ names(): string[];
140
+ /** Register one flow into the live seat. LOUD: a duplicate id
141
+ * refuses (one owner per flow id — the same interlock as cards
142
+ * and model families); the stage and validator interlocks ride
143
+ * verbatim. Returns the disposer; call it (or dispose the
144
+ * ctx.effect that owns it) and the flow is gone from every
145
+ * read.
146
+ * @param flow - the declaration to seat.
147
+ * @returns the disposer removing exactly this row. */
148
+ register(flow: RegistryFlow): () => void;
149
+ }
150
+ /** Resolve every fromFlow row against its source flow (Stage.from_flow
151
+ * verbatim: the source row's engine/card/description/expected/
152
+ * outputs/card_io/params ride; the link's id + inputs win). Throws
153
+ * LOUD on a dangling link (authoring bug — never a silent row). */
154
+
155
+
156
+
157
+
158
+
159
+
160
+
161
+
162
+
163
+
164
+
165
+
166
+
167
+
168
+ export declare function refuseRawWorkflowShape(flowId: string, st: RegistryStage): void;
169
+ export declare function expandRegistryFlow(flow: RegistryFlow, seat: FlowsSeat): RegistryFlow;
170
+
171
+
172
+
173
+
174
+ export declare function inlineStagesNameCards(doc: Record<string, unknown>): boolean;
175
+ /** The registry flow as a flow_from_body-shaped inline doc (the
176
+ * validate compile + start shim both ride the EXISTING inline
177
+ * pipelines — no second validator). Card rows ride card/card_io;
178
+ * skip_when rides verbatim. */
179
+ export declare function registryFlowToInline(flow: RegistryFlow): Record<string, unknown>;
180
+ export interface InitialsRoots {
181
+ readonly repoRoot: string;
182
+ readonly stateRoot: string;
183
+ }
184
+ /** The on-disk candidate paths one gate-blessed file initial may
185
+ * live at — the press gate's SAME trees, extracted so the
186
+ * claim-time re-probe (runsRegistry pump) judges by the identical
187
+ * set instead of re-spelling it. Contract: `raw` already passed
188
+ * checkFileInitial's shape gates (data:/blob:, extension vocab,
189
+ * traversal, malformed run-prefix URL) — this builds candidates
190
+ * only; a raw outside those gates gets a list that misses, which
191
+ * is the honest answer for a value the gate would have refused.
192
+ * @param raw the trimmed path reference ({path: …} unwrapped)
193
+ * @param roots the same roots manifest the press gate rode
194
+ * @returns the candidate paths, in the press gate's order */
195
+ export declare function initialFileCandidates(raw: string, roots: InitialsRoots): string[];
196
+ /** The compile-time gate over a registry flow's initial_validators:
197
+ * the first refusal text, or null when every PRESENT initial
198
+ * passes (absent initials ride — the $channel/branch arms own
199
+ * them). Runs BEFORE any run registers, on both doors. */
200
+ export declare function registryInitialsError(flow: RegistryFlow, body: Record<string, unknown>, roots: InitialsRoots): string | null;
201
+ /** The initial VALUE one gate-blessed body entry carries, in the
202
+ * string form the engine merge links a $spell against: file
203
+ * initials give their path ({path: …} unwraps — the two spellings
204
+ * the gate blesses), bake_params gives its params_json string
205
+ * (objects stringify — the dialect the belt validates). Null
206
+ * refuses a shape the gate would have refused, so a mangled
207
+ * durable body fails loud at the door instead of shipping an
208
+ * "[object Object]" literal to the engine.
209
+ * @param key the initial's declared name, for the refusal voice
210
+ * @param kind the declared validator kind
211
+ * @param value the raw body entry
212
+ * @returns the normalized string, or null when the shape is neither */
213
+ export declare function normalizedInitialValue(key: string, kind: RegistryInitialKind, value: unknown): string | null;
214
+ /** The request initials a body carries for a flow's declared
215
+ * validators, normalized per {@link normalizedInitialValue}:
216
+ * declared keys, present values only; absent stays absent (the
217
+ * $channel/branch arms own those). First refusal text, or null
218
+ * when every present value normalizes. Both start doors (the
219
+ * flow arm and the flow_inline replay arm, which recovers the
220
+ * declaration from the inline doc's registry id) call this —
221
+ * the replayed durable body re-extracts the same values the
222
+ * original start extracted, so a queued run that reboots mid-
223
+ * queue keeps its $spells linkable at the engine merge.
224
+ * @param flow the declaration whose initialValidators own the keys
225
+ * @param body the request body
226
+ * @returns the normalized initials record, or a refusal string */
227
+ export declare function extractRequestInitials(flow: RegistryFlow, body: Record<string, unknown>): {
228
+ initials: Record<string, string>;
229
+ } | {
230
+ refusal: string;
231
+ };
232
+ /** Render one registry flow as its skill-body text. */
233
+ export declare function registrySkillBody(flow: RegistryFlow, seat: FlowsSeat): string;
234
+ //# sourceMappingURL=flowsData.d.ts.map