@melite/estate-queue 0.1.5-pre-alpha → 0.2.2-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 (82) hide show
  1. package/LICENSE +561 -457
  2. package/README.md +0 -5
  3. package/lib/cardsArmError.d.ts +52 -3
  4. package/lib/cardsArmError.js +7 -1
  5. package/lib/cardsCompose.d.ts +31 -0
  6. package/lib/cardsCompose.js +98 -7
  7. package/lib/cardsFacts.d.ts +16 -0
  8. package/lib/cardsFacts.js +25 -1
  9. package/lib/cardsLanes.d.ts +51 -3
  10. package/lib/cardsLanes.js +337 -13
  11. package/lib/cardsLanesCopy.d.ts +21 -0
  12. package/lib/cardsLanesCopy.js +22 -0
  13. package/lib/cardsRegistry.d.ts +105 -5
  14. package/lib/cardsRegistry.js +826 -46
  15. package/lib/cardsVariant.d.ts +12 -7
  16. package/lib/cardsVariant.js +196 -58
  17. package/lib/discloseRegistry.d.ts +41 -6
  18. package/lib/discloseRegistry.js +155 -17
  19. package/lib/filmLead.js +5 -3
  20. package/lib/flowsData.d.ts +77 -21
  21. package/lib/flowsData.js +159 -21
  22. package/lib/flowsFamilyCompose.js +12 -1
  23. package/lib/flowsRegistryRows.d.ts +0 -3
  24. package/lib/flowsRegistryRows.js +166 -222
  25. package/lib/index.d.ts +1 -1
  26. package/lib/index.js +6 -4
  27. package/lib/loadPlane.d.ts +46 -4
  28. package/lib/loadPlane.js +116 -7
  29. package/lib/loadRegistry.js +9 -2
  30. package/lib/manageOps.js +2 -1
  31. package/lib/managePlane.d.ts +16 -1
  32. package/lib/managePlane.js +955 -65
  33. package/lib/managePreflight.d.ts +26 -0
  34. package/lib/managePreflight.js +211 -0
  35. package/lib/manageProbe.d.ts +52 -0
  36. package/lib/manageProbe.js +171 -1
  37. package/lib/queueCore.d.ts +14 -1
  38. package/lib/queueCore.js +13 -0
  39. package/lib/queueLock.js +19 -10
  40. package/lib/queueResurrect.d.ts +7 -5
  41. package/lib/queueResurrect.js +25 -9
  42. package/lib/queueRetry.d.ts +12 -10
  43. package/lib/queueRetry.js +2 -4
  44. package/lib/queueSidecar.d.ts +122 -1
  45. package/lib/queueSidecar.js +192 -7
  46. package/lib/queueSubmit.d.ts +70 -4
  47. package/lib/queueSubmit.js +159 -7
  48. package/lib/runsErrorCodes.js +5 -3
  49. package/lib/runsExecute.d.ts +16 -1
  50. package/lib/runsExecute.js +97 -39
  51. package/lib/runsGates.d.ts +16 -4
  52. package/lib/runsGates.js +17 -5
  53. package/lib/runsList.d.ts +100 -4
  54. package/lib/runsList.js +364 -63
  55. package/lib/runsRefusalVoices.js +50 -1
  56. package/lib/runsRegistry.d.ts +142 -9
  57. package/lib/runsRegistry.js +960 -163
  58. package/lib/runsStart.d.ts +30 -7
  59. package/lib/runsStart.js +136 -14
  60. package/lib/runsTypes.d.ts +46 -3
  61. package/lib/runsTypes.js +63 -9
  62. package/lib/runsValidate.d.ts +1 -0
  63. package/lib/runsValidate.js +5 -0
  64. package/lib/runsValidateArms.js +25 -0
  65. package/lib/runsValidateServe.js +25 -12
  66. package/lib/runsValidateShared.d.ts +8 -1
  67. package/lib/runsValidateShared.js +44 -4
  68. package/lib/runsValidateStages.d.ts +1 -1
  69. package/lib/runsValidateStages.js +107 -55
  70. package/lib/runtimeProvision.d.ts +119 -0
  71. package/lib/runtimeProvision.js +243 -0
  72. package/lib/skillAuthored.d.ts +50 -0
  73. package/lib/skillAuthored.js +178 -0
  74. package/lib/skillPlane.d.ts +40 -2
  75. package/lib/skillPlane.js +63 -13
  76. package/lib/skillRegistry.d.ts +24 -1
  77. package/lib/skillRegistry.js +69 -5
  78. package/lib/skillRows.d.ts +13 -3
  79. package/lib/skillRows.js +49 -5
  80. package/package.json +33 -23
  81. package/lib/resurrect.d.ts +0 -6
  82. package/lib/resurrect.js +0 -18
