INNER CODE UNIT · JavaScript
runFidelityLoop
Manavarya09/design-extract · src/fidelity/index.js:78
export async function runFidelityLoop({ measure, rebuild, threshold = 90, maxRounds = 4 } = {}) {
if (typeof measure !== 'function') throw new TypeError('runFidelityLoop requires a measure() function');
const rounds = [];
let final = null;
let converged = false;
for (let round = 1; round <= maxRounds; round++) {
const measured = await measure(round);
const combined = combineFidelity(measured);
rounds.push({ round, overall: combined.overall, visual: combined.visual, motion: combined.motion, directives: combined.directives.length });
final = combined;
if (combined.overall != null && combined.overall >= threshold) { converged = true; break; }
if (!combined.directives.length) { converged = combined.overall != null; break; }
if (round === maxRounds) break;
if (typeof rebuild === 'function') await rebuild(combined, round);
}