# Phase 3 — Finalize & Write

INPUT: the proposal draft approved at the review gate between Phase 2 and Phase 3. OUTPUT: `docs/business/<project-slug>/proposal.md`, assembled deterministically by a script. Run this phase only after the gate passes.

You do NOT hand-write the proposal document. You write a **content file** of `@@MARKER@@` blocks with the approved prose; `scripts/assemble-proposal.sh` reads the selected language template + content file and writes the final `.md` with the correct frontmatter, headings, and `::: {custom-style=...}` divs. Structure is owned by the template + script — never by you.

```
1. Resolve the output paths:
   - Directory: `docs/business/<project-slug>/` (create it if missing).
   - Final Markdown: `docs/business/<project-slug>/proposal.md`.
   - Temporary blocks file: `docs/business/<project-slug>/proposal.blocks`.
   - Based-on input path: `docs/inputs/<project-slug>/index.json`.
   - If `proposal.md` already exists, call `AskUserQuestion` with options "Overwrite" and "Cancel". Never overwrite silently.

2. Write the CONTENT FILE at `docs/business/<project-slug>/proposal.blocks` (UTF-8). EXACTLY these 11 markers, each ALONE on its own line, followed by the block content. Use the approved Phase 2 content verbatim.

   @@PROJECT_SUBTITLE@@
   <one line: "<solution or initiative> — <client/brand>" — no double quotes inside>
   @@DATE@@
   <one line: today, ISO YYYY-MM-DD>
   @@SLUG@@
   <one line: the project slug>
   @@INPUT_PATH@@
   docs/inputs/<project-slug>/index.json
   @@LANG@@
   <one line: resolved output language, exactly es or en>
   @@TARGET_MARKET@@
   <multi-line prose for section 1>
   @@PROBLEM_DEFINITION@@
   <multi-line prose for section 2>
   @@SOLUTION_COMPONENTS@@
   <multi-line prose for section 3>
   @@EXECUTION_APPROACH@@
   <multi-line prose for section 4>
   @@SUCCESS_FACTORS@@
   <bullets or short paragraphs for success factors, in the resolved output language>
   @@DISCOVERY_HOURS@@
   <EXACTLY ONE positive integer — your own estimate, sized to this project's complexity. Script validates ^[0-9]+$.>

   Rules for the content file:
   - Write ONLY content between markers.
   - NO headings (`#`, `##`, `###`), NO frontmatter (`---`), NO `::: {custom-style=...}` divs, NO Discovery title/bold line — all of those live in the selected template.
   - Frontmatter values (PROJECT_SUBTITLE, DATE, SLUG, INPUT_PATH, LANG) each on ONE line.
   - LANG MUST be exactly `es` or `en`; the assembly script selects the corresponding template.
   - Body sections (TARGET_MARKET through SUCCESS_FACTORS) MAY be multi-line.

3. Run the assembly script:

       bash "$CLAUDE_PLUGIN_ROOT/skills/business-proposal/scripts/assemble-proposal.sh" \
            "docs/business/<project-slug>/proposal.blocks" \
            "docs/business/<project-slug>/proposal.md"

   In a local checkout where $CLAUDE_PLUGIN_ROOT is not set, call the script by its repo path. On Windows, if `bash` resolves to a broken WSL install, use Git Bash directly (e.g. `C:\Program Files\Git\bin\bash.exe`).

4. If the script reports `missing required block @@...@@` or `@@DISCOVERY_HOURS@@ must be a single positive integer`, fix the content file and re-run. Do NOT hand-write the `.md` as a workaround.

5. Validate the assembled `proposal.md` before deleting `proposal.blocks`:
   - MUST start with frontmatter containing the selected title (`title: "PROPUESTA DE NEGOCIO"` for `es`, `title: "BUSINESS PROPOSAL"` for `en`), `subtitle:`, `source: business-proposal`, `proposal_date:`, `slug:`, `based_on:`, and `language: <es|en>`.
   - If `language: es`, MUST contain exactly the template-owned section structure: `# 1. Mercado Objetivo y Cliente Ideal`, `# 2. Definición del Problema`, `# 3. Componentes Clave de la Solución`, `# 4. Enfoque de Ejecución del Proyecto`, `## Factores clave de éxito`, `::: {custom-style="Internal Title"}`, and `::: {custom-style="Internal Subtitle"}`.
   - If `language: en`, MUST contain exactly the template-owned section structure: `# 1. Target Market and Ideal Client`, `# 2. Problem Definition`, `# 3. Key Solution Components`, `# 4. Project Execution Approach`, `## Key success factors`, `::: {custom-style="Internal Title"}`, and `::: {custom-style="Internal Subtitle"}`.
   - MUST NOT contain hand-written metadata fields such as `project_slug:`, `client_contact:`, `discovery_hours_estimate:`, or a `# Propuesta de negocio` / `# Business Proposal` heading.
   - MUST NOT contain `Próximo paso`, `Next step`, `Puntos a resolver`, `Open points`, `Puntos a confirmar`, or `Points to confirm`.
   - If validation fails, stop, keep `proposal.blocks` for debugging, and do NOT render DOCX.

6. Delete the content file: `rm docs/business/<project-slug>/proposal.blocks`. The final artifact is the `.md` only.
```

FINAL REPORT:

- Show the output path and a one-line summary: `<N> words · 6/6 sections`.
- Score against `references/checklist.md`.
- Print exactly `/machine-business:render-docx docs/business/<project-slug>/proposal.md` as the next-step suggestion. Do NOT print bare `/render-docx`, and do NOT run the command.
