// resources/velocity-report-resource.ts — MCP resource for planu://velocity/report
// Returns velocity reports aggregated across all registered projects (last 8 weeks).
// No parameters required.
import { getProjects } from '../storage/global-projects-store.js';
import { listSpecs } from '../storage/spec-store.js';
import { hashProjectPath } from '../storage/base-store.js';
import { buildVelocityReport } from '../engine/velocity-calculator.js';
const DEFAULT_WEEKS = 8;
/**
 * MCP resource handler for planu://velocity/report
 * Generates a velocity report for each registered project and returns them all.
 */
export async function handleVelocityReportResource() {
    const projects = await getProjects();
    if (projects.length === 0) {
        return JSON.stringify({
            generatedAt: new Date().toISOString(),
            projectCount: 0,
            message: 'No projects registered. Use register_project_path to add projects.',
            reports: [],
        }, null, 2);
    }
    const reports = await Promise.all(projects.map(async (project) => {
        const projectId = hashProjectPath(project.path);
        const specs = await listSpecs(projectId);
        const report = buildVelocityReport(specs, projectId, project.path, { weeks: DEFAULT_WEEKS });
        return {
            projectPath: project.path,
            totalSpecs: report.totalSpecs,
            summary: report.summary,
            wip: report.wip,
            leadTime: report.leadTime,
            cycleTime: report.cycleTime,
            flowEfficiency: report.flowEfficiency,
            throughput: report.throughput,
        };
    }));
    return JSON.stringify({
        generatedAt: new Date().toISOString(),
        projectCount: projects.length,
        weeks: DEFAULT_WEEKS,
        reports,
    }, null, 2);
}
export const velocityReportResourceDefinition = {
    uri: 'planu://velocity/report',
    name: 'Velocity Report',
    description: 'Velocity metrics for all registered projects: throughput, lead time, cycle time, WIP ' +
        '(last 8 weeks). Read-only. For a specific project or custom period use the velocity_report tool.',
    mimeType: 'application/json',
};
//# sourceMappingURL=velocity-report-resource.js.map