@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/README.md ADDED
@@ -0,0 +1,55 @@
1
+ ---
2
+ description: The estate's run core as Cordis services — serial queue, live-run registry, manage and flows seats, the skill plane, and the runs gate vocabulary.
3
+ kind: package-library
4
+ ---
5
+
6
+ # @melite/estate-queue
7
+
8
+ `@melite/estate-queue` is the run-queue core of the estate: the serial-GPU
9
+ lock, journal, sidecars, boot sweep, the live-run registry the Typert
10
+ adapters delegate to, the manage seat, the flows seat, the bench picks, and
11
+ the skill plane the agent engine's spawn-injection reader rides. It calls
12
+ the engines seat to execute runs and the drafts seat for draft validation;
13
+ the estate bundle mounts it once per fiber (`inject: ["timer"]`), and the
14
+ runs-registry row mounts after queue, drafts, and card registry.
15
+
16
+ ## Contract
17
+
18
+ - Seats mounted: `ctx.queue` (QueueService — lock, ledger, sidecars,
19
+ bootSweep), `ctx.runs` (RunsRuntimeService — start/status/stop/list/
20
+ validate, onRunChange), `ctx.manage` (ManageGatewayService), and
21
+ `ctx.meliteFlows` (the flows seat, mounted first in the row).
22
+ - Config: `{ repoRoot? }` for the default `data/runs` state root;
23
+ `MELITE_STATE_ROOT` overrides it, and `MELITE_STATE_ROOTS`
24
+ (colon-separated) declares the cross-roots manifest, own root first.
25
+ - The submit vocabulary lives here: draft-id law (re-exported from
26
+ estate-drafts), run gates, refusals, validation, ledger tail. The skill
27
+ plane serves skills over the same storage melite_load reads.
28
+ - Declared exports: `.` (everything the row and its consumers import) and
29
+ `./package.json`.
30
+
31
+ ## Model Experience
32
+
33
+ ### Request context and condition
34
+
35
+ #### What the model sees
36
+
37
+ None directly — run state reaches a model only when a tool surface (for
38
+ example run-status or ledger-tail) projects this seat's rows into a tool
39
+ result, and the agent engine, not this package, inlines skill leaves into
40
+ briefs.
41
+
42
+ #### Token effect
43
+
44
+ Zero-direct token effect.
45
+
46
+ #### KV Cache effect
47
+
48
+ Independent — no conversation state.
49
+
50
+ ## Known Limitations and Deferred Work
51
+
52
+ - **One serial queue per fiber** — the lock is the fiber's; two fibers mean
53
+ two queues with no cross-fiber ordering promise.
54
+ - **MELITE_STATE_ROOTS is colon-separated** — a root path containing a
55
+ colon cannot be declared; relocate such a root instead.
package/lib/bench.d.ts CHANGED
@@ -8,17 +8,25 @@ export interface StagePick {
8
8
  * estate's re-apply churn (each re-apply re-imports modules; the
9
9
  * globalThis pin keeps ONE cutoff per process). */
10
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>;
11
+ export declare function benchDir(storageRoot?: string): string;
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+ export declare function benchStorageRoot(): string;
16
23
  /** The LIVE bench's stage picks — docs written during this
17
24
  * 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[];
25
+ * sessions are invisible by law). Sync by need: buildSkillIndex
26
+ * rides the seat handler synchronously. Malformed or racing docs
27
+ * contribute nothing — never a crash.
28
+ * @param storageRoot the drafts store's resolved storage root —
29
+ * one root for writer and reader (the C1 law); defaults to the
30
+ * store's own default law. */
31
+ export declare function benchPicksSync(storageRoot?: string): StagePick[];
24
32
  //# sourceMappingURL=bench.d.ts.map
package/lib/bench.js CHANGED
@@ -13,10 +13,8 @@
13
13
  // (my own test residue, hours old). The cutoff is pinned ONCE PER
14
14
  // PROCESS on globalThis so the estate's re-apply churn (fresh
