// Planu — Code Analysis Engine
// Orchestrates project analysis by delegating to specialized detectors
import { loadStackSignatures, loadArchPatterns } from '../detection-utils.js';
import { detectLanguage, detectLanguageVersion } from '../language-detector.js';
import { detectFramework, detectFrameworkVersion, detectDatabase, detectOrm, detectPackageManager, detectBuildCommand, detectTestCommand, detectLintCommand, } from '../framework-detector.js';
import { detectArchitecture } from '../architecture-detector.js';
import { detectApps, isMonorepoProject, detectApiContracts } from '../multi-app-detector.js';
import { analyzeEnvSetup, discoverMcps, buildStackList, buildQualityProfile } from './env-setup.js';
import { detectAgentProjectKnowledge } from '../detectors/agent-framework-detector.js';
import { analyzeLinting, detectConventions, detectEnvironments, detectExternalServices, detectTooling, } from './detectors.js';
import { checkProjectCompleteness } from './completeness-checker.js';
import { detectProjectCategory } from '../platform-detector.js';
// === Public API ===
/**
 * Full project analysis: scans filesystem to build ProjectKnowledge.
 */
// eslint-disable-next-line max-lines-per-function -- orchestrator delegates to detectors, not decomposable
export async function analyzeProject(projectPath, projectId, locale = 'en', experienceLevel = 'intermediate', stackSignatures, archPatterns) {
    const signatures = stackSignatures ?? (await loadStackSignatures());
    const archConfig = archPatterns ?? (await loadArchPatterns());
    const [language, framework, packageManager, database, orm, apps, architecture, linting, envSetup, apiContracts, mcps, conventions, monorepo, _completeness,] = await Promise.all([
        detectLanguage(projectPath, signatures),
        detectFramework(projectPath, signatures),
        detectPackageManager(projectPath, signatures),
        detectDatabase(projectPath, signatures),
        detectOrm(projectPath),
        detectApps(projectPath, signatures, archConfig),
        detectArchitecture(projectPath, archConfig),
        analyzeLinting(projectPath),
        analyzeEnvSetup(projectPath, projectId),
        detectApiContracts(projectPath),
        discoverMcps(projectPath),
        detectConventions(projectPath),
        isMonorepoProject(projectPath),
        checkProjectCompleteness(projectPath),
    ]);
    const [languageVersion, frameworkVersion, buildCommand, testCommand, lintCommand, externalServices, tooling, environments, projectCategory, agentKnowledge,] = await Promise.all([
        detectLanguageVersion(projectPath, language),
        detectFrameworkVersion(projectPath, framework, signatures),
        detectBuildCommand(projectPath, packageManager),
        detectTestCommand(projectPath, packageManager),
        detectLintCommand(projectPath, packageManager),
        detectExternalServices(projectPath),
        detectTooling(projectPath),
        detectEnvironments(projectPath),
        detectProjectCategory(projectPath, framework),
        detectAgentProjectKnowledge(projectPath),
    ]);
    const stack = buildStackList(language, framework, database, packageManager);
    const layers = architecture.layers.map((l) => l.name);
    const qualityProfile = buildQualityProfile(linting, conventions);
    return {
        projectId,
        projectPath,
        locale,
        experienceLevel,
        language,
        languageVersion,
        framework,
        frameworkVersion,
        packageManager,
        buildCommand,
        testCommand,
        lintCommand,
        stack,
        database,
        orm,
        architecture,
        apps,
        conventions,
        layers,
        environments,
        apiContracts,
        monorepo,
        externalServices,
        tooling,
        specLocation: 'planu/specs',
        envSetup,
        linting,
        availableMcps: mcps,
        docsRegistry: {},
        qualityProfile,
        lastAnalyzed: new Date().toISOString(),
        projectCategory,
        agentKnowledge: agentKnowledge.framework !== null ? agentKnowledge : undefined,
    };
}
/**
 * Quick analysis: only detects language, framework, and package manager.
 */
export async function quickAnalyze(projectPath) {
    const signatures = await loadStackSignatures();
    const [language, framework, packageManager, database] = await Promise.all([
        detectLanguage(projectPath, signatures),
        detectFramework(projectPath, signatures),
        detectPackageManager(projectPath, signatures),
        detectDatabase(projectPath, signatures),
    ]);
    return { language, framework, packageManager, database };
}
//# sourceMappingURL=analyze-project.js.map