@melite/estate-queue 0.0.0-stage → 0.1.4-alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +557 -0
- package/lib/bakeParams.d.ts +17 -0
- package/lib/bakeParams.js +182 -0
- package/lib/bench.d.ts +24 -0
- package/lib/bench.js +121 -0
- package/lib/cardsArmError.d.ts +18 -0
- package/lib/cardsArmError.js +33 -0
- package/lib/cardsCompose.d.ts +41 -0
- package/lib/cardsCompose.js +247 -0
- package/lib/cardsDangling.d.ts +16 -0
- package/lib/cardsDangling.js +168 -0
- package/lib/cardsFacts.d.ts +74 -0
- package/lib/cardsFacts.js +64 -0
- package/lib/cardsLanes.d.ts +33 -0
- package/lib/cardsLanes.js +115 -0
- package/lib/cardsRegistry.d.ts +316 -0
- package/lib/cardsRegistry.js +1274 -0
- package/lib/cardsVariant.d.ts +28 -0
- package/lib/cardsVariant.js +190 -0
- package/lib/discloseRegistry.d.ts +94 -0
- package/lib/discloseRegistry.js +154 -0
- package/lib/filmLead.d.ts +4 -0
- package/lib/filmLead.js +17 -0
- package/lib/filmMemoryWarn.d.ts +27 -0
- package/lib/filmMemoryWarn.js +99 -0
- package/lib/flowsData.d.ts +179 -0
- package/lib/flowsData.js +547 -0
- package/lib/flowsFamilyCompose.d.ts +48 -0
- package/lib/flowsFamilyCompose.js +191 -0
- package/lib/flowsRegistryRows.d.ts +10 -0
- package/lib/flowsRegistryRows.js +378 -0
- package/lib/index.d.ts +50 -0
- package/lib/index.js +66 -0
- package/lib/ledgerTail.d.ts +20 -0
- package/lib/ledgerTail.js +123 -0
- package/lib/loadPlane.d.ts +93 -0
- package/lib/loadPlane.js +553 -0
- package/lib/loadRegistry.d.ts +22 -0
- package/lib/loadRegistry.js +55 -0
- package/lib/manageOps.d.ts +21 -0
- package/lib/manageOps.js +142 -0
- package/lib/managePlane.d.ts +120 -0
- package/lib/managePlane.js +1515 -0
- package/lib/manageProbe.d.ts +57 -0
- package/lib/manageProbe.js +154 -0
- package/lib/manageRegistry.d.ts +28 -0
- package/lib/manageRegistry.js +75 -0
- package/lib/managerRail.d.ts +33 -0
- package/lib/managerRail.js +91 -0
- package/lib/mediaKinds.d.ts +3 -0
- package/lib/mediaKinds.js +2 -0
- package/lib/queue.d.ts +9 -0
- package/lib/queue.js +76 -0
- package/lib/queueCore.d.ts +69 -0
- package/lib/queueCore.js +124 -0
- package/lib/queueLifecycle.d.ts +26 -0
- package/lib/queueLifecycle.js +65 -0
- package/lib/queueLock.d.ts +54 -0
- package/lib/queueLock.js +195 -0
- package/lib/queueResurrect.d.ts +59 -0
- package/lib/queueResurrect.js +249 -0
- package/lib/queueRetry.d.ts +36 -0
- package/lib/queueRetry.js +24 -0
- package/lib/queueSidecar.d.ts +145 -0
- package/lib/queueSidecar.js +182 -0
- package/lib/queueSubmit.d.ts +31 -0
- package/lib/queueSubmit.js +117 -0
- package/lib/queueSweep.d.ts +30 -0
- package/lib/queueSweep.js +121 -0
- package/lib/resurrect.d.ts +6 -0
- package/lib/resurrect.js +18 -0
- package/lib/rootsManifest.d.ts +11 -0
- package/lib/rootsManifest.js +11 -0
- package/lib/runStatus.d.ts +7 -0
- package/lib/runStatus.js +21 -0
- package/lib/runsChange.d.ts +53 -0
- package/lib/runsChange.js +63 -0
- package/lib/runsErrorCodes.d.ts +2 -0
- package/lib/runsErrorCodes.js +15 -0
- package/lib/runsExecute.d.ts +26 -0
- package/lib/runsExecute.js +356 -0
- package/lib/runsGates.d.ts +161 -0
- package/lib/runsGates.js +306 -0
- package/lib/runsList.d.ts +78 -0
- package/lib/runsList.js +580 -0
- package/lib/runsRefusalVoices.d.ts +9 -0
- package/lib/runsRefusalVoices.js +44 -0
- package/lib/runsRegistry.d.ts +253 -0
- package/lib/runsRegistry.js +1750 -0
- package/lib/runsSourceEcho.d.ts +54 -0
- package/lib/runsSourceEcho.js +275 -0
- package/lib/runsStart.d.ts +121 -0
- package/lib/runsStart.js +528 -0
- package/lib/runsTypes.d.ts +183 -0
- package/lib/runsTypes.js +282 -0
- package/lib/runsValidate.d.ts +5 -0
- package/lib/runsValidate.js +31 -0
- package/lib/runsValidateArms.d.ts +7 -0
- package/lib/runsValidateArms.js +285 -0
- package/lib/runsValidateInline.d.ts +6 -0
- package/lib/runsValidateInline.js +82 -0
- package/lib/runsValidateRefusals.d.ts +7 -0
- package/lib/runsValidateRefusals.js +18 -0
- package/lib/runsValidateServe.d.ts +15 -0
- package/lib/runsValidateServe.js +254 -0
- package/lib/runsValidateShared.d.ts +84 -0
- package/lib/runsValidateShared.js +88 -0
- package/lib/runsValidateStages.d.ts +25 -0
- package/lib/runsValidateStages.js +491 -0
- package/lib/runsValidateSweeps.d.ts +6 -0
- package/lib/runsValidateSweeps.js +143 -0
- package/lib/service.d.ts +45 -0
- package/lib/service.js +81 -0
- package/lib/skillFrontmatter.d.ts +11 -0
- package/lib/skillFrontmatter.js +46 -0
- package/lib/skillFs.d.ts +19 -0
- package/lib/skillFs.js +80 -0
- package/lib/skillPlane.d.ts +98 -0
- package/lib/skillPlane.js +263 -0
- package/lib/skillRegistry.d.ts +23 -0
- package/lib/skillRegistry.js +55 -0
- package/lib/skillRows.d.ts +126 -0
- package/lib/skillRows.js +466 -0
- package/lib/toolProjection.d.ts +30 -0
- package/lib/toolProjection.js +142 -0
- package/lib/vocab.d.ts +6 -0
- package/lib/vocab.js +18 -0
- package/package.json +47 -4
- package/README.md +0 -3
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
// bakeParams.ts — the AnnyBakeParams serve belt: params_json
|
|
2
|
+
// preset-dialect validation rides the initial_validators gate
|
|
3
|
+
// (bake_params initials refuse BEFORE any run registers).
|
|
4
|
+
// TS-native: the estate voice,
|
|
5
|
+
// renders, and the PyNum literal-holder are deleted.
|
|
6
|
+
//
|
|
7
|
+
// Erasable-syntax TS only (node --experimental-strip-types).
|
|
8
|
+
export function vErr(loc, msg, input) {
|
|
9
|
+
return { loc, msg, input };
|
|
10
|
+
}
|
|
11
|
+
/** The validation-error render: one "path: message" line per
|
|
12
|
+
* failure (model name heads model-level errors). */
|
|
13
|
+
export function renderErrors(model, errs) {
|
|
14
|
+
const lines = [];
|
|
15
|
+
for (const e of errs) {
|
|
16
|
+
const loc = e.loc.map(String).join(".");
|
|
17
|
+
lines.push((loc === "" ? model : loc) + ": " + e.msg);
|
|
18
|
+
}
|
|
19
|
+
return lines.join("\n");
|
|
20
|
+
}
|
|
21
|
+
/** Strict float slot: finite numbers ride; anything else errors. */
|
|
22
|
+
function parseFloatLax(v, loc, errs) {
|
|
23
|
+
if (typeof v === "number") {
|
|
24
|
+
if (!Number.isFinite(v)) {
|
|
25
|
+
errs.push(vErr(loc, "Input should be a valid number", v));
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
return v;
|
|
29
|
+
}
|
|
30
|
+
errs.push(vErr(loc, "Input should be a valid number", v));
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
function isPlainObject(v) {
|
|
34
|
+
if (typeof v !== "object" || v === null || Array.isArray(v))
|
|
35
|
+
return false;
|
|
36
|
+
const proto = Object.getPrototypeOf(v);
|
|
37
|
+
return proto === Object.prototype;
|
|
38
|
+
}
|
|
39
|
+
/** Required-field fetch (missing -> Field required on the parent). */
|
|
40
|
+
function reqField(v, key, loc, errs) {
|
|
41
|
+
if (!(key in v) || v[key] === undefined) {
|
|
42
|
+
errs.push(vErr([...loc, key], "Field required", v));
|
|
43
|
+
return { found: false, value: undefined };
|
|
44
|
+
}
|
|
45
|
+
return { found: true, value: v[key] };
|
|
46
|
+
}
|
|
47
|
+
/** Extra-key sweep (definition-order fields first, extras last in
|
|
48
|
+
* input order.) */
|
|
49
|
+
function extraSweep(v, known, loc, errs) {
|
|
50
|
+
for (const k of Object.keys(v)) {
|
|
51
|
+
if (!known.has(k)) {
|
|
52
|
+
errs.push(vErr([...loc, k], "Extra inputs are not permitted", v[k]));
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function validFloatTuple(v, loc, errs) {
|
|
57
|
+
if (!Array.isArray(v)) {
|
|
58
|
+
errs.push(vErr(loc, "value must be an array", v));
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
const items = [...v];
|
|
62
|
+
const nums = [];
|
|
63
|
+
let bad = false;
|
|
64
|
+
for (let i = 0; i < items.length; i++) {
|
|
65
|
+
const n = parseFloatLax(items[i], [...loc, i], errs);
|
|
66
|
+
if (n === null)
|
|
67
|
+
bad = true;
|
|
68
|
+
else
|
|
69
|
+
nums.push(n);
|
|
70
|
+
}
|
|
71
|
+
return bad ? null : { items, nums };
|
|
72
|
+
}
|
|
73
|
+
/** Validate a served params_json through the AnnyBakeParams shape
|
|
74
|
+
* (the serve-side belt). Failures render with the wire string as
|
|
75
|
+
* input, not the parsed doc.
|
|
76
|
+
* Returns the failure text, or null. */
|
|
77
|
+
export function validateBakeParams(s) {
|
|
78
|
+
let doc;
|
|
79
|
+
try {
|
|
80
|
+
doc = JSON.parse(s);
|
|
81
|
+
}
|
|
82
|
+
catch (exc) {
|
|
83
|
+
const msg = exc instanceof Error
|
|
84
|
+
? exc.message
|
|
85
|
+
:
|
|
86
|
+
|
|
87
|
+
String(exc);
|
|
88
|
+
return renderErrors("AnnyBakeParams", [
|
|
89
|
+
vErr([], "params_json is not JSON: " + msg, s),
|
|
90
|
+
]);
|
|
91
|
+
}
|
|
92
|
+
if (!isPlainObject(doc)) {
|
|
93
|
+
return renderErrors("AnnyBakeParams", [
|
|
94
|
+
vErr([], "params_json must be a JSON object, got " + (typeof doc), s),
|
|
95
|
+
]);
|
|
96
|
+
}
|
|
97
|
+
const errs = [];
|
|
98
|
+
let dialect = "";
|
|
99
|
+
const rd = reqField(doc, "dialect", [], errs);
|
|
100
|
+
if (!rd.found)
|
|
101
|
+
dialect = "";
|
|
102
|
+
else if (rd.value !== "authored" && rd.value !== "estimated") {
|
|
103
|
+
errs.push(vErr([], "Input should be 'authored' or 'estimated'", rd.value));
|
|
104
|
+
}
|
|
105
|
+
else
|
|
106
|
+
dialect = rd.value;
|
|
107
|
+
let phenotype = null;
|
|
108
|
+
const rp = reqField(doc, "phenotype", [], errs);
|
|
109
|
+
if (!rp.found)
|
|
110
|
+
phenotype = null;
|
|
111
|
+
else {
|
|
112
|
+
const t = validFloatTuple(rp.value, ["phenotype"], errs);
|
|
113
|
+
phenotype = t === null ? null : t.nums;
|
|
114
|
+
}
|
|
115
|
+
let locals = [];
|
|
116
|
+
let localsBad = false;
|
|
117
|
+
if ("local_changes" in doc && doc["local_changes"] !== undefined) {
|
|
118
|
+
const lv = doc["local_changes"];
|
|
119
|
+
if (!isPlainObject(lv)) {
|
|
120
|
+
errs.push(vErr([], "params_json local_changes must be an object", lv));
|
|
121
|
+
localsBad = true;
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
for (const k of Object.keys(lv)) {
|
|
125
|
+
const n = parseFloatLax(lv[k], ["local_changes", k], errs);
|
|
126
|
+
if (n === null)
|
|
127
|
+
localsBad = true;
|
|
128
|
+
else
|
|
129
|
+
locals.push({ name: k, value: n });
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
let scale = null;
|
|
134
|
+
if ("scale" in doc && doc["scale"] !== undefined && doc["scale"] !== null) {
|
|
135
|
+
const t = validFloatTuple(doc["scale"], ["scale"], errs);
|
|
136
|
+
if (t !== null)
|
|
137
|
+
scale = t.nums;
|
|
138
|
+
}
|
|
139
|
+
extraSweep(doc, new Set(["dialect", "phenotype", "local_changes", "scale"]), [], errs);
|
|
140
|
+
if (errs.length > 0 || phenotype === null || localsBad) {
|
|
141
|
+
return renderErrors("AnnyBakeParams", errs);
|
|
142
|
+
}
|
|
143
|
+
const fail = (msg) => renderErrors("AnnyBakeParams", [vErr([], msg, s)]);
|
|
144
|
+
if (dialect === "authored") {
|
|
145
|
+
if (phenotype.length !== 11) {
|
|
146
|
+
return fail("authored phenotype wants 11 dims, got " + phenotype.length +
|
|
147
|
+
" — the dims are gender/age/muscle/weight/height/proportions/cupsize/firmness/african/asian/caucasian");
|
|
148
|
+
}
|
|
149
|
+
for (let i = 0; i < phenotype.length; i++) {
|
|
150
|
+
const n = phenotype[i];
|
|
151
|
+
if (!(n >= 0.0 && n <= 1.0)) {
|
|
152
|
+
return fail("authored phenotype[" + i + "] = " + String(n) + " outside 0.0..1.0");
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
if (scale !== null) {
|
|
156
|
+
return fail("authored takes local_changes, not scale (that is the estimated dialect)");
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
if (phenotype.length !== 6) {
|
|
161
|
+
return fail("estimated phenotype wants 6 dims, got " + phenotype.length +
|
|
162
|
+
" (the estimator's identity coefficients, not the 11 authoring dims)");
|
|
163
|
+
}
|
|
164
|
+
if (scale === null) {
|
|
165
|
+
return fail("estimated wants scale (the estimator run's measurement vector)");
|
|
166
|
+
}
|
|
167
|
+
if (scale.length !== 139) {
|
|
168
|
+
return fail("estimated scale wants 139 entries, got " + scale.length);
|
|
169
|
+
}
|
|
170
|
+
if (locals.length > 0) {
|
|
171
|
+
return fail("estimated bakes phenotype+scale only — local_changes would be silently ignored (that is the authored dialect)");
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
for (const e of locals) {
|
|
175
|
+
if (!(e.value >= -1.0 && e.value <= 2.0)) {
|
|
176
|
+
return fail("local_changes[" + JSON.stringify(e.name) + "] = " +
|
|
177
|
+
String(e.value) + " outside -1.0..2.0");
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
return null;
|
|
181
|
+
}
|
|
182
|
+
//# sourceMappingURL=bakeParams.js.map
|
package/lib/bench.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/** One bench stage's picks — the card it composes and the model it
|
|
2
|
+
* names (the model is unstated unless explicitly put in params). */
|
|
3
|
+
export interface StagePick {
|
|
4
|
+
readonly card: string | null;
|
|
5
|
+
readonly model: string | null;
|
|
6
|
+
}
|
|
7
|
+
/** The process's melite boot instant — pinned once, survives the
|
|
8
|
+
* estate's re-apply churn (each re-apply re-imports modules; the
|
|
9
|
+
* globalThis pin keeps ONE cutoff per process). */
|
|
10
|
+
export declare function benchBootMs(): number;
|
|
11
|
+
export declare function benchDir(): string;
|
|
12
|
+
/** Cheap change signal — name+mtime+size over EVERY bench doc
|
|
13
|
+
* (cutoff never applies here: any write, live or stale, must
|
|
14
|
+
* retrigger the poll so the catalog follows the bench). */
|
|
15
|
+
export declare function benchFingerprint(): Promise<string>;
|
|
16
|
+
/** The LIVE bench's stage picks — docs written during this
|
|
17
|
+
* process's life only (the boot cutoff; stale docs from dead
|
|
18
|
+
* sessions are invisible by law). */
|
|
19
|
+
export declare function benchPicks(): Promise<StagePick[]>;
|
|
20
|
+
/** The sync twin of benchPicks — for sync surfaces (buildSkillIndex
|
|
21
|
+
* rides the seat handler synchronously). Same law: live docs only
|
|
22
|
+
* (mtime >= the process boot), malformed docs contribute nothing. */
|
|
23
|
+
export declare function benchPicksSync(): StagePick[];
|
|
24
|
+
//# sourceMappingURL=bench.d.ts.map
|
package/lib/bench.js
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
// bench.ts — THE LIVE BENCH (the selection's only source,
|
|
2
|
+
|
|
3
|
+
// surface — skill catalog, skill index, anything — may list craft
|
|
4
|
+
// the bench does not hold. The bench docs live in the drafts
|
|
5
|
+
// storage (one bench-session-<uuid>.json per chat session);
|
|
6
|
+
// a stage landing writes one mid-session.
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
// (mtime >= the process's first melite boot). A doc from a dead
|
|
11
|
+
// session must NEVER speak into a fresh one — the operator's two
|
|
12
|
+
// chats were injected at turn one by exactly such a stale file
|
|
13
|
+
// (my own test residue, hours old). The cutoff is pinned ONCE PER
|
|
14
|
+
// PROCESS on globalThis so the estate's re-apply churn (fresh
|
|
15
|
+
// module instances every ~21s) can never reset it.
|
|
16
|
+
import { readdir, readFile, stat } from "node:fs/promises";
|
|
17
|
+
import { readFileSync, readdirSync, statSync } from "node:fs";
|
|
18
|
+
import { join } from "node:path";
|
|
19
|
+
import { dshHomePath } from "@deepseek-ai/dsh-home-paths";
|
|
20
|
+
/** The process's melite boot instant — pinned once, survives the
|
|
21
|
+
* estate's re-apply churn (each re-apply re-imports modules; the
|
|
22
|
+
* globalThis pin keeps ONE cutoff per process). */
|
|
23
|
+
export function benchBootMs() {
|
|
24
|
+
const g = globalThis;
|
|
25
|
+
g.__meliteBenchBootMs ??= Date.now();
|
|
26
|
+
return g.__meliteBenchBootMs;
|
|
27
|
+
}
|
|
28
|
+
/** The cutoff with a 5s grace: mtime sub-ms precision vs the boot
|
|
29
|
+
* instant's integer ms can eat a same-tick write (probe:
|
|
30
|
+
* mtimeMs X.484 < bootMs X+1); the grace admits same-instant
|
|
31
|
+
* writes while dead-session docs (minutes/hours old) still die. */
|
|
32
|
+
function liveCutoffMs() {
|
|
33
|
+
return benchBootMs() - 5_000;
|
|
34
|
+
}
|
|
35
|
+
export function benchDir() {
|
|
36
|
+
return dshHomePath("storages", "drafts", "docs");
|
|
37
|
+
}
|
|
38
|
+
function benchFiles() {
|
|
39
|
+
return readdir(benchDir()).then((all) => all.filter((f) => f.startsWith("bench-") && f.endsWith(".json")), () => []);
|
|
40
|
+
}
|
|
41
|
+
/** Cheap change signal — name+mtime+size over EVERY bench doc
|
|
42
|
+
* (cutoff never applies here: any write, live or stale, must
|
|
43
|
+
* retrigger the poll so the catalog follows the bench). */
|
|
44
|
+
export async function benchFingerprint() {
|
|
45
|
+
const files = await benchFiles();
|
|
46
|
+
const parts = [];
|
|
47
|
+
for (const f of files) {
|
|
48
|
+
try {
|
|
49
|
+
const st = await stat(join(benchDir(), f));
|
|
50
|
+
parts.push(`${f}:${st.mtimeMs}:${st.size}`);
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
// a vanished doc between readdir and stat contributes nothing
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return parts.sort().join("|");
|
|
57
|
+
}
|
|
58
|
+
/** The LIVE bench's stage picks — docs written during this
|
|
59
|
+
* process's life only (the boot cutoff; stale docs from dead
|
|
60
|
+
* sessions are invisible by law). */
|
|
61
|
+
export async function benchPicks() {
|
|
62
|
+
const cutoff = liveCutoffMs();
|
|
63
|
+
const files = await benchFiles();
|
|
64
|
+
const picks = [];
|
|
65
|
+
for (const f of files) {
|
|
66
|
+
try {
|
|
67
|
+
const full = join(benchDir(), f);
|
|
68
|
+
const st = await stat(full);
|
|
69
|
+
if (st.mtimeMs < cutoff)
|
|
70
|
+
continue; // stale — a dead session's doc
|
|
71
|
+
const raw = JSON.parse(await readFile(full, "utf8"));
|
|
72
|
+
for (const stg of raw.record?.doc?.stages ?? raw.doc?.stages ?? []) {
|
|
73
|
+
picks.push({
|
|
74
|
+
card: typeof stg.card === "string" && stg.card !== "" ? stg.card : null,
|
|
75
|
+
model: typeof stg.params?.model === "string" && stg.params.model !== ""
|
|
76
|
+
? stg.params.model
|
|
77
|
+
: null,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
// a malformed or racing bench doc contributes nothing — never a crash
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return picks;
|
|
86
|
+
}
|
|
87
|
+
/** The sync twin of benchPicks — for sync surfaces (buildSkillIndex
|
|
88
|
+
* rides the seat handler synchronously). Same law: live docs only
|
|
89
|
+
* (mtime >= the process boot), malformed docs contribute nothing. */
|
|
90
|
+
export function benchPicksSync() {
|
|
91
|
+
const cutoff = liveCutoffMs();
|
|
92
|
+
let files = [];
|
|
93
|
+
try {
|
|
94
|
+
files = readdirSync(benchDir()).filter((f) => f.startsWith("bench-") && f.endsWith(".json"));
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
return [];
|
|
98
|
+
}
|
|
99
|
+
const picks = [];
|
|
100
|
+
for (const f of files) {
|
|
101
|
+
try {
|
|
102
|
+
const full = join(benchDir(), f);
|
|
103
|
+
if (statSync(full).mtimeMs < cutoff)
|
|
104
|
+
continue; // stale — dead session
|
|
105
|
+
const raw = JSON.parse(readFileSync(full, "utf8"));
|
|
106
|
+
for (const stg of raw.record?.doc?.stages ?? raw.doc?.stages ?? []) {
|
|
107
|
+
picks.push({
|
|
108
|
+
card: typeof stg.card === "string" && stg.card !== "" ? stg.card : null,
|
|
109
|
+
model: typeof stg.params?.model === "string" && stg.params.model !== ""
|
|
110
|
+
? stg.params.model
|
|
111
|
+
: null,
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
catch {
|
|
116
|
+
// malformed or racing — contributes nothing, never a crash
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return picks;
|
|
120
|
+
}
|
|
121
|
+
//# sourceMappingURL=bench.js.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare class CardArmError extends Error {
|
|
2
|
+
readonly status: number;
|
|
3
|
+
readonly code: string;
|
|
4
|
+
readonly loc?: string;
|
|
5
|
+
readonly expected?: string;
|
|
6
|
+
readonly got?: string;
|
|
7
|
+
constructor(status: number, message: string, code: string, loc?: string, expected?: string, got?: string);
|
|
8
|
+
}
|
|
9
|
+
/** The variant rail's own refusal (sampler_envelope) — a subclass
|
|
10
|
+
* so the WRITE seat can tell a DECL-own word from a selection
|
|
11
|
+
* failure (the audit's GAP 1: laneVerdict swallowed these with
|
|
12
|
+
* the selection tolerance, the bench admitted what the run
|
|
13
|
+
* refused, and no served face carried the envelope). Every
|
|
14
|
+
* instanceof CardArmError site still catches it. */
|
|
15
|
+
export declare class EnvelopeRefusal extends CardArmError {
|
|
16
|
+
}
|
|
17
|
+
export declare function phaseRefusal(phase: string, detail: string): CardArmError;
|
|
18
|
+
//# sourceMappingURL=cardsArmError.d.ts.map
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// cardsArmError.ts — the card-lane refusal error (status + the
|
|
2
|
+
// _refusal envelope shape). Extracted from cardsRegistry: the arm's
|
|
3
|
+
// error voice, shared by every card plane module (no cycles).
|
|
4
|
+
export class CardArmError extends Error {
|
|
5
|
+
status;
|
|
6
|
+
code;
|
|
7
|
+
loc;
|
|
8
|
+
expected;
|
|
9
|
+
got;
|
|
10
|
+
constructor(status, message, code, loc, expected, got) {
|
|
11
|
+
super(message);
|
|
12
|
+
this.status = status;
|
|
13
|
+
this.code = code;
|
|
14
|
+
if (loc !== undefined)
|
|
15
|
+
this.loc = loc;
|
|
16
|
+
if (expected !== undefined)
|
|
17
|
+
this.expected = expected;
|
|
18
|
+
if (got !== undefined)
|
|
19
|
+
this.got = got;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/** The variant rail's own refusal (sampler_envelope) — a subclass
|
|
23
|
+
* so the WRITE seat can tell a DECL-own word from a selection
|
|
24
|
+
* failure (the audit's GAP 1: laneVerdict swallowed these with
|
|
25
|
+
* the selection tolerance, the bench admitted what the run
|
|
26
|
+
* refused, and no served face carried the envelope). Every
|
|
27
|
+
* instanceof CardArmError site still catches it. */
|
|
28
|
+
export class EnvelopeRefusal extends CardArmError {
|
|
29
|
+
}
|
|
30
|
+
export function phaseRefusal(phase, detail) {
|
|
31
|
+
return new CardArmError(400, "card_compose phase " + phase + ": " + detail, "card_compose");
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=cardsArmError.js.map
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { FactsReads } from "@melite/comfyui-cordis";
|
|
2
|
+
import type { PreparedCard } from "./cardsRegistry.js";
|
|
3
|
+
import { type CardDeclRow, type ModelFactsRow } from "./cardsFacts.js";
|
|
4
|
+
export interface ComposeSeat {
|
|
5
|
+
cardDecls(facts?: Record<string, ModelFactsRow>): Record<string, CardDeclRow>;
|
|
6
|
+
modelFacts(): Record<string, import("./cardsFacts.js").ModelFactsRow>;
|
|
7
|
+
modelMids(): Set<string>;
|
|
8
|
+
objectInfo(): Record<string, unknown> | null;
|
|
9
|
+
primeObjectInfo(): Promise<boolean>;
|
|
10
|
+
readsSync(): FactsReads;
|
|
11
|
+
resolveCardFamily(mid: string, facts?: Record<string, import("./cardsFacts.js").ModelFactsRow>): string;
|
|
12
|
+
}
|
|
13
|
+
/** In-process compose (the core: steps 7-9) — per-call throwaway
|
|
14
|
+
* Context + ComfyUIService (owned by the call, never shared). */
|
|
15
|
+
/** THE NESTED STANZA UNWRAP (cli.ts:82-91, one function two seats):
|
|
16
|
+
* a `params` dict key in the incoming params IS the stanza;
|
|
17
|
+
* siblings merge over it. Exported so the phase-1 admission seat
|
|
18
|
+
* gates the LIFTED body, never the raw stanza shell. */
|
|
19
|
+
export declare function liftStanza(params: Record<string, unknown>): Record<string, unknown>;
|
|
20
|
+
export declare function composeOnce(deps: ComposeSeat, card: string, fam: string, params: Record<string, unknown>, runId: string, phase: string): Promise<Record<string, unknown>>;
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
export declare function admissionRefusal(deps: ComposeSeat, card: string, fam: string, lifted: Record<string, unknown>, phase: string): void;
|
|
26
|
+
/** Resolve + sweep + select + overlay + lift (steps 2-6):
|
|
27
|
+
* everything before compose. Throws CardArmError (the door maps
|
|
28
|
+
* it to the refusal envelope). `phase` stamps the phase-N voice
|
|
29
|
+
* on R1 selection refusals ("1" for validate/phase-1). Order
|
|
30
|
+
* mirrors resolve_card_model + the validate modelArm: artifact
|
|
31
|
+
* sweep FIRST (fail fast — a sloppy compose never runs), then
|
|
32
|
+
* legality, existence, the non-cordis arm check, selection,
|
|
33
|
+
* overlay, lift.
|
|
34
|
+
*
|
|
35
|
+
* @param factsArg a caller-resolved facts table. The validate
|
|
36
|
+
* door passes its degraded read (it answers from the catalog
|
|
37
|
+
* alone when the facts file is absent); omitted by every other
|
|
38
|
+
* seat, which takes the strict read here (`deps.modelFacts()`).
|
|
39
|
+
*/
|
|
40
|
+
export declare function prepareCardParams(deps: ComposeSeat, body: Record<string, unknown>, mid: string, phase: string, factsArg?: Record<string, ModelFactsRow>): PreparedCard;
|
|
41
|
+
//# sourceMappingURL=cardsCompose.d.ts.map
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
// cardsCompose.ts — the registry's compose core (extracted from
|
|
2
|
+
// cardsRegistry.ts, the god-file cut): param preparation (steps
|
|
3
|
+
// 2-6) and the in-process compose (steps 7-9). Explicit seat
|
|
4
|
+
// deps; no Service state beyond the accessors the seat passes.
|
|
5
|
+
import { ComfyUIService, resolveEngineBaseUrl, composeCards, ComposeRefusal, checkModelPresent, owningAtom } from "@melite/comfyui-cordis";
|
|
6
|
+
import { EngineContext, composeModPlane, loadFacts, theService } from "@melite/comfyui-cordis";
|
|
7
|
+
import { CardArmError, phaseRefusal } from "./cardsArmError.js";
|
|
8
|
+
import { findCardDangling } from "./cardsDangling.js";
|
|
9
|
+
import { selectCardVariant, stampCardOverlay, liftCardParams } from "./cardsVariant.js";
|
|
10
|
+
import { factsPath } from "./cardsFacts.js";
|
|
11
|
+
import { FLOW_ID_RE } from "./runsGates.js";
|
|
12
|
+
/** In-process compose (the core: steps 7-9) — per-call throwaway
|
|
13
|
+
* Context + ComfyUIService (owned by the call, never shared). */
|
|
14
|
+
/** THE NESTED STANZA UNWRAP (cli.ts:82-91, one function two seats):
|
|
15
|
+
* a `params` dict key in the incoming params IS the stanza;
|
|
16
|
+
* siblings merge over it. Exported so the phase-1 admission seat
|
|
17
|
+
* gates the LIFTED body, never the raw stanza shell. */
|
|
18
|
+
export function liftStanza(params) {
|
|
19
|
+
const inner = params["params"];
|
|
20
|
+
if (typeof inner === "object" && inner !== null && !Array.isArray(inner)) {
|
|
21
|
+
return {
|
|
22
|
+
...inner,
|
|
23
|
+
...Object.fromEntries(Object.entries(params).filter(([k]) => k !== "params")),
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
return params;
|
|
27
|
+
}
|
|
28
|
+
export async function composeOnce(deps, card, fam, params, runId, phase) {
|
|
29
|
+
// R3 (live): the engine's own node set arms the gate — an
|
|
30
|
+
// unreachable engine refuses CLOSED, never composes blind.
|
|
31
|
+
if (!(await deps.primeObjectInfo())) {
|
|
32
|
+
throw phaseRefusal(phase, "comfyui engine unreachable for live object_info (" +
|
|
33
|
+
resolveEngineBaseUrl() +
|
|
34
|
+
") — refusing closed (EXTENSION LAW: never compose unauthenticated)");
|
|
35
|
+
}
|
|
36
|
+
const oi = deps.objectInfo();
|
|
37
|
+
if (oi === null) {
|
|
38
|
+
throw phaseRefusal(phase, "comfyui live object_info primed empty — refusing closed (EXTENSION LAW: never compose unauthenticated)");
|
|
39
|
+
}
|
|
40
|
+
const ctx = new EngineContext();
|
|
41
|
+
await ctx.plugin({
|
|
42
|
+
apply(c) {
|
|
43
|
+
new ComfyUIService(c);
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// boot rides the SAME composition table as loadCardDefs —
|
|
48
|
+
// composeCards (exported from @melite/comfyui; the engine
|
|
49
|
+
// src/cards readdir glob died with the sweep). A card lands by
|
|
50
|
+
// adding its package + one table row; no shared-file edit.
|
|
51
|
+
await composeCards(ctx);
|
|
52
|
+
|
|
53
|
+
// service composed cards ONLY, so flavor rows were absent and
|
|
54
|
+
// every mod id refused at compose. Same composeModPlane as
|
|
55
|
+
// loadCardDefs — one composition, two riders.
|
|
56
|
+
await composeModPlane(ctx);
|
|
57
|
+
ctx.comfyui.setFacts(loadFacts(factsPath(), deps.readsSync()));
|
|
58
|
+
ctx.comfyui.setObjectInfo(oi);
|
|
59
|
+
|
|
60
|
+
// the compose door checks the run's touched provision rows
|
|
61
|
+
// against the models tree BEFORE composing — the module-level
|
|
62
|
+
// presence read (runtime tree + the endpoint mount leg, the
|
|
63
|
+
// manage door's own spelling). An absent weight refuses loud
|
|
64
|
+
// with its fetch URL, never a silent downstream death.
|
|
65
|
+
ctx.comfyui.setWeightPresent((relativePath, name) => checkModelPresent(relativePath, name) !== null);
|
|
66
|
+
// THE NESTED STANZA UNWRAP (cli.ts:82-91): a `params` dict key in
|
|
67
|
+
// the incoming params IS the stanza; siblings merge over it.
|
|
68
|
+
const lifted = liftStanza(params);
|
|
69
|
+
// THE ADMISSION CONTRACT GATE (cli.ts admission verbatim voice):
|
|
70
|
+
// every param key must be a declared knob or ride the admits row.
|
|
71
|
+
|
|
72
|
+
// question — phase1Card runs this gate BEFORE the lane-presence
|
|
73
|
+
// ENVIRONMENT gate, so the voice is box-independent; composeOnce
|
|
74
|
+
// re-runs the same function, never a divergent copy.)
|
|
75
|
+
admissionRefusal(deps, card, fam, lifted, phase);
|
|
76
|
+
try {
|
|
77
|
+
return ctx.comfyui.compose(card, fam, lifted, runId);
|
|
78
|
+
}
|
|
79
|
+
catch (e) {
|
|
80
|
+
if (e instanceof ComposeRefusal) {
|
|
81
|
+
throw phaseRefusal(phase, e.code + ": " + e.message);
|
|
82
|
+
}
|
|
83
|
+
throw phaseRefusal(phase, e instanceof Error
|
|
84
|
+
? e.message
|
|
85
|
+
:
|
|
86
|
+
|
|
87
|
+
String(e));
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
export function admissionRefusal(deps, card, fam, lifted, phase) {
|
|
95
|
+
const decls = deps.cardDecls();
|
|
96
|
+
// (prepareCardParams guarantees a registered card — its
|
|
97
|
+
// unknown-card arm refuses first — so the lookup never misses.)
|
|
98
|
+
const decl = decls[card];
|
|
99
|
+
const knobs = new Set(decl.schemaNames);
|
|
100
|
+
const admits = decl.admits;
|
|
101
|
+
|
|
102
|
+
// admission is the declared surface — and the mod fields a
|
|
103
|
+
// family ABSORBS are part of that surface (registerMod through
|
|
104
|
+
// the service; scope = declaring ∩ boarded, filtered to THIS
|
|
105
|
+
// run's family exactly as the emission scopes).
|
|
106
|
+
let modNames = new Set();
|
|
107
|
+
|
|
108
|
+
// unknown key that NAMES a mod pack gets a pointed refusal
|
|
109
|
+
// naming the flat fields (the maker burned a refusal-oracle
|
|
110
|
+
// turn on `qvoice_save` — the pack rides fields, never its own
|
|
111
|
+
// key). Pack → its family-scoped field names, same fold.
|
|
112
|
+
const packFields = new Map();
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
try {
|
|
117
|
+
// THE ROUTE→ATOM FOLD (qvoice across ALL qwen3-tts, operator
|
|
118
|
+
|
|
119
|
+
// specBody): flavors register for the FAMILY ATOM; a run at a
|
|
120
|
+
// VARIANT ROUTE address (qwen3-tts-base) asks with its owning
|
|
121
|
+
// atom or the absorbed surface drops and every mod param
|
|
122
|
+
// refuses as unknown (verified live by the maker: voice_name
|
|
123
|
+
// refused at the base route pre-fold). Atoms pass through
|
|
124
|
+
// unchanged (owningAtom: routes.get(id)?.modelId ?? id).
|
|
125
|
+
const envelopeAtom = owningAtom(fam);
|
|
126
|
+
for (const a of theService().cardModFields(card)) {
|
|
127
|
+
if (!a.families.includes(envelopeAtom))
|
|
128
|
+
continue;
|
|
129
|
+
const names = Object.keys(a.fields.dict ?? {});
|
|
130
|
+
for (const n of names)
|
|
131
|
+
modNames.add(n);
|
|
132
|
+
if (!packFields.has(a.pack))
|
|
133
|
+
packFields.set(a.pack, names);
|
|
134
|
+
}
|
|
135
|
+
/* v8 ignore stop */
|
|
136
|
+
}
|
|
137
|
+
catch {
|
|
138
|
+
// card defs not booted in this fiber — the mod surface is
|
|
139
|
+
// empty here; the knobs+admits rows still gate.
|
|
140
|
+
}
|
|
141
|
+
const admitted = (key) => knobs.has(key) ||
|
|
142
|
+
modNames.has(key) ||
|
|
143
|
+
admits.some((a) => a === key || (a.endsWith("*") && key.startsWith(a.slice(0, -1))));
|
|
144
|
+
const unknown = Object.keys(lifted).filter((k) => !admitted(k)).sort();
|
|
145
|
+
if (unknown.length > 0) {
|
|
146
|
+
const hints = unknown
|
|
147
|
+
.filter((k) => packFields.has(k))
|
|
148
|
+
.map((k) => " '" + k + "' is the '" + k + "' mod pack — it takes no key of its own; its fields ride flat top-level: " + packFields.get(k).join(", "));
|
|
149
|
+
throw phaseRefusal(phase, "compose-door: unknown param(s) on the " + card + " card: " + unknown.join(", ") +
|
|
150
|
+
" (admission is the declared surface — knobs + contract admits; see the card's TS definition)" +
|
|
151
|
+
(hints.length > 0 ? " Mod-pack keys:" + hints.join(";") : ""));
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
/** Resolve + sweep + select + overlay + lift (steps 2-6):
|
|
155
|
+
* everything before compose. Throws CardArmError (the door maps
|
|
156
|
+
* it to the refusal envelope). `phase` stamps the phase-N voice
|
|
157
|
+
* on R1 selection refusals ("1" for validate/phase-1). Order
|
|
158
|
+
* mirrors resolve_card_model + the validate modelArm: artifact
|
|
159
|
+
* sweep FIRST (fail fast — a sloppy compose never runs), then
|
|
160
|
+
* legality, existence, the non-cordis arm check, selection,
|
|
161
|
+
* overlay, lift.
|
|
162
|
+
*
|
|
163
|
+
* @param factsArg a caller-resolved facts table. The validate
|
|
164
|
+
* door passes its degraded read (it answers from the catalog
|
|
165
|
+
* alone when the facts file is absent); omitted by every other
|
|
166
|
+
* seat, which takes the strict read here (`deps.modelFacts()`).
|
|
167
|
+
*/
|
|
168
|
+
export function prepareCardParams(deps, body, mid, phase, factsArg) {
|
|
169
|
+
const facts = factsArg ?? deps.modelFacts();
|
|
170
|
+
const dangling = findCardDangling(body);
|
|
171
|
+
if (dangling !== null) {
|
|
172
|
+
const [location, ref, why] = dangling;
|
|
173
|
+
throw new CardArmError(400, "dangling artifact ref at " + JSON.stringify(location) + ": " + ref + " (" + why + ")", "invalid_request");
|
|
174
|
+
}
|
|
175
|
+
if (!FLOW_ID_RE.test(mid)) {
|
|
176
|
+
throw new CardArmError(400, "model id " + JSON.stringify(mid) + " is not a legal identifier", "invalid_request");
|
|
177
|
+
}
|
|
178
|
+
const resolves = mid in facts || deps.resolveCardFamily(mid, facts) in facts || deps.modelMids().has(mid);
|
|
179
|
+
if (!resolves) {
|
|
180
|
+
|
|
181
|
+
// Run-press law, the operator's wall): the bench's Run press
|
|
182
|
+
// addresses a family-less card by its OWN id — runCardStage's
|
|
183
|
+
// documented fallback, defaultFamilyForCard returning the
|
|
184
|
+
// card id when no family stands behind the card. The {model:}
|
|
185
|
+
// door therefore COMPOSES the card the press names (the GUI's
|
|
186
|
+
// shape is the contract), params verbatim: no family row, so
|
|
187
|
+
// no variant selection and no model-defaults overlay — the
|
|
188
|
+
// card's own declaration owns every default. The refusal
|
|
189
|
+
// below stays for ids that are neither family nor card.
|
|
190
|
+
const decls = deps.cardDecls(facts);
|
|
191
|
+
if (Object.prototype.hasOwnProperty.call(decls, mid)) {
|
|
192
|
+
const decl = decls[mid];
|
|
193
|
+
return {
|
|
194
|
+
mid,
|
|
195
|
+
// fam '' IS the model-less marker: the engine's compose
|
|
196
|
+
// lanes family-less cards on requiresModel===false +
|
|
197
|
+
// modelId==='' (service.ts:617) — a card id here would
|
|
198
|
+
// hit the not-boarded gate instead.
|
|
199
|
+
fam: "",
|
|
200
|
+
card: mid,
|
|
201
|
+
// the familyless compose lanes on modelId==='' (the
|
|
202
|
+
// engine's requiresModel===false arm) — the field the
|
|
203
|
+
|
|
204
|
+
modelId: "",
|
|
205
|
+
skeleton: decl.skeleton !== "" ? decl.skeleton : mid,
|
|
206
|
+
decl,
|
|
207
|
+
params: liftCardParams(body),
|
|
208
|
+
familyless: true,
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
throw new CardArmError(400, "no model unit for model: " + mid +
|
|
212
|
+
" (no .catalog.models row " + mid + " in the frozen discovery catalog and no family declares route " + mid +
|
|
213
|
+
" in its variants' cells — checked the class tree's _routes map)", "invalid_request");
|
|
214
|
+
}
|
|
215
|
+
const fam = deps.resolveCardFamily(mid, facts);
|
|
216
|
+
const famRow = facts[fam];
|
|
217
|
+
|
|
218
|
+
if (famRow === undefined) {
|
|
219
|
+
throw new CardArmError(400, "card_compose phase " + phase + ": model " + JSON.stringify(mid) +
|
|
220
|
+
" composes outside the cordis plane (no family row — the model resolves but the facts file declares nothing for it)", "card_compose");
|
|
221
|
+
}
|
|
222
|
+
const decls = deps.cardDecls(facts);
|
|
223
|
+
const decl = decls[famRow.card];
|
|
224
|
+
|
|
225
|
+
if (decl === undefined) {
|
|
226
|
+
throw new CardArmError(400, "card_compose phase " + phase + ": unknown card " + JSON.stringify(famRow.card) +
|
|
227
|
+
" (no registered card definition for the card model " + JSON.stringify(mid) + " names)", "card_compose");
|
|
228
|
+
}
|
|
229
|
+
const sel = selectCardVariant(mid, famRow, body, phase);
|
|
230
|
+
const stamped = stampCardOverlay(body, famRow, decl, sel, phase);
|
|
231
|
+
return {
|
|
232
|
+
mid,
|
|
233
|
+
fam,
|
|
234
|
+
// THE RESOLVED ADDRESS (the BROKEN-C fix): the variant's own
|
|
235
|
+
// re-point when it declares one, else the address the caller
|
|
236
|
+
// named. The engine resolves ITS facts row from this, so a base
|
|
237
|
+
// route composes the CLONE lane rather than the head's — the
|
|
238
|
+
// difference between a lawful bench state that runs and one
|
|
239
|
+
// that refuses at the door.
|
|
240
|
+
modelId: sel.variantRoute !== "" ? sel.variantRoute : mid,
|
|
241
|
+
card: famRow.card,
|
|
242
|
+
skeleton: decl.skeleton !== "" ? decl.skeleton : mid,
|
|
243
|
+
decl,
|
|
244
|
+
params: liftCardParams(stamped),
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
//# sourceMappingURL=cardsCompose.js.map
|