// tools/spec-cookbook-handler.ts — SPEC-361: Spec Cookbook handlers
import { listEntries, getEntry, searchEntries, applyEntry, contributeEntry, formatEntryMarkdown, formatEntriesListMarkdown, } from '../engine/spec-cookbook.js';
// eslint-disable-next-line @typescript-eslint/require-await -- sync logic, async signature required by safe() wrapper
export async function handleCookbookList(args) {
    const entries = listEntries(args.domain, args.featureType, args.limit ?? 50);
    const markdown = formatEntriesListMarkdown(entries);
    return { content: [{ type: 'text', text: markdown }] };
}
// eslint-disable-next-line @typescript-eslint/require-await -- sync logic, async signature required by safe() wrapper
export async function handleCookbookGet(args) {
    const entry = getEntry(args.id);
    if (entry === null) {
        return {
            content: [
                {
                    type: 'text',
                    text: `No cookbook entry found with ID \`${args.id}\`. Use \`cookbook_list\` to see available entries.`,
                },
            ],
            isError: true,
        };
    }
    const markdown = formatEntryMarkdown(entry);
    return { content: [{ type: 'text', text: markdown }] };
}
// eslint-disable-next-line @typescript-eslint/require-await -- sync logic, async signature required by safe() wrapper
export async function handleCookbookApply(args) {
    const entry = getEntry(args.id);
    if (entry === null) {
        return {
            content: [
                {
                    type: 'text',
                    text: `No cookbook entry found with ID \`${args.id}\`. Use \`cookbook_list\` to see available entries.`,
                },
            ],
            isError: true,
        };
    }
    const result = applyEntry(entry, args.projectName);
    const output = [
        `# Spec Template: ${result.title}`,
        ``,
        `Copy the spec content below and pass it to \`create_spec\` as the description, or save it as a spec file.`,
        `Replace all \`[PLACEHOLDER]\` markers with your project-specific content.`,
        ``,
        `---`,
        ``,
        result.specContent,
    ].join('\n');
    return { content: [{ type: 'text', text: output }] };
}
// eslint-disable-next-line @typescript-eslint/require-await -- sync logic, async signature required by safe() wrapper
export async function handleCookbookContribute(args) {
    const newEntry = contributeEntry({
        domain: args.domain,
        featureType: args.featureType,
        title: args.title,
        description: args.description,
        acceptanceCriteria: args.acceptanceCriteria,
        tags: args.tags,
    });
    const output = [
        `# Contribution Added`,
        ``,
        `Your entry has been added to the in-memory cookbook.`,
        ``,
        `**ID:** \`${newEntry.id}\``,
        `**Title:** ${newEntry.title}`,
        `**Domain:** ${newEntry.domain}`,
        ``,
        `Note: This entry is available for the current session. To permanently add it, submit a PR to the Planu repository.`,
    ].join('\n');
    return { content: [{ type: 'text', text: output }] };
}
// eslint-disable-next-line @typescript-eslint/require-await -- sync logic, async signature required by safe() wrapper
export async function handleCookbookSearch(args) {
    const entries = searchEntries(args.query, args.limit ?? 20);
    const markdown = formatEntriesListMarkdown(entries);
    const header = `# Search Results for "${args.query}"\n\n`;
    return { content: [{ type: 'text', text: header + markdown }] };
}
//# sourceMappingURL=spec-cookbook-handler.js.map