@melite/estate-queue 0.1.4-alpha → 0.2.0-alpha

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. package/LICENSE +561 -457
  2. package/README.md +55 -0
  3. package/lib/bench.d.ts +19 -11
  4. package/lib/bench.js +47 -57
  5. package/lib/cardsArmError.d.ts +94 -2
  6. package/lib/cardsArmError.js +34 -4
  7. package/lib/cardsCompose.d.ts +13 -1
  8. package/lib/cardsCompose.js +151 -67
  9. package/lib/cardsDangling.d.ts +2 -2
  10. package/lib/cardsDangling.js +82 -37
  11. package/lib/cardsFacts.d.ts +32 -3
  12. package/lib/cardsFacts.js +39 -1
  13. package/lib/cardsLanes.d.ts +62 -4
  14. package/lib/cardsLanes.js +407 -20
  15. package/lib/cardsLanesCopy.d.ts +21 -0
  16. package/lib/cardsLanesCopy.js +22 -0
  17. package/lib/cardsRegistry.d.ts +195 -10
  18. package/lib/cardsRegistry.js +959 -67
  19. package/lib/cardsVariant.d.ts +22 -8
  20. package/lib/cardsVariant.js +243 -52
  21. package/lib/discloseRegistry.d.ts +42 -11
  22. package/lib/discloseRegistry.js +163 -23
  23. package/lib/filmLead.js +5 -3
  24. package/lib/flowsData.d.ts +68 -13
  25. package/lib/flowsData.js +236 -107
  26. package/lib/flowsFamilyCompose.d.ts +5 -8
  27. package/lib/flowsFamilyCompose.js +25 -14
  28. package/lib/flowsParamsOverlay.d.ts +55 -0
  29. package/lib/flowsParamsOverlay.js +197 -0
  30. package/lib/flowsRegistryRows.d.ts +4 -1
  31. package/lib/flowsRegistryRows.js +325 -25
  32. package/lib/index.d.ts +1 -3
  33. package/lib/index.js +20 -5
  34. package/lib/lifecycleLatch.d.ts +16 -0
  35. package/lib/lifecycleLatch.js +42 -0
  36. package/lib/loadPlane.d.ts +3 -2
  37. package/lib/loadPlane.js +34 -8
  38. package/lib/loadRegistry.js +1 -1
  39. package/lib/manageOps.d.ts +8 -2
  40. package/lib/manageOps.js +28 -7
  41. package/lib/managePlane.d.ts +42 -1
  42. package/lib/managePlane.js +911 -101
  43. package/lib/managePreflight.d.ts +26 -0
  44. package/lib/managePreflight.js +179 -0
  45. package/lib/manageProbe.d.ts +15 -7
  46. package/lib/manageProbe.js +79 -8
  47. package/lib/manageRegistry.d.ts +42 -4
  48. package/lib/manageRegistry.js +45 -7
  49. package/lib/mediaKinds.d.ts +1 -1
  50. package/lib/mediaKinds.js +1 -1
  51. package/lib/queue.js +14 -10
  52. package/lib/queueCore.d.ts +21 -5
  53. package/lib/queueCore.js +22 -5
  54. package/lib/queueLifecycle.d.ts +0 -24
  55. package/lib/queueLifecycle.js +9 -63
  56. package/lib/queueLock.d.ts +8 -2
  57. package/lib/queueLock.js +9 -6
  58. package/lib/queueResurrect.d.ts +7 -2
  59. package/lib/queueResurrect.js +25 -6
  60. package/lib/queueSidecar.d.ts +114 -1
  61. package/lib/queueSidecar.js +178 -7
  62. package/lib/queueSubmit.d.ts +124 -10
  63. package/lib/queueSubmit.js +251 -48
  64. package/lib/queueSweep.js +13 -2
  65. package/lib/runsChange.d.ts +8 -0
  66. package/lib/runsChange.js +21 -5
  67. package/lib/runsErrorCodes.d.ts +1 -1
  68. package/lib/runsErrorCodes.js +35 -0
  69. package/lib/runsExecute.d.ts +26 -0
  70. package/lib/runsExecute.js +184 -6
  71. package/lib/runsGates.d.ts +5 -1
  72. package/lib/runsGates.js +10 -5
  73. package/lib/runsList.d.ts +43 -3
  74. package/lib/runsList.js +172 -58
  75. package/lib/runsRefusalVoices.js +101 -0
  76. package/lib/runsRegistry.d.ts +188 -12
  77. package/lib/runsRegistry.js +1233 -179
  78. package/lib/runsSourceEcho.d.ts +27 -0
  79. package/lib/runsSourceEcho.js +84 -18
  80. package/lib/runsStart.d.ts +80 -17
  81. package/lib/runsStart.js +303 -49
  82. package/lib/runsTypes.d.ts +62 -2
  83. package/lib/runsTypes.js +30 -6
  84. package/lib/runsValidateArms.js +61 -7
  85. package/lib/runsValidateServe.d.ts +2 -2
  86. package/lib/runsValidateServe.js +46 -14
  87. package/lib/runsValidateShared.d.ts +10 -1
  88. package/lib/runsValidateShared.js +14 -0
  89. package/lib/runsValidateStages.d.ts +10 -3
  90. package/lib/runsValidateStages.js +44 -12
  91. package/lib/runtimeProvision.d.ts +119 -0
  92. package/lib/runtimeProvision.js +243 -0
  93. package/lib/service.d.ts +24 -6
  94. package/lib/service.js +19 -11
  95. package/lib/skillFs.d.ts +9 -4
  96. package/lib/skillFs.js +12 -14
  97. package/lib/skillPlane.d.ts +3 -2
  98. package/lib/skillPlane.js +12 -6
  99. package/lib/skillRegistry.js +1 -1
  100. package/lib/skillRows.d.ts +4 -3
  101. package/lib/skillRows.js +21 -14
  102. package/lib/toolProjection.d.ts +1 -1
  103. package/lib/toolProjection.js +1 -1
  104. package/package.json +18 -17
  105. package/lib/runStatus.d.ts +0 -7
  106. package/lib/runStatus.js +0 -21
