@melite/estate-queue 0.0.0-stage → 0.1.5-pre-alpha

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (131) hide show
  1. package/LICENSE +557 -0
  2. package/README.md +54 -2
  3. package/lib/bakeParams.d.ts +17 -0
  4. package/lib/bakeParams.js +182 -0
  5. package/lib/bench.d.ts +32 -0
  6. package/lib/bench.js +111 -0
  7. package/lib/cardsArmError.d.ts +61 -0
  8. package/lib/cardsArmError.js +57 -0
  9. package/lib/cardsCompose.d.ts +53 -0
  10. package/lib/cardsCompose.js +295 -0
  11. package/lib/cardsDangling.d.ts +16 -0
  12. package/lib/cardsDangling.js +213 -0
  13. package/lib/cardsFacts.d.ts +87 -0
  14. package/lib/cardsFacts.js +78 -0
  15. package/lib/cardsLanes.d.ts +43 -0
  16. package/lib/cardsLanes.js +178 -0
  17. package/lib/cardsRegistry.d.ts +404 -0
  18. package/lib/cardsRegistry.js +1543 -0
  19. package/lib/cardsVariant.d.ts +37 -0
  20. package/lib/cardsVariant.js +243 -0
  21. package/lib/discloseRegistry.d.ts +95 -0
  22. package/lib/discloseRegistry.js +156 -0
  23. package/lib/filmLead.d.ts +4 -0
  24. package/lib/filmLead.js +17 -0
  25. package/lib/filmMemoryWarn.d.ts +27 -0
  26. package/lib/filmMemoryWarn.js +99 -0
  27. package/lib/flowsData.d.ts +234 -0
  28. package/lib/flowsData.js +673 -0
  29. package/lib/flowsFamilyCompose.d.ts +45 -0
  30. package/lib/flowsFamilyCompose.js +191 -0
  31. package/lib/flowsParamsOverlay.d.ts +55 -0
  32. package/lib/flowsParamsOverlay.js +197 -0
  33. package/lib/flowsRegistryRows.d.ts +12 -0
  34. package/lib/flowsRegistryRows.js +520 -0
  35. package/lib/index.d.ts +47 -0
  36. package/lib/index.js +75 -0
  37. package/lib/ledgerTail.d.ts +20 -0
  38. package/lib/ledgerTail.js +123 -0
  39. package/lib/lifecycleLatch.d.ts +16 -0
  40. package/lib/lifecycleLatch.js +42 -0
  41. package/lib/loadPlane.d.ts +94 -0
  42. package/lib/loadPlane.js +570 -0
  43. package/lib/loadRegistry.d.ts +22 -0
  44. package/lib/loadRegistry.js +55 -0
  45. package/lib/manageOps.d.ts +27 -0
  46. package/lib/manageOps.js +162 -0
  47. package/lib/managePlane.d.ts +151 -0
  48. package/lib/managePlane.js +1790 -0
  49. package/lib/manageProbe.d.ts +48 -0
  50. package/lib/manageProbe.js +165 -0
  51. package/lib/manageRegistry.d.ts +66 -0
  52. package/lib/manageRegistry.js +113 -0
  53. package/lib/managerRail.d.ts +33 -0
  54. package/lib/managerRail.js +91 -0
  55. package/lib/mediaKinds.d.ts +3 -0
  56. package/lib/mediaKinds.js +2 -0
  57. package/lib/queue.d.ts +9 -0
  58. package/lib/queue.js +80 -0
  59. package/lib/queueCore.d.ts +72 -0
  60. package/lib/queueCore.js +128 -0
  61. package/lib/queueLifecycle.d.ts +2 -0
  62. package/lib/queueLifecycle.js +11 -0
  63. package/lib/queueLock.d.ts +60 -0
  64. package/lib/queueLock.js +198 -0
  65. package/lib/queueResurrect.d.ts +59 -0
  66. package/lib/queueResurrect.js +249 -0
  67. package/lib/queueRetry.d.ts +36 -0
  68. package/lib/queueRetry.js +24 -0
  69. package/lib/queueSidecar.d.ts +149 -0
  70. package/lib/queueSidecar.js +183 -0
  71. package/lib/queueSubmit.d.ts +82 -0
  72. package/lib/queueSubmit.js +191 -0
  73. package/lib/queueSweep.d.ts +30 -0
  74. package/lib/queueSweep.js +132 -0
  75. package/lib/resurrect.d.ts +6 -0
  76. package/lib/resurrect.js +18 -0
  77. package/lib/rootsManifest.d.ts +11 -0
  78. package/lib/rootsManifest.js +11 -0
  79. package/lib/runsChange.d.ts +61 -0
  80. package/lib/runsChange.js +79 -0
  81. package/lib/runsErrorCodes.d.ts +2 -0
  82. package/lib/runsErrorCodes.js +48 -0
  83. package/lib/runsExecute.d.ts +52 -0
  84. package/lib/runsExecute.js +494 -0
  85. package/lib/runsGates.d.ts +161 -0
  86. package/lib/runsGates.js +307 -0
  87. package/lib/runsList.d.ts +78 -0
  88. package/lib/runsList.js +574 -0
  89. package/lib/runsRefusalVoices.d.ts +9 -0
  90. package/lib/runsRefusalVoices.js +96 -0
  91. package/lib/runsRegistry.d.ts +351 -0
  92. package/lib/runsRegistry.js +2394 -0
  93. package/lib/runsSourceEcho.d.ts +81 -0
  94. package/lib/runsSourceEcho.js +341 -0
  95. package/lib/runsStart.d.ts +163 -0
  96. package/lib/runsStart.js +667 -0
  97. package/lib/runsTypes.d.ts +218 -0
  98. package/lib/runsTypes.js +289 -0
  99. package/lib/runsValidate.d.ts +5 -0
  100. package/lib/runsValidate.js +31 -0
  101. package/lib/runsValidateArms.d.ts +7 -0
  102. package/lib/runsValidateArms.js +339 -0
  103. package/lib/runsValidateInline.d.ts +6 -0
  104. package/lib/runsValidateInline.js +82 -0
  105. package/lib/runsValidateRefusals.d.ts +7 -0
  106. package/lib/runsValidateRefusals.js +18 -0
  107. package/lib/runsValidateServe.d.ts +15 -0
  108. package/lib/runsValidateServe.js +276 -0
  109. package/lib/runsValidateShared.d.ts +84 -0
  110. package/lib/runsValidateShared.js +88 -0
  111. package/lib/runsValidateStages.d.ts +32 -0
  112. package/lib/runsValidateStages.js +511 -0
  113. package/lib/runsValidateSweeps.d.ts +6 -0
  114. package/lib/runsValidateSweeps.js +143 -0
  115. package/lib/service.d.ts +63 -0
  116. package/lib/service.js +89 -0
  117. package/lib/skillFrontmatter.d.ts +11 -0
  118. package/lib/skillFrontmatter.js +46 -0
  119. package/lib/skillFs.d.ts +24 -0
  120. package/lib/skillFs.js +78 -0
  121. package/lib/skillPlane.d.ts +99 -0
  122. package/lib/skillPlane.js +269 -0
  123. package/lib/skillRegistry.d.ts +23 -0
  124. package/lib/skillRegistry.js +55 -0
  125. package/lib/skillRows.d.ts +127 -0
  126. package/lib/skillRows.js +468 -0
  127. package/lib/toolProjection.d.ts +30 -0
  128. package/lib/toolProjection.js +142 -0
  129. package/lib/vocab.d.ts +6 -0
  130. package/lib/vocab.js +18 -0
  131. package/package.json +48 -4
