Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

24.7 KB
Raw Blame
/**
 * Universe Builder — refine the bible + influences (which collectively act as
 * the universe's style and negative prompts) based on user feedback. Mirrors
 * the media prompt-refine flow (see `mediaPromptRefiner.js`) but operates on
 * a universe template rather than an individual render.
 *
 * The LLM gets the originals + a free-form feedback string and returns:
 *   { starterPrompt, logline, premise, styleNotes, influences, rationale, changes? }
 *
 * The caller (route → UI) presents the refined fields for review before they
 * overwrite the draft, so the LLM never silently mutates a saved universe.
 */

import { ServerError } from "../lib/errorHandler.js";
import { extractNonPlaceholderJson } from "../lib/jsonExtract.js";
import { assertProvider, resolveProviderAndModel, resolveEffectiveModel, runPromptThroughProvider, assertVisionRunUsedImages } from "./promptRunner.js";
import { resolveAPIProvider } from './aiProvider.js';
import {
  renderCategoriesForPrompt as renderCategoriesShared,
  renderCompositesForPrompt as renderCompositesShared,
} from "../lib/universePromptRenderers.js";
import {
  COMPOSITE_PROMPT_MAX,
  COMPOSITE_SHEETS_MAX,
  LOCKABLE_FIELDS,
  LOCKABLE_FIELD_LABELS,
  LOGLINE_MAX,
  PREMISE_MAX,
  PROMPT_FRAGMENT_MAX,
  STARTER_PROMPT_MAX,
  STYLE_NOTES_MAX,
  VARIATIONS_PER_CATEGORY_MAX,
  VARIATION_LABEL_MAX,
  WORLD_CATEGORY_COUNT_MAX,
  isInfluenceLockField,
  mergeInfluencesWithLocksAdditive,
  normalizeCategoryKey,
  normalizeLabelKey,
  sanitizeCategories,
  sanitizeCompositeSheets,
  sanitizeInfluences,
  sanitizeLocked,
} from "./universeBuilder.js";
import { trimTo } from "../lib/textUtils.js";

const MAX_FEEDBACK = 3000;
const MAX_RATIONALE = 1200;
const MAX_CHANGES = 8;

const cleanChanges = (changes) =>
  Array.isArray(changes)
    ? changes
        .map((c) => trimTo(c, 240))
        .filter(Boolean)
        .slice(0, MAX_CHANGES)
    : [];

const lockedList = (locked) =>
  LOCKABLE_FIELDS.filter((k) => locked && locked[k] === true).map(
    (k) => `- ${LOCKABLE_FIELD_LABELS[k]} ("${k}")`,
  );

/**
 * Collapse multiple `Style direction:` blocks within the starter prompt into
 * one — keep the LAST occurrence (the latest refinement). We instruct the LLM
 * to maintain a single trailing block, but defense-in-depth here ensures the
 * starter never grows unboundedly across repeated refinements.
 *
 * Matches a heading-style line beginning with "Style direction:" (any case),
 * including the body text that follows up to the next heading or end of input.
 */
export function collapseStyleDirectionDupes(starter) {
  if (typeof starter !== "string" || !starter) return "";
  const re =
    /(?:^|\n)\s*Style direction:[\s\S]*?(?=(?:\n\s*Style direction:)|$)/gi;
  const matches = starter.match(re);
  if (!matches || matches.length <= 1) return starter;
  const stripped = starter.replace(re, "").trim();
  const last = matches[matches.length - 1].trim();
  return `${stripped}\n\n${last}`.trim();
}

const renderCategoriesForPrompt = (categories) =>
  renderCategoriesShared(categories, { showLocked: true });

const renderCompositesForPrompt = (composites) =>
  renderCompositesShared(composites, { showLocked: true });