package/lib/queueCore.js CHANGED
@@ -85,12 +85,16 @@ export class QueueCore {
85
85
  queued_ids: [...this.order],
86
86
  };
87
87
  }
88
- /** Settled-row eviction (_evict_settled 1137-1151): settled ==
89
- * completed|failed ONLY (stopped rows stay — a deliberate stop
90
- * is a live receipt, not garbage); past 500 the oldest
91
- * created_at leaves first. Returns evicted ids. */
88
+ /** Settled-row eviction (_evict_settled 1137-1151): settled is
89
+ * every terminal status — completed, failed, AND stopped (audit
90
+ * F-S11: stopped was exempt as "a live receipt", but terminal is
91
+ * terminal — a stop-heavy session minted rows the cap never
92
+ * touched, and the receipt lives on in the persist regardless;
93
+ * the 500-row window serves any interactive read). Past 500 the
94
+ * oldest created_at leaves first. Returns evicted ids. */
92
95
  evictSettled() {
93
- const settled = [...this.runs.values()].filter((r) => r.status === "completed" || r.status === "failed");
96
+ const settled = [...this.runs.values()].filter((r) => r.status === "completed" || r.status === "failed" ||
97
+ r.status === "stopped");
94
98
  const excess = settled.length - MAX_SETTLED_RUNS;
95
99
  if (excess <= 0)
96
100
  return [];
@@ -115,6 +119,19 @@ export function newRunId() {
115
119
  .padStart(8, "0");
116
120
  return "run-" + rand + "-" + ts;
117
121
  }
122
+ /** THE SWEEP RUN-ID FAMILY (friction #9, the seed sweep): one press,
123
+ * N seeds — every run of the sweep carries ONE shared `run-<base>`
124
+ * prefix plus its own `-s<k>` seat in seed order, so the family is
125
+ * identifiable in the registry, the runs tree, and the sweep
126
+ * answer's sweep_runs list. The base is one newRunId mint (the
127
+ * same producer); the suffix seats are part of the construction.
128
+ * @param count the sweep's seed count (the expansion already capped
129
+ * it at SEED_SWEEP_MAX).
130
+ * @returns the run ids, index k for seed k. */
131
+ export function sweepRunIds(count) {
132
+ const base = newRunId();
133
+ return Array.from({ length: count }, (_v, k) => (base + "-s" + String(k)));
134
+ }
118
135
  /** The terminal broadcast frame (worker 1413-1414): every
119
136
  * subscriber gets the final status exactly once. Shape pinned
120
137
  * here so the P6 bus port inherits it. */
@@ -1,26 +1,2 @@
1
- import type { QueueRefusal } from "./queueSubmit.js";
2
1
  export type LifecycleState = "queued" | "running" | "completed" | "failed" | "stopped" | "stopping";
3
- /** stop, unknown run (Gateway.stop 2042-2045). */
4
- export declare function refuseUnknownStop(runId: string): QueueRefusal;
5
- /** stop, settled run: 200 with error ONLY (no code
6
- * the dispatcher normalizes 4xx alone, and this is a 200). */
7
- export declare function refuseTerminalStop(state: string): QueueRefusal;
8
- /** resume, live run (resume 1919-1925). */
9
- export declare function refuseLiveResume(runId: string, liveStatus: string): QueueRefusal;
10
- /** resume/reproduce, no durable record (1930-1932 / 2011-2014). */
11
- export declare function refuseNoDurableRecord(runId: string): QueueRefusal;
12
- /** resume, completed run. */
13
- export declare function refuseCompletedResume(runId: string): QueueRefusal;
14
- /** resume, neither failed nor stopped. */
15
- export declare function refuseUnresumable(runId: string, status: string): QueueRefusal;
16
- /** resume, draft gone or half-written. */
17
- export declare function refuseUnusableRecord(runId: string): QueueRefusal;
18
- /** reproduce, live run. */
19
- export declare function refuseLiveReproduce(runId: string, liveStatus: string): QueueRefusal;
20
- /** reproduce, cardless legacy row. */
21
- export declare function refuseCardlessReplay(runId: string): QueueRefusal;
22
- /** reproduce, request body missing. */
23
- export declare function refuseMissingRequest(runId: string): QueueRefusal;
24
- /** reproduce, request non-object. */
25
- export declare function refuseNonObjectRequest(runId: string, gotType: string): QueueRefusal;
26
2
  //# sourceMappingURL=queueLifecycle.d.ts.map
@@ -1,65 +1,11 @@
1
+ // queueLifecycle.ts — the queue row's lifecycle state union (split
1
2
 
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
- import { refusal } from "./queueSubmit.js";
8
- /** stop, unknown run (Gateway.stop 2042-2045). */
9
- export function refuseUnknownStop(runId) {
10
- return refusal(400, "unknown run_id " + JSON.stringify(runId), "run_unknown", "run_id");
11
- }
12
- /** stop, settled run: 200 with error ONLY (no code
13
- * the dispatcher normalizes 4xx alone, and this is a 200). */
14
- export function refuseTerminalStop(state) {
15
- return {
16
- status: 200,
17
- payload: { error: "cannot stop run in state " + state },
18
- };
19
- }
20
- /** resume, live run (resume 1919-1925). */
21
- export function refuseLiveResume(runId, liveStatus) {
22
- return refusal(400, "run " + runId + " is still " + liveStatus + " — stop it before resuming", "run_live", "run_id", "failed|stopped", liveStatus);
23
- }
24
- /** resume/reproduce, no durable record (1930-1932 / 2011-2014). */
25
- export function refuseNoDurableRecord(runId) {
26
- return refusal(400, "no durable record for run " + JSON.stringify(runId), "run_unknown", "run_id");
27
- }
28
- /** resume, completed run. */
29
- export function refuseCompletedResume(runId) {
30
- return refusal(400, "run " + runId + " completed — nothing to resume", "run_completed", "run_id", "failed|stopped", "completed");
31
- }
32
- /** resume, neither failed nor stopped. */
33
- export function refuseUnresumable(runId, status) {
34
- const got = status === "" ? "unknown" : status;
35
- return refusal(400, "run " + runId + " is " + JSON.stringify(got) + " — resume needs failed or stopped", "run_not_resumable", "run_id", "failed|stopped", got);
36
- }
37
- /** resume, draft gone or half-written. */
38
- export function refuseUnusableRecord(runId) {
39
- return refusal(400, "run " +
40
- runId +
41
- " record is unusable (draft doc gone or half-written) — resubmit instead", "run_record_unusable", "run_id");
42
- }
43
- /** reproduce, live run. */
44
- export function refuseLiveReproduce(runId, liveStatus) {
45
- return refusal(400, "run " +
46
- runId +
47
- " is still " +
48
- liveStatus +
49
- " — wait for it to settle or stop it first", "run_live", "run_id", "completed|failed|stopped", liveStatus);
50
- }
51
- /** reproduce, cardless legacy row. */
52
- export function refuseCardlessReplay(runId) {
53
- return refusal(400, "run " +
54
- runId +
55
- " is a cardless legacy row (no draft_id) — compose a fresh card to replay it", "run_cardless", "draft_id", "doc-backed draft id", "absent");
56
- }
57
- /** reproduce, request body missing. */
58
- export function refuseMissingRequest(runId) {
59
- return refusal(400, "run " + runId + " has no recorded request body — cannot replay", "run_record_unusable", "run_id");
60
- }
61
- /** reproduce, request non-object. */
62
- export function refuseNonObjectRequest(runId, gotType) {
63
- return refusal(400, "run " + runId + " recorded a non-object request body", "run_record_unusable", "run_id", "object", gotType);
64
- }
3
+ // constructors that once lived here were deleted (the wire-chain
4
+
5
+ // throw RemoteError with their own runs/* codes directly — while
6
+ // carrying six envelope codes no table row owned, a latent
7
+ // unmapped-throw for the first future caller. Erasable-syntax TS
8
+ // only (node --experimental-strip-types): no enums, import type for
9
+ // types, .ts specifiers for relative imports.
10
+ export {};
65
11
  //# sourceMappingURL=queueLifecycle.js.map
@@ -9,8 +9,14 @@ export declare const RETRIES_MAX: number;
9
9
  /** The stderr line main() prints before exit(1).
10
10
  * NOTE the em-dash — byte-identical. */
11
11
  export declare function refuseStartLine(note: string): string;
12
- /** State root — MELITE_STATE_ROOT else <repo>/data/runs. */
13
- export declare function resolveStateRoot(repoRoot: string): string;
12
+
13
+
14
+
15
+
16
+ export declare function resolveStateRoot(config: Readonly<{
17
+ repoRoot?: string;
18
+ stateRoot?: string;
19
+ }>): string;
14
20
  /** Run-dir root — TEST_OUT_ROOT on test:true else OUT_ROOT (L3). */
15
21
  export declare function outRootFor(stateRoot: string, testFlag: boolean): string;
16
22
  /** Append-only journal path (LEDGER_PATH 2180: OUT_ROOT/_ledger). */
package/lib/queueLock.js CHANGED
@@ -22,12 +22,15 @@ export function refuseStartLine(note) {
22
22
  return ("[gateway] REFUSING TO START: " + note + " — one writer per state root");
23
23
  }
24
24
  // ── roots (STATE_ROOT/OUT_ROOT/TEST_OUT_ROOT) ───
25
- /** State root — MELITE_STATE_ROOT else <repo>/data/runs. */
26
- export function resolveStateRoot(repoRoot) {
27
- const override = process.env["MELITE_STATE_ROOT"] ?? "";
28
- if (override !== "")
29
- return override;
30
- return join(repoRoot, "data", "runs");
25
+
26
+
27
+
28
+
29
+ export function resolveStateRoot(config) {
30
+ const named = config.stateRoot ?? "";
31
+ if (named !== "")
32
+ return named;
33
+ return join(config.repoRoot ?? "", "data", "runs");
31
34
  }
32
35
  /** Run-dir root — TEST_OUT_ROOT on test:true else OUT_ROOT (L3). */
33
36
  export function outRootFor(stateRoot, testFlag) {
@@ -1,4 +1,5 @@
1
1
  import type { RunId } from "./queueCore.js";
2
+ import { type DraftId } from "@melite/contracts/benchStage";
2
3
  export interface ResurrectPlan {
3
4
  /** run_ids to re-queue, FIFO by created_at (order survives). */
4
5
  readonly order: RunId[];
@@ -27,7 +28,11 @@ export declare function graphRowsUsable(graph: unknown): boolean;
27
28
  * anything else throws (the raise road: plan + build agree on the
28
29
  * skip, never throw out). */
29
30
  export declare function sidecarList(value: unknown): unknown[];
30
- /** artifact names: the sidecar list filtered to non-empty strings. */
31
+ /** artifact names: non-empty strings ride; a mistyped entry takes
32
+ * the raise road (the caller orphans the record — the revived run
33
+ * never comes back short an artifact, unvoiced). Empty strings
34
+ * still filter: the writer's own harvest never emits them
35
+ * (runsExecute drops ""), so "" is absent, not a mistype. */
31
36
  export declare function artifactStrings(value: unknown): string[];
32
37
  /** created_at coerce: finite numbers ride; numeric strings parse;
33
38
  * everything else rides 0 and never throws (boot order for
@@ -41,7 +46,7 @@ export declare function coerceCreatedAt(value: unknown): number;
41
46
  export declare function durableRecordUsable(sidecarText: string, requestText: string, draftExists: boolean): boolean;
42
47
  /** Plan the resurrect (fs reads + order; the caller appends +
43
48
  * ledgers, or use bootResurrect below for the whole seam). */
44
- export declare function planResurrect(stateRoot: string, readSidecar?: (runId: string) => string | null, readRequest?: (runId: string) => string | null, draftExists?: (draftId: string) => boolean): ResurrectPlan;
49
+ export declare function planResurrect(stateRoot: string, readSidecar?: (runId: string) => string | null, readRequest?: (runId: string) => string | null, draftExists?: (draftId: DraftId) => boolean): ResurrectPlan;
45
50
  /** The state-root triple every boot seam takes (server.ts
46
51
  * bootState passes defaultAssetRoots through; the canonical layout
47
52
  * is runsRoot == stateRoot/output and ledgerPath ==
@@ -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);
@@ -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;
@@ -43,6 +52,98 @@ export declare function sidecarStageOf(stage: {
43
52
 
44
53
 
45
54
 
55
+
56
+
57
+
58
+
59
+
60
+
61
+
62
+
63
+
64
+ export interface GraphReceiptPair {
65
+ /** Workflow key count — the composed graph's node budget. */
66
+ readonly nodes: number;
67
+ /** Every judged doc key (scalar-valued), sorted. */
68
+ readonly populated: readonly string[];
69
+ /** The judged keys found in the graph, sorted. */
70
+ readonly carried: readonly string[];
71
+ /** The judged keys NOT found in the graph, sorted — the honesty face. */
72
+ readonly dropped: readonly string[];
73
+ readonly verdict: "complete" | "partial";
74
+ /** THE BAKE'S RECORD (study §7 item 2, the run voice): present
75
+ * iff the composed graph bakes or loads a refmod mod — read off
76
+ * the graph's own nodes (the extract/loader inputs VERBATIM),
77
+ * never off the doc, so the record cannot disagree with what
78
+ * the engine will actually run. Absent when no seat exists. */
79
+ readonly bake?: GraphReceiptBake;
80
+ }
81
+ /** The refmod bake's receipt: the graph-stated dials, the baked
82
+ * media count, the film's window count (one SamplerCustomAdvanced
83
+ * per window — the DiT pass set), and the run-voice price. */
84
+ export interface GraphReceiptBake {
85
+ /** "baked" = media bakes at run time (MiniMaxH3RefModExtract);
86
+ * "stems" = pre-baked .safetensors packs load (MiniMaxH3RefModsLoader). */
87
+ readonly source: "baked" | "stems";
88
+ readonly mode?: string;
89
+ readonly pool?: number;
90
+ readonly refinement_steps?: number;
91
+ readonly save?: boolean;
92
+ /** refs_image.* + refs_video.* slots the extract stacks. */
93
+ readonly visual_refs?: number;
94
+ /** loader mod_N slots ≠ "(none)". */
95
+ readonly stems?: number;
96
+ /** One SamplerCustomAdvanced per film window. */
97
+ readonly windows: number;
98
+ /** "bake: <steps> refinement steps × <refs> ref(s) × <windows> windows" */
99
+ readonly price: string;
100
+ }
101
+ /** One stage's queue-time doc→graph evidence row. */
102
+ export interface GraphReceiptStageRow extends GraphReceiptPair {
103
+ readonly stage: string;
104
+ }
105
+ /** The run-level fold of the per-stage rows (what `_flow.json`
106
+ * carries as `graph_receipt`, beside `compose_echo`). */
107
+ export interface GraphReceipt extends GraphReceiptPair {
108
+ /** Per-stage rows, in registration order. */
109
+ readonly stages: readonly GraphReceiptStageRow[];
110
+ /** THE ENGINE'S PROMPT ID — minted ENGINE-SIDE at POST /prompt,
111
+ * so it CANNOT exist at queue time. The execute outcome fold
112
+ * stamps it (runsExecute's runOne, beside the harvested
113
+ * result_outputs.prompt_id), and settle's sidecar rewrite
114
+ * carries it to disk. Absent until the run has submitted. */
115
+ readonly prompt_id?: string;
116
+ }
117
+ /** THE RECEIPT SPINE: receipt one doc against one composed
118
+ * workflow (the `{workflow, output_nodes}` envelope the card walk
119
+ * yields — only `workflow`'s node inputs are judged).
120
+ * @param params the run door's admitted doc params (the snapshot's
121
+ * own row — bench stage row params, or the card arm's admitted
122
+ * request body)
123
+ * @param composed the card walk's composed envelope
124
+ * @returns the pair — node count, populated/carried/dropped
125
+ * (sorted), verdict `complete` iff nothing dropped */
126
+ export declare function graphReceiptOf(params: Record<string, unknown>, composed: {
127
+ readonly workflow: unknown;
128
+ }): GraphReceiptPair;
129
+ /** Name one stage's pair with its stage id (the per-stage rows
130
+ * inside the run-level `graph_receipt`). */
131
+ export declare function graphReceiptStageOf(stage: string, pair: GraphReceiptPair): GraphReceiptStageRow;
132
+ /** Fold per-stage rows into the run-level receipt (nodes SUM —
133
+ * the run's graph key space; populated/carried/dropped the
134
+ * sorted union; verdict `complete` iff every stage is). */
135
+ export declare function graphReceiptFoldOf(rows: readonly GraphReceiptStageRow[], promptId?: string): GraphReceipt;
136
+
137
+
138
+
139
+
140
+
141
+
142
+
143
+
144
+
145
+
146
+
46
147
  export declare function variantOfBodies(bodies: unknown[]): string | undefined;
47
148
  /** The sidecar document: KEY ORDER as (run_id, status, error,
48
149
  * stages, skipped_stages, artifacts, created_at, test, draft_id,
@@ -58,13 +159,14 @@ export declare function sidecarDoc(args: {
58
159
  artifacts: string[];
59
160
  createdAt: number;
60
161
  testFlag: boolean;
61
- draftId: string;
162
+ draftId: DraftId;
62
163
  pipeline: string;
63
164
  graph: GraphRow[];
64
165
  /** THE SNAPSHOT KEYS (strokes 45/45d, carried stroke 48): the exact
65
166
  * card + bench that ran. Absent when unstamped (inline runs)
66
167
  * the pinned prefix above never shifts. */
67
168
  cardSnapshot?: unknown;
169
+ cardRecipe?: unknown;
68
170
  benchSnapshot?: unknown;
69
171
  /** F-6(b) ADMISSION WARNINGS (the film lane's VRAM-pressure
70
172
  * warn): the status row spells it `warnings` too — one spelling
@@ -80,6 +182,13 @@ export declare function sidecarDoc(args: {
80
182
  calls: number;
81
183
  benchRev: number | null;
82
184
  };
185
+ /** THE SERVED-GRAPH RECEIPT (the silent UI-drop purge's P1):
186
+ * the queue-time doc→graph evidence, run-level fold with its
187
+ * per-stage rows inside. The status row spells it
188
+ * `graph_receipt` too. Absent when the run composed no card
189
+ * stage (the receipt judges the card compose, never the
190
+ * verbatim inline envelope). */
191
+ graphReceipt?: GraphReceipt;
83
192
 
84
193
 
85
194
 
@@ -115,6 +224,10 @@ export declare function sidecarDoc(args: {
115
224
  reused_existing: boolean;
116
225
  voice_file: string;
117
226
  };
227
+
228
+
229
+
230
+ replaySuspect?: boolean;
118
231
  }): Record<string, unknown>;
119
232
  /** The door name the run started with (_pipeline_of 2111-2119:
120
233
  * exactly one of flow | flow_inline | model — the sidecar's
@@ -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')
@@ -33,6 +29,159 @@ export function sidecarStageOf(stage) {
33
29
  out.merged = true;
34
30
  return out;
35
31
  }
32
+ /** A v1-judged scalar: the receipt's scope gate. */
33
+ function receiptScalarOf(value) {
34
+ if (typeof value === "string")
35
+ return value.trim() !== "" ? value : undefined;
36
+ if (typeof value === "number")
37
+ return Number.isFinite(value) ? value : undefined;
38
+ if (typeof value === "boolean")
39
+ return value;
40
+ return undefined;
41
+ }
42
+ /** THE RECEIPT SPINE: receipt one doc against one composed
43
+ * workflow (the `{workflow, output_nodes}` envelope the card walk
44
+ * yields — only `workflow`'s node inputs are judged).
45
+ * @param params the run door's admitted doc params (the snapshot's
46
+ * own row — bench stage row params, or the card arm's admitted
47
+ * request body)
48
+ * @param composed the card walk's composed envelope
49
+ * @returns the pair — node count, populated/carried/dropped
50
+ * (sorted), verdict `complete` iff nothing dropped */
51
+ export function graphReceiptOf(params, composed) {
52
+ const carried = new Set();
53
+ let nodes = 0;
54
+ let windows = 0;
55
+ let bake;
56
+ const workflow = composed.workflow;
57
+ if (workflow !== null && typeof workflow === "object" && !Array.isArray(workflow)) {
58
+ for (const node of Object.values(workflow)) {
59
+ if (node === null || typeof node !== "object" || Array.isArray(node))
60
+ continue;
61
+ nodes += 1;
62
+ const cls = node.class_type;
63
+ if (cls === "SamplerCustomAdvanced")
64
+ windows += 1;
65
+ const inputs = node.inputs;
66
+ if (inputs === null || typeof inputs !== "object" || Array.isArray(inputs))
67
+ continue;
68
+ for (const v of Object.values(inputs)) {
69
+ if (typeof v === "string" || typeof v === "number" || typeof v === "boolean")
70
+ carried.add(v);
71
+ }
72
+ // THE BAKE RECORD (study §7 item 2): read off the graph's own
73
+ // seat nodes — the extract's declared dials verbatim, the
74
+ // ref count from its autogrow slots, the price string the run
75
+ // voice renders. One bake per graph; the visual seat wins
76
+ // over a stems-only loader (the per-call replace law).
77
+ if (cls === "MiniMaxH3RefModExtract" || cls === "MiniMaxH3RefModsLoader") {
78
+ const inp = inputs;
79
+ if (cls === "MiniMaxH3RefModExtract") {
80
+ const visualRefs = Object.keys(inp).filter((k) => k.startsWith("refs_image.") || k.startsWith("refs_video.")).length;
81
+ bake = {
82
+ source: "baked",
83
+ ...(typeof inp["mode"] === "string" ? { mode: inp["mode"] } : {}),
84
+ ...(typeof inp["pool_h"] === "number" ? { pool: inp["pool_h"] } : {}),
85
+ ...(typeof inp["identity"] === "number" ? { refinement_steps: inp["identity"] } : {}),
86
+ ...(typeof inp["save"] === "boolean" ? { save: inp["save"] } : {}),
87
+ visual_refs: visualRefs,
88
+ windows,
89
+ price: "",
90
+ };
91
+ }
92
+ else {
93
+ const stems = Object.entries(inp).filter(([k, v]) => /^mod_\d+$/.test(k) && v !== "(none)").length;
94
+ bake = { source: "stems", stems, windows, price: "" };
95
+ }
96
+ }
97
+ }
98
+ }
99
+ if (bake !== undefined) {
100
+ const windows_ = windows;
101
+ bake = bake.source === "baked"
102
+ ? {
103
+ ...bake,
104
+ windows: windows_,
105
+ price: "bake: " + String(bake.refinement_steps ?? "?") + " refinement steps × "
106
+ + String(bake.visual_refs ?? 0) + (bake.visual_refs === 1 ? " ref × " : " refs × ")
107
+ + String(windows_) + (windows_ === 1 ? " window" : " windows"),
108
+ }
109
+ : {
110
+ ...bake,
111
+ windows: windows_,
112
+ price: "bake: " + String(bake.stems ?? 0) + (bake.stems === 1 ? " stem × " : " stems × ")
113
+ + String(windows_) + (windows_ === 1 ? " window" : " windows"),
114
+ };
115
+ }
116
+ const populated = [];
117
+ const found = [];
118
+ const missed = [];
119
+ for (const [key, value] of Object.entries(params)) {
120
+ const scalar = receiptScalarOf(value);
121
+ if (scalar === undefined)
122
+ continue;
123
+ populated.push(key);
124
+ (carried.has(scalar) ? found : missed).push(key);
125
+ }
126
+ populated.sort();
127
+ found.sort();
128
+ missed.sort();
129
+ return {
130
+ nodes,
131
+ populated,
132
+ carried: found,
133
+ dropped: missed,
134
+ verdict: missed.length === 0 ? "complete" : "partial",
135
+ ...(bake !== undefined ? { bake } : {}),
136
+ };
137
+ }
138
+ /** Name one stage's pair with its stage id (the per-stage rows
139
+ * inside the run-level `graph_receipt`). */
140
+ export function graphReceiptStageOf(stage, pair) {
141
+ return {
142
+ stage,
143
+ nodes: pair.nodes,
144
+ populated: [...pair.populated],
145
+ carried: [...pair.carried],
146
+ dropped: [...pair.dropped],
147
+ verdict: pair.verdict,
148
+ ...(pair.bake !== undefined ? { bake: pair.bake } : {}),
149
+ };
150
+ }
151
+ /** Fold per-stage rows into the run-level receipt (nodes SUM —
152
+ * the run's graph key space; populated/carried/dropped the
153
+ * sorted union; verdict `complete` iff every stage is). */
154
+ export function graphReceiptFoldOf(rows, promptId) {
155
+ const union = (pick) => {
156
+ const s = new Set();
157
+ for (const r of rows)
158
+ for (const k of pick(r))
159
+ s.add(k);
160
+ return [...s].sort();
161
+ };
162
+ let nodes = 0;
163
+ let complete = true;
164
+ for (const r of rows) {
165
+ nodes += r.nodes;
166
+ if (r.verdict !== "complete")
167
+ complete = false;
168
+ }
169
+ return {
170
+ nodes,
171
+ populated: union((r) => r.populated),
172
+ carried: union((r) => r.carried),
173
+ dropped: union((r) => r.dropped),
174
+ verdict: complete ? "complete" : "partial",
175
+ stages: rows.map((r) => graphReceiptStageOf(r.stage, r)),
176
+ // THE BAKE rides the fold: the first stage that carries one
177
+ // (the card run's single stage; a multi-stage flow receipts the
178
+ // first bake seat it composes).
179
+ ...(rows.find((r) => r.bake !== undefined)?.bake !== undefined
180
+ ? { bake: rows.find((r) => r.bake !== undefined).bake }
181
+ : {}),
182
+ ...(promptId !== undefined && promptId !== "" ? { prompt_id: promptId } : {}),
183
+ };
184
+ }
36
185
 
37
186
 
38
187
 
@@ -81,21 +230,43 @@ export function sidecarDoc(args) {
81
230
  // reaches this. Derived from the very stages the doc stores, so
82
231
  // digest and array can never disagree; every writer (queued,
83
232
  // settled, resurrect) shares this one seat.
84
- stage_ids: args.stages.map((s) => s.id).filter((id) => id !== "").join(","),
233
+
234
+ // the digest is the bench read's MEMBERSHIP TICKET
235
+ // (melite-construct's withLastRun joins stage_ids against the
236
+ // bench draft's row ids) — a single-card press composes the
237
+ // card's own skeleton ('generate'), a namespace the draft doc
238
+ // never heard of, so the ticket takes the bench_stage_id seam
239
+ // first and falls back to the row id only when the draft
240
+ // address is absent (inline runs, multi-row bench loops — those
241
+ // stamp each row's own id). The skeleton survives on the stage
242
+ // row's own `id`, named beside its draft address.
243
+ stage_ids: args.stages
244
+ .map((s) => (s.bench_stage_id !== undefined && s.bench_stage_id !== "" ? s.bench_stage_id : s.id))
245
+ .filter((id) => id !== "")
246
+ .join(","),
85
247
  ...(args.exportName !== undefined && args.exportName !== "" ? { export_name: args.exportName } : {}),
86
248
  ...(args.exportPath !== undefined && args.exportPath !== "" ? { export_path: args.exportPath } : {}),
87
249
  ...(args.variant !== undefined && args.variant !== "" ? { variant: args.variant } : {}),
88
250
  ...(args.loudness !== undefined ? { loudness: args.loudness } : {}),
89
251
  ...(args.voiceFreshness !== undefined ? { voice_freshness: args.voiceFreshness } : {}),
252
+ ...(args.replaySuspect === true ? { replay_suspect: true } : {}),
90
253
  error: args.error !== "" ? JSON.stringify(args.error).slice(0, 20000) : "",
91
254
  stages: args.stages,
92
255
  skipped_stages: [...args.skippedStages],
93
256
  artifacts: [...args.artifacts],
94
257
  graph: args.graph,
95
258
  ...(args.cardSnapshot !== undefined ? { card_snapshot: args.cardSnapshot } : {}),
259
+ // THE RECIPE (the F27 cure): the admitted card doc — envelope
260
+ // lifted, stanza unwrapped — is a DIFFERENT document from the
261
+ // request that carried it (the raw body is `_request.json`, an
262
+ // envelope the compose never read); restore overlays THIS key so a
263
+ // restored stage is re-editable, never a fresh timeline with the
264
+ // artifact pasted in.
265
+ ...(args.cardRecipe !== undefined ? { card_recipe: args.cardRecipe } : {}),
96
266
  ...(args.benchSnapshot !== undefined ? { bench_snapshot: args.benchSnapshot } : {}),
97
267
  ...(args.warnings !== undefined && args.warnings.length > 0 ? { warnings: [...args.warnings] } : {}),
98
268
  ...(args.composeEcho !== undefined ? { compose_echo: args.composeEcho } : {}),
269
+ ...(args.graphReceipt !== undefined ? { graph_receipt: args.graphReceipt } : {}),
99
270
  ...(args.sourceEcho !== undefined ? { source_echo: args.sourceEcho } : {}),
100
271
  };
101
272
  }