@@ -1,4 +1,5 @@
1
1
  import { parseSidecar } from "./queueSidecar.js";
2
+ import { draftIdOf } from "@melite/contracts/benchStage";
2
3
  // queueResurrect.ts — resurrection planning + strict JSON reads
3
4
  // (boot tolerance for on-disk records; lenient arms deleted
4
5
 
@@ -88,11 +89,22 @@ export function sidecarList(value) {
88
89
  return [...src];
89
90
  throw new Error("unlistable sidecar value");
90
91
  }
91
- /** artifact names: the sidecar list filtered to non-empty strings. */
92
+ /** artifact names: non-empty strings ride; a mistyped entry takes
93
+ * the raise road (the caller orphans the record — the revived run
94
+ * never comes back short an artifact, unvoiced). Empty strings
95
+ * still filter: the writer's own harvest never emits them
96
+ * (runsExecute drops ""), so "" is absent, not a mistype. */
92
97
  export function artifactStrings(value) {
93
- return sidecarList(value)
94
- .filter((a) => typeof a === "string" && a !== "")
95
- .map((a) => a);
98
+ const names = [];
99
+ for (const entry of sidecarList(value)) {
100
+ if (entry === "")
101
+ continue;
102
+ if (typeof entry !== "string") {
103
+ throw new Error("unlistable sidecar artifact entry");
104
+ }
105
+ names.push(entry);
106
+ }
107
+ return names;
96
108
  }
97
109
  /** created_at coerce: finite numbers ride; numeric strings parse;
98
110
  * everything else rides 0 and never throws (boot order for
@@ -202,8 +214,15 @@ export function planResurrect(stateRoot, readSidecar = (runId) => {
202
214
  if (!name.startsWith("run-"))
203
215
  continue;
204
216
  const text = readSidecar(name);
205
- if (text === null)
217
+ if (text === null) {
218
+ // (purge §7 P7 SR — the reconcile surface): an unreadable
219
+
220
+ // surface lists it), never `continue`s into invisibility. A
221
+ // run-* row refused here is a run-* row the operator can see.
222
+ // Walled at tests/walls/ts/suites/run-door-single-resolve.spec.ts SR.
223
+ orphans.push(name);
206
224
  continue;
225
+ }
207
226
  let doc = null;
208
227
  try {
209
228
  doc = JSON.parse(text);
@@ -228,7 +247,7 @@ export function planResurrect(stateRoot, readSidecar = (runId) => {
228
247
  const req = readRequest(name);
229
248
  const usable = req !== null &&
230
249
  durableRecordUsable(text, req, typeof draftId === "string" && draftId !== ""
231
- ? draftExists(draftId)
250
+ ? draftExists(draftIdOf(draftId))
232
251
  : false);
233
252
  if (!usable) {
234
253
  orphans.push(name);
@@ -243,7 +262,4 @@ export function planResurrect(stateRoot, readSidecar = (runId) => {
243
262
  candidates.sort((a, b) => a.created - b.created);
244
263
  return { order: candidates.map((c) => c.runId), orphans };
245
264
  }
246
- /** One rebuilt queued run — RETIRED (stroke 83): the hollow
247
- * requeue road is deleted; the service's bootReconcile REPLAYS _request.json
248
- * through the start door so revived rows carry REAL params. */
249
265
  //# sourceMappingURL=queueResurrect.js.map
@@ -9,14 +9,16 @@ export interface RetryNote {
9
9
  retries_used: number;
10
10
  retry_last_error: string;
11
11
  };
12
- /** The durable row: ledger("run.stage_retry", ...). */
13
- readonly ledgerEvent: string;
14
- readonly ledgerData: {
15
- run_id: string;
16
- stage: string;
17
- attempt: number;
18
- error: string;
19
- };
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
20
22
  /** The live row: publish(run_id, stage/…/retry). Key order . */