export function buildWorldRefinePrompt({
  starterPrompt,
  logline = "",
  premise = "",
  styleNotes = "",
  influences = { embrace: [], avoid: [] },
  categories = null,
  compositeSheets = null,
  locked = {},
  feedback,
  hasImage = false,
}) {
  const lockedRules = lockedList(locked);
  const lockedSection = lockedRules.length
    ? `LOCKED FIELDS — DO NOT MODIFY (the user has pinned these; echo them back UNCHANGED in the JSON output, do not rewrite a single word):
${lockedRules.join("\n")}

`
    : "";

  const embrace = Array.isArray(influences?.embrace) ? influences.embrace : [];
  const avoid = Array.isArray(influences?.avoid) ? influences.avoid : [];

  const hasStructure =
    (categories && Object.keys(categories).length) ||
    (Array.isArray(compositeSheets) && compositeSheets.length);

  const structureRules = hasStructure
    ? `
STRUCTURE RULES (the universe has been expanded — categories and composite sheets are part of this refinement):
- Each category groups related prompt variations (factions, characters, vehicles, etc.). Each variation is { "label", "prompt" } and may be flagged [LOCKED].
- Each composite sheet is a multi-subject board (kind "reference_sheet" or "world_pitch_poster") with { "label", "prompt" }, also [LOCKED]-flaggable.
- Variations / composites flagged [LOCKED] must be returned with their EXACT original label + prompt — do not rephrase, expand, trim, or "lightly clean up" them. The server discards changes to locked items.
- Unlocked variations / composites may be rewritten, replaced (same label, new prompt), or REMOVED if the user's feedback warrants it. Removing an item means omitting it from the response.
- EXPLICIT REMOVAL IS A DIRECT ORDER. If the user names a specific variation, composite, faction, character, location, or other entity to remove ("drop X", "remove X", "delete X", "get rid of X", "no more X"), you MUST:
  (a) OMIT any variation whose label matches X from the response entirely (do not return it under a renamed label either).
  (b) OMIT any composite sheet whose primary subject IS X — even if a sibling subject remains. For example, if the user removes "Faction A" and a sheet is titled "Faction A vs Faction B branding sheet", omit the whole sheet; replace it with a single-subject sheet for Faction B only if the universe still warrants it.
  (c) SCRUB every textual reference to X from the prompts of any remaining unlocked composites and variations (faction lists, inset panels, comparison columns, callouts, etc.). Rewrite those prompts so X is not mentioned. If a remaining unlocked composite's prompt becomes incoherent once X is scrubbed, remove that composite too.
  (d) References to X inside LOCKED items (locked variations, locked composites, locked narrative fields) cannot be edited — leave them, but do not let them tempt you into re-adding X under a new label. The server will not re-add X just because a locked field still mentions it.
- You MAY ADD new variations to any existing category, propose ENTIRELY NEW categories, and ADD new composite sheets when the feedback motivates it. Use snake_case keys for new category names (e.g. "secret_rituals").
- Keep category counts manageable: at most ${WORLD_CATEGORY_COUNT_MAX} total categories, ${VARIATIONS_PER_CATEGORY_MAX} variations per category, ${COMPOSITE_SHEETS_MAX} composite sheets.
- Variation prompts ≤${PROMPT_FRAGMENT_MAX} chars; composite prompts ≤${COMPOSITE_PROMPT_MAX} chars; labels ≤${VARIATION_LABEL_MAX} chars.
- When updating an unlocked composite that references a renamed/removed variation, update the composite's prompt to match — keep the universe internally consistent.
- For LOCKED influence lists in this refine: preserve every existing token IN ORDER, but you MAY APPEND new tokens at the end. You may NOT remove, reorder, or rewrite existing locked tokens. The server enforces order preservation regardless.
`
    : "";

  const structureContext = hasStructure
    ? `
ORIGINAL CATEGORIES (current draft — items flagged [LOCKED] must round-trip unchanged):
${renderCategoriesForPrompt(categories) || "  (none)"}

ORIGINAL COMPOSITE SHEETS (current draft):
${renderCompositesForPrompt(compositeSheets) || "  (none)"}
`
    : "";

  const imageGuidance = hasImage
    ? `
REFERENCE IMAGE: A reference image is attached. Treat it as a VISUAL STYLE reference for this universe — read its palette, lighting, linework/brushwork, texture, era, and overall mood. Fold those qualities into "influences.embrace" (as short prompt tokens) and into "styleNotes" (as prose), and add "influences.avoid" tokens for qualities the image deliberately lacks. The image informs STYLE ONLY — do NOT invent narrative, characters, or plot from it, and do not contradict the user's written feedback below where they conflict.
`
    : "";

  const structureSchema = hasStructure
    ? `,
  "categories": { "<category_key>": { "variations": [ { "label": "<short label>", "prompt": "<full prompt fragment>", "locked": true } ] } },
  "compositeSheets": [ { "kind": "reference_sheet" | "world_pitch_poster", "label": "<short label>", "prompt": "<full board prompt>", "locked": true } ]`
    : "";

  return `You are a senior universe-building editor for a Stable-Diffusion-style image-generation pipeline AND a story-bible drafter for a comic/TV production pipeline.

The user has five top-level fields that define a "universe":
- STARTER IDEA — the high-concept seed the universe expander fans out into categories.
- LOGLINE — one-sentence narrative hook.
- PREMISE — 1-3 paragraph elevator pitch (setting, conflict, stakes, tone).
- STYLE NOTES — narrative-side prose about references, mood, palette, pacing, voice.
- INFLUENCES — structured { embrace: [string], avoid: [string] } token lists. THESE ARE THE UNIVERSE'S STYLE + NEGATIVE PROMPT. The "embrace" list is joined verbatim as the positive style prompt prepended to every render (palette tokens, lighting, render quality, artist references — e.g. "moebius linework", "cel-shading", "dust palette"). The "avoid" list is joined verbatim as the negative prompt (e.g. "blurry", "lowres", "watermark"). Each entry is a short prompt-token-style label, NOT a full sentence. Max 30 entries per list, max 120 chars each.

The user has given feedback about the story, mood, style, or design they want refined. Rewrite ALL fields so they more faithfully express the user's intention and stay internally consistent. Output the COMPLETE rewritten text/values for each — not a placeholder, not a summary, not a diff.

${lockedSection}Return ONLY valid JSON in this schema (replace every <…> with real content; do NOT output the literal angle-bracket text):
{
  "starterPrompt": "<full rewritten high-concept starter idea, 1-3 sentences. Stays a clean seed — do NOT append style direction prose here, that belongs in influences + styleNotes>",
  "logline": "<full rewritten one-sentence narrative hook>",
  "premise": "<full rewritten 1-3 paragraph elevator pitch>",
  "styleNotes": "<full rewritten narrative-style prose about references, mood, palette, pacing, voice>",
  "influences": { "embrace": ["<short style prompt token>", "..."], "avoid": ["<short negative prompt token>", "..."] }${structureSchema},
  "rationale": "<one concise sentence explaining the overall edit>",
  "changes": ["<short bullet of what changed and why>"]
}

Rules:
- Preserve story/character/universe DNA from the originals unless the user's feedback explicitly contradicts it.
- The "starterPrompt" stays a clean high-concept seed — no category content (landscapes, factions, etc.) and no style-direction prose. The structured "influences" field carries that direction so re-expansions inherit it deterministically.
- The "influences" lists are the canonical positive + negative prompt set. Each token is short (a name, a movement, a palette descriptor, a render-quality token) — they are joined verbatim into the renderer prompt. Add what the user's feedback embraces, drop what's no longer relevant, and add explicit avoids for things they're moving away from. If the universe relies on text/typography (e.g. pitch posters), avoid putting "text" in the avoid list — prefer "watermark", "logo", "unreadable tiny text", "text artifacts" so title typography remains possible.
- The "logline", "premise", and "styleNotes" must stay narratively coherent with the refined influences.
- Apply the user's feedback decisively. If they ask for a different style/mood/era, move toward it in influences + styleNotes, and name the things to avoid in influences.avoid.
- No field may equal the schema placeholder text — output real rewritten content for every key.
${lockedRules.length ? "- Any field listed under LOCKED FIELDS above must be returned EXACTLY as the original — do not reword, expand, or trim it. The server will discard any change to a locked field, but echoing the original keeps the JSON consistent.\n" : ""}${structureRules}
ORIGINAL STARTER IDEA:
${starterPrompt || "(empty)"}

ORIGINAL LOGLINE:
${logline || "(empty)"}

ORIGINAL PREMISE:
${premise || "(empty)"}

ORIGINAL STYLE NOTES:
${styleNotes || "(empty)"}

ORIGINAL INFLUENCES:
Embrace: ${embrace.length ? embrace.join(", ") : "(none)"}
Avoid: ${avoid.length ? avoid.join(", ") : "(none)"}
${structureContext}${imageGuidance}
USER FEEDBACK:
${feedback}`;
}

