@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
@@ -3,6 +3,33 @@
3
3
  * like the engine's; the sliced tail keeps its case). */
4
4
  export declare const MEDIA_RUNS_PREFIX: string;
5
5
  export declare const ASSET_RUNS_PREFIX: string;
6
+ /** The gallery's read route (packages/web/infer-gallery/src/index.ts
7
+ * registers this exact path — retyped, never derived: no contract
8
+ * owns the gallery's spelling, so the twin names its owner here).
9
+ * Detection is case-insensitive like the engine's estate prefixes;
10
+ * the decoded tail keeps its case. Exported for the compose sweep
11
+ * (cardsDangling) — one spelling, both readers. */
12
+ export declare const GALLERY_ARTIFACT_PATH = "/infer-gallery/artifact";
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
+ export declare function galleryTail(t: string): string | null;
6
33
  export type SourceFace = "run" | "abs";
7
34
  /** A collected pointer: the VERBATIM string (history stamps what
8
35
  * the params held — the engine trims for staging, the record
@@ -1,3 +1,4 @@
1
+ import { isFile } from "./skillFs.js";
1
2
  import { segmentConfined, servableLeaf } from "@melite/contracts/mediaKinds";
2
3
 
3
4
  // every generation run carries history pointing at the files that
@@ -17,6 +18,15 @@ import { segmentConfined, servableLeaf } from "@melite/contracts/mediaKinds";
17
18
  // those arms and refuses them loud itself):
18
19
  // /melite-media/runs/<run>/<rel> (the media route)
19
20
  // /v1/assets/runs/<run>/<rel> (the assets route — same trees)
21
+ // /infer-gallery/artifact?path=<run>/<rel>
22
+ // (the gallery's read route — the
23
+ // restore stamp + the drill's
24
+ // artifact harvest mint this URL-
25
+ // encoded tail; the estate stages
26
+ // what it serves, so the guard
27
+ // reads it back onto the same
28
+ // trees instead of misfiling it
29
+ // as an absolute disk path)
20
30
  // <run-id>/<rel> (runs-relative tails; the first
21
31
  // segment must match the mint
22
32
  // grammar — prose with slashes
@@ -43,21 +53,76 @@ export const MEDIA_RUNS_PREFIX = RUN_MEDIA_PREFIX + "/";
43
53
  export const ASSET_RUNS_PREFIX = LEGACY_RUN_MEDIA_PREFIX + "/";
44
54
  /** The run-dir basename grammar (the mint law — media index.ts). */
45
55
  const RUN_ID = RUN_ID_RE;
