Skip to content

refactor(code-review): harmonize step-01 intent cascade#2206

Merged
alexeyv merged 2 commits intomainfrom
refactor/code-review-cascade
Apr 5, 2026
Merged

refactor(code-review): harmonize step-01 intent cascade#2206
alexeyv merged 2 commits intomainfrom
refactor/code-review-cascade

Conversation

@alexeyv
Copy link
Copy Markdown
Collaborator

@alexeyv alexeyv commented Apr 4, 2026

Summary

  • Restructures bmad-code-review/steps/step-01-gather-context.md instruction 1 from keyword-matching entry point to a 5-tier priority cascade matching quick-dev and checkpoint-preview
  • Cascade: explicit argument, recent conversation, sprint tracking, current git state, ask
  • Diff-mode keyword detection preserved as sub-check within tiers 1-2
  • Instructions 2-6 (diff construction, spec question, chunk warning) unchanged

Review patches

  • Spec-file routing in Tier 1: checks baseline_commit frontmatter before falling through
  • Explicit None fall through clause in Tier 3 sprint tracking
  • VCS-unavailable guard added to Tier 4

Test plan

  • Read the rewritten instruction 1 and confirm the cascade mirrors checkpoint-preview structure
  • Verify diff-mode keywords are preserved with identical semantics
  • Verify instructions 2-6, CHECKPOINT, and NEXT sections are untouched
  • Run npm run quality -- all checks pass

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 4, 2026

📝 Walkthrough

Walkthrough

This is a documentation-only change to the code review context-gathering step. It replaces phrase-based intent detection with a five-tier cascading logic: explicit arguments, recent conversation history, sprint tracking, git state confirmation, and user prompts, restructuring control flow to skip remaining tiers once a target is identified.

Changes

Cohort / File(s) Summary
Context-Gathering Logic Documentation
src/bmm-skills/4-implementation/bmad-code-review/steps/step-01-gather-context.md
Replaced triggering-phrase-based detection with tiered cascade for target identification: (Tier 1) explicit arguments with PR/commit/SHA/branch/spec/diff resolution, (Tier 2) recent conversation signals, (Tier 3) sprint tracking, (Tier 4) git state on non-main branches, (Tier 5) user prompts. Control flow restructured to proceed to diff construction once any tier identifies the review target.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Suggested reviewers

  • bmadcode
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'refactor(code-review): harmonize step-01 intent cascade' directly reflects the main change—restructuring the step-01-gather-context.md instruction 1 to use a 5-tier priority cascade approach.
Description check ✅ Passed The description clearly explains the restructuring from keyword-matching to a 5-tier cascade, lists the tiers, mentions preserved functionality, and provides specific review patches and test plan—all directly related to the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/code-review-cascade

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/bmm-skills/4-implementation/bmad-code-review/steps/step-01-gather-context.md (1)

57-62: ⚠️ Potential issue | 🟠 Major

Instruction 3 missing handlers for staged-only and uncommitted diff modes.

Tier 1 keywords (lines 26-27) detect "staged" and "uncommitted" modes, and instruction 2 (lines 51-52) offers these as explicit options. However, instruction 3's diff construction logic only handles:

  • Branch diff (line 58)
  • Commit range (line 59)
  • Provided diff (line 60)
  • File list (line 61)

When Tier 1 detects "staged changes" or "uncommitted changes" and proceeds directly to instruction 3 (per line 48), there's no corresponding construction handler. This creates a logic gap where identified targets have no execution path.

Proposed fix to add staged and uncommitted handlers
 3. Construct `{diff_output}` from the chosen source.
