/**
 * Nexus Prime — Deep Bootstrap
 *
 * Performs heavyweight preparation:
 *   - Candidate file discovery
 *   - Knowledge fabric composition
 *   - Artifact shortlisting
 *   - Token budgeting
 *   - Worker topology hints
 *
 * Only called when BootstrapFastResult.needsDeepBootstrap is true,
 * or when explicitly requested. Results are cached for the session.
 */
import { writeBootstrapReceipt, buildRepoIdentity } from './bootstrap-registry.js';
/**
 * Execute deep bootstrap. Assumes fast bootstrap already ran.
 * Updates the durable receipt with deep=true.
 */
export async function bootstrapDeep(task, fastResult, deps) {
    const { files: candidateFiles, dropped: candidateFilesDropped } = deps.discoverCandidateFiles(task);
    const filePaths = candidateFiles.map((f) => f.path);
    const fabric = deps.composeKnowledgeFabric(task, filePaths);
    const shortlist = deps.resolveShortlist(task);
    const sourceMixRecommendation = {
        dominantSource: fabric.dominantSource,
        reasons: fabric.reasons,
    };
    const knowledgeWarmup = {
        repoSelectedFiles: fabric.selectedFiles,
        memorySources: fabric.memorySources,
        ragChunks: fabric.ragChunks,
        patternHits: fabric.patternHits,
    };
    const topologyHints = deps.computeTopologyHints(task, candidateFiles.length, fastResult.intent.complexity);
    const catalogHealth = deps.scanCatalogHealth();
    const deepBootstrappedAt = Date.now();
    // Update the durable receipt to reflect deep completion
    writeBootstrapReceipt(deps.stateRoot, {
        workspaceStateKey: fastResult.workspace.stateKey,
        sessionId: fastResult.runtime.sessionId,
        bootstrappedAt: fastResult.bootstrappedAt,
        fast: true,
        deep: true,
        recommendedNextStep: 'nexus_orchestrate',
        repoIdentity: buildRepoIdentity(deps.repoRoot),
    });
    return {
        candidateFiles,
        candidateFilesDropped,
        shortlist,
        sourceMixRecommendation,
        knowledgeWarmup,
        topologyHints,
        catalogHealth,
        deepBootstrappedAt,
    };
}
