/**
 * ProposeAcceptanceCriteriaUseCase — spec 097, FR-27.
 *
 * Given an issue body, returns a markdown checklist of acceptance criteria
 * suitable for posting back into the issue or for use as the brief for a
 * `/shep-kit:new-feature` invocation. Reusable from `groom-issue` and from
 * manual CLI calls.
 *
 * Determinism: the executor is invoked with `temperature: 0` (when the
 * adapter respects that hint) and a stable system prompt; combined with
 * the structured output schema this gives the use case the idempotent
 * behavior the acceptance criteria require.
 */
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
    return function (target, key) { decorator(target, key, paramIndex); }
};
import { inject, injectable } from 'tsyringe';
const SYSTEM_PROMPT = [
    'You write acceptance criteria for open-source contributor issues.',
    'Each criterion is a single GitHub markdown checkbox (`- [ ] ...`).',
    'Criteria are independently verifiable, observable from the outside,',
    'and avoid implementation details. Return between 2 and 6 criteria.',
].join(' ');
const MIN_CRITERIA = 2;
let ProposeAcceptanceCriteriaUseCase = class ProposeAcceptanceCriteriaUseCase {
    agentProvider;
    constructor(agentProvider) {
        this.agentProvider = agentProvider;
    }
    async execute(input) {
        const executor = await this.agentProvider.getExecutor();
        const prompt = renderPrompt(input);
        const result = await executor.execute(prompt, {
            systemPrompt: SYSTEM_PROMPT,
            outputSchema: {
                type: 'object',
                properties: {
                    criteria: {
                        type: 'array',
                        items: { type: 'string' },
                    },
                },
                required: ['criteria'],
            },
        });
        const criteria = parseCriteria(result.result);
        return { criteria, markdown: criteria.join('\n') };
    }
};
ProposeAcceptanceCriteriaUseCase = __decorate([
    injectable(),
    __param(0, inject('IAgentExecutorProvider')),
    __metadata("design:paramtypes", [Object])
], ProposeAcceptanceCriteriaUseCase);
export { ProposeAcceptanceCriteriaUseCase };
function renderPrompt(input) {
    return [
        'Write acceptance criteria for the GitHub issue below.',
        'Return JSON: { "criteria": ["- [ ] ...", "- [ ] ..."] }.',
        '',
        input.title ? `Title: ${input.title}` : '',
        `Body: ${input.body}`,
    ]
        .filter(Boolean)
        .join('\n');
}
function parseCriteria(raw) {
    const parsed = JSON.parse(raw);
    if (!Array.isArray(parsed.criteria)) {
        throw new Error('Agent did not return a "criteria" array.');
    }
    const criteria = parsed.criteria
        .filter((c) => typeof c === 'string')
        .map(normalizeCriterion);
    if (criteria.length < MIN_CRITERIA) {
        throw new Error(`Agent returned too few criteria (got ${criteria.length}, need at least ${MIN_CRITERIA}).`);
    }
    return criteria;
}
function normalizeCriterion(line) {
    const trimmed = line.trim();
    if (trimmed.startsWith('- [ ]'))
        return trimmed;
    if (trimmed.startsWith('- '))
        return `- [ ] ${trimmed.slice(2)}`;
    return `- [ ] ${trimmed}`;
}