+   - For **staged changes only**: run `git diff --cached` to capture staged changes.
+   - For **uncommitted changes** (staged + unstaged): run `git diff HEAD` to capture all uncommitted changes.
    - 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.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/bmm-skills/4-implementation/bmad-code-review/steps/step-01-gather-context.md`
around lines 57 - 62, Instruction 3 lacks handlers for "staged" and
"uncommitted" modes so add explicit branches that construct {diff_output} for
those cases: for "staged" generate the diff from the staged index (use the
cached/staged git diff form) and for "uncommitted" generate the diff of the
working tree vs HEAD/index (include unstaged changes and untracked files using
--no-index where needed for new files); in both handlers validate the result is
parseable and non-empty and HALT with a clear prompt if empty or unparseable,
matching the same error/ask behavior described for
branch/commit/provided/file-list paths in Instruction 3.
🧹 Nitpick comments (1)
src/bmm-skills/4-implementation/bmad-code-review/steps/step-01-gather-context.md (1)

42-43: Consider rewording to reduce repetition.

Three successive sentences begin with "If", which creates a slightly monotonous flow. While grammatically correct, varying the sentence structure improves readability.

Suggested rewrite
    **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.
+   Skip to Tier 5 if version control is unavailable. Otherwise, check the current branch and HEAD. When 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?" Treat as a branch diff against `main` if confirmed, otherwise fall through.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/bmm-skills/4-implementation/bmad-code-review/steps/step-01-gather-context.md`
around lines 42 - 43, Edit the "Tier 4 — Current git state." paragraph to remove
repetitive sentence starts by combining checks and varying sentence openings:
first state to check the current branch and HEAD, then describe the
branch-not-main flow with a confirmation prompt phrased differently (e.g., "When
the branch is not `main` (or the default), prompt: 'I see HEAD is `<short-sha>`
on `<branch>` — do you want to review this branch's changes?'; if yes, treat as
a branch diff against `main`, otherwise fall through"), ensuring the same logic
is preserved but sentence openings are varied to improve readability.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@src/bmm-skills/4-implementation/bmad-code-review/steps/step-01-gather-context.md`:
- Line 34: Replace the phrase "wants reviewed" in the sentence on
step-01-gather-context.md with a standard form such as "wants to be reviewed"
(or "wants reviewing") so the sentence reads e.g. "Do the last few messages
reveal what the user wants to be reviewed?" — locate the exact string "wants
reviewed" and update it accordingly.
- Line 24: The Tier 1 branch should always assign the provided spec path to the
spec_file variable regardless of whether baseline_commit is present: update the
logic where you inspect spec frontmatter/baseline_commit so that when a spec is
provided (Tier 1) you set spec_file = <provided spec> in both the
baseline_commit-found and baseline_commit-not-found branches; then modify
Instruction 4 (the question block currently phrased "Is there a spec?") to check
the spec_file variable instead of re-asking, and remove the ambiguous "note the
spec for instruction 4" behavior so downstream steps rely on spec_file.

---

Outside diff comments:
In
`@src/bmm-skills/4-implementation/bmad-code-review/steps/step-01-gather-context.md`:
- Around line 57-62: Instruction 3 lacks handlers for "staged" and "uncommitted"
modes so add explicit branches that construct {diff_output} for those cases: for
"staged" generate the diff from the staged index (use the cached/staged git diff
form) and for "uncommitted" generate the diff of the working tree vs HEAD/index
(include unstaged changes and untracked files using --no-index where needed for
new files); in both handlers validate the result is parseable and non-empty and
HALT with a clear prompt if empty or unparseable, matching the same error/ask
behavior described for branch/commit/provided/file-list paths in Instruction 3.

---

Nitpick comments:
In
`@src/bmm-skills/4-implementation/bmad-code-review/steps/step-01-gather-context.md`:
- Around line 42-43: Edit the "Tier 4 — Current git state." paragraph to remove
repetitive sentence starts by combining checks and varying sentence openings:
first state to check the current branch and HEAD, then describe the
branch-not-main flow with a confirmation prompt phrased differently (e.g., "When
the branch is not `main` (or the default), prompt: 'I see HEAD is `<short-sha>`
on `<branch>` — do you want to review this branch's changes?'; if yes, treat as
a branch diff against `main`, otherwise fall through"), ensuring the same logic
is preserved but sentence openings are varied to improve readability.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 48709b51-f55b-4dfa-acbe-1d15242cd32e

📥 Commits

Reviewing files that changed from the base of the PR and between 3a24d8f and 87fa2b4.

📒 Files selected for processing (1)
  • src/bmm-skills/4-implementation/bmad-code-review/steps/step-01-gather-context.md

@augmentcode
Copy link
Copy Markdown

augmentcode bot commented Apr 4, 2026

🤖 Augment PR Summary

Summary: Refactors the Step 1 “Gather Context” logic to determine what code should be reviewed using a structured intent cascade.

Changes:

  • Replaces keyword-only invocation parsing with a 5-tier priority cascade (explicit args → recent context → sprint tracking → current git state → ask)
  • Preserves the existing diff-mode keyword detection as a sub-check within the higher-priority tiers
  • Adds explicit fallthrough behavior when no sprint “review” story exists
  • Adds a guard to skip the git-state tier when version control is unavailable
  • Leaves instructions 2–6, CHECKPOINT, and NEXT unchanged

Technical Notes: Tier 1 can route via PR/commit/branch or spec baseline_commit; Tier 4 can default to branch diff vs main after user confirmation.

🤖 Was this summary useful? React with 👍 or 👎

Copy link
Copy Markdown

@augmentcode augmentcode bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed. 3 suggestions posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

Copy link
Copy Markdown

@don-petry don-petry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Human Review — Claude Opus 4.6

Overall Assessment: Approve with minor suggestions

The 5-tier priority cascade is a clear improvement over the previous flat keyword-matching approach. The structure mirrors checkpoint-preview and quick-dev patterns, which is good for consistency across the skill suite.

The cascade design (Tiers 1-5)

Solid. The priority ordering is intuitive and matches how users actually invoke reviews:

  1. Explicit argument — highest signal, correct to check first
  2. Recent conversation — natural for multi-turn workflows where the user just finished implementing something
  3. Sprint tracking — good ambient intelligence fallback
  4. Git state — sensible heuristic when nothing else is available
  5. Ask — correct last resort

The "stop as soon as the review target is identified" rule and "never ask extra questions beyond what the cascade prescribes" constraint are good guardrails that prevent over-prompting.

Backward compatibility for diff-mode keywords

Preserved correctly. The keyword list (staged, uncommitted, branch diff, commit range, provided diff) is identical to the original. Moving them into Tiers 1-2 as sub-checks rather than top-level entry points is the right call — they narrow scope within an already-identified target rather than being the target themselves.

Issues worth addressing

1. spec_file variable gap (agree with CodeRabbit + Augment)
Both bots flagged the same real issue: when a spec is provided in Tier 1 without baseline_commit, the instruction says "note the spec for instruction 4" but never sets {spec_file}. This is vague and conflicts with the "never ask extra questions" constraint — instruction 4 would re-ask for a spec the user already provided. Fix: set {spec_file} immediately in Tier 1 when a spec is provided, regardless of baseline_commit. Then make instruction 4 conditional on {spec_file} not already being set.

2. Instruction 3 missing staged/uncommitted handlers (agree with CodeRabbit)
Tier 1 can detect "staged" or "uncommitted" and proceed to instruction 3, but instruction 3 only has handlers for branch diff, commit range, provided diff, and file list. The staged/uncommitted handlers existed implicitly before but need explicit sub-cases now. This is outside the diff but the refactor creates the gap — worth fixing in this PR.

3. {branch} / {sha} placeholder ambiguity (disagree with Augment — low risk)
Augment flagged {branch} and {sha}..{sha} as potentially conflicting with variable resolution. I'd rate this low: these appear inside quoted keyword examples (e.g., "compared to {branch}"), not as standalone variable references. An LLM reading this will understand them as pattern descriptions. If the project has strict variable validation that would flag these, then escaping makes sense, but otherwise this is cosmetic.

4. Minor grammar: "wants reviewed" (line 34)
Dialectal phrasing — "wants to be reviewed" is standard. Trivial fix.

Summary

Good refactor. The two substantive items (spec_file variable coordination and staged/uncommitted handlers in instruction 3) should be addressed before merge. The rest is polish.

…v and checkpoint-preview

Replace keyword-matching entry point with 5-tier priority cascade:
explicit argument → recent conversation → sprint tracking → git state → ask.
Diff-mode keyword detection preserved as sub-check within tier 1.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@alexeyv alexeyv force-pushed the refactor/code-review-cascade branch from 87fa2b4 to cd3d697 Compare April 5, 2026 01:51
- 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"
@alexeyv
Copy link
Copy Markdown
Collaborator Author

alexeyv commented Apr 5, 2026

Triage Summary

6 findings triaged — FIX: 5, DISMISS: 1, DEFER: 0

# Severity Title Decision
F1 Critical Set {spec_file} variable when spec is provided in Tier 1 FIX
F2 Minor Grammar: "wants reviewed" → "wants to be reviewed" FIX
F3 Medium Duplicate of F1 (Augment) DISMISS
F4 High {branch}/{sha} placeholder ambiguity in examples FIX
F5 Low {story_key} vs {{story-id}} placeholder mismatch FIX
F6 High Instruction 3 missing staged/uncommitted handlers FIX

All fixes in commit cc209dd.

@alexeyv alexeyv merged commit 1050415 into main Apr 5, 2026
5 checks passed
@alexeyv alexeyv deleted the refactor/code-review-cascade branch April 5, 2026 03:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants