/**
 * Implement Phase Prompt
 *
 * Builds per-phase implementation prompts that include full spec/research/plan
 * context plus the specific tasks for the current phase, with TDD guidance
 * and verification instructions.
 */
import { readSpecFile } from '../node-helpers.js';
function formatTaskSection(task) {
    let section = `### Task ${task.id}: ${task.title}\n${task.description}\n`;
    section += `\n**Acceptance Criteria:**\n`;
    for (const criterion of task.acceptanceCriteria) {
        section += `- ${criterion}\n`;
    }
    if (task.tdd) {
        section += `\n**TDD Guidance:**\n`;
        section += `- Write tests for: ${task.tdd.red.join('; ')}\n`;
        section += `- Implement: ${task.tdd.green.join('; ')}\n`;
        section += `- Then consider: ${task.tdd.refactor.join('; ')}\n`;
    }
    if (task.dependencies.length > 0) {
        section += `\nDepends on: ${task.dependencies.join(', ')}\n`;
    }
    return section;
}
/**
 * Build the implementation prompt for a single phase (or a single task
 * within a parallel phase). Includes full project context so each
 * executor session is self-contained.
 */
export function buildImplementPhasePrompt(state, phase, tasks, context) {
    const specContent = readSpecFile(state.specDir, 'spec.yaml');
    const researchContent = readSpecFile(state.specDir, 'research.yaml');
    const planContent = readSpecFile(state.specDir, 'plan.yaml');
    const cwd = state.worktreePath || state.repositoryPath;
    const taskSections = tasks.map(formatTaskSection).join('\n');
    const verificationBlock = context.isLastPhase
        ? `4. Run full project validation:
   - \`pnpm test\` (all tests must pass)
   - \`pnpm lint\` (no lint errors)
   - \`pnpm typecheck\` (no type errors)
   - Fix any issues before finishing`
        : `4. Run tests relevant to what you changed:
   - Run targeted tests for modified files (e.g. \`pnpm test:single <test-file>\`)
   - Fix any test failures before moving on`;
    return `You are a senior software engineer performing autonomous implementation.
You are executing phase ${context.phaseIndex + 1} of ${context.totalPhases}: "${phase.name}".

## Feature Specification

\`\`\`yaml
${specContent}
\`\`\`

## Research Decisions

\`\`\`yaml
${researchContent}
\`\`\`

## Implementation Plan

\`\`\`yaml
${planContent}
\`\`\`

## Your Tasks for This Phase: "${phase.name}"

${taskSections}

## Implementation Instructions

1. Work through each task in dependency order
2. For tasks with TDD guidance: write tests alongside implementation following the hints provided — use them as guidance, not rigid steps
3. Follow existing codebase conventions for file placement, naming patterns, and architecture layers
${verificationBlock}
5. Commit your work with descriptive conventional commit messages (e.g. \`feat(scope): description\`)

## Working Directory

${cwd}

## Constraints

- Implement ONLY the tasks listed above — do not work ahead to future phases
- Follow existing codebase conventions and architecture patterns
- Do NOT modify any spec YAML files (spec.yaml, research.yaml, plan.yaml, tasks.yaml, feature.yaml)
- Do NOT skip writing tests for tasks that have TDD guidance
- Keep changes focused and minimal — avoid unnecessary refactoring beyond what the tasks specify`;
}
