src/bmm-skills/ship/bmad-build/step-01-clarify-and-route.md
{{.communication_language}}. Write any file output in {{.document_output_language}}.Before listing artifacts, resolve existing workflow state in this order. Skip the remaining checks as soon as a branch applies. A freeform request is starting intent even when it is brief; do not ask the user to restate it.
Explicit argument Did the user pass a specific file path, spec name, or clear instruction this message?
spec_folder and story_id. Read {spec_folder}/stories.yaml; if it is missing or fails to parse, HALT rather than falling back to {{.implementation_artifacts}}. Find the one entry whose string id exactly equals story_id; if none exists, HALT rather than falling back. Use that entry's title and description as the starting intent.
{spec_folder}/stories/{story_id}-*.md. More than one match → HALT rather than choosing one. Exactly one match → set spec_file to that path and process it exactly as if the user had supplied that specific file path, including Story-key resolution and the existing status route below. No matches → derive a valid kebab-case slug from the entry's title (and description if needed), then set spec_file = {spec_folder}/stories/{story_id}-{slug}.md and proceed to INSTRUCTIONS.status frontmatter with a recognized value: draft, ready-for-dev, in-progress, in-review, or done) → set spec_file. Before exiting, run Story-key resolution (below). Then EARLY EXIT to the appropriate step: draft → [[bmad-snapshot:step-02-plan.md]], ready-for-dev/in-progress → [[bmad-snapshot:step-03-implement.md]] (or [[bmad-snapshot:step-oneshot.md]] when route is oneshot), in-review → [[bmad-snapshot:step-04-review.md]]. For done, ingest as context and proceed to INSTRUCTIONS — do not resume.Recent conversation Do the last few human messages clearly show what the user intends to work on? Use the same routing as above.
Otherwise — scan artifacts and ask
draft, ready-for-dev, in-progress, in-review) in {{.implementation_artifacts}}? → List them and HALT. Give the user a choice:
draft selected: Set spec_file. Run Story-key resolution (below). EARLY EXIT → [[bmad-snapshot:step-02-plan.md]] (resume planning from the draft)
If ready-for-dev or in-progress selected: Set spec_file. Run Story-key resolution (below). EARLY EXIT → [[bmad-snapshot:step-03-implement.md]] (or [[bmad-snapshot:step-oneshot.md]] when route is oneshot)
If in-review selected: Set spec_file. Run Story-key resolution (below). EARLY EXIT → [[bmad-snapshot:step-04-review.md]]
If the user chooses New: proceed to INSTRUCTIONSstatus frontmatter? → Suggest treating its contents as the starting intent. Do NOT attempt to infer a state and resume it.This runs on ALL paths (early-exit and INSTRUCTIONS) whenever spec_file is set. Determine whether the spec is an epic story — use the spec's filename, frontmatter, and any loaded epics file to identify epic_num and story_num. If the spec is not an epic story, skip silently and leave story_key unset.
If the spec is an epic story and {{.implementation_artifacts}}/sprint-status.yaml exists: find the development_status key matching {epic_num}-{story_num} by exact numeric equality on the first two segments (so 1-1 never collides with 1-10). Exactly one match → set story_key to that full key. Zero or multiple matches → leave story_key unset (warn on multiple).
Load context.
List files in {{.planning_artifacts}} and {{.implementation_artifacts}}.
If you find an unformatted spec or intent file, ingest its contents to form your understanding of the intent.
Determine context strategy. Using the intent and the artifact listing, infer whether the current work is a story from an epic. Do not rely on filename patterns or regex — reason about the intent, the listing, and any epics file content together.
A) Epic story path — if the intent is clearly an epic story:
Identify the epic number {epic_num} and (if present) the story number {story_num}. If you can't identify an epic number, use path B.
Check for a valid cached epic context. Look for {{.implementation_artifacts}}/epic-<N>-context.md (where <N> is the epic number). A file is valid when it exists, is non-empty, starts with # Epic <N> Context: (with the correct epic number), and no file in {{.planning_artifacts}} is newer.
Compile epic context. Produce {{.implementation_artifacts}}/epic-<N>-context.md by following [[bmad-snapshot:compile-epic-context.md]], in order of preference:
[[bmad-snapshot:compile-epic-context.md]] as its prompt. Pass it the epic number, the epics file path, the {{.planning_artifacts}} directory, and the output path {{.implementation_artifacts}}/epic-<N>-context.md.[[bmad-snapshot:compile-epic-context.md]] yourself and follow its instructions to produce the same output file.Verify. After compilation, verify the output file exists, is non-empty, and starts with # Epic <N> Context:. If valid, load it. If verification fails, HALT and report the failure.
Previous story continuity. Regardless of which context source succeeded above, scan {{.implementation_artifacts}} for specs from the same epic with status: done and a lower story number. Load the most recent one (highest story number below current). Extract its Code Map, Design Notes, Spec Change Log, and task list as continuity context for step-02 planning. If no done spec is found but an in-review spec exists for the same epic with a lower story number, note it to the user and ask whether to load it.
Resolve {story_key}. If not already set by an earlier early-exit path, run Story-key resolution (above) now.
B) Freeform path — if the intent is not an epic story:
*prd*) — product requirements and success criteria*architecture*) — technical design decisions and constraints*ux*) — user experience and interaction design*epic*) — feature breakdown into implementable stories*brief*) — project vision and scopeCarry the intent and loaded evidence forward as-is. Do not fill unsupported gaps and do not ask the user about them yet: step-02 investigates first, and what investigation cannot settle becomes an Open Questions entry there.
Version control sanity check. Is the working tree clean? Does the current branch make sense for this intent — considering its name and recent history? If the tree is dirty or the branch is an obvious mismatch, HALT and ask the human before proceeding. If version control is unavailable, skip this check.
Multi-goal check (see SCOPE STANDARD). If the intent fails the single-goal criteria:
{{.implementation_artifacts}}/deferred-work.md using this format. Do not modify existing entries or look for duplicates. Narrow scope to the first-mentioned goal. Continue routing.
- source_spec: none
summary: <one sentence naming the deferred goal>
evidence: <why this was split from the current intent>
Set the spec file.
If the explicit spec-folder-plus-story-id pair had no matching story file, keep the colocated spec_file selected above. Otherwise, derive a valid kebab-case slug from the current intent. If the intent references a tracking identifier (story number, issue number, ticket ID), lead the slug with it (e.g. 3-2-digest-delivery, gh-47-fix-auth). If {{.implementation_artifacts}}/spec-{slug}.md already exists: if its status is draft, treat it as the same work and resume it (set spec_file to that path, EARLY EXIT → [[bmad-snapshot:step-02-plan.md]]); otherwise append -2, -3, etc. Set spec_file = {{.implementation_artifacts}}/spec-{slug}.md.
Read fully and follow [[bmad-snapshot:step-02-plan.md]]