import { collectGitWorkingEnvironment } from './git.js';
import { collectCodingProjectSignals } from './project-signals.js';
import { collectCodingWorkspaceTree } from './workspace-tree.js';
export async function collectCodingWorkingEnvironment(input) {
    const sources = [{
            kind: 'filesystem',
            path: input.workspaceRoot,
            note: 'workspace root',
        }];
    const limits = [];
    const gitResult = await collectGitWorkingEnvironment(input.workspaceRoot);
    sources.push(...gitResult.sources);
    limits.push(...gitResult.limits);
    return {
        environment: {
            workspaceRoot: input.workspaceRoot,
            gitRepositoryRoot: gitResult.environment.gitRepositoryRoot,
            gitBranch: gitResult.environment.gitBranch,
            gitShortCommit: gitResult.environment.gitShortCommit,
            isGitRepository: gitResult.environment.isGitRepository,
            isDirty: gitResult.environment.isDirty,
            paths: gitResult.environment.paths,
        },
        sources,
        limits,
    };
}
export async function collectCodingProjectDashboard(input) {
    const environmentResult = await collectCodingWorkingEnvironment(input);
    const [treeResult, projectSignalsResult] = await Promise.all([
        collectCodingWorkspaceTree({
            workspaceRoot: input.workspaceRoot,
            maxDepth: input.maxDepth,
            maxEntries: input.maxEntries,
        }),
        collectCodingProjectSignals({
            workspaceRoot: input.workspaceRoot,
            environment: environmentResult.environment,
        }),
    ]);
    return {
        environment: environmentResult.environment,
        workspaceTree: treeResult.tree,
        projectSignals: projectSignalsResult.projectSignals,
        inspectionSurfaces: projectSignalsResult.inspectionSurfaces,
        sources: mergeSources(environmentResult.sources, treeResult.sources, projectSignalsResult.sources),
        limits: [...environmentResult.limits, ...treeResult.limits, ...projectSignalsResult.limits],
    };
}
function mergeSources(...sourceGroups) {
    const seen = new Set();
    const merged = [];
    for (const sources of sourceGroups) {
        for (const source of sources) {
            const key = `${source.kind}|${source.command ?? ''}|${source.path ?? ''}|${source.note ?? ''}`;
            if (seen.has(key)) {
                continue;
            }
            seen.add(key);
            merged.push(source);
        }
    }
    return merged;
}
//# sourceMappingURL=workspace.js.map