15
15
  // module instances every ~21s) can never reset it.
16
- import { readdir, readFile, stat } from "node:fs/promises";
17
16
  import { readFileSync, readdirSync, statSync } from "node:fs";
18
17
  import { join } from "node:path";
19
- import { dshHomePath } from "@deepseek-ai/dsh-home-paths";
20
18
  /** The process's melite boot instant — pinned once, survives the
21
19
  * estate's re-apply churn (each re-apply re-imports modules; the
22
20
  * globalThis pin keeps ONE cutoff per process). */
@@ -32,74 +30,66 @@ export function benchBootMs() {
32
30
  function liveCutoffMs() {
33
31
  return benchBootMs() - 5_000;
34
32
  }
35
- export function benchDir() {
36
- return dshHomePath("storages", "drafts", "docs");
33
+ export function benchDir(storageRoot) {
34
+
35
+ // the reader follows the WRITER — the drafts store's own storage
36
+ // root (<stateRoot>/storage, the store's default law
37
+ // `data/runs/storage`), never a second tree under the DSH home
38
+ // (the retired seam left 181 files there with no writer). A
39
+ // caller that knows the resolved state root passes it; the
40
+ // default matches the store's own default so a config-free
41
+ // caller and the store resolve the SAME tree.
42
+ return join(storageRoot ?? benchStorageRoot(), "drafts", "docs");
37
43
  }
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("|");
44
+
45
+
46
+
47
+
48
+
49
+
50
+
51
+
52
+
53
+
54
+ export function benchStorageRoot() {
55
+ return process.env["MELITE_BENCH_STORAGE"] ?? join("data", "runs", "storage");
57
56
  }
57
+
58
+ // a catalog-follow poll that never landed — the probe found zero
59
+ // production importers (the spec alone). BENCHPICKS (async) went
60
+ // with it for the same reason: the sync twin is the one live seat
61
+ // (skillPlane's buildSkillIndex rides it). benchBootMs and benchDir
62
+ // stay exported for the spec's direct-src pins; the index.ts face
63
+
58
64
  /** The LIVE bench's stage picks — docs written during this
59
65
  * 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() {
66
+ * sessions are invisible by law). Sync by need: buildSkillIndex
67
+ * rides the seat handler synchronously. Malformed or racing docs
68
+ * contribute nothing — never a crash.
69
+ * @param storageRoot the drafts store's resolved storage root —
70
+ * one root for writer and reader (the C1 law); defaults to the
71
+ * store's own default law. */
72
+ export function benchPicksSync(storageRoot) {
91
73
  const cutoff = liveCutoffMs();
74
+ const dir = benchDir(storageRoot);
92
75
  let files = [];
93
76
  try {
94
- files = readdirSync(benchDir()).filter((f) => f.startsWith("bench-") && f.endsWith(".json"));
77
+ files = readdirSync(dir).filter((f) => f.startsWith("bench-") && f.endsWith(".json"));
95
78
  }
96
- catch {
79
+ catch (error) {
80
+ // the roster dir may not exist yet (first bench, nothing
81
+ // persisted) or may be unreadable — both mean "no picks to
82
+ // list", the function's own empty answer, never a crash of a
83
+ // census/read path that must degrade to nothing
84
+ if (error.code !== "ENOENT") {
85
+ console.error("[benchPicksSync] roster read failed:", error);
86
+ }
97
87
  return [];
98
88
  }
99
89
  const picks = [];
100
90
  for (const f of files) {
101
91
  try {
102
- const full = join(benchDir(), f);
92
+ const full = join(dir, f);
103
93
  if (statSync(full).mtimeMs < cutoff)
104
94
  continue; // stale — dead session
105
95
  const raw = JSON.parse(readFileSync(full, "utf8"));
@@ -1,10 +1,87 @@
1
+ import { RUNS_ERROR_CODES } from "./runsErrorCodes.js";
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+ export interface LaneMissRow {
14
+ /** The lane slot key (text_encoder, vae, …). */
15
+ readonly slot: string;
16
+ /** The declared file name that has no store copy. */
17
+ readonly name: string;
18
+ /** The model folders the presence probe checked, in order. */
19
+ readonly folders: readonly string[];
20
+ /** The DECL provision's declared size in bytes, when the family
21
+ * fetches the file itself (a pack-borne file declares none). */
22
+ readonly sizeBytes?: number;
23
+ /** The provision URL when the family declares one for the file. */
24
+ readonly fetchUrl?: string;
25
+ }
26
+ export interface LaneInputMiss {
27
+ /** The model family id whose lane_inputs declared the row. */
28
+ readonly family: string;
29
+ /** The lane slot key (text_encoder, vae, …). */
30
+ readonly slot: string;
31
+ /** The declared file name that has no store copy. */
32
+ readonly missing: string;
33
+ /** The model folders the presence probe checked, in order. */
34
+ readonly folders: readonly string[];
35
+ /** The provision URL when the family declares one for the file. */
36
+ readonly fetchUrl?: string;
37
+
38
+
39
+
40
+
41
+
42
+
43
+
44
+ readonly missingAll?: readonly LaneMissRow[];
45
+ /** The artifact class the popup's action keys on. "runtime" is
46
+ * the tool-runtime leg (E2-2 Piece A): the slot is the consuming
47
+ * param, missing is the runtime name, folders are the checked
48
+ * engine-tree paths, and there is no fetchUrl (the provision is
49
+ * a command the banner voices from the prose, never a URL). */
50
+ readonly kind: "model" | "extension" | "runtime";
51
+ }
52
+ /** THE IN-FLIGHT ACQUISITION ROW (ERRORS.md k2, NEVER-RUN-ON-
53
+ * INCOMPLETE): the structured truth a lane-presence miss carries when
54
+ * the missing file is LANDING right now — the popup keys its face on
55
+ * these fields, never on prose, and the fresh-fetch hint is absent by
56
+ * law (a fetch already runs; offering another re-pops the loop). */
57
+ export interface AcquireInFlightDetails {
58
+ readonly acquire_in_flight: true;
59
+ /** The live acquire's operation id (the poll key). */
60
+ readonly operation_id: string;
61
+ /** Real landed bytes at the refusal moment. */
62
+ readonly bytes: number;
63
+ /** The DECL's declared total (0 when no row declares one). */
64
+ readonly total: number;
65
+ }
1
66
  export declare class CardArmError extends Error {
2
67
  readonly status: number;
3
- readonly code: string;
68
+
69
+
70
+
71
+
72
+
73
+ readonly code: keyof typeof RUNS_ERROR_CODES;
4
74
  readonly loc?: string;
5
75
  readonly expected?: string;
6
76
  readonly got?: string;
7
- constructor(status: number, message: string, code: string, loc?: string, expected?: string, got?: string);
77
+ /** The structured lane-miss evidence — set only by the
78
+ * lane_input_missing throw site (cardsLanes.lanePresenceMiss). */
79
+ readonly lane?: LaneInputMiss;
80
+ /** The structured in-flight-acquisition evidence — set only by the
81
+ * lane_input_missing throw site's in-flight arm, beside (never
82
+ * instead of) the lane miss itself. */
83
+ readonly details?: AcquireInFlightDetails;
84
+ constructor(status: number, message: string, code: keyof typeof RUNS_ERROR_CODES, loc?: string, expected?: string, got?: string, lane?: LaneInputMiss, details?: AcquireInFlightDetails);
8
85
  }
9
86
  /** The variant rail's own refusal (sampler_envelope) — a subclass
10
87
  * so the WRITE seat can tell a DECL-own word from a selection
@@ -15,4 +92,19 @@ export declare class CardArmError extends Error {
15
92
  export declare class EnvelopeRefusal extends CardArmError {
16
93
  }
17
94
  export declare function phaseRefusal(phase: string, detail: string): CardArmError;
95
+
96
+
97
+
98
+
99
+
100
+
101
+
102
+
103
+
104
+
105
+
106
+
107
+
108
+
109
+ export declare function phaseRefusalCode(detail: string, code: keyof typeof RUNS_ERROR_CODES): CardArmError;
18
110
  //# sourceMappingURL=cardsArmError.d.ts.map
@@ -1,13 +1,22 @@
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
1
  export class CardArmError extends Error {
5
2
  status;
3
+
4
+
5
+
6
+
7
+
6
8
  code;
7
9
  loc;
8
10
  expected;
9
11
  got;
10
- constructor(status, message, code, loc, expected, got) {
12
+ /** The structured lane-miss evidence — set only by the
13
+ * lane_input_missing throw site (cardsLanes.lanePresenceMiss). */
14
+ lane;
15
+ /** The structured in-flight-acquisition evidence — set only by the
16
+ * lane_input_missing throw site's in-flight arm, beside (never
17
+ * instead of) the lane miss itself. */
18
+ details;
19
+ constructor(status, message, code, loc, expected, got, lane, details) {
11
20
  super(message);
12
21
  this.status = status;
13
22
  this.code = code;
@@ -17,6 +26,10 @@ export class CardArmError extends Error {
17
26
  this.expected = expected;
18
27
  if (got !== undefined)
19
28
  this.got = got;
29
+ if (lane !== undefined)
30
+ this.lane = lane;
31
+ if (details !== undefined)
32
+ this.details = details;
20
33
  }
21
34
  }
22
35
  /** The variant rail's own refusal (sampler_envelope) — a subclass
@@ -30,4 +43,21 @@ export class EnvelopeRefusal extends CardArmError {
30
43
  export function phaseRefusal(phase, detail) {
31
44
  return new CardArmError(400, "card_compose phase " + phase + ": " + detail, "card_compose");
32
45
  }
46
+
47
+
48
+
49
+
50
+
51
+
52
+
53
+
54
+
55
+
56
+
57
+
58
+
59
+
60
+ export function phaseRefusalCode(detail, code) {
61
+ return new CardArmError(400, detail, code);
62
+ }
33
63
  //# sourceMappingURL=cardsArmError.js.map
@@ -1,3 +1,5 @@
1
+ import { cardAdmits } from "./cardsFacts.js";
2
+ export { cardAdmits };
1
3
  import type { FactsReads } from "@melite/comfyui-cordis";
2
4
  import type { PreparedCard } from "./cardsRegistry.js";
3
5
  import { type CardDeclRow, type ModelFactsRow } from "./cardsFacts.js";
@@ -9,6 +11,9 @@ export interface ComposeSeat {
9
11
  primeObjectInfo(): Promise<boolean>;
10
12
  readsSync(): FactsReads;
11
13
  resolveCardFamily(mid: string, facts?: Record<string, import("./cardsFacts.js").ModelFactsRow>): string;
14
+ /** The §23 cross-roots manifest (the queue seat's stateRoots —
15
+ * the dangling sweep's trees; J12: config-named, never env). */
16
+ stateRoots(): readonly string[];
12
17
  }
13
18
  /** In-process compose (the core: steps 7-9) — per-call throwaway
14
19
  * Context + ComfyUIService (owned by the call, never shared). */
@@ -22,7 +27,14 @@ export declare function composeOnce(deps: ComposeSeat, card: string, fam: string
22
27
 
23
28
 
24
29
 
25
- export declare function admissionRefusal(deps: ComposeSeat, card: string, fam: string, lifted: Record<string, unknown>, phase: string): void;
30
+
31
+
32
+
33
+
34
+
35
+
36
+
37
+ export declare function admissionRefusal(deps: ComposeSeat, card: string, fam: string, lifted: Record<string, unknown>, phase: string, facts?: Record<string, ModelFactsRow>): void;
26
38
  /** Resolve + sweep + select + overlay + lift (steps 2-6):
27
39
  * everything before compose. Throws CardArmError (the door maps
28
40
  * it to the refusal envelope). `phase` stamps the phase-N voice