56
+ /** The gallery's read route (packages/web/infer-gallery/src/index.ts
57
+ * registers this exact path — retyped, never derived: no contract
58
+ * owns the gallery's spelling, so the twin names its owner here).
59
+ * Detection is case-insensitive like the engine's estate prefixes;
60
+ * the decoded tail keeps its case. Exported for the compose sweep
61
+ * (cardsDangling) — one spelling, both readers. */
62
+ export const GALLERY_ARTIFACT_PATH = "/infer-gallery/artifact";
63
+
64
+
65
+
66
+
67
+
68
+
69
+
70
+
71
+
72
+
73
+
74
+
75
+
76
+
77
+
78
+
79
+
80
+
81
+
82
+ export function galleryTail(t) {
83
+ const lower = t.toLowerCase();
84
+ if (!lower.startsWith(GALLERY_ARTIFACT_PATH))
85
+ return null;
86
+ const next = lower[GALLERY_ARTIFACT_PATH.length];
87
+ if (next !== undefined && next !== "?")
88
+ return null;
89
+ let path = null;
90
+ try {
91
+ path = new URL(t, "http://source-echo.invalid").searchParams.get("path");
92
+ }
93
+ catch {
94
+ return null;
95
+ }
96
+ if (path === null || path === "")
97
+ return null;
98
+ return path;
99
+ }
46
100
  /** The detection grammar (runs on the trimmed string — the engine
47
101
  * trims before every arm, so detection sees what staging sees):
48
- * either estate prefix (either case), an absolute path, or a
49
- * run-tail whose first segment matches the mint grammar. Prose
50
- * with slashes never qualifies — no false refusals on prompts. */
102
+ * either estate prefix (either case), the gallery's artifact route,
103
+ * an absolute path, or a run-tail whose first segment matches the
104
+ * mint grammar. Prose with slashes never qualifies — no false
105
+ * refusals on prompts. The gallery face returns its tail already
106
+ * decoded (decoded: true) — the per-segment decode below must not
107
+ * run twice (a legal `%` in a filename would false-refuse as a bad
108
+ * escape); confinement still judges every segment. */
51
109
  function detectFace(t) {
52
110
  const lower = t.toLowerCase();
53
111
  // Both estate prefixes end in "/runs/" — one slice serves both
54
112
  // faces (detection is case-insensitive like the engine's; the
55
113
  // tail keeps its case).
56
114
  if (lower.startsWith(MEDIA_RUNS_PREFIX) || lower.startsWith(ASSET_RUNS_PREFIX)) {
57
- return { face: "run", rest: t.slice(lower.indexOf("/runs/") + "/runs/".length) };
115
+ return { face: "run", rest: t.slice(lower.indexOf("/runs/") + "/runs/".length), decoded: false };
58
116
  }
117
+
118
+ // serves — a gallery artifact URL resolves onto the same trees
119
+ // as the media route. Before the absolute arm: the URL starts
120
+ // with "/" and would otherwise misfile as a disk path.
121
+ const tail = galleryTail(t);
122
+ if (tail !== null)
123
+ return { face: "run", rest: tail, decoded: true };
59
124
  if (t.startsWith("/"))
60
- return { face: "abs", rest: t };
125
+ return { face: "abs", rest: t, decoded: false };
61
126
 
62
127
  // `t.includes("..")` substring ban refused a LEGAL name the engine
63
128
  // mints (`still..frame.png`) while judging the whole string —
@@ -78,7 +143,7 @@ function detectFace(t) {
78
143
  }
79
144
  if (!RUN_ID.test(decodedHead))
80
145
  return null;
81
- return { face: "run", rest: t };
146
+ return { face: "run", rest: t, decoded: false };
82
147
  }
83
148
  /** Collect every source pointer in a params tree (deep walk over
84
149
  * objects/arrays — card params nest refs inside calls, clips,
@@ -150,12 +215,21 @@ export function parseSourceRef(ref) {
150
215
  }
151
216
  const relParts = [];
152
217
  for (const seg of parts.slice(1)) {
218
+ // The gallery face arrives already decoded exactly once (the
219
+ // URL parser's doing, twinning the server) — decoding again
220
+ // would corrupt a legal `%` in a filename into a bad escape.
221
+ // Confinement judges every segment on every face.
153
222
  let decoded;
154
- try {
155
- decoded = decodeURIComponent(seg);
223
+ if (det.decoded) {
224
+ decoded = seg;
156
225
  }
157
- catch {
158
- throw new Error("malformed media source (bad percent-escape): " + JSON.stringify(ref));
226
+ else {
227
+ try {
228
+ decoded = decodeURIComponent(seg);
229
+ }
230
+ catch {
231
+ throw new Error("malformed media source (bad percent-escape): " + JSON.stringify(ref));
232
+ }
159
233
  }
160
234
  if (!segmentConfined(decoded)) {
161
235
  throw new Error("media source refuses traversal: " + JSON.stringify(ref));
@@ -187,14 +261,6 @@ function isDir(p) {
187
261
  return false;
188
262
  }
189
263
  }
190
- function isFile(p) {
191
- try {
192
- return statSync(p).isFile();
193
- }
194
- catch {
195
- return false;
196
- }
197
- }
198
264
  /** Resolve every pointer the way the engine stages it — run faces
199
265
  * walk the manifest trees (first root holding the RUN DIR wins,
200
266
  * the file rides under it — the server's and the stager's shared
@@ -1,13 +1,42 @@
1
+ import { type DraftId } from "@melite/contracts/benchStage";
1
2
  import type { EngineJson } from "@melite/comfyui-cordis";
2
- import type { QueueRefusal } from "./queue.js";
3
+ import type { FlowStageRow } from "./runsValidateShared.js";
4
+ import type { GraphReceiptStageRow, QueueRefusal } from "./queue.js";
5
+ export { envelopeRefusal, unknownDraftRefusal } from "./queueSubmit.js";
3
6
  import type { RunId } from "./queueCore.js";
4
7
  import type { RunRecord } from "./runsTypes.js";
5
8
  /** The door's refusal shape (status carries the HTTP class; the
6
9
  * remote folds it into RemoteError details). */
