/**
 * AI Behavior Regeneration
 *
 * Thin wrapper around the ai-behaviors-generator's regenerateAiBehaviors
 * helper. Published via @specverse/engines/ai so the generated CLI can
 * call it without reaching into libs/ paths.
 *
 * Used by `specverse ai regenerate <Owner.fn>`.
 */
import { existsSync } from 'fs';
import { join, dirname } from 'path';
import { fileURLToPath } from 'url';
/**
 * Load the AI behaviors generator module dynamically — it lives under
 * engines/libs/ (not src/) and has to be loaded from the compiled .js in
 * dist/libs/ at runtime because the template is compiled separately.
 */
async function loadGenerator() {
    const __dirname = dirname(fileURLToPath(import.meta.url));
    // dist/ai/ → dist/libs/instance-factories/services/templates/prisma/
    const candidates = [
        join(__dirname, '..', 'libs', 'instance-factories', 'services', 'templates', 'prisma', 'ai-behaviors-generator.js'),
        // Fallback: uncompiled .ts source (only works in dev)
        join(__dirname, '..', '..', 'libs', 'instance-factories', 'services', 'templates', 'prisma', 'ai-behaviors-generator.ts'),
    ];
    for (const path of candidates) {
        if (existsSync(path)) {
            return await import(path);
        }
    }
    throw new Error('ai-behaviors-generator not found — is @specverse/engines installed correctly?');
}
export async function regenerateBehavior(opts) {
    const mod = await loadGenerator();
    if (typeof mod.regenerateAiBehaviors !== 'function') {
        throw new Error('regenerateAiBehaviors helper not found in @specverse/engines. ' +
            'Upgrade to engines >= 4.1.21.');
    }
    return mod.regenerateAiBehaviors(opts);
}
//# sourceMappingURL=behavior-regenerate.js.map