@@ -0,0 +1,161 @@
1
+ export { RETIRED_RUNNER_KNOBS, RETIRED_CARRY_KEYS, DOOR_KEYS } from "./vocab.js";
2
+ import { STAGE_PATCH_KEYS } from "@melite/contracts/benchStage";
3
+ export { STAGE_PATCH_KEYS };
4
+ /** flow_inline top-level keys (the served shape). */
5
+ export declare const INLINE_TOP_KEYS: readonly string[];
6
+ /** flow_inline stage keys (extra=forbid at the door) — the
7
+ * CONTRACT'S list now (benchStage.ts WIRE_STAGE_KEYS): the agent's
8
+ * bench projection needs the same rule to build a wire row, and two
9
+ * copies of a door's key list is how a reader and a writer drift. */
10
+ export declare const STAGE_KEYS: readonly string[];
11
+ /** Stage/flow identifier shape. */
12
+ export declare const FLOW_ID_RE: RegExp;
13
+
14
+
15
+
16
+ /** Draft id shape (DRAFT_ID_RE in @melite/estate-drafts spec.ts): 1..96 chars of [A-Za-z0-9_-]. */
17
+ export { DRAFT_ID_RE };
18
+ /** The strict-wire outcome: decoded text, or the exact 400 shape. */
19
+ export type StrictWire = {
20
+ text: string;
21
+ } | {
22
+ status: number;
23
+ payload: Record<string, unknown>;
24
+ };
25
+ /** Decode one strict body: "" decodes as {} (body.decode() or
26
+ * "{}"). The TEXT embeds the host parser's message — walls assert
27
+ * status + code + prefix, never bytes. */
28
+ export declare function decodeStrictBody(body: Uint8Array): StrictWire;
29
+ /** The strict JSON body parse — mirrors route() 4335-4340. Owned
30
+ * here; doors/uploads.ts re-exports it (wall-pinned address). */
31
+ export declare function parseStrictJson(body: Uint8Array): {
32
+ doc: unknown;
33
+ } | {
34
+ status: number;
35
+ payload: Record<string, unknown>;
36
+ };
37
+ /** Estate record check: a plain-prototype mapping, never an array,
38
+ * never null, never a class instance. */
39
+ export declare function isRecord(v: unknown): v is Record<string, unknown>;
40
+ /** typeof v === "string" (absent/null/non-strings refuse). */
41
+ export declare function isStringField(v: unknown): v is string;
42
+ /** typeof v === "boolean" — strict: 0/1/"true" refuse (gate). */
43
+ export declare function isBoolField(v: unknown): v is boolean;
44
+ /** typeof v === "number" — pure-JSON domain only. */
45
+ export declare function isNumberField(v: unknown): v is number;
46
+ /** Array.isArray — the closed-list shape gate. */
47
+ export declare function isListField(v: unknown): v is unknown[];
48
+ /** Dict gate: the estate isRecord FIRST (class-instance exclusion), then the
49
+ * schema (intent declaration — the guard carries the invariant). */
50
+ export declare function isDictField(v: unknown): v is Record<string, unknown>;
51
+ import { draftIdOk, DRAFT_ID_RE } from "@melite/estate-drafts";
52
+ export { draftIdOk };
53
+ /** The strict-body offense lists for one body. */
54
+ export interface StrictBodyOffense {
55
+ readonly bad: string[];
56
+ readonly carry: string[];
57
+ }
58
+ /** Split one body's keys into retired-knob vs pipe-carry offenses. */
59
+ export declare function checkStrictBody(body: Record<string, unknown>): StrictBodyOffense;
60
+ /** The uploads-body structure verdict. */
61
+ export type UploadsStructure = {
62
+ kind: "ok";
63
+ filename: string;
64
+ dataUrl: string;
65
+ } | {
66
+ kind: "not-object";
67
+ } | {
68
+ kind: "bad-filename";
69
+ } | {
70
+ kind: "bad-data";
71
+ };
72
+ /** Structure-gate one uploads doc (content rules stay in the door). */
73
+ export declare function checkUploadsStructure(doc: unknown): UploadsStructure;
74
+ /** Static verdict→voice table for the uploads door (every arm is
75
+ * fully static — the door does one lookup, no if-chain). */
76
+ export declare const UPLOADS_VOICE: Record<Exclude<UploadsStructure["kind"], "ok">, string>;
77
+ /** The start-envelope structure verdict. */
78
+ export type FlowsStartEnvelope = {
79
+ kind: "ok";
80
+ body: Record<string, unknown>;
81
+ testFlag: boolean;
82
+ } | {
83
+ kind: "not-object";
84
+ doc: unknown;
85
+ } | {
86
+ kind: "bad-test";
87
+ testFlag: unknown;
88
+ } | {
89
+ kind: "missing-draft";
90
+ } | {
91
+ kind: "malformed-draft";
92
+ draftId: string;
93
+ };
94
+ /** Structure-gate one start doc (draft lookup stays in the door). */
95
+ export declare function checkFlowsStartEnvelope(doc: unknown): FlowsStartEnvelope;
96
+ /** The flow_inline top-structure verdict. */
97
+ export type FlowInlineTop = {
98
+ kind: "ok";
99
+ rec: Record<string, unknown>;
100
+ } | {
101
+ kind: "not-object";
102
+ } | {
103
+ kind: "unknown-keys";
104
+ dead: string[];
105
+ } | {
106
+ kind: "missing-id-stages";
107
+ keys: string[];
108
+ } | {
109
+ kind: "bad-stages";
110
+ };
111
+ /** Structure-gate one flow_inline value. */
112
+ export declare function checkFlowInlineTop(inline: unknown): FlowInlineTop;
113
+ /** Static verdict→voice table for the flow_inline top gate (the
114
+ * two fully static arms — unknown-keys and missing-id-stages
115
+ * interpolate request values, so their mapping stays in the
116
+ * door). */
117
+ export declare const FLOW_INLINE_TOP_VOICE: Record<"not-object" | "bad-stages", string>;
118
+ /** One flow_inline stage's door-level structure verdict. */
119
+ export type FlowStageCheck = {
120
+ kind: "ok";
121
+ st: Record<string, unknown>;
122
+ } | {
123
+ kind: "not-object";
124
+ } | {
125
+ kind: "unknown-fields";
126
+ st: Record<string, unknown>;
127
+ extras: string[];
128
+ } | {
129
+ kind: "bad-id";
130
+ st: Record<string, unknown>;
131
+ };
132
+ /** Structure-gate one stage row (id legality via FLOW_ID_RE). */
133
+ export declare function checkFlowStage(st: unknown): FlowStageCheck;
134
+ /** The stage-patch structure verdict. */
135
+ export type DraftPatchCheck = {
136
+ kind: "ok";
137
+ patch: Record<string, unknown>;
138
+ } | {
139
+ kind: "not-object";
140
+ } | {
141
+ kind: "unknown-keys";
142
+ unknown: string[];
143
+ } | {
144
+ kind: "bad-result";
145
+ } | {
146
+ kind: "bad-runStatus";
147
+ } | {
148
+ kind: "bad-params";
149
+ } | {
150
+ kind: "bad-inputs";
151
+ } | {
152
+ kind: "bad-inputOutputs";
153
+ };
154
+ /** Structure-gate one stage patch value. */
155
+ export declare function checkDraftPatch(patch: unknown): DraftPatchCheck;
156
+ /** Static verdict→voice table for the stage-patch gate (every arm
157
+ * but unknown-keys is fully static — the door does one lookup for
158
+ * those; unknown-keys interpolates the request keys, so its
159
+ * mapping stays in the door). */
160
+ export declare const DRAFT_PATCH_VOICE: Record<Exclude<DraftPatchCheck["kind"], "ok" | "unknown-keys">, string>;
161
+ //# sourceMappingURL=runsGates.d.ts.map
@@ -0,0 +1,307 @@
1
+ // runsGates.ts — the gateway-plane admission gate.
2
+ //
3
+
4
+ // Python-era paths it names (core/params.ts, doors/*, runs.ts,
5
+ // bridges.ts) are gone with the gateway itself; the gates they
6
+ // described are the ones implemented here, and the path references
7
+ // are provenance, not addresses.
8
+ //
9
+ // CORDIS CORE law: the card plane
10
+ // admits params through schemastery (the card plane's Schemastery
11
+ // schemas, direct — the knob vocabulary; cli.ts's admission-contract
12
+ // gate refuses unknown keys
13
+ // LOUD). The gateway plane admits request bodies through THIS module:
14
+ // schemastery owns STRUCTURE (which keys, which types), the doors
15
+ // keep the pinned VOICE (shaped refusal bytes), and the refusal
16
+ // envelope rides the door plugins — structure moves, bytes do
17
+ // not.
18
+ //
19
+ // THE SPLIT (why schemastery cannot own the voice): schemastery
20
+ // ValidationError messages differ from the texts the walls pin
21
+ // byte-exact. So every helper returns a STRUCTURE verdict (boolean
22
+ // or a `kind`-tagged union) and the door maps it to its existing
23
+ // refusal text VERBATIM — no ValidationError message ever reaches
24
+ // the wire. Fully static mappings live HERE as voice tables (one
25
+ // door lookup); interpolating texts stay door if-chains.
26
+ //
27
+ // WHAT LIVES HERE vs WHAT STAYS:
28
+ // - HERE: the strict-body vocab SSOT (was duplicated across
29
+ // the old doors — one list now),
30
+ // the strict-wire decode (route() 4335-4340 — was triplicated),
31
+ // the draft_id_ok shape (was triplicated; the law now lives
32
+ // in @melite/estate-drafts),
33
+ // schemastery field/composite STRUCTURE verdicts for the
34
+ // pure-JSON-domain doors, and the static verdict→voice DATA
35
+ // tables (UPLOADS_VOICE, DRAFT_PATCH_VOICE,
36
+ // FLOW_INLINE_TOP_VOICE, DRAFT_PATCH_FIELDS).
37
+ // - STAYS in the doors (byte-pinned): value-content checks,
38
+ // mirroring coercions, dynamic refusal STRINGS, every refusal
39
+ // STRING (a formatting mini-language would be new machinery
40
+ // for zero byte gain — named residual).
41
+ // - STAYS hand-rolled by necessity (documented, not ported):
42
+ // isRecord — cosmokit's isPlainObject (which schemastery's
43
+ // object resolver uses) returns true for CLASS INSTANCES, so
44
+ // the prototype check stays estate-owned.
45
+ // runs.ts parseIntOrNull, the studios lax-coercion family, and
46
+ // bridges.ts manageActionName's .get-crash 500 leg likewise.
47
+ //
48
+ // Schemas are side-effect-free: no transforms, no autofix, results
49
+ // discarded except where returned — input docs are never mutated
50
+ // (the doors reuse `doc` after the verdict).
51
+ //
52
+ // Erasable-syntax TS only (node --experimental-strip-types): no
53
+ // enums, .ts specifiers for relative imports.
54
+ import z from "@deepseek-ai/schemastery";
55
+ // ── shared vocab SSOT ──────────
56
+ // The retired-runner-knob + pipe-carry + door-key sets were
57
+ // copy-pasted across the old doors (and
58
+ // draft_id_ok thrice). One list now — drift fails at the import,
59
+ // never silently at one door.
60
+ // Vocab SSOT (ledger row 27): the knob/carry/door sets live ONCE in
61
+ // ./vocab.ts — re-exported here for the gates' callers.
62
+ export { RETIRED_RUNNER_KNOBS, RETIRED_CARRY_KEYS, DOOR_KEYS } from "./vocab.js";
63
+ import { RETIRED_RUNNER_KNOBS, RETIRED_CARRY_KEYS, DOOR_KEYS } from "./vocab.js";
64
+ import { WIRE_STAGE_KEYS, STAGE_PATCH_KEYS } from "@melite/contracts/benchStage";
65
+ export { STAGE_PATCH_KEYS };
66
+ /** flow_inline top-level keys (the served shape). */
67
+ export const INLINE_TOP_KEYS = ["description", "id", "stages"];
68
+ /** flow_inline stage keys (extra=forbid at the door) — the
69
+ * CONTRACT'S list now (benchStage.ts WIRE_STAGE_KEYS): the agent's
70
+ * bench projection needs the same rule to build a wire row, and two
71
+ * copies of a door's key list is how a reader and a writer drift. */
72
+ export const STAGE_KEYS = WIRE_STAGE_KEYS;
73
+ /** Stage/flow identifier shape. */
74
+ export const FLOW_ID_RE = /^[a-z_][a-z0-9_-]*$/;
75
+
76
+
77
+
78
+ /** Draft id shape (DRAFT_ID_RE in @melite/estate-drafts spec.ts): 1..96 chars of [A-Za-z0-9_-]. */
79
+ // THE DRAFT ID GRAMMAR MIRRORS ITS OWNER (the census's H13: this copy
80
+ // had NO length cap, so a 200-char id passed this door and was
81
+ // refused by the next with a different voice). The drafts package
82
+ // OWNS the rule (DRAFT_ID_RE, 1..96) and this module re-exports that
83
+ // exact object — the drafts spec's own JSDoc says the queue
84
+ // re-exports it, which was false while the queue kept its own
85
+ // byte-identical copy. (The draft-id-grammar wall's old equality
86
+ // arm is deleted — with the mirror gone it compared one object
87
+ // with itself; the one-declaration law lives in closure-gate
88
+ // RULE 4d, and the sampling arms exercise the ONE grammar.)
89
+ export { DRAFT_ID_RE };
90
+ /** Decode one strict body: "" decodes as {} (body.decode() or
91
+ * "{}"). The TEXT embeds the host parser's message — walls assert
92
+ * status + code + prefix, never bytes. */
93
+ export function decodeStrictBody(body) {
94
+ const text = Buffer.from(body).toString("utf-8");
95
+ const src = text === "" ? "{}" : text;
96
+ try {
97
+ JSON.parse(src);
98
+ }
99
+ catch (exc) {
100
+ const msg = exc instanceof Error ? exc.message : String(exc);
101
+ return {
102
+ status: 400,
103
+ payload: { error: "bad JSON: " + msg, code: "bad_json" },
104
+ };
105
+ }
106
+ return { text: src };
107
+ }
108
+ /** The strict JSON body parse — mirrors route() 4335-4340. Owned
109
+ * here; doors/uploads.ts re-exports it (wall-pinned address). */
110
+ export function parseStrictJson(body) {
111
+ const wire = decodeStrictBody(body);
112
+ if (!("text" in wire))
113
+ return { status: wire.status, payload: wire.payload };
114
+ return { doc: JSON.parse(wire.text) };
115
+ }
116
+ // ── the object gate schemastery cannot own ──────────────────────
117
+ // See header: cosmokit isPlainObject accepts class instances, so a
118
+ // bare z.object() would take a class instance for a record.
119
+ // The prototype check excludes class instances; on the pure-JSON
120
+ // wire domain it agrees with typeof exactly (JSON.parse yields
121
+ // only plain-prototype values).
122
+ /** Estate record check: a plain-prototype mapping, never an array,
123
+ * never null, never a class instance. */
124
+ export function isRecord(v) {
125
+ if (typeof v !== "object" || v === null || Array.isArray(v))
126
+ return false;
127
+ const proto = Object.getPrototypeOf(v);
128
+ return proto === Object.prototype || proto === null;
129
+ }
130
+ // ── schemastery leaf schemas (STRUCTURE owners) ─────────────────
131
+ // `.required()` matters: without it, absent/undefined PASSES (the
132
+ // doors treat absent as a refusal, so the schema must too). Voices
133
+ // never escape — verdicts are booleans, messages stay in the doors.
134
+ /** The leaf vocabulary as data: gate name → required schema. One
135
+ * table, one runner — the five isXField helpers below are thin
136
+ * typed addresses over it (wall-pinned call sites). */
137
+ const LEAF = {
138
+ string: z.string().required(),
139
+ boolean: z.boolean().required(),
140
+ number: z.number().required(),
141
+ list: z.array(z.any()).required(),
142
+ dict: z.object({}).required(),
143
+ };
144
+ /** Run one leaf schema, returning the structure verdict only. */
145
+ function tryLeaf(schema, v) {
146
+ try {
147
+ z.resolve(v, schema, {});
148
+ return true;
149
+ }
150
+ catch {
151
+ return false;
152
+ }
153
+ }
154
+ /** typeof v === "string" (absent/null/non-strings refuse). */
155
+ export function isStringField(v) {
156
+ return tryLeaf(LEAF.string, v);
157
+ }
158
+ /** typeof v === "boolean" — strict: 0/1/"true" refuse (gate). */
159
+ export function isBoolField(v) {
160
+ return tryLeaf(LEAF.boolean, v);
161
+ }
162
+ /** typeof v === "number" — pure-JSON domain only. */
163
+ export function isNumberField(v) {
164
+ return tryLeaf(LEAF.number, v);
165
+ }
166
+ /** Array.isArray — the closed-list shape gate. */
167
+ export function isListField(v) {
168
+ return tryLeaf(LEAF.list, v);
169
+ }
170
+ /** Dict gate: the estate isRecord FIRST (class-instance exclusion), then the
171
+ * schema (intent declaration — the guard carries the invariant). */
172
+ export function isDictField(v) {
173
+ if (!isRecord(v))
174
+ return false;
175
+ return tryLeaf(LEAF.dict, v);
176
+ }
177
+ // draft_id_ok: the ONE address is @melite/estate-drafts (spec.ts —
178
+ // the SSOT re-home; the dead core's own copy is gone). Re-exported
179
+ // for the gates' callers.
180
+ import { draftIdOk, DRAFT_ID_RE } from "@melite/estate-drafts";
181
+ export { draftIdOk };
182
+ // ── shared key-set helper ───────────────────────────────────────
183
+ // Three composite gates refuse sorted unknown-key lists (flow top,
184
+ // stage, draft patch) — one helper, three tables.
185
+ /** Sorted keys of `v` outside `allowed`. */
186
+ function unknownKeys(v, allowed) {
187
+ return Object.keys(v).filter((k) => !allowed.includes(k)).sort();
188
+ }
189
+ /** Split one body's keys into retired-knob vs pipe-carry offenses. */
190
+ export function checkStrictBody(body) {
191
+ const bad = Object.keys(body).filter((k) => RETIRED_RUNNER_KNOBS.includes(k) ||
192
+ (k.startsWith("_") && !DOOR_KEYS.includes(k)));
193
+ const carry = Object.keys(body).filter((k) => RETIRED_CARRY_KEYS.includes(k));
194
+ return { bad, carry };
195
+ }
196
+ /** Structure-gate one uploads doc (content rules stay in the door). */
197
+ export function checkUploadsStructure(doc) {
198
+ if (!isRecord(doc))
199
+ return { kind: "not-object" };
200
+ const rawName = doc["filename"];
201
+ const dataUrl = doc["data"];
202
+ if (!isStringField(rawName))
203
+ return { kind: "bad-filename" };
204
+ if (!isStringField(dataUrl))
205
+ return { kind: "bad-data" };
206
+ return { kind: "ok", filename: rawName, dataUrl: dataUrl };
207
+ }
208
+ /** Static verdict→voice table for the uploads door (every arm is
209
+ * fully static — the door does one lookup, no if-chain). */
210
+ export const UPLOADS_VOICE = {
211
+ "not-object": "uploads: body must be a JSON object {filename, data}",
212
+ "bad-filename": "uploads: filename is required",
213
+ "bad-data": "uploads: data must be a FileReader data: URL",
214
+ };
215
+ /** Structure-gate one start doc (draft lookup stays in the door). */
216
+ export function checkFlowsStartEnvelope(doc) {
217
+ if (!isRecord(doc))
218
+ return { kind: "not-object", doc };
219
+ const testFlag = doc["test"] ?? false;
220
+ if (!isBoolField(testFlag))
221
+ return { kind: "bad-test", testFlag };
222
+ const draftId = doc["draft_id"];
223
+ if (typeof draftId !== "string" || draftId === "")
224
+ return { kind: "missing-draft" };
225
+ if (!draftIdOk(draftId))
226
+ return { kind: "malformed-draft", draftId };
227
+ return { kind: "ok", body: doc, testFlag };
228
+ }
229
+ /** Structure-gate one flow_inline value. */
230
+ export function checkFlowInlineTop(inline) {
231
+ if (!isRecord(inline))
232
+ return { kind: "not-object" };
233
+ const dead = unknownKeys(inline, INLINE_TOP_KEYS);
234
+ if (dead.length > 0)
235
+ return { kind: "unknown-keys", dead };
236
+ if (!("id" in inline) || !("stages" in inline)) {
237
+ return { kind: "missing-id-stages", keys: Object.keys(inline).sort() };
238
+ }
239
+ if (!Array.isArray(inline["stages"]) || inline["stages"].length === 0) {
240
+ return { kind: "bad-stages" };
241
+ }
242
+ return { kind: "ok", rec: inline };
243
+ }
244
+ /** Static verdict→voice table for the flow_inline top gate (the
245
+ * two fully static arms — unknown-keys and missing-id-stages
246
+ * interpolate request values, so their mapping stays in the
247
+ * door). */
248
+ export const FLOW_INLINE_TOP_VOICE = {
249
+ "not-object": "flow body must be a JSON object",
250
+ "bad-stages": "flow stages must be a non-empty list",
251
+ };
252
+ /** Structure-gate one stage row (id legality via FLOW_ID_RE). */
253
+ export function checkFlowStage(st) {
254
+ if (!isRecord(st))
255
+ return { kind: "not-object" };
256
+ const extras = unknownKeys(st, STAGE_KEYS);
257
+ if (extras.length > 0)
258
+ return { kind: "unknown-fields", st, extras };
259
+ const sid = String(st["id"] ?? "");
260
+ if (!FLOW_ID_RE.test(sid))
261
+ return { kind: "bad-id", st };
262
+ return { kind: "ok", st };
263
+ }
264
+ /** Per-field gates as data: key → leaf gate → refusal verdict, in
265
+ * the door's fixed shape-check order. The loop below walks this
266
+ * table; the isRecord pre-guard + unknown-keys arm stay explicit
267
+ * (different shapes, not table rows). */
268
+ const DRAFT_PATCH_FIELDS = [
269
+ ["result", "dict", "bad-result"],
270
+ ["runStatus", "string", "bad-runStatus"],
271
+ ["params", "dict", "bad-params"],
272
+ ["inputs", "list", "bad-inputs"],
273
+ ["inputOutputs", "list", "bad-inputOutputs"],
274
+ ];
275
+ /** Leaf gate by table name. */
276
+ const FIELD_GATES = {
277
+ string: isStringField,
278
+ list: isListField,
279
+ dict: isDictField,
280
+ };
281
+ /** Structure-gate one stage patch value. */
282
+ export function checkDraftPatch(patch) {
283
+ if (!isRecord(patch))
284
+ return { kind: "not-object" };
285
+ const unknown = unknownKeys(patch, STAGE_PATCH_KEYS);
286
+ if (unknown.length > 0)
287
+ return { kind: "unknown-keys", unknown };
288
+ for (const [key, gate, verdict] of DRAFT_PATCH_FIELDS) {
289
+ if (key in patch && !FIELD_GATES[gate](patch[key])) {
290
+ return { kind: verdict };
291
+ }
292
+ }
293
+ return { kind: "ok", patch };
294
+ }
295
+ /** Static verdict→voice table for the stage-patch gate (every arm
296
+ * but unknown-keys is fully static — the door does one lookup for
297
+ * those; unknown-keys interpolates the request keys, so its
298
+ * mapping stays in the door). */
299
+ export const DRAFT_PATCH_VOICE = {
300
+ "not-object": "patch body must be an object",
301
+ "bad-result": "stage patch 'result' must be dict",
302
+ "bad-runStatus": "stage patch 'runStatus' must be str",
303
+ "bad-params": "stage patch 'params' must be dict",
304
+ "bad-inputs": "stage patch 'inputs' must be list",
305
+ "bad-inputOutputs": "stage patch 'inputOutputs' must be list",
306
+ };
307
+ //# sourceMappingURL=runsGates.js.map
@@ -0,0 +1,78 @@
1
+ /** Leading-int read (sidecar tails): optional space, optional
2
+ * sign, then digits; 0 when no digits lead. */
3
+ export declare function parseLeadingInt(s: string): number;
4
+ /** sidecar_num: first `"key":`, strtol the tail, default when the key is absent. */
5
+ export declare function sidecarNum(text: string, key: string, dflt: number): number;
6
+ /** sidecar_str: BYTE-wise exact — first `"key":`, skip spaces/tabs, expect `"`, decode \\n \\r \\t \" \\ (any other escape lands literally — \u stays "u"), stop at cap-1 BYTES. Operates on the UTF-8 bytes (D5). */
7
+ export declare function sidecarStr(raw: Uint8Array, key: string, cap: number): string;
8
+ /** _sidecar_str_impl found-ness: only the runs-list status site reads it — a present-but-empty "status" serves "" (the gate then skips the row), while an absent/non-string key serves "unknown". */
9
+ export declare function sidecarStrFound(raw: Uint8Array, key: string, cap: number): [boolean, string];
10
+ export declare function artifactType(name: string): string;
11
+ interface MediaCand {
12
+ readonly rel: string;
13
+ readonly full: string;
14
+ }
15
+ /** _media_candidates: top-level files (non-underscore) then ONE level down (underscore + deeper dirs skipped), each tier byte-sorted. */
16
+ export declare function mediaCandidates(runDir: string): MediaCand[];
17
+ /** run_artifacts: image/video/audio/model rows (image capped at _MAX_IMGS — counted but unlisted past it), everything else skipped; the {truncated,listed,total} marker when entries went unlisted. */
18
+ /** path keeps the "./output/<run>/" literal. */
19
+ export declare function runArtifacts(runDir: string, outDirLiteral: string): Record<string, unknown>[];
20
+ /** _run_thumbnail: cached poster wins, else the first image candidate (same one-level rule, so nested-only runs still get a poster). */
21
+ export declare function runThumbnail(runDir: string, runId: string): string;
22
+ /** _run_dir_has_media: the media-FIRST sort key — top-level names, then one level down. */
23
+ /** NOTE the absences: NO `_` skip (a lone `_poster.jpg` counts), NO inner isdir check (a nested DIR named x.mp4 counts) — probed live, mirrored exactly. */
24
+ /** Gallery sets only (svg/bmp classify but do not list — the media-kinds.json contract). */
25
+ export declare function runDirHasMedia(runDir: string): boolean;
26
+ /** The RunRow gate — the row dict, or null when the gate refuses it (the caller logs LOUD and skips). */
27
+ /** Key order is the RunRow field order. */
28
+ export declare function runRowOrNull(row: {
29
+ run_id: string;
30
+ name: string;
31
+ flow: string;
32
+ status: string;
33
+ created_at: number;
34
+ prompt: string;
35
+ seed: number;
36
+ thumbnail: string;
37
+ artifacts: Record<string, unknown>[];
38
+ params: Record<string, unknown>;
39
+ draft_id: string;
40
+ /** THE STAGE-ID DIGEST (commission 015, §6 finding 6): the ids
41
+ * of the stages the run composed. Optional — older sidecars
42
+ * predate the digest, and such runs cannot name their stages. */
43
+ stage_ids?: string[];
44
+ /** THE EXPORT NAME (023's self-critique #4/#6): optional —
45
+ * older sidecars predate it, and only export lanes stamp it. */
46
+ export_name?: string;
47
+ /** THE EXPORT PATH (the export FULL PATH): optional — the
48
+ * engine-reported minted .qvoice absolute path; older sidecars
49
+ * predate it, load lanes stamp nothing. */
50
+ export_path?: string;
51
+ }): Record<string, unknown> | null;
52
+ /** Strict int parse: surrounding whitespace stripped, one optional
53
+ * sign, ASCII digits with single internal underscores ("1_0" ->
54
+ * 10). null = not an int (the 400 arm). */
55
+ export declare function parseIntOrNull(s: string): number | null;
56
+ /** parse_qs (drops blank values): first non-blank
57
+ * value wins; the shared ctx parseQuery keeps blanks, so the
58
+ * filter lives here (parse_qs default). */
59
+ export declare function firstQuery(qs: Record<string, string[]>, name: string, dflt: string): string;
60
+ /** The runs-list envelope (the restore port): the output-root scan, media-first + newest sort, the limit parse (raw STRING — the lane/remote pass the raw text; underscores parse, non-ints refuse), refused cards SKIPPED but counted. */
61
+ /** url/thumbnail are run-RELATIVE (the /v1/assets prefix died with the app — the header's law). */
62
+ export declare function listRuns(stateRoot: string, limit: number, hasDraft: (draftId: string) => Promise<boolean>): Promise<{
63
+ count: number;
64
+ runs: Record<string, unknown>[];
65
+ }>;
66
+
67
+
68
+
69
+
70
+
71
+
72
+
73
+ export declare function listRunsAcross(roots: string[], limit: number, hasDraft: (draftId: string) => Promise<boolean>): Promise<{
74
+ count: number;
75
+ runs: Record<string, unknown>[];
76
+ }>;
77
+ export {};
78
+ //# sourceMappingURL=runsList.d.ts.map