21
23
  readonly busFrame: {
22
24
  type: string;
@@ -30,7 +32,7 @@ export interface RetryNote {
30
32
  * retries (both the exception arm 1754 and the error-dict arm
31
33
  * 1775-1778 gate on the stop flag). */
32
34
  export declare function shouldRetry(ask: RetryAsk): boolean;
33
- /** One documented retry: sidecar row + events bus +
34
- * ledger — never a silent re-run. */
35
+ /** One documented retry: sidecar row + events bus — never a
36
+ * silent re-run, never a journal row (see RetryNote). */
35
37
  export declare function noteStageRetry(runId: string, stageId: string, stageIndex: number, attempt: number, why: string): RetryNote;
36
38
  //# sourceMappingURL=queueRetry.d.ts.map
package/lib/queueRetry.js CHANGED
@@ -11,13 +11,11 @@
11
11
  export function shouldRetry(ask) {
12
12
  return ask.attempt < ask.maxExtra && !ask.stopSet;
13
13
  }
14
- /** One documented retry: sidecar row + events bus +
15
- * ledger — never a silent re-run. */
14
+ /** One documented retry: sidecar row + events bus — never a
15
+ * silent re-run, never a journal row (see RetryNote). */
16
16
  export function noteStageRetry(runId, stageId, stageIndex, attempt, why) {
17
17
  return {
18
18
  stagePatch: { retries_used: attempt, retry_last_error: why },
19
- ledgerEvent: "run.stage_retry",
20
- ledgerData: { run_id: runId, stage: stageId, attempt, error: why },
21
19
  busFrame: { type: "stage", stage: stageId, index: stageIndex, retry: attempt },
22
20
  };
23
21
  }
@@ -1,3 +1,4 @@
1
+ import type { DraftId } from "@melite/contracts/benchStage";
1
2
  export interface GraphRow {
2
3
  readonly id: string;
3
4
  readonly type: string;
@@ -8,6 +9,14 @@ export interface GraphRow {
8
9
  }
9
10
  export interface SidecarStage {
10
11
  readonly id: string;
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+ readonly bench_stage_id?: string;
11
20
  readonly name: string;
12
21
  readonly index: number;
13
22
  readonly status: string;
@@ -17,6 +26,13 @@ export interface SidecarStage {
17
26
  name: string;
18
27
  }>;
19
28
  readonly result_outputs?: Record<string, unknown>;
29
+
30
+
31
+
32
+
33
+
34
+
35
+ readonly result_metadata?: Record<string, unknown>;
20
36
  readonly error?: string;
21
37
  readonly merged?: boolean;
22
38
  readonly outputs: Record<string, unknown>;
@@ -43,6 +59,98 @@ export declare function sidecarStageOf(stage: {
43
59
 
44
60
 
45
61
 
62
+
63
+
64
+
65
+
66
+
67
+
68
+
69
+
70
+
71
+ export interface GraphReceiptPair {
72
+ /** Workflow key count — the composed graph's node budget. */
73
+ readonly nodes: number;
74
+ /** Every judged doc key (scalar-valued), sorted. */
75
+ readonly populated: readonly string[];
76
+ /** The judged keys found in the graph, sorted. */
77
+ readonly carried: readonly string[];
78
+ /** The judged keys NOT found in the graph, sorted — the honesty face. */
79
+ readonly dropped: readonly string[];
80
+ readonly verdict: "complete" | "partial";
81
+ /** THE BAKE'S RECORD (study §7 item 2, the run voice): present
82
+ * iff the composed graph bakes or loads a refmod mod — read off
83
+ * the graph's own nodes (the extract/loader inputs VERBATIM),
84
+ * never off the doc, so the record cannot disagree with what
85
+ * the engine will actually run. Absent when no seat exists. */
86
+ readonly bake?: GraphReceiptBake;
87
+ }
88
+ /** The refmod bake's receipt: the graph-stated dials, the baked
89
+ * media count, the film's window count (one SamplerCustomAdvanced
90
+ * per window — the DiT pass set), and the run-voice price. */
91
+ export interface GraphReceiptBake {
92
+ /** "baked" = media bakes at run time (MiniMaxH3RefModExtract);
93
+ * "stems" = pre-baked .safetensors packs load (MiniMaxH3RefModsLoader). */
94
+ readonly source: "baked" | "stems";
95
+ readonly mode?: string;
96
+ readonly pool?: number;
97
+ readonly refinement_steps?: number;
98
+ readonly save?: boolean;
99
+ /** refs_image.* + refs_video.* slots the extract stacks. */
100
+ readonly visual_refs?: number;
101
+ /** loader mod_N slots ≠ "(none)". */
102
+ readonly stems?: number;
103
+ /** One SamplerCustomAdvanced per film window. */
104
+ readonly windows: number;
105
+ /** "bake: <steps> refinement steps × <refs> ref(s) × <windows> windows" */
106
+ readonly price: string;
107
+ }
108
+ /** One stage's queue-time doc→graph evidence row. */
109
+ export interface GraphReceiptStageRow extends GraphReceiptPair {
110
+ readonly stage: string;
111
+ }
112
+ /** The run-level fold of the per-stage rows (what `_flow.json`
113
+ * carries as `graph_receipt`, beside `compose_echo`). */
114
+ export interface GraphReceipt extends GraphReceiptPair {
115
+ /** Per-stage rows, in registration order. */
116
+ readonly stages: readonly GraphReceiptStageRow[];
117
+ /** THE ENGINE'S PROMPT ID — minted ENGINE-SIDE at POST /prompt,
118
+ * so it CANNOT exist at queue time. The execute outcome fold
119
+ * stamps it (runsExecute's runOne, beside the harvested
120
+ * result_outputs.prompt_id), and settle's sidecar rewrite
121
+ * carries it to disk. Absent until the run has submitted. */
122
+ readonly prompt_id?: string;
123
+ }
124
+ /** THE RECEIPT SPINE: receipt one doc against one composed
125
+ * workflow (the `{workflow, output_nodes}` envelope the card walk
126
+ * yields — only `workflow`'s node inputs are judged).
127
+ * @param params the run door's admitted doc params (the snapshot's
128
+ * own row — bench stage row params, or the card arm's admitted
129
+ * request body)
130
+ * @param composed the card walk's composed envelope
131
+ * @returns the pair — node count, populated/carried/dropped
132
+ * (sorted), verdict `complete` iff nothing dropped */
133
+ export declare function graphReceiptOf(params: Record<string, unknown>, composed: {
134
+ readonly workflow: unknown;
135
+ }): GraphReceiptPair;
136
+ /** Name one stage's pair with its stage id (the per-stage rows
137
+ * inside the run-level `graph_receipt`). */
138
+ export declare function graphReceiptStageOf(stage: string, pair: GraphReceiptPair): GraphReceiptStageRow;
139
+ /** Fold per-stage rows into the run-level receipt (nodes SUM —
140
+ * the run's graph key space; populated/carried/dropped the
141
+ * sorted union; verdict `complete` iff every stage is). */
142
+ export declare function graphReceiptFoldOf(rows: readonly GraphReceiptStageRow[], promptId?: string): GraphReceipt;
143
+
144
+
145
+
146
+
147
+
148
+
149
+
150
+
151
+
152
+
153
+
46
154
  export declare function variantOfBodies(bodies: unknown[]): string | undefined;
47
155
  /** The sidecar document: KEY ORDER as (run_id, status, error,
48
156
  * stages, skipped_stages, artifacts, created_at, test, draft_id,
@@ -58,13 +166,19 @@ export declare function sidecarDoc(args: {
58
166
  artifacts: string[];
59
167
  createdAt: number;
60
168
  testFlag: boolean;
61
- draftId: string;
169
+ draftId: DraftId;
62
170
  pipeline: string;
171
+ /** THE BENCH INCARNATION (W-3 / F3-11): the draft doc's `epoch`
172
+ * at press — the identity-prefix `bench_epoch` key, the join
173
+ * half of the stage-id-reuse cure. Optional: pre-cure runs and
174
+ * epoch-less benches stamp nothing (never guessed). */
175
+ benchEpoch?: string;
63
176
  graph: GraphRow[];
64
177
  /** THE SNAPSHOT KEYS (strokes 45/45d, carried stroke 48): the exact
65
178
  * card + bench that ran. Absent when unstamped (inline runs)
66
179
  * the pinned prefix above never shifts. */
67
180
  cardSnapshot?: unknown;
181
+ cardRecipe?: unknown;
68
182
  benchSnapshot?: unknown;
69
183
  /** F-6(b) ADMISSION WARNINGS (the film lane's VRAM-pressure
70
184
  * warn): the status row spells it `warnings` too — one spelling
@@ -80,6 +194,13 @@ export declare function sidecarDoc(args: {
80
194
  calls: number;
81
195
  benchRev: number | null;
82
196
  };
197
+ /** THE SERVED-GRAPH RECEIPT (the silent UI-drop purge's P1):
198
+ * the queue-time doc→graph evidence, run-level fold with its
199
+ * per-stage rows inside. The status row spells it
200
+ * `graph_receipt` too. Absent when the run composed no card
201
+ * stage (the receipt judges the card compose, never the
202
+ * verbatim inline envelope). */
203
+ graphReceipt?: GraphReceipt;
83
204
 
84
205
 
85
206
 
@@ -1,9 +1,3 @@
1
-
2
- // pure move, zero logic changes — the queue.ts barrel re-exports
3
- // every symbol, so the public surface is byte-identical).
4
- //
5
- // Erasable-syntax TS only (node --experimental-strip-types): no
6
- // enums, import type for types, .ts specifiers for relative imports.
7
1
  export function sidecarStageOf(stage) {
8
2
  const out = {
9
3
  id: stage.id,
@@ -13,6 +7,8 @@ export function sidecarStageOf(stage) {
13
7
  outputs: stage.outputs ?? {},
14
8
  expected: stage.expected ?? {},
15
9
  };
10
+ if (typeof stage.benchStageId === 'string' && stage.benchStageId !== '')
11
+ out.bench_stage_id = stage.benchStageId;
16
12
  if (typeof stage.engine === 'string')
17
13
  out.engine = stage.engine;
18
14
  if (typeof stage.url === 'string')
@@ -27,12 +23,170 @@ export function sidecarStageOf(stage) {
27
23
  if (typeof stage.result_outputs === 'object' && stage.result_outputs !== null && !Array.isArray(stage.result_outputs)) {
28
24
  out.result_outputs = stage.result_outputs;
29
25
  }
26
+ if (typeof stage.metadata === 'object' && stage.metadata !== null && !Array.isArray(stage.metadata)) {
27
+ const meta = stage.metadata;
28
+ if (Object.keys(meta).length > 0)
29
+ out.result_metadata = meta;
30
+ }
30
31
  if (typeof stage.error === 'string')
31
32
  out.error = stage.error;
32
33
  if (stage.merged === true)
33
34
  out.merged = true;
34
35
  return out;
35
36
  }
37
+ /** A v1-judged scalar: the receipt's scope gate. */
38
+ function receiptScalarOf(value) {
39
+ if (typeof value === "string")
40
+ return value.trim() !== "" ? value : undefined;
41
+ if (typeof value === "number")
42
+ return Number.isFinite(value) ? value : undefined;
43
+ if (typeof value === "boolean")
44
+ return value;
45
+ return undefined;
46
+ }
47
+ /** THE RECEIPT SPINE: receipt one doc against one composed
48
+ * workflow (the `{workflow, output_nodes}` envelope the card walk
49
+ * yields — only `workflow`'s node inputs are judged).
50
+ * @param params the run door's admitted doc params (the snapshot's
51
+ * own row — bench stage row params, or the card arm's admitted
52
+ * request body)
53
+ * @param composed the card walk's composed envelope
54
+ * @returns the pair — node count, populated/carried/dropped
55
+ * (sorted), verdict `complete` iff nothing dropped */
56
+ export function graphReceiptOf(params, composed) {
57
+ const carried = new Set();
58
+ let nodes = 0;
59
+ let windows = 0;
60
+ let bake;
61
+ const workflow = composed.workflow;
62
+ if (workflow !== null && typeof workflow === "object" && !Array.isArray(workflow)) {
63
+ for (const node of Object.values(workflow)) {
64
+ if (node === null || typeof node !== "object" || Array.isArray(node))
65
+ continue;
66
+ nodes += 1;
67
+ const cls = node.class_type;
68
+ if (cls === "SamplerCustomAdvanced")
69
+ windows += 1;
70
+ const inputs = node.inputs;
71
+ if (inputs === null || typeof inputs !== "object" || Array.isArray(inputs))
72
+ continue;
73
+ for (const v of Object.values(inputs)) {
74
+ if (typeof v === "string" || typeof v === "number" || typeof v === "boolean")
75
+ carried.add(v);
76
+ }
77
+ // THE BAKE RECORD (study §7 item 2): read off the graph's own
78
+ // seat nodes — the extract's declared dials verbatim, the
79
+ // ref count from its autogrow slots, the price string the run
80
+ // voice renders. One bake per graph; the visual seat wins
81
+ // over a stems-only loader (the per-call replace law).
82
+ if (cls === "MiniMaxH3RefModExtract" || cls === "MiniMaxH3RefModsLoader") {
83
+ const inp = inputs;
84
+ if (cls === "MiniMaxH3RefModExtract") {
85
+ const visualRefs = Object.keys(inp).filter((k) => k.startsWith("refs_image.") || k.startsWith("refs_video.")).length;
86
+ bake = {
87
+ source: "baked",
88
+ ...(typeof inp["mode"] === "string" ? { mode: inp["mode"] } : {}),
89
+ ...(typeof inp["pool_h"] === "number" ? { pool: inp["pool_h"] } : {}),
90
+ ...(typeof inp["identity"] === "number" ? { refinement_steps: inp["identity"] } : {}),
91
+ ...(typeof inp["save"] === "boolean" ? { save: inp["save"] } : {}),
92
+ visual_refs: visualRefs,
93
+ windows,
94
+ price: "",
95
+ };
96
+ }
97
+ else {
98
+ const stems = Object.entries(inp).filter(([k, v]) => /^mod_\d+$/.test(k) && v !== "(none)").length;
99
+ bake = { source: "stems", stems, windows, price: "" };
100
+ }
101
+ }
102
+ }
103
+ }
104
+ if (bake !== undefined) {
105
+ const windows_ = windows;
106
+ bake = bake.source === "baked"
107
+ ? {
108
+ ...bake,
109
+ windows: windows_,
110
+ price: "bake: " + String(bake.refinement_steps ?? "?") + " refinement steps × "
111
+ + String(bake.visual_refs ?? 0) + (bake.visual_refs === 1 ? " ref × " : " refs × ")
112
+ + String(windows_) + (windows_ === 1 ? " window" : " windows"),
113
+ }
114
+ : {
115
+ ...bake,
116
+ windows: windows_,
117
+ price: "bake: " + String(bake.stems ?? 0) + (bake.stems === 1 ? " stem × " : " stems × ")
118
+ + String(windows_) + (windows_ === 1 ? " window" : " windows"),
119
+ };
120
+ }
121
+ const populated = [];
122
+ const found = [];
123
+ const missed = [];
124
+ for (const [key, value] of Object.entries(params)) {
125
+ const scalar = receiptScalarOf(value);
126
+ if (scalar === undefined)
127
+ continue;
128
+ populated.push(key);
129
+ (carried.has(scalar) ? found : missed).push(key);
130
+ }
131
+ populated.sort();
132
+ found.sort();
133
+ missed.sort();
134
+ return {
135
+ nodes,
136
+ populated,
137
+ carried: found,
138
+ dropped: missed,
139
+ verdict: missed.length === 0 ? "complete" : "partial",
140
+ ...(bake !== undefined ? { bake } : {}),
141
+ };
142
+ }
143
+ /** Name one stage's pair with its stage id (the per-stage rows
144
+ * inside the run-level `graph_receipt`). */
145
+ export function graphReceiptStageOf(stage, pair) {
146
+ return {
147
+ stage,
148
+ nodes: pair.nodes,
149
+ populated: [...pair.populated],
150
+ carried: [...pair.carried],
151
+ dropped: [...pair.dropped],
152
+ verdict: pair.verdict,
153
+ ...(pair.bake !== undefined ? { bake: pair.bake } : {}),
154
+ };
155
+ }
156
+ /** Fold per-stage rows into the run-level receipt (nodes SUM —
157
+ * the run's graph key space; populated/carried/dropped the
158
+ * sorted union; verdict `complete` iff every stage is). */
159
+ export function graphReceiptFoldOf(rows, promptId) {
160
+ const union = (pick) => {
161
+ const s = new Set();
162
+ for (const r of rows)
163
+ for (const k of pick(r))
164
+ s.add(k);
165
+ return [...s].sort();
166
+ };
167
+ let nodes = 0;
168
+ let complete = true;
169
+ for (const r of rows) {
170
+ nodes += r.nodes;
171
+ if (r.verdict !== "complete")
172
+ complete = false;
173
+ }
174
+ return {
175
+ nodes,
176
+ populated: union((r) => r.populated),
177
+ carried: union((r) => r.carried),
178
+ dropped: union((r) => r.dropped),
179
+ verdict: complete ? "complete" : "partial",
180
+ stages: rows.map((r) => graphReceiptStageOf(r.stage, r)),
181
+ // THE BAKE rides the fold: the first stage that carries one
182
+ // (the card run's single stage; a multi-stage flow receipts the
183
+ // first bake seat it composes).
184
+ ...(rows.find((r) => r.bake !== undefined)?.bake !== undefined
185
+ ? { bake: rows.find((r) => r.bake !== undefined).bake }
186
+ : {}),
187
+ ...(promptId !== undefined && promptId !== "" ? { prompt_id: promptId } : {}),
188
+ };
189
+ }
36
190
 
37
191
 
38
192
 
@@ -81,7 +235,30 @@ export function sidecarDoc(args) {
81
235
  // reaches this. Derived from the very stages the doc stores, so
82
236
  // digest and array can never disagree; every writer (queued,
83
237
  // settled, resurrect) shares this one seat.
84
- stage_ids: args.stages.map((s) => s.id).filter((id) => id !== "").join(","),
238
+
239
+ // the digest is the bench read's MEMBERSHIP TICKET
240
+ // (melite-construct's withLastRun joins stage_ids against the
241
+ // bench draft's row ids) — a single-card press composes the
242
+ // card's own skeleton ('generate'), a namespace the draft doc
243
+ // never heard of, so the ticket takes the bench_stage_id seam
244
+ // first and falls back to the row id only when the draft
245
+ // address is absent (inline runs, multi-row bench loops — those
246
+ // stamp each row's own id). The skeleton survives on the stage
247
+ // row's own `id`, named beside its draft address.
248
+ stage_ids: args.stages
249
+ .map((s) => (s.bench_stage_id !== undefined && s.bench_stage_id !== "" ? s.bench_stage_id : s.id))
250
+ .filter((id) => id !== "")
251
+ .join(","),
252
+
253
+ // doc's `epoch` at press (drafts clearBench is its only writer),
254
+ // stamped into the identity prefix so the list row carries it
255
+ // and melite-construct's withLastRun can require equality
256
+ // alongside draft_id — a post-clear read binds only post-clear
257
+ // runs. Absent on pre-cure runs (the optional-key law: never
258
+ // guessed); runsList projects it verbatim beside the digest.
259
+ ...(args.benchEpoch !== undefined && args.benchEpoch !== ""
260
+ ? { bench_epoch: args.benchEpoch }
261
+ : {}),
85
262
  ...(args.exportName !== undefined && args.exportName !== "" ? { export_name: args.exportName } : {}),
86
263
  ...(args.exportPath !== undefined && args.exportPath !== "" ? { export_path: args.exportPath } : {}),
87
264
  ...(args.variant !== undefined && args.variant !== "" ? { variant: args.variant } : {}),
@@ -94,9 +271,17 @@ export function sidecarDoc(args) {
94
271
  artifacts: [...args.artifacts],
95
272
  graph: args.graph,
96
273
  ...(args.cardSnapshot !== undefined ? { card_snapshot: args.cardSnapshot } : {}),
274
+ // THE RECIPE (the F27 cure): the admitted card doc — envelope
275
+ // lifted, stanza unwrapped — is a DIFFERENT document from the
276
+ // request that carried it (the raw body is `_request.json`, an
277
+ // envelope the compose never read); restore overlays THIS key so a
278
+ // restored stage is re-editable, never a fresh timeline with the
279
+ // artifact pasted in.
280
+ ...(args.cardRecipe !== undefined ? { card_recipe: args.cardRecipe } : {}),
97
281
  ...(args.benchSnapshot !== undefined ? { bench_snapshot: args.benchSnapshot } : {}),
98
282
  ...(args.warnings !== undefined && args.warnings.length > 0 ? { warnings: [...args.warnings] } : {}),
99
283
  ...(args.composeEcho !== undefined ? { compose_echo: args.composeEcho } : {}),
284
+ ...(args.graphReceipt !== undefined ? { graph_receipt: args.graphReceipt } : {}),
100
285
  ...(args.sourceEcho !== undefined ? { source_echo: args.sourceEcho } : {}),
101
286
  };
102
287
  }
@@ -1,3 +1,4 @@
1
+ import { type DraftId } from "@melite/contracts/benchStage";
1
2
  export interface QueueRefusal {
2
3
  readonly status: number;
3
4
  readonly payload: Record<string, unknown>;
@@ -12,8 +13,9 @@ export declare function envelopeRefusal(kind: "not-object" | "bad-test" | "missi
12
13
  draftId?: string;
13
14
  }): QueueRefusal;
14
15
  /** The unknown-draft refusal (door-verbatim; the probe rides the
15
- * caller's drafts domain — the remote hops the ctx seat). */
16
- export declare function unknownDraftRefusal(draftId: string): QueueRefusal;
16
+ * caller's drafts domain — the remote hops the ctx seat). Takes the
17
+ * branded id: the walker mints it off the validated wire body. */
18
+ export declare function unknownDraftRefusal(draftId: DraftId): QueueRefusal;
17
19
  /** Draft id rule (draftIdOk in @melite/estate-drafts, re-exported below): <=96 chars of [A-Za-z0-9_-]. */
18
20
  /** This core re-checks nothing: it BUILDS the refusal for a caller-computed verdict (the check is one regex, owned by the drafts package so envelope validation is whole). */
19
21
  /** Callers pass the raw draft_id; the malformed/unknown split needs the existence probe too — see walkSubmitEnvelope. */
@@ -36,6 +38,16 @@ export declare function strictBodyCheck(body: Record<string, unknown>): QueueRef
36
38
 
37
39
 
38
40
 
41
+ export declare function resolveTestFlag(body: Record<string, unknown>): unknown;
42
+
43
+
44
+
45
+
46
+
47
+
48
+
49
+
50
+
39
51
 
40
52
 
41
53
 
@@ -44,6 +56,42 @@ export declare function submitEnvelopeStructuralRefusal(doc: unknown): QueueRefu
44
56
  /** Door-selection order (resolve_request 302: flow/flow_inline/
45
57
  * model fixed order — ambiguity lists in DOOR order, not sorted). */
46
58
  export declare const SUBMIT_DOORS: readonly string[];
59
+ /** THE SEED-SWEEP CAP (the GPU-spend law): one press fans out to at
60
+ * most this many runs — a runaway array mints that many runs, each
61
+ * a full render. Larger compares split across presses. */
62
+ export declare const SEED_SWEEP_MAX = 16;
63
+ /** The door's KNOB PRESENCE-PROBES (the envelope wall's counterpart
64
+ * list): card knob names the submit door reads the PRESENCE of to
65
+ * refuse an ambiguous press — never consumed, never lifted, and
66
+ * deliberately NEVER envelope-registered (a registered probe would
67
+ * stop being a knob and liftCardParams would drop it from the
68
+ * card's params). Today: `seed`, probed so a `seeds` sweep never
69
+ * silently overrides a stated single seed at either seat (the
70
+ * sibling top-level key or the params stanza — siblings win the
71
+ * lift, so the override would be silent). */
72
+ export declare const DOOR_KNOB_PROBES: readonly string[];
73
+ /** The seed-sweep expansion's verdict: no `seeds` key (the legacy
74
+ * single run), a judged sweep, or a loud refusal. */
75
+ export type SeedSweep = {
76
+ kind: "single";
77
+ } | {
78
+ kind: "sweep";
79
+ seeds: readonly number[];
80
+ } | {
81
+ kind: "refusal";
82
+ refusal: QueueRefusal;
83
+ };
84
+
85
+
86
+
87
+
88
+
89
+
90
+
91
+
92
+
93
+
94
+ export declare function expandSeedSweep(body: Record<string, unknown>): SeedSweep;
47
95
  /** The walker's chain in order: non-object body (bad_envelope/body)
48
96
  * -> non-bool test (bad_envelope/test) -> draft required
49
97
  * (draft_required) -> malformed (draft_malformed) -> unknown doc
@@ -61,6 +109,18 @@ export declare function submitDoorsOf(body: Record<string, unknown>): string[];
61
109
  export declare function ambiguousDoorsRefusal(doors: string[]): QueueRefusal;
62
110
  /** The no-door refusal (text is the wire contract). */
63
111
  export declare function noDoorRefusal(): QueueRefusal;
112
+ /** THE PER-RUN CEILING VERDICT (the F8 law): `execute_ceil_ms` is a
113
+ * finite number (<= 0 disables the fuse) or absent; any other shape
114
+ * refuses at the start door — a typo must never silently ride the
115
+ * config default past a 30-min kill. */
116
+ export type ExecuteCeilVerdict = {
117
+ kind: "ok";
118
+ ceilMs: number | undefined;
119
+ } | {
120
+ kind: "bad";
121
+ value: unknown;
122
+ };
123
+ export declare function executeCeilOf(doc: Record<string, unknown>): ExecuteCeilVerdict;
64
124
  /** THE ONE ENVELOPE WALKER (the S3 twin cure): the structural
65
125
  * faces, the draft probe ordering and the ok face live HERE and
66
126
  * the runs registration delegates — there is no second sync face
@@ -70,11 +130,17 @@ export declare function noDoorRefusal(): QueueRefusal;
70
130
  * when the envelope may proceed to door selection, which the live
71
131
  * face owns at startReserved (strict then doors, after the
72
132
  * replay/reservation verdict). */
73
- export declare function walkSubmitEnvelope(doc: unknown, draftExists: (draftId: string) => boolean | Promise<boolean>): Promise<{
133
+ export declare function walkSubmitEnvelope(doc: unknown, draftExists: (draftId: DraftId) => boolean | Promise<boolean>): Promise<{
74
134
  kind: "ok";
75
135
  body: Record<string, unknown>;
76
136
  testFlag: boolean;
77
- draftId: string;
137
+ /** Undefined on the FLOW-DOC EXEMPTION (a {flow}/{flow_inline}
138
+ * body with no draft_id — the flow's own doc is the birth
139
+ * doc). Every other shape carries one (the CARD BIRTH LAW). */
140
+ draftId: DraftId | undefined;
141
+ /** The start body's own execute ceiling (absent = the queue
142
+ * config decides; <= 0 disables the fuse). */
143
+ ceilMs: number | undefined;
78
144
  } | {
79
145
  kind: "refusal";
80
146
  refusal: QueueRefusal;