microsoft/hve-core

Public

mirrored fromhttps://github.com/microsoft/hve-coreAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
feat-ds-agent

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

.github/instructions/ado-create-pull-request.instructions.md

788lines · modecode

1---
2description: "Required protocol for creating Azure DevOps pull requests with work item discovery, reviewer identification, and automated linking."
3applyTo: '**/.copilot-tracking/pr/new/**'
4---
5
6# Azure DevOps Pull Request Creation
7
8Follow all instructions from #file:./ado-wit-planning.instructions.md for planning file conventions while executing this workflow.
9
10## Scope
11
12Apply this procedure when creating a new Azure DevOps pull request with automated PR description generation, work item discovery and linking, reviewer identification from git history, and complete traceability through planning documents.
13
14Output planning files to `.copilot-tracking/pr/new/<normalized-branch-name>/` using the specified Azure DevOps project `${input:adoProject}` and repository `${input:repository}`.
15
16## Inputs
17
18* `${input:adoProject}`: (Required) Azure DevOps project name or ID.
19* `${input:repository}`: (Required) Repository name or ID.
20* `${input:sourceBranch}`: (Optional) Source branch name. Defaults to current git branch.
21* `${input:baseBranch:origin/main}`: (Optional) Base branch for comparison.
22* `${input:similarityThreshold:50}`: (Optional) Minimum similarity score (0-100) for work item matching.
23* `${input:workItemStates:["New", "Active", "Resolved"]}`: (Optional) Work item state filter.
24* `${input:workItemIds}`: (Optional) Explicit work item IDs to link, bypassing discovery.
25* `${input:isDraft:false}`: (Optional) Create PR as draft.
26* `${input:noGates:false}`: (Optional) Skip user confirmation gates.
27* `${input:includeMarkdown:true}`: (Optional) Include markdown file diffs in PR reference.
28
29## Deliverables
30
31* `pr-reference.xml` - Git diff and commit history
32* `pr.md` - Pull request description
33* `pr-analysis.md` - Change analysis and work item findings
34* `reviewer-analysis.md` - Reviewer analysis with rationale
35* `planning-log.md` - Operational log
36* `handoff.md` - Final PR creation plan
37* Conversational recap with PR URL
38
39## Tooling
40
41Git operations via `run_in_terminal`:
42
43* `git fetch <remote> <branch-name> --prune` to sync remote
44* `scripts/dev-tools/pr-ref-gen.sh --base-branch "${input:baseBranch}" --output "<path>/pr-reference.xml"` for PR reference
45* `git config user.email` for current user
46* `git log --all --pretty=format:'%H %an <%ae>' -- <file-pattern> | head -20` for contributors
47
48### Azure DevOps MCP Tools
49
50* `mcp_ado_repo_get_repo_by_name_or_id` - Resolve repository IDs from name. Parameters: `project`, `repositoryNameOrId`.
51* `mcp_ado_repo_create_pull_request` - Create pull request. Required: `repositoryId`, `sourceRefName`, `targetRefName`, `title`. Optional: `description`, `isDraft`, `labels` (array), `workItems` (space-separated IDs), `forkSourceRepositoryId`.
52* `mcp_ado_repo_update_pull_request` - Update PR settings. Required: `repositoryId`, `pullRequestId`. Optional: `title`, `description`, `status` (Active|Abandoned), `isDraft`, `autoComplete`, `mergeStrategy` (NoFastForward|Squash|Rebase|RebaseMerge), `deleteSourceBranch`, `transitionWorkItems`, `bypassReason`, `labels`.
53* `mcp_ado_repo_update_pull_request_reviewers` - Add or remove reviewers. Required: `repositoryId`, `pullRequestId`, `reviewerIds` (array of GUIDs), `action` (add|remove).
54* `mcp_ado_wit_link_work_item_to_pull_request` - Link work item to PR. Required: `projectId` (GUID), `repositoryId`, `pullRequestId`, `workItemId`. Optional: `pullRequestProjectId` (for cross-project linking).
55* `mcp_ado_search_workitem` - Search work items. Parameters: `searchText`, `project`, `workItemType`, `state`, `assignedTo`, `top`, `skip`.
56* `mcp_ado_wit_get_work_item` - Get work item details. Parameters: `id`, `project`, `expand`, `fields`.
57* `mcp_ado_wit_get_work_items_batch_by_ids` - Batch get work items. Parameters: `project`, `ids` (array), `fields`.
58* `mcp_ado_core_get_identity_ids` - Resolve identity GUIDs from email or name. Parameters: `searchFilter`.
59
60Workspace utilities: `list_dir`, `read_file`, `grep_search`
61
62Persist all tool output into planning files per ado-wit-planning.instructions.md.
63
64## Tracking Directory Structure
65
66All PR creation tracking artifacts reside in `.copilot-tracking/pr/new/{{normalized branch name}}`.
67
68```plaintext
69.copilot-tracking/
70 pr/
71 new/
72 {{normalized branch name}}/
73 pr-reference.xml # Generated git diff and commit history
74 pr.md # Generated PR description
75 pr-analysis.md # Change analysis and work item findings
76 reviewer-analysis.md # Potential reviewer analysis
77 planning-log.md # Operational log
78 handoff.md # Final PR creation plan
79```
80
81**Branch Name Normalization Rules**:
82
83* Convert to lowercase characters
84* Replace `/` with `-`
85* Strip special characters except hyphens
86* Example: `feat/ACR-Private-Public` → `feat-acr-private-public`
87
88## Planning File Formats
89
90### pr-analysis.md
91
92````markdown
93# Pull Request Analysis - [Branch Name]
94* **Source Branch**: [Source branch name]
95* **Target Branch**: [Target branch name]
96* **Project**: [Azure DevOps project]
97* **Repository**: [Repository name or ID]
98
99## Change Summary
100
101[1-5 sentence summary of what changed based on pr-reference.xml analysis]
102
103## Changed Files
104
105* [file/path/one.ext]: [Brief description of changes]
106* [file/path/two.ext]: [Brief description of changes]
107
108## Commit Summary
109* [Aggregated summary of commit messages]
110
111## Work Item Discovery
112
113### Keyword Groups for Search
114
1151. [Keyword group 1]: [term1 OR term2 OR "multi word term"]
1162. [Keyword group 2]: [term1 OR term2]
117
118### Discovered Work Items
119
120#### ADO-[Work Item ID] - [Similarity Score] - [Type]
121* **Title**: [Work item title]
122* **State**: [Current state]
123* **Relevance Reasoning**: [Why this work item relates to the PR]
124* **User Decision**: [Pending|Link|Skip]
125
126## Notes
127
128* [Optional notes about the analysis]
129````
130
131### reviewer-analysis.md
132
133````markdown
134# Reviewer Analysis - [Branch Name]
135* **Current User**: [Current git user email]
136* **Changed Files**: [Count]
137
138## Contributor Analysis
139
140### Changed File: [file/path/one.ext]
141* **Recent Contributors** (last 20 commits):
142 * [Contributor 1 Name] <[email]> - [commit count] commits
143 * [Contributor 2 Name] <[email]> - [commit count] commits
144
145### Changed File: [file/path/two.ext]
146* **Recent Contributors** (last 20 commits):
147 * [Contributor 1 Name] <[email]> - [commit count] commits
148
149### Surrounding Files: [directory/**]
150* **Recent Contributors** (last 20 commits):
151 * [Contributor Name] <[email]> - [commit count] commits
152
153## Potential Reviewers (excluding current user)
154
1551. **[Reviewer 1 Name]** <[email]>
156 * **Identity ID**: [Azure DevOps GUID or "Manual addition required"]
157 * **Contribution Score**: [High|Medium|Low]
158 * **Files**: [List of changed files they contributed to]
159 * **Rationale**: [Why they would be a good reviewer]
160 * **User Decision**: [Pending|Required|Optional|Skip]
161
1622. **[Reviewer 2 Name]** <[email]>
163 * **Identity ID**: [Azure DevOps GUID or "Manual addition required"]
164 * **Contribution Score**: [High|Medium|Low]
165 * **Files**: [List of changed files they contributed to]
166 * **Rationale**: [Why they would be a good reviewer]
167 * **User Decision**: [Pending|Required|Optional|Skip]
168
169## Reviewer Recommendation
170
171* **Recommended Reviewers**: [List of high-contribution reviewers]
172* **Additional Reviewers**: [List of lower-contribution reviewers]
173````
174
175### handoff.md
176
177````markdown
178# Pull Request Creation Handoff
179* **Project**: [Azure DevOps project]
180* **Repository**: [Repository name or ID]
181* **Repository ID**: [Repository ID for MCP tool]
182* **Source Branch**: [Source branch name]
183* **Target Branch**: [Target branch name]
184* **Is Draft**: [true|false]
185
186## Planning Files
187
188* .copilot-tracking/pr/new/[normalized-branch-name]/handoff.md
189* .copilot-tracking/pr/new/[normalized-branch-name]/pr-analysis.md
190* .copilot-tracking/pr/new/[normalized-branch-name]/reviewer-analysis.md
191* .copilot-tracking/pr/new/[normalized-branch-name]/planning-log.md
192* .copilot-tracking/pr/new/[normalized-branch-name]/pr.md
193
194## PR Details
195
196### Title
197
198[Generated PR title from pr.md]
199
200### Description
201
202```markdown
203[Complete PR description from pr.md]
204```
205
206## Work Items to Link
207
208* [ ] ADO-[Work Item ID] - [Type] - [Title]
209 * **Similarity**: [Score]
210 * **Reason**: [Why linking this work item]
211* [ ] ADO-[Work Item ID] - [Type] - [Title]
212 * **Similarity**: [Score]
213 * **Reason**: [Why linking this work item]
214
215**Total Work Items**: [Count]
216
217## Reviewers to Add
218
219### Reviewers
220
221* [ ] [Reviewer Name] <[email]>
222 * **Rationale**: [Why they should review]
223
224* [ ] [Reviewer Name] <[email]>
225 * **Rationale**: [Why they should review]
226
227**Total Reviewers**: [Count]
228
229## MCP Tool Call Plan
230
231### 1. Create Pull Request
232
233**Tool**: `mcp_ado_repo_create_pull_request`
234
235**Parameters**:
236* `repositoryId`: "[Repository ID]"
237* `sourceRefName`: "refs/heads/[source-branch-name]"
238* `targetRefName`: "refs/heads/[target-branch-name]"
239* `title`: "[PR title from pr.md first line WITHOUT the markdown heading marker hash]"
240 * Example: `feat(scope): description` (NOT `# feat(scope): description`)
241* `description`: "[PR description from pr.md body WITH full markdown formatting]"
242* `isDraft`: [true|false]
243* `labels`: ["label-name"] (optional)
244* `workItems`: "[space-separated work item IDs]" (optional, alternative to separate linking calls)
245
246**Expected Result**: Pull request created with ID [PR-ID]
247
248### 2. Link Work Items
249
250**Tool**: `mcp_ado_wit_link_work_item_to_pull_request` (call once per work item)
251
252**Parameters for each work item**:
253* `projectId`: "[Project ID]"
254* `repositoryId`: "[Repository ID]"
255* `pullRequestId`: [PR-ID from step 1]
256* `workItemId`: [Work Item ID]
257
258**Total Calls**: [Count of work items to link]
259
260### 3. Add Reviewers
261
262**Tool**: `mcp_ado_repo_update_pull_request_reviewers`
263
264**Parameters**:
265* `repositoryId`: "[Repository ID]"
266* `pullRequestId`: [PR-ID from step 1]
267* `reviewerIds`: [[Array of resolved identity GUIDs from mcp_ado_core_get_identity_ids]]
268* `action`: "add"
269
270**Expected Result**: Reviewers added to pull request [PR-ID]
271
272**Note**: Reviewers without resolved identity IDs must be added manually via Azure DevOps UI.
273
274## User Signoff
275
276* [ ] PR details reviewed and approved
277* [ ] Work items confirmed
278* [ ] Reviewers confirmed
279* [ ] Ready to create PR
280
281**User Confirmation**: [Pending|Approved]
282````
283
284### planning-log.md
285
286````markdown
287# Planning Log - [Branch Name]
288
289* **Source Branch**: [branch name]
290* **Target Branch**: [target branch]
291* **Project**: [Azure DevOps project]
292* **Repository**: [Repository name]
293* **Current Phase**: [Phase number]
294* **Previous Phase**: [Phase number or N/A]
295
296## Phase Progress
297
298| Phase | Status | Notes |
299|----------------------------------|----------------------------------------|---------|
300| Phase 1: Setup | [Complete/In Progress/Pending] | [Notes] |
301| Phase 2: PR Description | [Complete/In Progress/Pending] | [Notes] |
302| Phase 3: Work Item Discovery | [Complete/In Progress/Pending/Skipped] | [Notes] |
303| Phase 3a: Work Item Creation | [Complete/In Progress/Pending/Skipped] | [Notes] |
304| Phase 4: Reviewer Identification | [Complete/In Progress/Pending] | [Notes] |
305| Phase 5: User Confirmation | [Complete/In Progress/Pending/Skipped] | [Notes] |
306| Phase 6: PR Creation | [Complete/In Progress/Pending] | [Notes] |
307| Phase 7: Final Recap | [Complete/In Progress/Pending] | [Notes] |
308
309## Artifacts
310
311* **pr-reference.xml**: [Generated/Existing/Pending]
312* **pr.md**: [Generated/Pending]
313* **pr-analysis.md**: [Generated/Pending]
314* **reviewer-analysis.md**: [Generated/Pending]
315* **handoff.md**: [Generated/Pending]
316
317## Work Items
318
319* Discovered: [Count]
320* Created: [Count or N/A]
321* Selected for linking: [Count]
322* IDs: [Comma-separated list]
323
324## Reviewers
325
326* Identified: [Count]
327* Identity resolved: [Count]
328* Pending manual addition: [Count]
329
330## Recovery Information
331
332If context is summarized, read all files from the planning directory and resume from the current phase recorded above.
333````
334
335## Protocol Overview
336
337This workflow follows a progressive confirmation model where user reviews and approves each section before proceeding:
338
3391. **Setup & Analysis** (Phases 1-4): Silent preparation - generate artifacts, analyze changes, discover work items and reviewers
3402. **User Review & Confirmation** (Phase 5): Present information in stages with confirmation gates
3413. **PR Creation** (Phase 6): Execute after final user signoff
3424. **Completion** (Phase 7): Deliver recap with PR URL
343
344Present each confirmation gate separately and wait for user response before proceeding to the next gate. Avoid presenting all information at once.
345
346### No-Gates Mode
347
348When `${input:noGates}` is true:
349
350* Skip Phase 5 (all confirmation gates) entirely
351* After completing Phase 4, proceed directly to Phase 6
352* Use all discovered work items (no user selection)
353* If Phase 3a created a work item, use that created work item automatically
354* Add minimum of 2 optional reviewers (top 2 by contribution score)
355* Create PR immediately with all discovered linkages
356* Deliver final recap in Phase 7 as usual
357
358## Required Phases
359
360### Phase 1: Setup and PR Reference Generation
361
362Execute without presenting details to user:
363
3641. Determine normalized branch name from `${input:sourceBranch}` or current git branch.
3652. Create planning directory: `.copilot-tracking/pr/new/<normalized-branch-name>/`
3663. Initialize `planning-log.md` with Phase-1 status.
3674. Check if `pr-reference.xml` exists:
368 * If exists: Use existing file silently.
369 * If not exists: Generate using `scripts/dev-tools/pr-ref-gen.sh` with optional `--no-md-diff` flag if `${input:includeMarkdown}` is false.
3705. Read complete `pr-reference.xml`. For files exceeding 2000 lines, read in 1000-2000 line chunks, capturing complete commit boundaries before advancing to the next chunk.
3716. Log artifact in `planning-log.md` with status `Complete`.
372
373### Phase 2: Generate PR Description
374
375Execute without presenting to user yet:
376
3771. Analyze `pr-reference.xml` completely before writing any content. Include only changes visible in the reference file; do not invent or assume changes.
3782. Generate `pr.md` in the planning directory (not in root) following the PR File Format below.
3793. Extract commit types, scopes, and key changes for PR title and description.
3804. Use past tense for all descriptions.
3815. Describe WHAT changed, not speculating WHY.
3826. Use natural, conversational language that reads like human communication.
3837. Match tone and terminology from commit messages.
3848. Group and order changes by SIGNIFICANCE and IMPORTANCE (most significant first).
3859. Combine related changes into single descriptive points.
38610. Only add sub-bullets when they provide genuine clarification value.
38711. Only include "Notes," "Important," or "Follow-up" sections if supported by commit messages or code comments.
38812. Extract changed file list with descriptions for Gate 1 presentation.
38913. Log generation in `planning-log.md`.
390
391**PR File Format for pr.md**:
392
393```markdown
394# {{type}}({{scope}}): {{concise description}}
395
396{{Summary paragraph of overall changes in natural, human-friendly language}}
397
398- **{{type}}**(_{{scope}}_): {{description of change with key context included}}
399
400- **{{type}}**(_{{scope}}_): {{description of change}}
401 - {{sub-bullet only if it adds genuine clarification value}}
402
403- **{{type}}**: {{description of change without scope, including essential details}}
404
405## Notes (optional)
406
407- Note 1 identified from code comments or commit message
408- Note 2 identified from code comments or commit message
409
410## Important (optional)
411
412- Critical information 1 identified from code comments or commit message
413- Warning 2 identified from code comments or commit message
414
415## Follow-up Tasks (optional)
416
417- Task 1 with file reference
418- Task 2 with specific component mention
419
420{{emoji representing the changes}} - Generated by Copilot
421```
422
423**Type and Scope**:
424
425* Determine from commits in `pr-reference.xml`
426* Use branch name as primary source for type/scope
427* Common types: feat, fix, docs, chore, refactor, test, ci
428* Scope should reference component or area affected
429
430**Title Construction Rules**:
431
432* Format: `{type}({scope}): {concise description}`
433* If branch name is not descriptive, rely on commit messages
434* Keep concise but descriptive
435
436**Never Include**:
437
438* Changes related to linting errors or auto-generated documentation
439* Speculative benefits ("improves security") unless explicit in commits
440* Follow-up tasks for documentation or tests (unless in commit messages)
441
442### Phase 3: Discover Related Work Items
443
444**Skip this phase entirely if `${input:workItemIds}` is provided by the user.**
445
446Execute without presenting to user yet:
447
4481. Build ACTIVE KEYWORD GROUPS from:
449 * Changed file paths (component names, directories)
450 * Commit messages (subjects and bodies)
451 * Conventional commit scopes
452 * Technical terms from diff content
4532. For each keyword group, call `mcp_ado_search_workitem` with:
454 * `project`: `${input:adoProject}`
455 * `searchText`: constructed from keyword groups using OR/AND syntax
456 * `workItemType`: ["User Story", "Bug"] (NEVER include Feature or Epic)
457 * `state`: Parse `${input:workItemStates}` into array format
458 * `top`: 50; increment `skip` as needed
459 * Optional filters: `${input:areaPath}`, `${input:iterationPath}`
4603. Hydrate results via `mcp_ado_wit_get_work_item` (batch variant preferred).
4614. Compute similarity using semantic analysis of:
462 * Work item title + description vs. PR title + description
463 * Work item acceptance criteria vs. PR change summary
464 * Boost for matching commit scopes, file paths, technical terms
4655. Filter work items with similarity >= `${input:similarityThreshold}`.
4666. Capture findings in `pr-analysis.md` with relevance reasoning.
4677. Log discovered work items in `planning-log.md`.
4688. If NO viable work items are discovered (zero work items with similarity >= threshold):
469 * Proceed to Phase 3a - Create Work Item for PR
470 * After Phase 3a completion, continue to Phase 4
471
472### Phase 3a: Create Work Item for PR
473
474Execute this phase when Phase 3 discovers zero viable work items.
475
476Follow ado-wit-discovery.instructions.md and ado-update-wit-items.instructions.md to create a work item:
477
4781. Create planning directory `.copilot-tracking/workitems/discovery/<folder-name>/` using the branch name without prefix.
4792. Reuse `pr-reference.xml`, PR title, description, and keyword groups from previous phases.
4803. Follow ado-wit-discovery.instructions.md phases to plan creation of ONE User Story or Bug based on PR content. Derive type from branch name or commit type (feat → User Story, fix → Bug).
4814. Execute work item creation following ado-update-wit-items.instructions.md. Capture created work item ID in `handoff-logs.md`.
4825. Store created work item ID for Phase 6 linking. Update `pr-analysis.md` with created work item details.
483
484### Phase 4: Identify Potential Reviewers
485
486Execute without presenting to user yet:
487
4881. Get current user email: `git config user.email`
4892. For each changed file in `pr-reference.xml`:
490 * Extract file path
491 * Get recent contributors: `git log --all --pretty=format:'%H %an <%ae>' -- <file-path> | head -20`
492 * Parse output to count commits per author
4933. For surrounding directories of changed files:
494 * Use parent directory patterns (e.g., `path/to/dir/**`)
495 * Get recent contributors: `git log --all --pretty=format:'%H %an <%ae>' -- <dir-pattern> | head -20`
4964. Aggregate contributors across all changed files and directories:
497 * Count total commits per contributor
498 * Exclude current user
499 * Rank by contribution score (High: >10 commits, Medium: 3-10, Low: 1-2)
5005. Resolve Azure DevOps identity IDs:
501 * For each unique reviewer email, call `mcp_ado_core_get_identity_ids` with `searchFilter` set to the email
502 * Extract `id` (GUID) from response and store with reviewer record
503 * For GitHub noreply emails (`*@users.noreply.github.com`): Search git history for alternative email addresses using `git log --author="<username>" --pretty=format:'%ae' | sort -u`, then retry identity resolution with discovered alternatives
504 * If no match found after alternatives, mark reviewer for manual addition
505 * If multiple matches found, use most recent activity or mark for user disambiguation
5066. Capture analysis in `reviewer-analysis.md` with rationale and resolved identity IDs.
5077. Log potential reviewers and resolution status in `planning-log.md`.
508
509### Phase 5: User Review and Confirmation
510
511Skip this phase when `${input:noGates}` is true; proceed directly to Phase 6 using all discovered work items, created work items from Phase 3a, and top 2 reviewers by contribution score.
512
513Present each gate separately and wait for user approval before proceeding to the next gate.
514
515#### Gate 1: Changed Files Review
516
5171. Extract all changed files from `pr-reference.xml`.
5182. For each file, provide brief description of changes from diff analysis.
5193. Perform quality review and identify:
520 * Accidental or unintended changes (e.g., debug code, commented code)
521 * Missing files that should be tracked
522 * Extra files that should not be included (e.g., build artifacts, temp files)
523 * Security issues (secrets, credentials, PII)
524 * Compliance issues (non-compliant language, FIXME, WIP, etc in committed code)
525 * Code quality concerns (styling violations, linting issues)
526
527**File Count Handling**:
528
529* If ≤ 50 files: Present full list inline with change descriptions
530* If > 50 files: Provide summary statistics and link to `pr-analysis.md`, instruct user to review and confirm when ready
531
532**Presentation Format**:
533
534```markdown
535## 📄 Changed Files Review
536
537I've analyzed [count] changed files in your PR:
538
539### Modified Files
5401. [path/to/file1.ext]: [Brief description of changes]
5412. [path/to/file2.ext]: [Brief description of changes]
542
543### Quality Review
544✅ No Issues Found (or ⚠️ list issues requiring attention)
545
546Please review the changes. Reply with "Continue", "Remove [filename]", or "Add [filename]".
547```
548
549For changesets over 50 files, provide summary statistics and link to `pr-analysis.md`.
550
551**Wait for user response before proceeding to Gate 2.**
552
553#### Gate 2: PR Title & Description Review
554
5551. Extract PR title from `pr.md` first line:
556 * Remove leading `#` and whitespace
557 * Example: `# feat(scope): description` → `feat(scope): description`
558 * This cleaned title will be used for Azure DevOps PR creation
5592. Present complete PR description from `pr.md` body (after first line):
560 * Preserve all markdown formatting including headings with `#` markers
5613. Perform security/compliance analysis on `pr-reference.xml`:
562 * Customer information leaks (PII, customer data)
563 * Secrets or credentials (API keys, passwords, tokens)
564 * Non-compliant language (FIXME, WIP, etc in committed code)
565 * Unintended changes or accidental file inclusion
566 * Missing referenced files
567
568**Presentation Format**:
569
570```markdown
571## 📝 Pull Request Title & Description
572
573**Title**: [Generated title from pr.md]
574
575**Description**:
576[Complete PR description from pr.md with markdown preserved]
577
578**Security & Compliance Check**: [Results]
579
580Reply with "Continue", "Change title to: [new title]", or "Regenerate description".
581```
582
583**Wait for user response before proceeding to Gate 3.**
584
585#### Gate 3: Work Items Review
586
5871. If `${input:workItemIds}` was provided: Present those work items for confirmation.
5882. If work item was created in Phase 3a: Present the created work item for confirmation.
5893. If discovered in Phase 3: Present up to 10 highest similarity work items.
5904. For each work item provide:
591 * Work item ID and type
592 * Title
593 * Current state (for Closed items, add note: "Linking provides historical traceability")
594 * Similarity score (percentage) - or "Created for this PR" if from Phase 3a
595 * 1-2 sentence relevance reasoning
5965. For work items in Closed state, ask user to confirm if linking for historical traceability is desired.
597
598**Presentation Format**:
599
600```markdown
601## 🔗 Work Items to Link
602
603I found [count] work items that may relate to your changes:
604
6051. ADO-[ID] - [Type] - [State]: [Title] ([XX]% similarity)
606 Why: [1-2 sentence relevance]
607
608Reply with "Link [ID1], [ID2]", "Link all", or "Skip".
609```
610
611**Wait for user response and capture selections. Proceed to Gate 4.**
612
613#### Gate 4: Reviewers Review
614
6151. Present suggested reviewers from `reviewer-analysis.md`.
6162. Separate into Recommended and Additional categories based on contribution score.
6173. Provide contribution score and rationale for each.
618
619**Presentation Format**:
620
621```markdown
622## 👥 Suggested Reviewers
623
624Based on git history of changed files:
625
6261. [Name] ([email]) - [High/Medium] - [XX] commits: [Rationale]
6272. [Name] ([email]) - [Medium/Low] - [XX] commits: [Rationale]
628
629Reply with "Continue", "Add [email]", "Remove [email]", or "Skip".
630```
631
632**Wait for user response and capture selections. Proceed to Gate 5.**
633
634#### Gate 5: Final Summary & Signoff
635
6361. Build complete `handoff.md` with all user-confirmed selections.
6372. Present comprehensive summary of everything that will be created.
6383. Request final signoff before executing PR creation.
639
640**Presentation Format**:
641
642```markdown
643## ✨ Final Pull Request Summary
644
645**Pull Request**: [Title] | [source-branch] → [target-branch] | [count] files
646**Work Items**: [count] to link
647**Reviewers**: [count] total
648
649Reply with "Create PR", "Modify [aspect]", or "Cancel".
650```
651
652**Wait for explicit "Create PR" or "Approved" confirmation before proceeding to Phase 6.**
653
654### Phase 5 Modification Handling
655
656When user requests modifications at any gate, update the relevant planning file, log changes in `planning-log.md`, and re-present that gate for confirmation. Track modification count per gate; after 3+ iterations, suggest an alternative approach or pause.
657
658### Phase 6: Create Pull Request and Link Work Items
659
660Proceed after user gives explicit approval.
661
6621. Resolve repository and project IDs:
663 * Use `${input:repository}` directly if GUID format; otherwise call `mcp_ado_repo_get_repo_by_name_or_id` with project and repository name.
664 * Use `${input:adoProject}` directly if GUID; otherwise extract from `mcp_ado_search_workitem` response metadata.
665 * For GitHub-backed Azure DevOps projects where repository is not found: Verify the GitHub connection in Azure DevOps project settings (Project Settings → Repos → GitHub connections). The repository may require explicit configuration before appearing in ADO queries.
666 * Log both IDs in `planning-log.md`.
667
6682. Prepare branch references:
669 * Source: `refs/heads/${input:sourceBranch}` (or current branch)
670 * Target: Remove remote prefix from `${input:baseBranch}` and prepend `refs/heads/`. Examples:
671 * `origin/main` → `refs/heads/main`
672 * `upstream/develop` → `refs/heads/develop`
673 * `main` → `refs/heads/main`
674
6753. Create pull request using `mcp_ado_repo_create_pull_request` with `repositoryId`, `sourceRefName`, `targetRefName`, and `title` (from pr.md without leading #). Optionally include `description`, `isDraft`, and `labels`. The `workItems` parameter accepts space-separated IDs to link work items during creation, simplifying the workflow. Capture returned PR ID and URL.
676
6774. Link additional work items using `mcp_ado_wit_link_work_item_to_pull_request` for each selected work item not linked during creation. Requires `projectId` (GUID format), `repositoryId`, `pullRequestId`, and `workItemId`. For cross-project linking, include `pullRequestProjectId`. Log results in `planning-log.md`.
678
6795. Add reviewers using `mcp_ado_repo_update_pull_request_reviewers` with resolved identity GUIDs. All reviewers are added as optional by default. In no-gates mode, add top 2 by contribution score. Document unresolved reviewers for manual addition.
680
6816. Validate completion by reading `handoff.md` to verify checkboxes and confirming PR URL accessibility.
682
683## MCP Tool Reference
684
685```javascript
686// Resolve repository ID from name
687mcp_ado_repo_get_repo_by_name_or_id({
688 project: "<project-name-or-guid>",
689 repositoryNameOrId: "<repo-name>"
690})
691
692// Create PR (with optional work item and label linking)
693mcp_ado_repo_create_pull_request({
694 repositoryId: "<guid>",
695 sourceRefName: "refs/heads/<branch>",
696 targetRefName: "refs/heads/main",
697 title: "feat(scope): description",
698 description: "## Summary\n\nChanges...",
699 isDraft: false,
700 labels: ["label-name"], // Optional: add labels at creation
701 workItems: "1234 5678" // Optional: space-separated work item IDs
702})
703
704// Update PR (set autocomplete, merge strategy, labels)
705mcp_ado_repo_update_pull_request({
706 repositoryId: "<guid>",
707 pullRequestId: 1234,
708 autoComplete: true, // Enable autocomplete when policies pass
709 mergeStrategy: "Squash", // NoFastForward|Squash|Rebase|RebaseMerge
710 deleteSourceBranch: true, // Delete source after merge
711 transitionWorkItems: true // Transition linked work items
712})
713
714// Link work item (for cross-project, add pullRequestProjectId)
715mcp_ado_wit_link_work_item_to_pull_request({
716 projectId: "<project-guid>",
717 repositoryId: "<repo-guid>",
718 pullRequestId: 1234,
719 workItemId: 5678,
720 pullRequestProjectId: "<pr-project-guid>" // Optional: cross-project linking
721})
722
723// Resolve identity (requires activate_ado_identity_and_search_tools)
724mcp_ado_core_get_identity_ids({ searchFilter: "user@example.com" })
725
726// Add reviewers
727mcp_ado_repo_update_pull_request_reviewers({
728 repositoryId: "<guid>",
729 pullRequestId: 1234,
730 reviewerIds: ["<identity-guid-1>", "<identity-guid-2>"],
731 action: "add"
732})
733```
734
735### Phase 7: Deliver Final Recap
736
737Provide conversational summary covering PR creation status and URL, work items linked, reviewers status, planning workspace location, and next steps.
738
739```markdown
740## ✅ Pull Request Created Successfully
741
742**PR**: [PR ID] | [PR URL] | [Active|Draft]
743**Linked**: ADO-[ID], ADO-[ID]
744**Reviewers**: [Name] (added) | [Name] (manual)
745**Files**: `.copilot-tracking/pr/new/[branch]/`
746```
747
748## Error Recovery
749
750* **Phase 1**: PR reference generation fails → verify git state, branch existence, base branch validity
751* **Phase 3**: Too many/no work items → adjust similarity threshold or keyword groups; if still none, proceed to Phase 3a to create work item
752* **Phase 3a**: Work item creation fails → log error, inform user, proceed to Phase 4 without work item (user can link manually later)
753* **Phase 4**: Identity resolution fails → mark reviewer for manual addition via Azure DevOps UI
754* **Phase 6**: Repository/Project ID not found → search workspace config or request from user
755* **Phase 6**: PR creation fails → verify branch refs, permissions, no duplicate PR
756* **Phase 6**: Work item linking fails → verify work item exists, project ID is GUID format, PR created successfully
757* **Phase 6**: Reviewer addition fails → provide manual addition instructions with PR URL
758
759## Presentation Guidelines
760
761* Use markdown: **bold** for emphasis, emoji for visual clarity (✅, 📄, 🔍)
762* Present summaries before details; avoid information overload
763* Provide clear options with suggested responses
764* Confirm before irreversible actions
765
766## State Persistence & Recovery
767
768* Maintain `planning-log.md` after each major action
769* Update phase transitions in `planning-log.md`
770* If context is summarized:
771 1. Read all planning files from `.copilot-tracking/pr/new/<normalized-branch>/`
772 2. Rebuild context from `planning-log.md` current phase
773 3. Resume from last incomplete step
774 4. Inform user of recovery process
775
776## Repository-Specific Conventions
777
778When working in this repository:
779
780* Follow PR description format specified in Phase 2 (pr-file-format block)
781* Use conventional commit types in PR titles
782* Include component scope when applicable
783* Reference changed files for reviewer context
784* Link related documentation when available
785* Follow markdown linting rules per `.markdownlint.json`
786* Use natural, human-friendly language in PR descriptions
787* Group changes by significance and importance
788* Avoid speculating about benefits not stated in commits
789