// engine/well-known/manifest-generator.ts — SPEC-162: Generate .well-known/planu.json manifest
import { KNOWN_CAPABILITIES } from './manifest-schema.js';
/** Private statuses excluded from the manifest unless includePrivate=true. */
const PRIVATE_STATUSES = new Set(['private', 'draft']);
/**
 * Determine capabilities to declare based on the spec list.
 * Always includes 'spec-registry' as a base capability.
 */
function inferCapabilities(specs) {
    const caps = new Set(['spec-registry']);
    const hasEstimation = specs.some((s) => s.estimation.devHours > 0);
    if (hasEstimation) {
        caps.add('estimation');
    }
    const hasChangelog = specs.some((s) => s.status === 'done');
    if (hasChangelog) {
        caps.add('changelog');
    }
    // Only emit known capabilities to avoid leaking internal state
    return KNOWN_CAPABILITIES.filter((k) => caps.has(k));
}
/**
 * Build a ManifestSpec summary from a full Spec object.
 * Description is capped at 200 characters to keep the manifest compact.
 */
function toManifestSpec(spec) {
    // Spec does not have a description field — use the title as fallback.
    const rawDescription = spec.title;
    const description = rawDescription.length > 200 ? rawDescription.slice(0, 197) + '...' : rawDescription;
    return {
        id: spec.id,
        title: spec.title,
        status: spec.status,
        type: spec.type,
        description,
        tags: Array.isArray(spec.tags) ? spec.tags : [],
        created: spec.createdAt.split('T')[0] ?? spec.createdAt,
    };
}
/**
 * Generate a WellKnownManifest from a list of project specs.
 * Filters out private/draft specs unless includePrivate is true.
 */
export function generateManifest(options) {
    const { projectName, specs, includePrivate } = options;
    const filteredSpecs = includePrivate
        ? specs
        : specs.filter((s) => !PRIVATE_STATUSES.has(s.status));
    const manifestSpecs = filteredSpecs.map(toManifestSpec);
    const capabilities = inferCapabilities(filteredSpecs);
    return {
        version: 1,
        name: projectName,
        specCount: manifestSpecs.length,
        specs: manifestSpecs,
        capabilities,
        generatedAt: new Date().toISOString(),
    };
}
//# sourceMappingURL=manifest-generator.js.map