1---2name: write-product-spec3description: Use when a user asks for a product spec with invariants, a tech spec, or a PRD. Modes: product (default), technical, requirements. Not for task breakdown: use plan.4---56# Write product spec78## Contract910| Field | Bound contract |11|---|---|12| Trigger | User asks for a product spec with numbered behavioral invariants, a technical implementation plan, or an evidence-backed PRD. |13| Authority | Human-gated: in requirements mode, previews and confirms credentials, paid actions, and remote publishing before execution; otherwise writes only the named artifact. Rollback is delete the file. No remote mutation without explicit human approval in requirements mode. |14| Side effect | Writes one PRODUCT.md, TECH.md, or PRD artifact; in requirements mode also stages, commits, and opens a PR after explicit confirmation. |15| Done | The named artifact exists, meets its mode-specific contract, and the output is confirmed. |1617## Inputs1819- Mode (required): `product` (default), `technical`, or `requirements`.20- Feature identifier or intent (required): for `product` and `requirements`, a short kebab-case feature name or ticket or issue number; for `technical`, a description of the feature, change, or system to specify.21- Feature summary (required for `product` and `requirements`): one to three sentences describing what the feature does and the desired outcome.22- Target consumers (optional for `product`): who consumes the surface. Defaults to the end user.23- Key behaviors and edge cases (optional for `product`): gather via dialogue; do not guess.24- Codebase context (optional for `technical`): existing files, modules, or architecture the spec must integrate with.25- Target users (optional for `requirements`): who the feature serves.26- Constraints (optional for `requirements`): limits on the feature.27- Related URLs or docs (optional for `requirements`): sources to cite.28- Priority level (optional for `requirements`): P0, P1, or P2.2930## Procedure31321. Select the mode. Ask or infer from the request: `product` for behavioral invariants, `technical` for implementation plan, `requirements` for evidence-backed PRD. Default to `product` if the request does not name a mode. Done when: the mode is confirmed.332. Confirm scope. Ask only what is strictly necessary; do not guess.34 - Mode `product`: confirm the feature identifier, feature summary, target consumers, key behaviors, edge cases, and validation approach.35 - Mode `technical`: confirm the intent, codebase context, and constraints.36 - Mode `requirements`: confirm the feature name or description, target users, constraints, related URLs or docs, and priority level.37 Done when: the required scope for the selected mode is confirmed.383. Mode `requirements`: gather supporting evidence. Read local sources when present and non-stale (≤7 days): `reports/customer_feedback_summaries/`, `reports/competitor_changelog_reports/` or `reports/feature_research/`, `reports/git_history_analysis/`, `reports/weekly_product_briefings/`. Note absent or stale sources. Cite every claim in the Problem Statement and Technical Considerations sections; tag unattributed claims `[UNCITED]`. Done when: available sources are read and stale or missing sources are noted.394. Draft the artifact structure.40 - Mode `product`: Summary (required), Behavior (required, numbered invariants), optional Problem, optional Goals/Non-goals, optional Open questions. Do not include Validation, Success criteria, or Testing sections.41 - Mode `technical`: Objective, Background, Design, Implementation plan, Risks and mitigations, Open questions. No placeholders or TODOs.42 - Mode `requirements`: TL;DR, Problem Statement, Goals & Success Metrics, Target Users, Scope, Proposed Solution, Technical Considerations, Competitive Context, Open Questions, References. Include a header block with title, author, date, status (Draft), priority.43 Done when: the section list is decided with required and optional sections.445. Produce the content.45 - Mode `product`: write Behavior as numbered, testable invariants from the consumer's perspective. Cover default flow, states, inputs, empty/error/loading/cancellation states, edge cases, keyboard/accessibility, and invariants. Keep framing thin relative to Behavior.46 - Mode `technical`: write each section. Validate every implementation step against the codebase: confirm referenced paths, types, and interfaces exist or are created by a prior step.47 - Mode `requirements`: write each section with citations. Derive the feature slug from the feature name (lowercase, hyphenated).48 Done when: all sections are drafted with concrete content and the mode-specific contract is satisfied.496. Write the artifact.50 - Mode `product`: `specs/<id>/PRODUCT.md` where `<id>` is the feature identifier.51 - Mode `technical`: `TECH.md` in the working directory.52 - Mode `requirements`: `reports/prds/prd_<feature_slug>_YYYY-MM-DD.md`.53 Create the directory if it does not exist. Done when: the file is written to the correct path.547. Mode `requirements`: publish the PRD. Present the saved path and a content summary. Obtain explicit confirmation. Stage and commit the PRD file; open a pull request against the default branch. If VCS commands fail, report the error. Inform the user that optional exports to Google Docs, Notion, or Slack are separate steps. Done when: the PR is open or the user stops before the PR.558. Confirm the output. Present the file path, a one-line summary, and a count (behavior invariants for `product`, implementation steps for `technical`, or sections for `requirements`). Done when: the summary and count are presented.5657## Failure and recovery5859| Failure class | Mode | Partial-result rule | Recovery |60|---|---|---|---|61| Missing scope | all | No file written | Stop; ask for the missing input. |62| Conflicting requirements | technical | No file written | Stop; name the conflict and present the trade-off. |63| Scope creep | technical | Bound to the original ask | Note out-of-scope items in Open questions. |64| Technical uncertainty | technical | Record the assumption | Flag the assumption in Open questions with the test or investigation needed. |65| Unclear behavior | product | No file written | Write `**Open question:** ...` inline in Behavior; do not guess. |66| File write fails | all | No artifact on disk | Report the error with the path and root cause. |67| Source read fails | requirements | Continue without that source | Note the absence; do not halt. |68| Stale data (>7 days) | requirements | Note staleness | Proceed; do not block. |69| Uncited claim | requirements | Tag `[UNCITED]` | Resolve or move to Open Questions. |70| Missing required section | all | Incomplete artifact | Do not claim Done; report which section is absent. |71| PR creation fails | requirements | PRD file exists | Report the error; do not delete the PRD file. |72| Partial stop | all | No file written | Do not save a partial artifact. |7374To reverse the side effect, delete the written artifact. In requirements mode, a partial result that produced a file but not a PR leaves the file in place.7576## Output7778- Mode `product`: `specs/<id>/PRODUCT.md` with sections in order: Summary, Behavior (numbered invariants), optional Problem, optional Goals/Non-goals, optional Open questions; no Validation, Success criteria, or Testing sections.79- Mode `technical`: `TECH.md` with sections in order: Objective, Background, Design, Implementation plan, Risks and mitigations, Open questions; no placeholders or TODOs.80- Mode `requirements`: `reports/prds/prd_<feature_slug>_YYYY-MM-DD.md` with sections in order: TL;DR, Problem Statement, Goals & Success Metrics, Target Users, Scope, Proposed Solution, Technical Considerations, Competitive Context, Open Questions, References; plus an open PR against the default branch.