|
| 1 | +--- |
| 2 | +name: Gather Context |
| 3 | +description: 'Determine what to review, construct the diff, and load any spec/context documents.' |
| 4 | +diff_output: '' # set at runtime |
| 5 | +spec_file: '' # set at runtime (path or empty) |
| 6 | +review_mode: '' # set at runtime: "full" or "no-spec" |
| 7 | +--- |
| 8 | + |
| 9 | +# Step 1: Gather Context |
| 10 | + |
| 11 | +## RULES |
| 12 | + |
| 13 | +- YOU MUST ALWAYS SPEAK OUTPUT in your Agent communication style with the config `{communication_language}` |
| 14 | +- The prompt that triggered this workflow IS the intent — not a hint. |
| 15 | +- Do not modify any files. This step is read-only. |
| 16 | + |
| 17 | +## INSTRUCTIONS |
| 18 | + |
| 19 | +1. **Detect review intent from invocation text.** Check the triggering prompt for phrases that map to a review mode: |
| 20 | + - "staged" / "staged changes" → Staged changes only |
| 21 | + - "uncommitted" / "working tree" / "all changes" → Uncommitted changes (staged + unstaged) |
| 22 | + - "branch diff" / "vs main" / "against main" / "compared to {branch}" → Branch diff (extract base branch if mentioned) |
| 23 | + - "commit range" / "last N commits" / "{sha}..{sha}" → Specific commit range |
| 24 | + - "this diff" / "provided diff" / "paste" → User-provided diff (do not match bare "diff" — it appears in other modes) |
| 25 | + - When multiple phrases match, prefer the most specific match (e.g., "branch diff" over bare "diff"). |
| 26 | + - **If a clear match is found:** Announce the detected mode (e.g., "Detected intent: review staged changes only") and proceed directly to constructing `{diff_output}` using the corresponding sub-case from instruction 3. Skip to instruction 4 (spec question). |
| 27 | + - **If no match from invocation text, check sprint tracking.** Look for a sprint status file (`*sprint-status*`) in `{implementation_artifacts}` or `{planning_artifacts}`. If found, scan for any story with status `review`. Handle as follows: |
| 28 | + - **Exactly one `review` story:** 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, fall through to instruction 2. |
| 29 | + - **Multiple `review` stories:** Present them as numbered options alongside a manual choice option. Wait for user selection. Then use the selected story's context to determine the diff source as in the single-story case above, and proceed to instruction 3. |
| 30 | + - **If no match and no sprint tracking:** Fall through to instruction 2. |
| 31 | + |
| 32 | +2. Ask the user: **What do you want to review?** Present these options: |
| 33 | + - **Uncommitted changes** (staged + unstaged) |
| 34 | + - **Staged changes only** |
| 35 | + - **Branch diff** vs a base branch (ask which base branch) |
| 36 | + - **Specific commit range** (ask for the range) |
| 37 | + - **Provided diff or file list** (user pastes or provides a path) |
| 38 | + |
| 39 | +3. Construct `{diff_output}` from the chosen source. |
| 40 | + - 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. |
| 41 | + - For **commit range**: verify the range resolves. If it does not, HALT and ask the user for a valid range. |
| 42 | + - 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. |
| 43 | + - For **file list**: validate each path exists in the working tree. Construct `{diff_output}` by running `git diff HEAD -- <path1> <path2> ...`. If the diff is empty (files have no uncommitted changes), ask the user whether to review the full file contents or to specify a different baseline. |
| 44 | + - 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. |
| 45 | + |
| 46 | +4. Ask the user: **Is there a spec or story file that provides context for these changes?** |
| 47 | + - If yes: set `{spec_file}` to the path provided, verify the file exists and is readable, then set `{review_mode}` = `"full"`. |
| 48 | + - If no: set `{review_mode}` = `"no-spec"`. |
| 49 | + |
| 50 | +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. |
| 51 | + |
| 52 | +6. Sanity check: if `{diff_output}` exceeds approximately 3000 lines, warn the user and offer to chunk the review by file group. |
| 53 | + - If the user opts to chunk: agree on the first group, narrow `{diff_output}` accordingly, and list the remaining groups for the user to note for follow-up runs. |
| 54 | + - If the user declines: proceed as-is with the full diff. |
| 55 | + |
| 56 | +### CHECKPOINT |
| 57 | + |
| 58 | +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. |
| 59 | + |
| 60 | + |
| 61 | +## NEXT |
| 62 | + |
| 63 | +Read fully and follow `./step-02-review.md` |
0 commit comments