// Lock semantics for categories + composites are the same: locked items
// round-trip verbatim from the originals; LLM output is taken for everything
// else, but any LLM entry whose label collides with a locked one is dropped
// (we never let the LLM "rewrite" a locked item by re-using its label).
const mergeCategoriesWithLocks = (originalCategories, llmCategories) => {
  const orig = originalCategories || {};
  const fresh = (llmCategories && typeof llmCategories === "object") ? llmCategories : {};
  const merged = {};

  // Build normalized-key lookups so the merge can find a fresh entry whose
  // raw key is e.g. "Secret Rituals" via the normalized form "secret_rituals"
  // (the LLM may not echo back the exact snake_case the schema uses).
  const buildLookup = (obj) => {
    const out = {};
    for (const [rawKey, value] of Object.entries(obj)) {
      out[normalizeCategoryKey(rawKey) || rawKey] = value;
    }
    return out;
  };
  const origByNorm = buildLookup(orig);
  const freshByNorm = buildLookup(fresh);
  const allKeys = new Set([...Object.keys(origByNorm), ...Object.keys(freshByNorm)]);

  for (const key of allKeys) {
    const origVars = Array.isArray(origByNorm[key]?.variations) ? origByNorm[key].variations : [];
    const llmVars = Array.isArray(freshByNorm[key]?.variations) ? freshByNorm[key].variations : [];
    const lockedOrig = origVars.filter((v) => v?.locked === true);
    const lockedLabels = new Set(lockedOrig.map((v) => normalizeLabelKey(v.label)));

    const out = [...lockedOrig];
    for (const v of llmVars) {
      if (!v || typeof v !== "object") continue;
      const label = typeof v.label === "string" ? v.label.trim() : "";
      if (!label || lockedLabels.has(normalizeLabelKey(label))) continue;
      out.push({ label, prompt: typeof v.prompt === "string" ? v.prompt : "" });
    }
    merged[key] = { variations: out };
  }

  return sanitizeCategories(merged);
};

const mergeCompositesWithLocks = (originalSheets, llmSheets) => {
  const orig = Array.isArray(originalSheets) ? originalSheets : [];
  const fresh = Array.isArray(llmSheets) ? llmSheets : [];
  const lockedOrig = orig.filter((s) => s?.locked === true);
  const lockedLabels = new Set(lockedOrig.map((s) => normalizeLabelKey(s.label)));

  const merged = [...lockedOrig];
  for (const s of fresh) {
    if (!s || typeof s !== "object") continue;
    const label = typeof s.label === "string" ? s.label.trim() : "";
    if (!label || lockedLabels.has(normalizeLabelKey(label))) continue;
    merged.push({ kind: s.kind, label, prompt: s.prompt });
  }
  return sanitizeCompositeSheets(merged);
};

// Routes through the central handler so cli/api/tui providers all work; the
// per-CLI argv quirks (codex `exec -`, gemini stdin pipe, claude `-p -`) live
// inside runner.js#buildCliArgs and the TUI paste/idle handshake lives in
// tuiPromptRunner.js — both reached via runPromptThroughProvider.
async function runRefine(provider, model, prompt, screenshots = []) {
  return runPromptThroughProvider({
    provider, prompt, source: "universe-builder-refine", model,
    // Vision style-reference path: API providers base64-inline these as
    // image_url blocks; CLI/TUI providers ignore them (the caller forces an API
    // provider when an image is supplied).
    screenshots: Array.isArray(screenshots) ? screenshots : [],
  }).catch((err) => {
    throw new ServerError(err?.message || "Universe refinement failed", {
      status: 502,
      code: "WORLD_REFINE_FAILED",
    });
  });
}

