import { waitForSootsimIdle } from './settling' import type { WsBridge } from '../../ws-bridge' // default: layout hash stable for 3 consecutive polls. --strict additionally // requires worker queryStats animation flags to be false — use when the // target app has no perpetual background animation. export async function runSettleSubcommand(opts: { bridge: WsBridge args: string[] positional: string[] }): Promise { const { bridge, args, positional } = opts const maxMs = positional[1] ? Number(positional[1]) * 1000 : 3000 if (bridge.plane === 'cloud') { const maxFrames = Math.max(1, Math.min(600, Math.ceil(maxMs / 16))) const result: unknown = await bridge.send({ type: 'settle', maxFrames }) const frames = result !== null && typeof result === 'object' ? Reflect.get(result, 'frames') : null console.log( typeof frames === 'number' ? ` settled in ${frames} frames` : ' settled', ) return } const strict = args.includes('--strict') const { elapsed, settled } = await waitForSootsimIdle({ bridge, maxMs, strict }) if (settled) { console.log(` settled in ${elapsed}ms`) } else { console.log(` timed out after ${elapsed}ms (may still be animating)`) } }