7
10
  export type StartRefusal = QueueRefusal;
8
- /** One compiled stage (the rim the worker splices). */
11
+ export declare function compiledStageRow(st: CompiledStage): FlowStageRow;
12
+ /** THE DOC-LOCAL DERIVATION (audits F-S4/S5): validate derives a
13
+ * row's expected kinds from the card ports BEFORE the lattice runs;
14
+ * a durable doc carries no cards, so the replay judge derives from
15
+ * the doc's own declared upstream outputs — an absent expected
16
+ * takes the upstream kind, and a wire to an upstream output the doc
17
+ * never declares refuses here with the lattice's link voice
18
+ * (kindsOk's mismatch arm would fire first and name the wrong
19
+ * fact). Declared expected rows re-judge exactly as validate did.
20
+ * An edge to a stage OUTSIDE the doc (the bench lane's cross-wire —
21
+ * the worker injects those stages at compose) is not doc-derivable
22
+ * and drops out of the judged rows: the judge runs only where the
23
+ * kinds were derivable, never a false refusal on the legal wire.
24
+ * A doc with ANY filled-outputs row skips the judge wholesale: its
25
+ * real channels live in the card plane (validate + the compose own
26
+ * those verdicts), and the doc is not self-describing. */
27
+ export declare function replayJudgeRows(compiled: {
28
+ stages: CompiledStage[];
29
+ }): FlowStageRow[];
9
30
  export interface CompiledStage {
10
31
  readonly id: string;
32
+
33
+
34
+
35
+
36
+
37
+
38
+
39
+ readonly benchStageId?: string;
11
40
  /** The stage's engine id (stroke 53): the card plane's engine or 'mcp:<server>'
12
41
  * — the door's engine gate admits exactly these; carried through
13
42
  * to the run rows so the worker dispatches by it. */
@@ -17,6 +46,11 @@ export interface CompiledStage {
17
46
  readonly expected: Record<string, EngineJson>;
18
47
  readonly outputNodes: Record<string, EngineJson>;
19
48
  readonly inputNames: Record<string, string>;
49
+ /** The stage DECLARED its outputs map (false = the engine-table
50
+ * fill supplied {default: ...}). The replay judge judges only
51
+ * fully-declared docs — a filled row's real channels live in the
52
+ * card plane (validate + the compose own those verdicts). */
53
+ readonly outputsDeclared: boolean;
20
54
  }
21
55
  /** flow_inline structural compile — door-verbatim (structure via
22
56
  * the admission verdicts, voice here; the engine policy +
@@ -33,20 +67,17 @@ export declare function compileFlowInline(inline: unknown, knownEngines?: readon
33
67
  } | StartRefusal;
34
68
  /** The door-selection gate: exactly one of flow / flow_inline /
35
69
  * model, in DOOR order for the ambiguity text (resolve_request
36
- * 302). Returns the selected door key, or the refusal. */
37
- export declare function selectSubmitDoor(body: Record<string, unknown>): {
38
- door: "flow" | "flow_inline" | "model";
70
+ * 302). Returns the selected door key, or the refusal. The
71
+ * `draftBench` option admits the DRAFT DOOR: a body with no door
72
+ * key over a live bench draft (the tool's familyless bench walk
73
+ * presses {test, draft_id} alone — a model key would select the
74
+ * card arm and hit the board check), which the caller restages
75
+ * onto the wired-bench compose. */
76
+ export declare function selectSubmitDoor(body: Record<string, unknown>, opts?: {
77
+ draftBench?: boolean;
78
+ }): {
79
+ door: "flow" | "flow_inline" | "model" | "draft";
39
80
  } | StartRefusal;
40
- /** The envelope refusal texts (door-verbatim, for the remote's
41
- * envelope walk). Kept as a table — one voice each, like the
42
- * admission gate's static tables. */
43
- export declare function envelopeRefusal(kind: "not-object" | "bad-test" | "missing-draft" | "malformed-draft", doc: unknown, detail?: {
44
- testFlag?: unknown;
45
- draftId?: string;
46
- }): StartRefusal;
47
- /** The unknown-draft refusal (door-verbatim; the probe rides the
48
- * caller's drafts domain — the remote hops the ctx seat). */
49
- export declare function unknownDraftRefusal(draftId: string): StartRefusal;
50
81
  /** The registration tail (door-verbatim): mint the id, route the
51
82
  * out root on the test flag, build the rich run row. The caller
52
83
  * (the remote) enqueues it on the queue core + kicks the pump.
@@ -56,14 +87,17 @@ export declare function registerCompiledRun(args: {
56
87
  stages: CompiledStage[];
57
88
  };
58
89
  testFlag: boolean;
59
- draftId: string;
90
+ /** The start body's own execute ceiling (the F8 burn; absent = the
91
+ * queue config decides). */
92
+ executeCeilMs?: number;
93
+ draftId: DraftId;
60
94
  stateRoot: string;
61
95
  enqueue: (row: {
62
96
  runId: RunId;
63
97
  status: string;
64
98
  error: string;
65
99
  createdAt: number;
66
- draftId: string;
100
+ draftId: DraftId;
67
101
  testFlag: boolean;
68
102
  stopFlag: boolean;
69
103
  }) => number;
@@ -102,6 +136,14 @@ export declare function registerCompiledRun(args: {
102
136
  * stamped and pipeline still rides the door. */
103
137
  cardId?: string;
104
138
  requestBody: Record<string, unknown>;
139
+ /** THE ADMITTED RECIPE (the F27 cure): the card doc the door
140
+ * admitted — envelope lifted, stanza unwrapped by the one lift —
141
+ * stamped beside the raw request echo so restore pastes what
142
+ * RAN, never a later draft edit. Absent on inline runs. */
143
+ cardRecipe?: {
144
+ card: string;
145
+ params: Record<string, unknown>;
146
+ };
105
147
  /** The flow arms' request initials (the start body's values for
106
148
  * the flow's declared initial validators, extracted after the
107
149
  * compile-time gate passed): threaded to the engine merge so
@@ -109,10 +151,31 @@ export declare function registerCompiledRun(args: {
109
151
  * initials, on the card arm, and on a hand-authored or
110
152
  * bench-composed inline doc. */
111
153
  initials?: Record<string, EngineJson>;
154
+ /** The FILE-kind subset of initials' keys (photo | glb) — the
155
+ * claim-time re-probe's contract (the row stamps it beside
156
+ * initials so the pump knows which entries to re-judge on
157
+ * disk). Absent when no file initials ride. */
158
+ initialFileKeys?: string[];
112
159
  /** The bench doc read at submit (stroke 45d) — the FULL workflow
113
160
  * the run was born from (all stages + intent), stamped verbatim
114
161
  * so the wand restores the whole flow, not just the ran card. */
115
162
  benchDoc?: Record<string, unknown>;
163
+
164
+
165
+
166
+ fam?: string;
167
+ /** The flow arm's {stageId: fam} ledger for the same probe (the
168
+ * stage rows stay schema-clean). */
169
+ stageFams?: Record<string, string>;
170
+ /** THE GRAPH-RECEIPT LEDGER (the silent UI-drop purge's P1):
171
+ * the per-stage queue-time doc→graph evidence rows, keyed by
172
+ * stage id. The flow/bench arms fill it through
173
+ * composeCardStageRow's receiptsOut; the card arm stamps its
174
+ * own single-stage row. Stamped on the run as the folded
175
+ * run-level receipt (per-stage rows inside), beside
176
+ * compose_echo — card-composed runs ride it; inline runs carry
177
+ * none (nothing composed). */
178
+ graphReceipts?: Record<string, GraphReceiptStageRow>;
116
179
  };
117
180
  }): Promise<{
118
181
  run: RunRecord;