---
name: draft-prds
description: Use when the user wants to create draft PRDs from Discovery RF requirements. Reads docs/discovery/<project-slug>/requirements/index.json, creates PRD Markdown items under draft-prds/items/, and maintains draft-prds/index.json with each PRD associated to a list of RF IDs. Triggers on "/machine-discovery:draft-prds <project-slug>", "/draft-prds <project-slug>", and requests to draft PRDs from Discovery.
---

# Draft PRDs

Create draft PRDs from indexed functional requirements. PRDs are Discovery outputs, not final `machine-work` PRDs.

## Inputs

```text
docs/discovery/<project-slug>/inputs/business-proposal.md
docs/discovery/<project-slug>/requirements/index.json
docs/discovery/<project-slug>/requirements/requirements.md
docs/discovery/<project-slug>/requirements/items/RF-###.md
docs/discovery/<project-slug>/requirements/items/RNF-###.md
```

Only RF entries are assigned to PRD `rf` lists. RNF entries MAY be referenced as constraints inside PRD bodies.

## Outputs

```text
docs/discovery/<project-slug>/draft-prds/
  index.json
  items/
    PRD-001.md
```

## PRD index contract

`docs/discovery/<project-slug>/draft-prds/index.json`:

```json
{
  "project": "<project-slug>",
  "prds": []
}
```

Each entry MUST use this shape:

```json
{
  "id": "PRD-001",
  "title": "Gestion de clientes",
  "md": "items/PRD-001.md",
  "rf": ["RF-001", "RF-002"],
  "status": "draft"
}
```

## Operating protocol

1. Parse `$ARGUMENTS` and resolve the output language.
   - The first token MUST be a kebab-case ASCII project slug.
   - A second token MAY be `es` or `en`; if present, it wins.
   - If a second token is present and is not `es` or `en`, stop with `NEEDS INPUT: language must be es or en`.
   - If no language argument is present, inherit `language` from `requirements/requirements.md`; otherwise from `planning/phase-plan.md`; if missing, use the current user request language; if ambiguous, default to `es`.
   - If missing or invalid, stop with `NEEDS INPUT: indica el project slug, por ejemplo /machine-discovery:draft-prds acme-demo`.
2. Validate prerequisites:
   - `inputs/business-proposal.md` MUST exist and be non-empty.
   - `requirements/index.json` MUST exist and include at least one `kind: "FR"` requirement.
   - `requirements/requirements.md` MUST exist and be non-empty.
   - Every referenced item RF/RNF Markdown file MUST exist and be readable.
3. Read or initialize `draft-prds/index.json`.
   - If missing, create the empty PRD index contract.
   - If present, validate `project`, `prds` array, every `id`, every `md`, and every `rf` list.
   - If an indexed PRD file is missing, stop and ask whether the user wants to restore it or intentionally remove the index entry.
   - Ensure `docs/discovery/<project-slug>/draft-prds/items/` exists.
4. Group RFs into draft PRDs by module, user workflow, bounded context, or product capability evidenced in the requirement titles and descriptions.
5. Reuse existing PRDs before adding new ones:
   - If an existing PRD has the same normalized title or the same RF set, reuse it and do not rewrite its file.
   - If a new PRD is needed, allocate the next `PRD-###` ID.
6. For each new PRD:
   - Write a temporary content file beside the item output: `items/<PRD-ID>.blocks`.
   - The content file MUST contain one `@@KEY@@` block for each placeholder in `templates/draft-prd.<lang>.md.tmpl`, including `@@LANG@@`.
   - Run `bash plugins/machine-discovery/scripts/assemble-doc.sh plugins/machine-discovery/skills/draft-prds/templates/draft-prd.<lang>.md.tmpl docs/discovery/<project-slug>/draft-prds/items/<PRD-ID>.blocks docs/discovery/<project-slug>/draft-prds/items/<PRD-ID>.md`.
   - Delete the `.blocks` file only after the assembled Markdown is validated.
   - Include a `Requisitos funcionales asociados` section with every RF ID in the PRD index entry.
   - Include relevant RNF constraints separately. RNF IDs MUST NOT appear inside the PRD index `rf` list.
7. Update `draft-prds/index.json`:
   - Preserve existing entries and order.
   - Append new entries in PRD ID order.
   - `md` MUST be relative to `docs/discovery/<project-slug>/draft-prds/` and MUST point to `items/<PRD-ID>.md`.
8. Score against [references/checklist.md](references/checklist.md). Pass criterion: 8/8.
9. Final report MUST print exactly `/machine-discovery:project-doc <project-slug>` as the next-step suggestion.

## Hard rules

- **RF association required.** Every PRD MUST have a non-empty `rf` list in `draft-prds/index.json`.
- **RF only in index association.** `rf` lists MUST contain only IDs that exist with `kind: "FR"` in `requirements/index.json`.
- **No orphan PRDs.** Do not create a PRD file without adding it to `draft-prds/index.json`.
- **PRD items only.** Generated PRD Markdown files MUST live under `draft-prds/items/`.
- **Script-owned Markdown.** Final PRD Markdown files MUST be assembled by `scripts/assemble-doc.sh` from `.blocks` files and templates.
- **Selected-language output.** Generated titles, body prose, and template-owned headings MUST match the resolved output language; verbatim source quotes stay unchanged.
- **No silent overwrite.** Existing PRD files MUST NOT be overwritten unless the user explicitly asked to regenerate them.
- **Draft status only.** Generated PRDs MUST use `status: "draft"` until a later workflow promotes them.
- **No auto-chaining.** Suggest `/machine-discovery:project-doc <project-slug>` after success, but do not run it.

## References

- Draft PRD templates: [templates/draft-prd.es.md.tmpl](templates/draft-prd.es.md.tmpl), [templates/draft-prd.en.md.tmpl](templates/draft-prd.en.md.tmpl)
- Quality checklist: [references/checklist.md](references/checklist.md)
