From cc209dddad1eb075ad0c92e0e3db1f958e838cfd Mon Sep 17 00:00:00 2001 From: Alex Verkhovsky Date: Sat, 4 Apr 2026 20:02:48 -0700 Subject: [PATCH] fix(code-review): address review findings in step-01 intent cascade - Set {spec_file} immediately in Tier 1 when spec provided - Add staged/uncommitted handlers to instruction 3 dispatch table - Replace undefined {branch}/{sha} placeholders with angle brackets - Fix {story_key} vs {{story-id}} placeholder mismatch - Correct "wants reviewed" grammar to "wants to be reviewed" --- .../steps/step-01-gather-context.md | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/bmm-skills/4-implementation/bmad-code-review/steps/step-01-gather-context.md b/src/bmm-skills/4-implementation/bmad-code-review/steps/step-01-gather-context.md index 614c99a5c..22b9fbd3d 100644 --- a/src/bmm-skills/4-implementation/bmad-code-review/steps/step-01-gather-context.md +++ b/src/bmm-skills/4-implementation/bmad-code-review/steps/step-01-gather-context.md @@ -21,21 +21,21 @@ story_key: '' # set at runtime when discovered from sprint status Did the user pass a PR, commit SHA, branch, spec file, or diff source this message? - PR reference → resolve to branch/commit via `gh pr view`. If resolution fails, ask for a SHA or branch. - Commit or branch → use directly. - - Spec file → check its frontmatter for `baseline_commit`. If found, use as diff baseline. If not found, note the spec for instruction 4 and continue the cascade (a spec alone does not identify a diff source). + - Spec file → set `{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). - Also scan the argument for diff-mode keywords that narrow the scope: - "staged" / "staged changes" → Staged changes only - "uncommitted" / "working tree" / "all changes" → Uncommitted changes (staged + unstaged) - - "branch diff" / "vs main" / "against main" / "compared to {branch}" → Branch diff (extract base branch if mentioned) - - "commit range" / "last N commits" / "{sha}..{sha}" → Specific commit range + - "branch diff" / "vs main" / "against main" / "compared to " → Branch diff (extract base branch if mentioned) + - "commit range" / "last N commits" / ".." → Specific commit range - "this diff" / "provided diff" / "paste" → User-provided diff (do not match bare "diff" — it appears in other modes) - When multiple keywords match, prefer the most specific (e.g., "branch diff" over bare "diff"). **Tier 2 — Recent conversation.** - Do the last few messages reveal what the user wants 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. + 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`: - - **Exactly one `review` story:** Set `{story_key}` to the story's key (e.g., `1-2-user-auth`). Suggest it: "I found story {{story-id}} in `review` status. Would you like to review its changes? [Y] Yes / [N] No, let me choose". If confirmed, use the story context to determine the diff source (branch name derived from story slug, or uncommitted changes). If declined, clear `{story_key}` and fall through. + - **Exactly one `review` story:** Set `{story_key}` to the story's key (e.g., `1-2-user-auth`). Suggest it: "I found story in `review` status. Would you like to review its changes? [Y] Yes / [N] No, let me choose". If confirmed, use the story context to determine the diff source (branch name derived from story slug, or uncommitted changes). If declined, clear `{story_key}` and fall through. - **Multiple `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. - **None:** Fall through. @@ -55,15 +55,19 @@ story_key: '' # set at runtime when discovered from sprint status - **Provided diff or file list** (user pastes or provides a path) 3. Construct `{diff_output}` from the chosen source. + - For **staged changes only**: run `git diff --cached`. + - For **uncommitted changes** (staged + unstaged): run `git diff HEAD`. - For **branch diff**: verify the base branch exists before running `git diff`. If it does not exist, HALT and ask the user for a valid branch. - For **commit range**: verify the range resolves. If it does not, HALT and ask the user for a valid range. - For **provided diff**: validate the content is non-empty and parseable as a unified diff. If it is not parseable, HALT and ask the user to provide a valid diff. - For **file list**: validate each path exists in the working tree. Construct `{diff_output}` by running `git diff HEAD -- ...`. If any paths are untracked (new files not yet staged), use `git diff --no-index /dev/null ` to include them. 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. - After constructing `{diff_output}`, verify it is non-empty regardless of source type. If empty, HALT and tell the user there is nothing to review. -4. Ask the user: **Is there a spec or story file that provides context for these changes?** - - If yes: set `{spec_file}` to the path provided, verify the file exists and is readable, then set `{review_mode}` = `"full"`. - - If no: set `{review_mode}` = `"no-spec"`. +4. **Set the spec context.** + - If `{spec_file}` is already set (from Tier 1 or Tier 2): verify the file exists and is readable, then set `{review_mode}` = `"full"`. + - Otherwise, ask the user: **Is there a spec or story file that provides context for these changes?** + - If yes: set `{spec_file}` to the path provided, verify the file exists and is readable, then set `{review_mode}` = `"full"`. + - If no: set `{review_mode}` = `"no-spec"`. 5. 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.