src/bmm-skills/ship/bmad-code-review/steps/step-01-gather-context.md
{communication_language}{diff_file} and the claims file is the only change this step may make. Otherwise it is read-only.Find the review target. The conversation context before this skill was triggered IS your starting point — not a blank slate. Check in this order — stop as soon as the review target is identified:
Tier 1 — Explicit argument. Did the user pass a PR, commit SHA, branch, spec file, or diff source this message?
gh pr view. If resolution fails, ask for a SHA or branch.spec_file to the provided path. Check its frontmatter for baseline_commit. If found, use as diff baseline. If not found, continue the cascade (a spec alone does not identify a diff source).Tier 2 — Recent conversation. Do the last few messages reveal what the user wants to be reviewed? Look for spec paths, commit refs, branches, PRs, or descriptions of a change. Apply the same diff-mode keyword scan and routing as Tier 1.
Tier 3 — Sprint tracking.
Look for a sprint status file (*sprint-status*) in {implementation_artifacts} or {planning_artifacts}. If found, scan for stories with status review:
review story: Set story_key to the story's key (e.g., 1-2-user-auth). HALT and give the user a choice:
<story-id> (status review).story_key and fall through.review stories: Present them as numbered options alongside a manual choice option. Wait for user selection. If a story is selected, set story_key and use its context to determine the diff source. If manual choice is selected, clear story_key and fall through.Tier 4 — Current git state.
If version control is unavailable, skip to Tier 5. Otherwise, check the current branch and HEAD. If the branch is not main (or the default branch), confirm: "I see HEAD is <short-sha> on <branch> — do you want to review this branch's changes?" If confirmed, treat as a branch diff against main. If declined, fall through.
Tier 5 — Ask. Fall through to instruction 2.
Never ask extra questions beyond what the cascade prescribes. If a tier above already identified the target, skip the remaining tiers and proceed to instruction 3 (construct diff).
HALT. Ask the user: What do you want to review? Present these options:
Write the diff for the chosen source to {diff_file} — a uniquely-named file in the system temp directory, so concurrent reviews cannot collide. The review layers read that file; the diff text is never pasted into their prompts.
git diff --cached > {diff_file}.git diff HEAD > {diff_file}.git diff <base-branch>...HEAD > {diff_file}. If it does not exist, HALT and ask the user for a valid branch.git diff <range> > {diff_file}. If it does not resolve, HALT and ask the user for a valid range.{diff_file}.git diff HEAD -- <path1> <path2> ... > {diff_file}. If any paths are untracked (new files not yet staged), append them with git diff --no-index /dev/null <path> >> {diff_file}. If the diff is empty (files have no uncommitted changes and are not untracked), ask the user whether to review the full file contents or to specify a different baseline.{diff_file}, verify it is non-empty regardless of source type. If empty, HALT and tell the user there is nothing to review.{diff_file} yourself whenever you need the diff for your own context — triage and presentation later in this workflow.Stage the claims file. Collect the change's own narrative: for a branch diff or commit range, the commit messages it covers (git log <base>..<head>); for other sources, whatever description of the change the user or conversation supplied. Write it verbatim to a uniquely-named file in the system temp directory and set claims_file to its path. If there is no narrative, set claims_file = ''. Do not analyze or summarize the narrative — it is input for one review layer, staged as a file precisely so the other layers never see it.
Set the spec context.
review_mode = no-spec and clear spec_file (set it to ''). Do not ask for a spec. Do not infer no-spec mode merely because the invocation omitted a spec path.spec_file is already set (from Tier 1 or Tier 2): verify the file exists and is readable, then set review_mode = full.spec_file to that path, verify the file exists and is readable, then set review_mode = full.review_mode = no-spec.If review_mode = full and the file at {spec_file} has a context field in its frontmatter listing additional docs, load each referenced document. Warn the user about any docs that cannot be found.
Sanity check: if wc -l {diff_file} exceeds approximately 3000 lines, warn the user and offer to chunk the review by file group.
{diff_file} narrowed to that group, and list the remaining groups for the user to note for follow-up runs.Present a summary before proceeding: diff stats (files changed, lines added/removed), {review_mode}, and loaded spec/context docs (if any). HALT and wait for user confirmation to proceed.
Read fully and follow ./step-02-review.md