/**
 * Nexus Prime — Fast Bootstrap
 *
 * Performs lightweight orientation only:
 *   - workspace resolution
 *   - memory recall + stats
 *   - session DNA loading
 *   - session summary recovery
 *   - project memory recovery
 *   - intent classification
 *
 * This should return within milliseconds, not seconds.
 * Deep preparation (candidate files, knowledge fabric, planning) is deferred
 * to bootstrap_deep or on-demand during orchestrate.
 */
import { writeBootstrapReceipt, buildRepoIdentity } from './bootstrap-registry.js';
/**
 * Execute fast bootstrap. Returns BootstrapFastResult immediately.
 * Persists a durable receipt so the adapter can check bootstrap state.
 */
export async function bootstrapFast(task, deps) {
    const workspace = deps.getWorkspaceEnvelope();
    const runtime = deps.getRuntimeIdentity();
    const intent = deps.classifyIntent(task);
    const projectId = `project:${workspace.stateKey}`;
    const repoId = `repo:${workspace.repoName}`;
    const memoryStats = deps.getMemoryStats();
    const quarantined = deps.getQuarantinedCount();
    const [memoryRecall, sessionSummary, projectMemory] = await Promise.all([
        deps.recallMemory(task, 8),
        Promise.resolve(deps.recoverSessionSummary(projectId)),
        Promise.resolve(deps.recoverProjectMemory(repoId)),
    ]);
    const memoryHealth = {
        prefrontal: memoryStats.prefrontal,
        hippocampus: memoryStats.hippocampus,
        cortex: memoryStats.cortex,
        quarantined,
        totalEntries: memoryStats.prefrontal + memoryStats.hippocampus + memoryStats.cortex,
    };
    // Heuristic: recommend deep bootstrap if we have enough memory/context to leverage
    const needsDeepBootstrap = memoryRecall.count > 3 || intent.complexity > 5;
    const tokenOptimizationLikely = memoryHealth.totalEntries > 50;
    const bootstrappedAt = Date.now();
    const result = {
        workspace,
        runtime,
        sessionSummary,
        projectMemory,
        memoryHealth,
        memoryRecall,
        intent,
        recommendedNextStep: 'nexus_orchestrate',
        needsDeepBootstrap,
        tokenOptimizationLikely,
        bootstrappedAt,
    };
    // Persist durable receipt
    writeBootstrapReceipt(deps.stateRoot, {
        workspaceStateKey: workspace.stateKey,
        sessionId: runtime.sessionId,
        bootstrappedAt,
        fast: true,
        deep: false,
        recommendedNextStep: result.recommendedNextStep,
        repoIdentity: buildRepoIdentity(deps.repoRoot),
    });
    return result;
}
