@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,123 @@
1
+ // ledgerTail.ts — the journal tail, RE-HOMED (REBUILD-19,
2
+
3
+ // doors/assets.ts _h_ledger, killed with the gateway app) ports
4
+ // verbatim as a pure over the state root — the queue seat's own
5
+ // journal (appendLedger writes it; this reads it back).
6
+ //
7
+ // The door's law rides EXACTLY (assets.ts 698-764): limit default
8
+ // 50, clamp 1..500, garbage -> 50 (NEVER a 400); event truncated
9
+ // to 64 chars, matched on the RAW line substring
10
+ // '"event":"<ev>'; the tail keeps the LAST N lines; unparseable
11
+ // lines count as matched but never as entries; output oldest ->
12
+ // newest within the tail; a missing journal reads empty.
13
+ //
14
+
15
+ // manifest root's journal into ONE timeline (ts-ordered, own root
16
+ // first on ties) and names the searched roots — a two-roots box
17
+ // answers "what happened" across both processes, not just the
18
+ // tree the seat happens to own.
19
+ import { readFileSync } from "node:fs";
20
+ import { join } from "node:path";
21
+ const parseLimit = (rawLimit) => {
22
+ if (/^\s*[+-]?\d+\s*$/.test(rawLimit)) {
23
+ return Math.max(1, Math.min(500, Number(rawLimit.trim())));
24
+ }
25
+ return 50;
26
+ };
27
+ /** Per-file scan (the door's law, intact): every line matched on
28
+ * the RAW substring, unparseables counted, a missing journal
29
+ * reading empty. */
30
+ const matchedLines = (ledgerPath, ev) => {
31
+ const needle = '"event":"' + ev;
32
+ const lines = [];
33
+ let matched = 0;
34
+ try {
35
+ const text = readFileSync(ledgerPath, "utf8");
36
+ // File iteration (`for line in f`): a trailing newline is NOT
37
+ // a phantom line, but a real blank line mid-file IS iterated
38
+ // (matched, then parse-skipped below).
39
+ const split = text.split("\n");
40
+ if (split.length > 0 && split[split.length - 1] === "" && text.endsWith("\n")) {
41
+ split.pop();
42
+ }
43
+ for (const line of split) {
44
+ if (ev !== "" && !line.includes(needle))
45
+ continue;
46
+ matched++;
47
+ lines.push(line);
48
+ }
49
+ }
50
+ catch {
51
+ // Missing journal reads empty (OSError -> pass).
52
+ }
53
+ return { lines, matched };
54
+ };
55
+ /** The entry ts (seconds) for the merge sort; 0 when absent —
56
+ * malformed rows sort oldest, and they parse-skip at the end
57
+ * anyway (never entries). */
58
+ const lineTs = (line) => {
59
+ const at = line.indexOf('"ts":');
60
+ if (at < 0)
61
+ return 0;
62
+ const rest = line.slice(at + 5);
63
+ const m = rest.match(/^\s*(-?\d+)/);
64
+ return m === null ? 0 : Number(m[1]);
65
+ };
66
+ const parseTail = (lines) => {
67
+ const out = [];
68
+ for (const e of lines) {
69
+ try {
70
+ out.push(JSON.parse(e));
71
+ }
72
+ catch {
73
+ continue;
74
+ }
75
+ }
76
+ return out;
77
+ };
78
+ /** The per-file tail (the door's law, byte-pinned by the REBUILD-19
79
+ * wall): every matched line, last-N window kept, unparseables
80
+ * occupy slots (they parse-skip at the end, never entries). */
81
+ const fileTail = (ledgerPath, ev, limit) => {
82
+ const { lines, matched } = matchedLines(ledgerPath, ev);
83
+ const tail = [];
84
+ for (const line of lines) {
85
+ tail.push(line);
86
+ if (tail.length > limit)
87
+ tail.shift();
88
+ }
89
+ return { tail, matched };
90
+ };
91
+ export function tailLedger(ledgerPath, rawLimit, rawEvent) {
92
+ const limit = parseLimit(rawLimit);
93
+ const ev = rawEvent.slice(0, 64);
94
+ const { tail, matched } = fileTail(ledgerPath, ev, limit);
95
+ const out = parseTail(tail);
96
+ return { entries: out, shown: out.length, matched };
97
+ }
98
+ /** §23 CROSS-ROOTS: every root's journal, one merged timeline. The
99
+ * per-file law rides VERBATIM first (match + last-N window per
100
+ * root — an unparseable line still occupies its slot); the
101
+ * per-file TAILS then merge by ts (stable — a tie keeps manifest
102
+ * order, own root first) and the last N merged serve. matched
103
+ * counts every root's matches. The answer names the searched
104
+ * roots. A single root degenerates to tailLedger exactly. */
105
+ export function tailLedgerAcross(roots, rawLimit, rawEvent) {
106
+ const limit = parseLimit(rawLimit);
107
+ const ev = rawEvent.slice(0, 64);
108
+ const merged = [];
109
+ let matched = 0;
110
+ for (const root of roots) {
111
+ const { tail, matched: m } = fileTail(join(root, "output", "_ledger.jsonl"), ev, limit);
112
+ matched += m;
113
+ for (const line of tail)
114
+ merged.push({ line, ts: lineTs(line) });
115
+ }
116
+ merged.sort((a, b) => a.ts - b.ts);
117
+ const tail = merged
118
+ .slice(Math.max(0, merged.length - limit))
119
+ .map((e) => e.line);
120
+ const out = parseTail(tail);
121
+ return { entries: out, shown: out.length, matched, searched: roots };
122
+ }
123
+ //# sourceMappingURL=ledgerTail.js.map
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Hold the latch for one door; the door releases it in its own finally.
3
+ * Holds nest under the same action name and across names; a release
4
+ * only retires its own hold.
5
+ * @param action the destructive action in flight (the door's own name)
6
+ * @returns the door's release closure, idempotent for its own hold
7
+ */
8
+ export declare function holdLifecycle(action: string): () => void;
9
+ /**
10
+ * The earliest action whose teardown is in flight, or null — read by
11
+ * the run press before its press reserve and record mint, and re-read
12
+ * by the press after its last await (runsStart's enqueue gate).
13
+ * @returns the held action name, or null when no teardown is in flight
14
+ */
15
+ export declare function lifecycleInFlight(): string | null;
16
+ //# sourceMappingURL=lifecycleLatch.d.ts.map
@@ -0,0 +1,42 @@
1
+
2
+ //
3
+ // The guard half (guardLifecycle in manageOps.ts) refuses a teardown
4
+ // when runs are already live, but five of the six destructive doors
5
+ // await on the vendor call as their first act — a run born during
6
+ // that await tears mid-render (round-19 F1: sidecar says running
7
+ // while its engine reboots). The latch is the reservation half: a
8
+ // guarded door holds it across its destructive section and the run
9
+ // press (RunsRegistry.start) refuses while it names an action.
10
+ // Doors overlap (the manage dispatch is unserialized): one slot would
11
+ // let the first finisher's release clear the other's live hold. Each
12
+ // holder counts under its own action name; the read names the earliest
13
+ // holder (Map insertion order).
14
+ const holders = new Map();
15
+ /**
16
+ * Hold the latch for one door; the door releases it in its own finally.
17
+ * Holds nest under the same action name and across names; a release
18
+ * only retires its own hold.
19
+ * @param action the destructive action in flight (the door's own name)
20
+ * @returns the door's release closure, idempotent for its own hold
21
+ */
22
+ export function holdLifecycle(action) {
23
+ holders.set(action, (holders.get(action) ?? 0) + 1);
24
+ return () => {
25
+ const left = (holders.get(action) ?? 1) - 1;
26
+ if (left <= 0)
27
+ holders.delete(action);
28
+ else
29
+ holders.set(action, left);
30
+ };
31
+ }
32
+ /**
33
+ * The earliest action whose teardown is in flight, or null — read by
34
+ * the run press before its press reserve and record mint, and re-read
35
+ * by the press after its last await (runsStart's enqueue gate).
36
+ * @returns the held action name, or null when no teardown is in flight
37
+ */
38
+ export function lifecycleInFlight() {
39
+ const first = holders.keys().next();
40
+ return first.done ? null : first.value;
41
+ }
42
+ //# sourceMappingURL=lifecycleLatch.js.map
@@ -0,0 +1,94 @@
1
+ import { emitModifierKinds } from "@melite/comfyui-cordis";
2
+ import type { ModelsService } from "@melite/comfyui-cordis";
3
+ import type { CardRegistryService } from "./cardsRegistry.js";
4
+ import type { FlowsSeat } from "./flowsData.js";
5
+ import { toolBaseRows } from "./toolProjection.js";
6
+ import type { FamilyModelsSeat } from "./flowsFamilyCompose.js";
7
+ /** A card id → its package dir. The cardPackages rows are package
8
+ * NAMES ('@melite/<genre>-<card>'); the id is the row's tail past
9
+ * the genre prefix, which is NOT reparseable from the string alone
10
+ * (ids carry dashes) — so match rows ending in '-' + id, split the
11
+ * genre against the LIVE domain tier (readdir packages/), and keep
12
+ * the ones whose dir carries src/card.ts (the cardUnitDirs guard).
13
+ * Node resolution is the WRONG tool (pnpm links only dependents —
14
+ * require.resolve starves); the repo tree is the truth.
15
+ * Zero hits = unknown id; two = a data bug — both refuse LOUD at
16
+ * the door, never a silent pick. */
17
+ export declare function resolveCardPackageDir(repo: string, cardId: string): string;
18
+ /** The card's agents md (src/agents/**, AGENT.md first, sorted,
19
+ * capped — the cap is the contract: lines route, bodies stay
20
+ * bounded). */
21
+ export declare function cardSkillDocs(pkgDir: string): Array<{
22
+ path: string;
23
+ text: string;
24
+ }>;
25
+ /** The card's tool-call signature — the /v1/tools row
26
+ * envelope (ROW_KEYS mirror toolsEmit — one projection, the
27
+ * emitter imported, the envelope shared by construction). */
28
+ export declare function toolRowFor(id: string, def: {
29
+ schemaCarrier?: unknown;
30
+ schema: unknown;
31
+ boarded: readonly string[];
32
+ mods?: Parameters<typeof emitModifierKinds>[0];
33
+ }, rows: ReturnType<typeof toolBaseRows>): Record<string, unknown>;
34
+ /** The bundle digest (the DSH session-catalog half we CAN own:
35
+ * their catalog is digest-diffed "stable, never duplicated" — we
36
+ * don't own the loop so we can't clear the agent's context, but a
37
+ * stable content hash lets the agent dedupe its own reloads: quote
38
+ * the digests you hold, skip reload on a match). sha16 of the
39
+ * canonical bundle JSON (the asset pipeline's sha16 convention). */
40
+ export declare function bundleDigest(bundle: Record<string, unknown>): string;
41
+ /** Tier-1 skill LINES for one card id (the melite_skill_index truth —
42
+ * wireSkill rows over the planes buckets, card-skill scope only;
43
+ * the card's AGENT.md rides full under agents, never as a line).
44
+ * Merged across engines, id-deduped; unknown cards line nothing
45
+ * (the walk is the truth — never a refusal). */
46
+ export declare function skillLinesForCard(repo: string, cardId: string): Array<Record<string, unknown>>;
47
+
48
+
49
+
50
+
51
+
52
+
53
+
54
+
55
+
56
+
57
+ export declare function skillLinesForFamilies(repo: string, fams: readonly string[]): Array<Record<string, unknown>>;
58
+ export declare function flowLeafDocs(repo: string, flowName: string): Array<{
59
+ path: string;
60
+ text: string;
61
+ }>;
62
+ /** Resolve one skill ref (a card:/model:/flow: sid) to its tier-1
63
+ * line through the planes registry (the melite_skill_index truth).
64
+ * Dangling refs line null — visible drift, never a refusal. */
65
+ /** @param modelsSeat the context's models service when mounted (the
66
+ * same seat-threading law the runs doors ride) */
67
+ export declare function skillLineForRef(repo: string, ref: string, modelsSeat?: FamilyModelsSeat | null, flowsSeat?: FlowsSeat | null): Record<string, unknown>;
68
+ /** The lane's models seat as the CARD arm reads it: the four
69
+ * disclosure methods (family rows, path/file presence, catalog
70
+ * artifacts). ModelsService satisfies it structurally; ctx.get
71
+ * returns the same service, so the card arm discloses from the
72
+ * lane that serves the run (the lane-seat law). */
73
+ export type CardModelsSeat = Pick<ModelsService, "allDecls" | "checkModelPresent" | "checkModelPathPresent" | "resolveCatalogArtifact">;
74
+ /** Melite load for a CARD: agents md + tool-call signature +
75
+ * tier-1 skill lines (the card's own AND every boarded family's
76
+ * model skills — ONE load hands the agent the whole craft: loading
77
+ * image-gen serves model:anima:prompt-enhance beside the card
78
+ * lines, so the prompt guide is read before compose, never hunted
79
+ * after) + model hints (the boarded families' DECL identity —
80
+ * presence-marked, never a run-time surprise; LLM-powered enhance
81
+ * stays the user's ✦ door, never served here). Throws LOUD
82
+ * on unknown ids (the door maps to 404). */
83
+ export declare function loadCard(repo: string, cards: CardRegistryService, modelsSeat: CardModelsSeat | null | undefined, cardId: string): Record<string, unknown>;
84
+ /** Melite load for a FLOW: the leaf agents md + the registry
85
+ * signature (the tool overlay verbatim — ONE spelling, the same
86
+ * object validate/start enforce; null when the row declares
87
+ * none) + slim stages + the author's skill refs (verbatim) with
88
+ * their tier-1 lines. Throws LOUD on unknown flows. */
89
+ /** @param modelsSeat the context's models service when mounted — the
90
+ * flow's skill lines resolve through the seat the runs doors
91
+ * thread (the lane-seat law); the booted singleton otherwise */
92
+ export declare function loadFlow(repo: string, flowName: string, modelsSeat?: FamilyModelsSeat | null, flowsSeat?: FlowsSeat | null): Record<string, unknown>;
93
+ /** First-non-blank query value (the catalogs qFirst shape). */
94
+ //# sourceMappingURL=loadPlane.d.ts.map