/**
 * Refine universe fields. Operates in two modes:
 *  - Bible-only (pre-Expand): categories + compositeSheets omitted; behavior
 *    matches the original refine — rewrite the seven scalar/influence fields
 *    per feedback.
 *  - Holistic (post-Expand): caller passes `categories` and/or `compositeSheets`
 *    and the LLM may edit/replace/remove unlocked variations + composites, add
 *    new ones, and propose new categories. Locked items (per-field, per-list,
 *    per-variation, per-composite) round-trip verbatim. Locked influence lists
 *    become APPEND-ONLY in this path (preserve order, may add new tokens).
 *
 * @param {object} args
 * @param {string} args.starterPrompt   — original
 * @param {string} [args.logline]        — original bible logline (may be empty)
 * @param {string} [args.premise]        — original bible premise (may be empty)
 * @param {string} [args.styleNotes]     — original bible style notes (may be empty)
 * @param {object} [args.influences]     — { embrace, avoid } — the universe's style + negative prompt tokens
 * @param {object} [args.categories]     — full categories map from the draft (with per-item locks)
 * @param {Array}  [args.compositeSheets] — composite sheets from the draft (with per-item locks)
 * @param {object} [args.locked]         — { field: true } for fields the user has pinned; locked fields are echoed back unchanged
 * @param {string} args.feedback        — required user feedback
 * @param {string} [args.providerId]    — overrides the active provider
 * @param {string} [args.model]         — overrides the provider's default model
 */
export async function refineWorldPrompts({
  starterPrompt,
  logline = "",
  premise = "",
  styleNotes = "",
  influences,
  categories,
  compositeSheets,
  locked = {},
  feedback,
  providerId,
  model,
  // Absolute path to a gallery image used as a visual style reference (resolved
  // by the route). When set, refinement runs through a vision-capable API
  // provider so the model can read the image.
  imagePath = null,
} = {}) {
  if (!feedback || !feedback.trim()) {
    throw new ServerError("Feedback is required", {
      status: 400,
      code: "FEEDBACK_REQUIRED",
    });
  }
  if (!starterPrompt || !starterPrompt.trim()) {
    throw new ServerError("Starter prompt is required to refine", {
      status: 400,
      code: "STARTER_REQUIRED",
    });
  }
  const safeLocked = sanitizeLocked(locked);
  // hasStructure also unblocks an all-top-level-locked refine — the user
  // can still want to tune unlocked variations or composite boards.
  const hasStructure =
    (categories && typeof categories === "object" && Object.keys(categories).length > 0) ||
    (Array.isArray(compositeSheets) && compositeSheets.length > 0);
  // Refusing the run if everything is locked AND there is no structure spares
  // the user a confusing "nothing changed" outcome (the LLM would echo every
  // field, then the server would overwrite with originals, then the modal
  // would show no diff). When there is structure to refine, fall through.
  if (LOCKABLE_FIELDS.every((k) => safeLocked[k]) && !hasStructure) {
    throw new ServerError(
      "All fields are locked — unlock at least one before refining",
      { status: 400, code: "ALL_FIELDS_LOCKED" },
    );
  }

  const hasImage = typeof imagePath === "string" && imagePath.length > 0;
  // With a style-reference image, vision is API-only (only executeApiRun
  // base64-inlines images) — force an API provider so the model actually sees
  // it rather than refining text-only. Without an image, keep the original
  // resolution so CLI/TUI providers still work for text-only refines.
  let provider;
  let selectedModel;
  if (hasImage) {
    provider = await resolveAPIProvider(providerId);
    assertProvider(provider, {
      message:
        "Refining with a reference image needs an API-based AI provider with a vision-capable model (e.g. Ollama with a llava/qwen-vl model, LM Studio, or an OpenAI-compatible endpoint). Configure one under Settings → Providers.",
      code: "NO_API_PROVIDER",
      status: 503,
    });
    selectedModel = resolveEffectiveModel(provider, model);
  } else {
    ({ provider, selectedModel } = await resolveProviderAndModel({ providerId, model }));
  }
  assertProvider(provider, {
    message: "No AI provider available for universe refinement",
    code: "NO_PROVIDER",
    status: 400,
  });
  if (provider.enabled === false) {
    throw new ServerError(
      `Provider "${provider.name || provider.id}" is disabled — enable it in Settings → Providers first`,
      { status: 400, code: "PROVIDER_DISABLED" },
    );
  }

  if (!selectedModel && provider.type === "api") {
    throw new ServerError("Model is required for universe refinement", {
      status: 400,
      code: "MODEL_REQUIRED",
    });
  }

  // Trim originals up front so we can pass them to both the LLM AND use them
  // verbatim as the lock fallback below.
  const originals = {
    starterPrompt: trimTo(starterPrompt, STARTER_PROMPT_MAX),
    logline: trimTo(logline, LOGLINE_MAX),
    premise: trimTo(premise, PREMISE_MAX),
    styleNotes: trimTo(styleNotes, STYLE_NOTES_MAX),
    influences: sanitizeInfluences(influences),
    categories: hasStructure ? sanitizeCategories(categories || {}) : null,
    compositeSheets: hasStructure ? sanitizeCompositeSheets(compositeSheets || []) : null,
  };

  const llmPrompt = buildWorldRefinePrompt({
    ...originals,
    locked: safeLocked,
    feedback: trimTo(feedback, MAX_FEEDBACK),
    hasImage,
  });

  const runResult = await runRefine(provider, selectedModel, llmPrompt, hasImage ? [imagePath] : []);
  const { text, runId } = runResult;

  // A CLI/TUI fallback silently drops the image and would refine from the text
  // prompt alone — reject it so the user isn't told the image was used when it
  // wasn't.
  if (hasImage) assertVisionRunUsedImages(runResult, provider);

  let parsed;
  try {
    parsed = extractNonPlaceholderJson(text || "", { field: "starterPrompt" });
  } catch (e) {
    console.warn(
      `⚠️ universe-refine [${provider.id}/${selectedModel || "default"} runId=${runId}] parse failed: ${e.message} (response size: ${(text || "").length} chars)`,
    );
    throw new ServerError(e.message, {
      status: 502,
      code: "WORLD_REFINE_BAD_JSON",
    });
  }

  const FIELD_CAPS = {
    starterPrompt: STARTER_PROMPT_MAX,
    logline: LOGLINE_MAX,
    premise: PREMISE_MAX,
    styleNotes: STYLE_NOTES_MAX,
  };

  // Scalar fields: if locked, echo the original; otherwise take the LLM's
  // value, distinguishing "key absent / null" (fall back to original) from
  // an intentional "" (apply — the user asked to clear it). Mirrors the
  // expand merge's pick semantics so an unlocked field like negativePrompt
  // can actually be cleared by refine. Influences uses per-list locks and is
  // handled separately below.
  const refined = {};
  for (const key of LOCKABLE_FIELDS) {
    if (isInfluenceLockField(key)) continue;
    if (safeLocked[key]) {
      refined[key] = originals[key];
      continue;
    }
    const raw = parsed[key];
    if (raw === null || raw === undefined) {
      refined[key] = originals[key];
    } else {
      refined[key] = trimTo(raw, FIELD_CAPS[key]);
    }
  }
  // Refine path uses APPEND-ONLY semantics for locked influence lists — the
  // user wants "lock = don't rebuild, but you may append". Expand still calls
  // the strict variant.
  refined.influences = mergeInfluencesWithLocksAdditive(
    safeLocked,
    parsed.influences,
    originals.influences,
  );

  // Legacy cleanup: prior refinements may have stuffed a "Style direction:"
  // paragraph into the starter. Now that influences carries the direction
  // structurally, collapse any leftover duplicates so the starter doesn't
  // keep growing across iterations. The new refine prompt no longer asks
  // for the clause, but the cleanup is cheap.
  if (!safeLocked.starterPrompt) {
    refined.starterPrompt = collapseStyleDirectionDupes(refined.starterPrompt);
  }

  if (!refined.starterPrompt) {
    throw new ServerError("LLM returned an empty starter prompt", {
      status: 502,
      code: "WORLD_REFINE_EMPTY_STARTER",
    });
  }

  // Structure merge — only when the caller passed categories/composites.
  // Empty / pre-Expand calls return without these keys so the response shape
  // stays identical to the bible-only contract.
  const result = {
    ...refined,
    locked: safeLocked,
    rationale: trimTo(parsed.rationale, MAX_RATIONALE),
    changes: cleanChanges(parsed.changes),
    providerId: provider.id,
    model: selectedModel,
  };

  if (hasStructure) {
    result.categories = mergeCategoriesWithLocks(
      originals.categories || {},
      parsed.categories,
    );
    result.compositeSheets = mergeCompositesWithLocks(
      originals.compositeSheets || [],
      parsed.compositeSheets,
    );
  }

  return result;
}

export const __testing = {
  buildWorldRefinePrompt,
  collapseStyleDirectionDupes,
  mergeCategoriesWithLocks,
  mergeCompositesWithLocks,
};