@chris1807/claude-kit 2.1.58 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -331,7 +331,8 @@ Claude automatically:
331
331
  3. Creates a PR targeting the `staging` branch — merging it triggers the Staging pipeline
332
332
  4. Links all work items to the PR
333
333
  5. Asks who verifies each product group on Staging (`COM`, `PAY`, …) — candidates are the non-developer names already on those work items
334
- 6. Watches the PR and the Staging pipeline; once it's green, moves the work items to `Staging` and assigns them to the approved verifiers
334
+ 6. Waits for Serena (the AI reviewer) to approve the PR, then completes it — for `dev`, `test`, and `staging` only; a `prod` PR you merge yourself
335
+ 7. Watches the Staging pipeline; once it's green, moves the work items to `Staging` and assigns them to the approved verifiers
335
336
 
336
337
  The same command walks a release through `test` → `staging` → `prod`; with no environment given it picks the next one.
337
338
 
@@ -341,7 +342,7 @@ The same command walks a release through `test` → `staging` → `prod`; with n
341
342
  /cherry-pick AB#1234 AB#1235 prod
342
343
  ```
343
344
 
344
- Cherry-picks specific work items to an environment without a formal release. Same gate check, same verifier question, and the same automatic state advance + assignment once the pipeline is green as `/deploy-release`. `main` is also a valid target — that's how a hot fix that went straight to `prod` is brought back into the compare branch.
345
+ Cherry-picks specific work items to an environment without a formal release. Same gate check, same verifier question, and the same automatic state advance + assignment once the pipeline is green as `/deploy-release`. Targeting `dev`, `test`, or `staging` it also merges the PR itself once Serena approves it; a `prod` PR waits for a person. `main` is also a valid target — that's how a hot fix that went straight to `prod` is brought back into the compare branch.
345
346
 
346
347
  ### Promote an Environment
347
348
 
@@ -351,7 +352,7 @@ Cherry-picks specific work items to an environment without a formal release. Sam
351
352
  /promote ← auto-detects from the current branch
352
353
  ```
353
354
 
354
- Creates a PR to promote all code from one branch to the next in the chain (`main → dev → test → staging → prod`). Shows every commit and work item before confirming, gate-checks the work items, asks who verifies each product group, and advances and assigns them once the merge's pipeline is green. `main → dev` is the usual first hop after feature PRs merge — nothing has deployed before that.
355
+ Creates a PR to promote all code from one branch to the next in the chain (`main → dev → test → staging → prod`). Shows every commit and work item before confirming, gate-checks the work items, asks who verifies each product group, and advances and assigns them once the merge's pipeline is green. Below production it also **merges the PR for you**: it polls until Serena (the AI reviewer) approves, then completes it with autocomplete — a PR into `prod` is always merged by a person. `main → dev` is the usual first hop after feature PRs merge — nothing has deployed before that.
355
356
 
356
357
  ### Rollback a Deployment
357
358
 
@@ -509,7 +510,7 @@ The PR merges into `main`. **That merge deploys nothing** — `main` is the comp
509
510
  /promote main dev
510
511
  ```
511
512
 
512
- Merge that PR. Claude asks who verifies each product group on Dev, watches the Dev pipeline, and once it's green moves the work items to `Ready for Testing` and assigns them to those people.
513
+ Claude asks who verifies each product group on Dev, waits for Serena to approve the PR and merges it, watches the Dev pipeline, and once it's green moves the work items to `Ready for Testing` and assigns them to those people. (Dev, Test, and Staging merge themselves this way; a production PR you merge yourself.)
513
514
 
514
515
  ### Step 2: Deploy Changes (Quick Commits)
515
516
 
@@ -569,7 +570,7 @@ When stakeholders have verified on Staging and set the items to `Ready to Deploy
569
570
  /deploy-release 23 prod
570
571
  ```
571
572
 
572
- Same process — gate `Ready to Deploy`, cherry-picks from `staging` into a PR targeting `prod`. After merge the Production CD pipeline triggers; when it comes back green the items move to `Deployed` and are assigned to whoever you named for each product group.
573
+ Same process — gate `Ready to Deploy`, cherry-picks from `staging` into a PR targeting `prod`. **You merge this one** — Claude auto-merges only into `dev`, `test`, and `staging`. After merge the Production CD pipeline triggers; when it comes back green the items move to `Deployed` and are assigned to whoever you named for each product group.
573
574
 
574
575
  ### Selective Deployment
575
576
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chris1807/claude-kit",
3
- "version": "2.1.58",
3
+ "version": "2.2.0",
4
4
  "description": "Claude Code starter kit for Azure DevOps teams — agents, hooks, MCP servers, slash commands, and end-to-end work item → PR → release → deploy workflow automation",
5
5
  "type": "module",
6
6
  "bin": {
@@ -33,6 +33,37 @@ Fetch each work item from Azure DevOps via MCP. Compare each one's `System.State
33
33
  Cherry-pick {count} work items to {environment}? Items behind the gate: include / drop / cancel
34
34
  ```
35
35
 
36
+ ### Step 1b: Scripts That Have to Be Run
37
+
38
+ A deployment script — a SQL migration, a data backfill, a PowerShell step — is attached to the work item it belongs to, and it has to run in **every** environment that item's code lands in. A promotion carries the code; it does not carry the script, and nothing in the PR says one exists. That is how an environment ends up half-deployed.
39
+
40
+ Fetch each carried work item with its attachments — `wit_work_item` `action: get`, `expand: "Relations"`, one call per item (`get_batch` has no `expand`) — and keep every relation whose `rel` is `AttachedFile` and whose filename extension is **not** a document, image or video:
41
+
42
+ ```
43
+ .xlsx .xls .xlsm .xlsb .csv .docx .doc .docm .pdf
44
+ .png .jpg .jpeg .gif .bmp .ico .svg .webp .tiff .tif
45
+ .mp4 .mov .avi .webm .mkv .wmv .flv .m4v
46
+ ```
47
+
48
+ Everything else counts, extensionless files included. The rule is deliberately loose, because the two mistakes do not cost the same: a filename someone glances at and dismisses costs seconds, a migration nobody ran costs an environment.
49
+
50
+ Show them with the table above, before the confirmation:
51
+
52
+ ```
53
+ 📜 Scripts to run with this promotion:
54
+
55
+ | Work Item | Script |
56
+ |-----------|--------|
57
+ | AB#1234 | 2026-09-11_add_delivery_index.sql |
58
+ | AB#1240 | backfill-tenant-flags.ps1 |
59
+
60
+ Download them from the work items. This command does not run them.
61
+ ```
62
+
63
+ If nothing carries an attachment, say `No deployment scripts attached` on one line and move on.
64
+
65
+ **Reported, never enforced.** A script does not block the promotion and does not change the gate check: the attachment may already have been run, may be a reference copy, may not be a script at all. Listing it is the whole job — the person deploying decides.
66
+
36
67
  Wait for confirmation. `drop` removes flagged items from this cherry-pick only.
37
68
 
38
69
  ## Step 2: Find Commits
@@ -91,7 +122,7 @@ Cherry-picking:
91
122
  - **sourceRefName**: `refs/heads/cherry-pick/<date>-to-<environment>`
92
123
  - **targetRefName**: `refs/heads/<target-environment-branch>`
93
124
  - **title**: `Cherry-pick AB#1234, AB#1235 → {Environment}`
94
- - **description**: List all work items with IDs and titles
125
+ - **description**: List all work items with IDs and titles, and — under a `Scripts to run` heading — any deployment scripts found in Step 1b, so whoever merges sees them without opening the work items
95
126
  3. Link all work items to the PR via `wit_link_work_item_to_pull_request`
96
127
 
97
128
  ## Step 6: Pick Who Verifies Each Group (before the merge)
@@ -162,9 +193,19 @@ Approve? (yes / change)
162
193
 
163
194
  `change` re-asks 6c. Only after `yes` do you move on — if the PR merges before the user answers, keep waiting for the answer, then run Step 8.
164
195
 
165
- ## Step 7: Watch the Merge, Then the Pipeline
196
+ ## Step 7: Get the PR Merged, Then Watch the Pipeline
197
+
198
+ ### 7a. Who completes the PR depends on the target
199
+
200
+ | Target | Who merges |
201
+ |---|---|
202
+ | `dev`, `test`, `staging` | **You do** — poll until Serena approves, then complete the PR (7b–7c) |
203
+ | `prod` | A human. **Never auto-merge into production.** |
204
+ | `main` | A human. No pipeline and no state change either — report the PR and stop. |
205
+
206
+ Resolve the target through the Pipeline Configuration table, not by the spelling of the branch — a project whose staging branch is named `Staging` or `release/staging` is still staging, and a project with no `test` row simply has no test hop.
166
207
 
167
- Do NOT merge the PR yourself — a reviewer approves and completes it. Report the PR, then watch for the deployment:
208
+ Report the PR either way:
168
209
 
169
210
  ```
170
211
  Cherry-pick PR created for {environment}.
@@ -174,13 +215,88 @@ Work items:
174
215
  - AB#1234: COM - Add payment export
175
216
  - AB#1240: PAY - Fix login redirect
176
217
 
177
- Merging the PR triggers the CD pipeline for {environment}. I'm watching the PR
178
- and that pipeline — when it comes back green I'll set these {count} items to
179
- `{state after merge}` and assign them as approved above. Nothing is written
180
- until then. Say `stop watching` to leave the states alone.
218
+ {merge line}
219
+ ```
220
+
221
+ `{merge line}` for `dev` / `test` / `staging`:
222
+
181
223
  ```
224
+ Waiting on Serena's review. When she approves I'll complete the PR, which
225
+ triggers the {environment} CD pipeline; when that comes back green I'll set
226
+ these {count} items to `{state after merge}` and assign them as approved
227
+ above. Say `don't merge` to stop before the merge, or `stop watching` to
228
+ leave the work item states alone.
229
+ ```
230
+
231
+ `{merge line}` for `prod` / `main`:
232
+
233
+ ```
234
+ A reviewer approves and completes this one — I don't merge into {environment}.
235
+ I'm watching the PR and that pipeline: when it comes back green I'll set these
236
+ {count} items to `{state after merge}` and assign them as approved above.
237
+ Nothing is written until then. Say `stop watching` to leave the states alone.
238
+ ```
239
+
240
+ ### 7b. Wait for Serena's approval (`dev` / `test` / `staging` only)
182
241
 
183
- 1. **Wait for the PR to complete.** Poll `repo_pull_request` until `status` is `completed`; note the merge commit and completion time. `abandoned` → stop, change nothing, report it.
242
+ Serena is the AI reviewer on this org's pull requests. Find her among the PR's reviewers by matching `serena` case-insensitively against `displayName` / `uniqueName` — never hardcode an identity id, and never count another reviewer's approval as hers.
243
+
244
+ Reviewer votes: `10` approved · `5` approved with suggestions · `0` no vote yet · `-5` waiting for author · `-10` rejected.
245
+
246
+ - `10` or `5` → approved. Go to 7c.
247
+ - `-5` or `-10` → **do not merge.** List her threads (`repo_pull_request_thread` `action: list`), report what she flagged, and stop. `/resolve-feedback {pr-id}` addresses them; her vote is re-evaluated after the next push.
248
+ - `0`, or she is not on the reviewer list yet → keep polling.
249
+
250
+ **Never cast a vote on the PR yourself** to satisfy an approval policy, and never add yourself as a reviewer to do it.
251
+
252
+ Poll in the background — never a foreground `sleep`:
253
+
254
+ ```bash
255
+ ORG=<org-url>; PR=<pr-id>; TRIES=0
256
+ while [ $TRIES -lt 120 ]; do
257
+ VOTE=$(az repos pr show --id "$PR" --org "$ORG" \
258
+ --query "reviewers[].[displayName,vote]" -o tsv \
259
+ | grep -i serena | cut -f2 | head -1)
260
+ case "$VOTE" in
261
+ 10|5) echo "APPROVED vote=$VOTE"; break ;;
262
+ -5|-10) echo "BLOCKED vote=$VOTE"; break ;;
263
+ *) TRIES=$((TRIES + 1)); sleep 30 ;;
264
+ esac
265
+ done
266
+ [ $TRIES -ge 120 ] && echo "TIMEOUT - no Serena vote after 60 minutes"
267
+ ```
268
+
269
+ Run it with `Monitor` (or Bash `run_in_background`). An empty `VOTE` means she isn't a reviewer yet, which is why the loop keeps going rather than treating it as a decision. Without the Azure CLI, poll `repo_pull_request` `action: get` on the same ~30-second cadence and read `reviewers[]`.
270
+
271
+ If the loop times out, leave the PR open and ask whether to keep waiting or merge without her. **If she was never added as a reviewer at all, say exactly that** — it usually means the PR was never picked up for review, not that it sailed through.
272
+
273
+ ### 7c. Complete the PR
274
+
275
+ Merge with `repo_pull_request_write` `action: update`:
276
+
277
+ | Field | Value | Why |
278
+ |---|---|---|
279
+ | `autoComplete` | `true` | ADO completes it the moment the remaining branch policies pass — a required build still gates the merge |
280
+ | `mergeStrategy` | `NoFastForward` | one merge commit, cherry-pick history intact |
281
+ | `transitionWorkItems` | `false` | **required.** This command owns the work item states (Step 8); ADO's own transition moves parents too |
282
+ | `deleteSourceBranch` | `true` | the `cherry-pick/...` branch is disposable |
283
+ | `bypassPolicy` | **never set it** | a policy that isn't passing is a stop, not an obstacle |
284
+
285
+ Then poll `repo_pull_request` `action: get` until `status` is `completed`. If it stays `Active` with autocomplete queued, a branch policy is unmet — report which one and stop; do not bypass it and do not push to the source branch to force it.
286
+
287
+ CLI fallback if the MCP update fails:
288
+
289
+ ```bash
290
+ az repos pr update --id <pr-id> --org <org-url> \
291
+ --auto-complete true --transition-work-items false --delete-source-branch true \
292
+ --merge-commit-message "Cherry-pick AB#1234, AB#1240 -> {Environment}"
293
+ ```
294
+
295
+ If the user said `don't merge`, leave the PR open, say so, and skip to 7d — a human merging it later still gets the pipeline watch and the state changes.
296
+
297
+ ### 7d. Watch the CD pipeline
298
+
299
+ 1. **Confirm the PR completed.** Poll `repo_pull_request` until `status` is `completed`; note the merge commit and completion time. `abandoned` → stop, change nothing, report it.
184
300
  2. **Find the CD run.** Look up the target branch's pipeline ID(s) in the Pipeline Configuration table, then poll `pipelines_build` for runs on `refs/heads/<target-branch>` queued at or after the merge time — match the merge commit when the run exposes it — and **capture each run's id**. A run that was already completed before the merge is not this deployment; ignore it. A branch with more than one pipeline (API + Client) must have **all** of them green.
185
301
  3. **Wait for a terminal result** on each run: `succeeded`, `partiallySucceeded`, `failed`, or `canceled`.
186
302
 
@@ -234,3 +350,10 @@ Next: {the human step — "QA tests on Test and sets Ready for Staging" / "stake
234
350
  ```
235
351
 
236
352
  If the user said `stop watching`, or an update fails, leave the rest alone, say exactly which items were and were not updated, and note that `/track` will flag the lag later.
353
+
354
+ If any carried item had a deployment script (Step 1b), repeat it here — this is the moment it has to run, and the list is stale in the scroll-back by now:
355
+
356
+ ```
357
+ 📜 Still to run on {environment}: AB#1234 2026-09-11_add_delivery_index.sql, AB#1240 backfill-tenant-flags.ps1
358
+ ```
359
+
@@ -74,6 +74,37 @@ Include them anyway, or drop them from this deploy? (include / drop / cancel)
74
74
 
75
75
  Wait for the answer. `drop` removes them from **this deploy only** — they stay in the release.
76
76
 
77
+ ## Step 3b: Scripts That Have to Be Run
78
+
79
+ A deployment script — a SQL migration, a data backfill, a PowerShell step — is attached to the work item it belongs to, and it has to run in **every** environment that item's code lands in. A promotion carries the code; it does not carry the script, and nothing in the PR says one exists. That is how an environment ends up half-deployed.
80
+
81
+ Fetch each carried work item with its attachments — `wit_work_item` `action: get`, `expand: "Relations"`, one call per item (`get_batch` has no `expand`) — and keep every relation whose `rel` is `AttachedFile` and whose filename extension is **not** a document, image or video:
82
+
83
+ ```
84
+ .xlsx .xls .xlsm .xlsb .csv .docx .doc .docm .pdf
85
+ .png .jpg .jpeg .gif .bmp .ico .svg .webp .tiff .tif
86
+ .mp4 .mov .avi .webm .mkv .wmv .flv .m4v
87
+ ```
88
+
89
+ Everything else counts, extensionless files included. The rule is deliberately loose, because the two mistakes do not cost the same: a filename someone glances at and dismisses costs seconds, a migration nobody ran costs an environment.
90
+
91
+ Show them with the gate check, before Step 4's confirmation:
92
+
93
+ ```
94
+ 📜 Scripts to run with this promotion:
95
+
96
+ | Work Item | Script |
97
+ |-----------|--------|
98
+ | AB#1234 | 2026-09-11_add_delivery_index.sql |
99
+ | AB#1240 | backfill-tenant-flags.ps1 |
100
+
101
+ Download them from the work items. This command does not run them.
102
+ ```
103
+
104
+ If nothing carries an attachment, say `No deployment scripts attached` on one line and move on.
105
+
106
+ **Reported, never enforced.** A script does not block the promotion and does not change the gate check: the attachment may already have been run, may be a reference copy, may not be a script at all. Listing it is the whole job — the person deploying decides.
107
+
77
108
  ## Step 4: Confirm
78
109
 
79
110
  ```
@@ -147,7 +178,7 @@ Cherry-picking commits for Release #{N}:
147
178
  - **sourceRefName**: `refs/heads/release/{N}-to-<environment>`
148
179
  - **targetRefName**: `refs/heads/<target-environment-branch>`
149
180
  - **title**: `Release #{N} → {Environment}`
150
- - **description**: List all work items included with their IDs and titles
181
+ - **description**: List all work items included with their IDs and titles, and — under a `Scripts to run` heading — any deployment scripts found in Step 3b, so whoever merges sees them without opening the work items
151
182
  3. Link all work items to the PR via `wit_link_work_item_to_pull_request`
152
183
 
153
184
  ## Step 8: Pick Who Verifies Each Group (before the merge)
@@ -217,9 +248,20 @@ Approve? (yes / change)
217
248
 
218
249
  `change` re-asks 8c. Only after `yes` do you move on — if the PR merges before the user answers, keep waiting for the answer, then run Step 10.
219
250
 
220
- ## Step 9: Watch the Merge, Then the Pipeline
251
+ ## Step 9: Get the PR Merged, Then Watch the Pipeline
252
+
253
+ Never trigger the CD pipeline by hand — it triggers on the merge.
221
254
 
222
- Do NOT merge the PR yourself, and do NOT trigger the CD pipeline — it triggers on the merge. Report the PR, then watch for the deployment:
255
+ ### 9a. Who completes the PR depends on the target
256
+
257
+ | Target | Who merges |
258
+ |---|---|
259
+ | `dev`, `test`, `staging` | **You do** — poll until Serena approves, then complete the PR (9b–9c) |
260
+ | `prod` | A human. **Never auto-merge into production.** |
261
+
262
+ Resolve the target through the Pipeline Configuration table, not by the spelling of the branch — a project whose staging branch is named `Staging` or `release/staging` is still staging, and a project with no `test` row simply has no test hop.
263
+
264
+ Report the PR either way:
223
265
 
224
266
  ```
225
267
  Release #{N} PR created for {environment}.
@@ -232,13 +274,89 @@ Work items included:
232
274
  - AB#1236: COM - View history
233
275
  - AB#1240: PAY - Fix login redirect
234
276
 
235
- Review and approve the PR — merging it triggers the CD pipeline for {environment}.
236
- I'm watching the PR and that pipeline; when it comes back green I'll set these
277
+ {merge line}
278
+ ```
279
+
280
+ `{merge line}` for `dev` / `test` / `staging`:
281
+
282
+ ```
283
+ Waiting on Serena's review. When she approves I'll complete the PR, which
284
+ triggers the {environment} CD pipeline; when that comes back green I'll set
285
+ these {count} items to `{state after merge}` and assign them as approved
286
+ above. Say `don't merge` to stop before the merge, or `stop watching` to
287
+ leave the work item states alone.
288
+ ```
289
+
290
+ `{merge line}` for `prod`:
291
+
292
+ ```
293
+ Review and approve the PR — a person merges this one; I don't merge into
294
+ production. Merging it triggers the CD pipeline for {environment}. I'm
295
+ watching the PR and that pipeline; when it comes back green I'll set these
237
296
  {count} items to `{state after merge}` and assign them as approved above.
238
297
  Nothing is written until then. Say `stop watching` to leave the states alone.
239
298
  ```
240
299
 
241
- 1. **Wait for the PR to complete.** Poll `repo_pull_request` until `status` is `completed`; note the merge commit and completion time. `abandoned` → stop, change nothing, report it.
300
+ ### 9b. Wait for Serena's approval (`dev` / `test` / `staging` only)
301
+
302
+ Serena is the AI reviewer on this org's pull requests. Find her among the PR's reviewers by matching `serena` case-insensitively against `displayName` / `uniqueName` — never hardcode an identity id, and never count another reviewer's approval as hers.
303
+
304
+ Reviewer votes: `10` approved · `5` approved with suggestions · `0` no vote yet · `-5` waiting for author · `-10` rejected.
305
+
306
+ - `10` or `5` → approved. Go to 9c.
307
+ - `-5` or `-10` → **do not merge.** List her threads (`repo_pull_request_thread` `action: list`), report what she flagged, and stop. A release branch is a cherry-pick of commits that already merged upstream, so the fix usually belongs on the source branch and comes forward in the next release — not as a patch commit on `release/{N}-to-{environment}`.
308
+ - `0`, or she is not on the reviewer list yet → keep polling.
309
+
310
+ **Never cast a vote on the PR yourself** to satisfy an approval policy, and never add yourself as a reviewer to do it.
311
+
312
+ Poll in the background — never a foreground `sleep`:
313
+
314
+ ```bash
315
+ ORG=<org-url>; PR=<pr-id>; TRIES=0
316
+ while [ $TRIES -lt 120 ]; do
317
+ VOTE=$(az repos pr show --id "$PR" --org "$ORG" \
318
+ --query "reviewers[].[displayName,vote]" -o tsv \
319
+ | grep -i serena | cut -f2 | head -1)
320
+ case "$VOTE" in
321
+ 10|5) echo "APPROVED vote=$VOTE"; break ;;
322
+ -5|-10) echo "BLOCKED vote=$VOTE"; break ;;
323
+ *) TRIES=$((TRIES + 1)); sleep 30 ;;
324
+ esac
325
+ done
326
+ [ $TRIES -ge 120 ] && echo "TIMEOUT - no Serena vote after 60 minutes"
327
+ ```
328
+
329
+ Run it with `Monitor` (or Bash `run_in_background`). An empty `VOTE` means she isn't a reviewer yet, which is why the loop keeps going rather than treating it as a decision. Without the Azure CLI, poll `repo_pull_request` `action: get` on the same ~30-second cadence and read `reviewers[]`.
330
+
331
+ If the loop times out, leave the PR open and ask whether to keep waiting or merge without her. **If she was never added as a reviewer at all, say exactly that** — it usually means the PR was never picked up for review, not that it sailed through.
332
+
333
+ ### 9c. Complete the PR
334
+
335
+ Merge with `repo_pull_request_write` `action: update`:
336
+
337
+ | Field | Value | Why |
338
+ |---|---|---|
339
+ | `autoComplete` | `true` | ADO completes it the moment the remaining branch policies pass — a required build still gates the merge |
340
+ | `mergeStrategy` | `NoFastForward` | one merge commit, cherry-pick history intact |
341
+ | `transitionWorkItems` | `false` | **required.** This command owns the work item states (Step 10); ADO's own transition moves parents too |
342
+ | `deleteSourceBranch` | `true` | the `release/{N}-to-{environment}` branch is disposable — the release itself lives in the iteration and the `release-{N}` tags |
343
+ | `bypassPolicy` | **never set it** | a policy that isn't passing is a stop, not an obstacle |
344
+
345
+ Then poll `repo_pull_request` `action: get` until `status` is `completed`. If it stays `Active` with autocomplete queued, a branch policy is unmet — report which one and stop; do not bypass it and do not push to the source branch to force it.
346
+
347
+ CLI fallback if the MCP update fails:
348
+
349
+ ```bash
350
+ az repos pr update --id <pr-id> --org <org-url> \
351
+ --auto-complete true --transition-work-items false --delete-source-branch true \
352
+ --merge-commit-message "Release #{N} -> {Environment}"
353
+ ```
354
+
355
+ If the user said `don't merge`, leave the PR open, say so, and skip to 9d — a human merging it later still gets the pipeline watch and the state changes.
356
+
357
+ ### 9d. Watch the CD pipeline
358
+
359
+ 1. **Confirm the PR completed.** Poll `repo_pull_request` until `status` is `completed`; note the merge commit and completion time. `abandoned` → stop, change nothing, report it.
242
360
  2. **Find the CD run.** Look up the target branch's pipeline ID(s) in the Pipeline Configuration table, then poll `pipelines_build` for runs on `refs/heads/<target-branch>` queued at or after the merge time — match the merge commit when the run exposes it — and **capture each run's id**. A run that was already completed before the merge is not this deployment; ignore it. A branch with more than one pipeline (API + Client) must have **all** of them green.
243
361
  3. **Wait for a terminal result** on each run: `succeeded`, `partiallySucceeded`, `failed`, or `canceled`.
244
362
 
@@ -294,6 +412,13 @@ Next: {the human step — "QA tests on Test and sets Ready for Staging" / "stake
294
412
 
295
413
  If the user said `stop watching`, or an update fails, leave the rest alone, say exactly which items were and were not updated, and note that `/track release {N}` will flag the lag later.
296
414
 
415
+ If any carried item had a deployment script (Step 3b), repeat it here — this is the moment it has to run, and the list is stale in the scroll-back by now:
416
+
417
+ ```
418
+ 📜 Still to run on {environment}: AB#1234 2026-09-11_add_delivery_index.sql, AB#1240 backfill-tenant-flags.ps1
419
+ ```
420
+
421
+
297
422
  ## Step 11: Notify Team (if Teams MCP is configured)
298
423
 
299
424
  Send a notification to the project's Teams channel via the Microsoft Teams MCP server — once when the PR is created:
@@ -79,6 +79,37 @@ Which? (1 / 2)
79
79
 
80
80
  For `main → dev` the gate is `Code Review`: an item still at `Code Review` whose commits are on `main` has had its PR merged, which is exactly right — not a warning. Features and Tasks are skipped. Items *ahead* of the gate are reported and left alone.
81
81
 
82
+ ## Step 3b: Scripts That Have to Be Run
83
+
84
+ A deployment script — a SQL migration, a data backfill, a PowerShell step — is attached to the work item it belongs to, and it has to run in **every** environment that item's code lands in. A promotion carries the code; it does not carry the script, and nothing in the PR says one exists. That is how an environment ends up half-deployed.
85
+
86
+ Fetch each carried work item with its attachments — `wit_work_item` `action: get`, `expand: "Relations"`, one call per item (`get_batch` has no `expand`) — and keep every relation whose `rel` is `AttachedFile` and whose filename extension is **not** a document, image or video:
87
+
88
+ ```
89
+ .xlsx .xls .xlsm .xlsb .csv .docx .doc .docm .pdf
90
+ .png .jpg .jpeg .gif .bmp .ico .svg .webp .tiff .tif
91
+ .mp4 .mov .avi .webm .mkv .wmv .flv .m4v
92
+ ```
93
+
94
+ Everything else counts, extensionless files included. The rule is deliberately loose, because the two mistakes do not cost the same: a filename someone glances at and dismisses costs seconds, a migration nobody ran costs an environment.
95
+
96
+ Show them with the gate check, before the confirmation:
97
+
98
+ ```
99
+ 📜 Scripts to run with this promotion:
100
+
101
+ | Work Item | Script |
102
+ |-----------|--------|
103
+ | AB#1234 | 2026-09-11_add_delivery_index.sql |
104
+ | AB#1240 | backfill-tenant-flags.ps1 |
105
+
106
+ Download them from the work items. This command does not run them.
107
+ ```
108
+
109
+ If nothing carries an attachment, say `No deployment scripts attached` on one line and move on.
110
+
111
+ **Reported, never enforced.** A script does not block the promotion and does not change the gate check: the attachment may already have been run, may be a reference copy, may not be a script at all. Listing it is the whole job — the person deploying decides.
112
+
82
113
  Then confirm: `Promote {count} commits from {source} to {target}? (yes/no)` — and wait.
83
114
 
84
115
  ## Step 4: Create PR
@@ -88,7 +119,7 @@ Create a PR directly from the source branch to the target branch via Azure DevOp
88
119
  - **sourceRefName**: `refs/heads/<source-branch>`
89
120
  - **targetRefName**: `refs/heads/<target-branch>`
90
121
  - **title**: `Promote {source} → {target}`
91
- - **description**: List all commits and associated work items being promoted
122
+ - **description**: List all commits and associated work items being promoted, and — under a `Scripts to run` heading — any deployment scripts found in Step 3b, so whoever merges sees them without opening the work items
92
123
 
93
124
  Link the associated work items to the PR.
94
125
 
@@ -159,9 +190,18 @@ Approve? (yes / change)
159
190
 
160
191
  `change` re-asks 5c. Only after `yes` do you move on — if the PR merges before the user answers, keep waiting for the answer, then run Step 7.
161
192
 
162
- ## Step 6: Watch the Merge, Then the Pipeline
193
+ ## Step 6: Get the PR Merged, Then Watch the Pipeline
194
+
195
+ ### 6a. Who completes the PR depends on the target
196
+
197
+ | Target | Who merges |
198
+ |---|---|
199
+ | `dev`, `test`, `staging` | **You do** — poll until Serena approves, then complete the PR (6b–6c) |
200
+ | `prod` | A human. **Never auto-merge into production.** |
201
+
202
+ Resolve the target through the Pipeline Configuration table, not by the spelling of the branch — a project whose staging branch is named `Staging` or `release/staging` is still staging, and a project with no `test` row simply has no test hop.
163
203
 
164
- Do NOT merge the PR yourself — a reviewer approves and completes it. Report the PR, then watch for the deployment:
204
+ Report the PR either way:
165
205
 
166
206
  ```
167
207
  Promotion PR created: {source} → {target}
@@ -169,13 +209,88 @@ Promotion PR created: {source} → {target}
169
209
  PR: {pr-url}
170
210
 
171
211
  {count} commits, {n} work items included.
172
- Merging the PR triggers the CD pipeline for {target}. I'm watching the PR and
173
- that pipeline — when it comes back green I'll set the {n} work items to
174
- `{state after merge}` and assign them as approved above. Nothing is written
175
- until then. Say `stop watching` to leave the states alone.
212
+ {merge line}
213
+ ```
214
+
215
+ `{merge line}` for `dev` / `test` / `staging`:
216
+
217
+ ```
218
+ Waiting on Serena's review. When she approves I'll complete the PR, which
219
+ triggers the {target} CD pipeline; when that comes back green I'll set the
220
+ {n} work items to `{state after merge}` and assign them as approved above.
221
+ Say `don't merge` to stop before the merge, or `stop watching` to leave the
222
+ work item states alone.
223
+ ```
224
+
225
+ `{merge line}` for `prod`:
226
+
227
+ ```
228
+ A reviewer approves and completes this one — I don't merge into production.
229
+ I'm watching the PR and that pipeline: when it comes back green I'll set the
230
+ {n} work items to `{state after merge}` and assign them as approved above.
231
+ Nothing is written until then. Say `stop watching` to leave the states alone.
232
+ ```
233
+
234
+ ### 6b. Wait for Serena's approval (`dev` / `test` / `staging` only)
235
+
236
+ Serena is the AI reviewer on this org's pull requests. Find her among the PR's reviewers by matching `serena` case-insensitively against `displayName` / `uniqueName` — never hardcode an identity id, and never count another reviewer's approval as hers.
237
+
238
+ Reviewer votes: `10` approved · `5` approved with suggestions · `0` no vote yet · `-5` waiting for author · `-10` rejected.
239
+
240
+ - `10` or `5` → approved. Go to 6c.
241
+ - `-5` or `-10` → **do not merge.** List her threads (`repo_pull_request_thread` `action: list`), report what she flagged, and stop. On a promotion the fix belongs on the source branch, not on the PR — a promotion PR has no branch of its own to push to.
242
+ - `0`, or she is not on the reviewer list yet → keep polling.
243
+
244
+ **Never cast a vote on the PR yourself** to satisfy an approval policy, and never add yourself as a reviewer to do it.
245
+
246
+ Poll in the background — never a foreground `sleep`:
247
+
248
+ ```bash
249
+ ORG=<org-url>; PR=<pr-id>; TRIES=0
250
+ while [ $TRIES -lt 120 ]; do
251
+ VOTE=$(az repos pr show --id "$PR" --org "$ORG" \
252
+ --query "reviewers[].[displayName,vote]" -o tsv \
253
+ | grep -i serena | cut -f2 | head -1)
254
+ case "$VOTE" in
255
+ 10|5) echo "APPROVED vote=$VOTE"; break ;;
256
+ -5|-10) echo "BLOCKED vote=$VOTE"; break ;;
257
+ *) TRIES=$((TRIES + 1)); sleep 30 ;;
258
+ esac
259
+ done
260
+ [ $TRIES -ge 120 ] && echo "TIMEOUT - no Serena vote after 60 minutes"
176
261
  ```
177
262
 
178
- 1. **Wait for the PR to complete.** Poll `repo_pull_request` until `status` is `completed`; note the merge commit and the completion time. `abandoned` → stop, change nothing, report it.
263
+ Run it with `Monitor` (or Bash `run_in_background`). An empty `VOTE` means she isn't a reviewer yet, which is why the loop keeps going rather than treating it as a decision. Without the Azure CLI, poll `repo_pull_request` `action: get` on the same ~30-second cadence and read `reviewers[]`.
264
+
265
+ If the loop times out, leave the PR open and ask whether to keep waiting or merge without her. **If she was never added as a reviewer at all, say exactly that** — it usually means the PR was never picked up for review, not that it sailed through.
266
+
267
+ ### 6c. Complete the PR
268
+
269
+ Merge with `repo_pull_request_write` `action: update`:
270
+
271
+ | Field | Value | Why |
272
+ |---|---|---|
273
+ | `autoComplete` | `true` | ADO completes it the moment the remaining branch policies pass — a required build still gates the merge |
274
+ | `mergeStrategy` | `NoFastForward` | one merge commit; never squash a promotion — it rewrites the commit ids the next hop cherry-picks by |
275
+ | `transitionWorkItems` | `false` | **required.** This command owns the work item states (Step 7); ADO's own transition moves parents too |
276
+ | `deleteSourceBranch` | **`false`** | the source is a long-lived environment branch (`main`, `dev`, `test`, `staging`) — deleting it would destroy the promotion chain |
277
+ | `bypassPolicy` | **never set it** | a policy that isn't passing is a stop, not an obstacle |
278
+
279
+ Then poll `repo_pull_request` `action: get` until `status` is `completed`. If it stays `Active` with autocomplete queued, a branch policy is unmet — report which one and stop; do not bypass it and do not push to the source branch to force it.
280
+
281
+ CLI fallback if the MCP update fails:
282
+
283
+ ```bash
284
+ az repos pr update --id <pr-id> --org <org-url> \
285
+ --auto-complete true --transition-work-items false --delete-source-branch false \
286
+ --merge-commit-message "Promote {source} -> {target}"
287
+ ```
288
+
289
+ If the user said `don't merge`, leave the PR open, say so, and skip to 6d — a human merging it later still gets the pipeline watch and the state changes.
290
+
291
+ ### 6d. Watch the CD pipeline
292
+
293
+ 1. **Confirm the PR completed.** Poll `repo_pull_request` until `status` is `completed`; note the merge commit and the completion time. `abandoned` → stop, change nothing, report it.
179
294
  2. **Find the CD run.** Look up the target branch's pipeline ID(s) in the Pipeline Configuration table, then poll `pipelines_build` for runs on `refs/heads/<target-branch>` queued at or after the merge time — match the merge commit when the run exposes it — and **capture each run's id**. A run that was already completed before the merge is not this deployment; ignore it. A branch with more than one pipeline (API + Client) must have **all** of them green.
180
295
  3. **Wait for a terminal result** on each run: `succeeded`, `partiallySucceeded`, `failed`, or `canceled`.
181
296
 
@@ -228,3 +343,10 @@ Next: {the human step — "QA tests on Test and sets Ready for Staging" / "stake
228
343
  ```
229
344
 
230
345
  If the user said `stop watching`, or an update fails, leave the rest alone, say exactly which items were and were not updated, and note that `/track` will flag the lag later.
346
+
347
+ If any carried item had a deployment script (Step 3b), repeat it here — this is the moment it has to run, and the list is stale in the scroll-back by now:
348
+
349
+ ```
350
+ 📜 Still to run on {target}: AB#1234 2026-09-11_add_delivery_index.sql, AB#1240 backfill-tenant-flags.ps1
351
+ ```
352
+
@@ -102,7 +102,7 @@ Claude maintains persistent memory across sessions in `~/.claude/projects/.../me
102
102
  4. **PR merges** into `main` — the compare branch. **Nothing deploys yet.** The work item stays in `Code Review` until it is promoted
103
103
  5. **Promote or release** — `/promote main dev` carries everything on `main` to Dev; `/create-release <N>` groups work items so `/deploy-release <N> test` → `staging` → `prod` can carry just those
104
104
  6. **Say who verifies** — before the merge, the command asks who each product group (`COM`, `PAY`, …) should be assigned to in the target environment, offering the non-developer names already on those work items
105
- 7. **Merge each promotion PR** — that merge triggers the environment's CD pipeline. The command watches it and, once it's green, sets the work items to `Testing`, `Staging`, or `Deployed` **and** assigns them to the approved verifiers — automatically, no reply needed
105
+ 7. **The promotion PR merges** — for `dev`, `test`, and `staging`, the deploy commands wait for Serena to approve and then complete the PR themselves; a `prod` PR is always merged by a person. That merge triggers the environment's CD pipeline. The command watches it and, once it's green, sets the work items to `Testing`, `Staging`, or `Deployed` **and** assigns them to the approved verifiers — automatically, no reply needed
106
106
  8. **Test** using Playwright MCP for browser testing
107
107
  9. **Track** work items via the Azure DevOps MCP server
108
108
  10. **Learn** — Claude saves what worked for next time
@@ -179,9 +179,18 @@ How the commands use this table:
179
179
 
180
180
  - **Gate check before the PR.** `/deploy-release`, `/cherry-pick`, and `/promote` compare each carried work item's state against the gate for the target environment. Anything behind the gate (e.g. still `Testing` when deploying to `staging`) is flagged and the user decides whether to include it. Items *ahead* of the gate (e.g. already `Deployed` on a cherry-pick to `prod`) are reported and left alone.
181
181
  - **Advance on a green pipeline, automatically.** `/promote`, `/cherry-pick`, and `/deploy-release` do not stop at the PR. They poll it until it is `completed`, then poll the target branch's CD pipeline until every run finishes. Only on `succeeded` do they write the new state — for every carried User Story, Bug, and Hot Fix, never a Feature or Task, and never backward. A failed or canceled run changes **nothing** and is reported with the log link. `/track` reports items whose state lags the branch their commits are on and offers to catch them up.
182
+ - **Auto-merge below production.** When the target is `dev`, `test`, or `staging`, all three commands poll the PR until **Serena** (the AI reviewer) votes, then complete it with autocomplete — remaining branch policies still gate the merge, work item transitions are left off so the command's own state logic owns them, and a branch policy that isn't passing is a stop, never a bypass. A rejection or *waiting for author* vote stops the merge and reports her threads. A PR into `prod` (or into `main`) is **always** merged by a person.
182
183
  - **Assign the verifier at the same time.** The state change hands the item to a person, so the same three commands ask **before the merge** who each group of items should go to, then apply the assignee alongside the state once the pipeline is green. See **Verifier Assignment** below.
183
184
  - **Never assume the state list.** Confirm with `mcp__azure-devops__wit_work_item` (`action: get_type`) on an unfamiliar project before writing a state name — a bad name is accepted silently by a query and rejected only at write time.
184
185
 
186
+ #### Deployment Scripts
187
+
188
+ A SQL migration or a backfill script is attached to the work item it belongs to, and it has to run in **every** environment that item's code lands in — test, then staging, then prod. The promotion carries the code, never the script.
189
+
190
+ `/promote`, `/cherry-pick` and `/deploy-release` therefore read the carried items' attachments (`wit_work_item` `action: get`, `expand: "Relations"`) and list any that look like something to run: an `AttachedFile` whose extension is **not** a document, image or video (`.docx .xlsx .csv .pdf .png .jpg .mp4` and friends). Everything else counts — the rule is loose on purpose, because a filename glanced at and dismissed costs seconds while a migration nobody ran costs an environment. The list appears before the confirmation, in the PR description, and again once the pipeline is green, which is when it actually has to be run.
191
+
192
+ **Reported, never enforced.** A script never blocks a promotion and never changes the gate check — it may already have been run, or be a reference copy. The person deploying decides; the commands only make sure nobody finds out afterwards.
193
+
185
194
  #### Verifier Assignment
186
195
 
187
196
  Moving an item to `Testing`, `Staging`, or `Deployed` puts it on someone's plate, so `/promote`, `/cherry-pick`, and `/deploy-release` also change who owns it. The developer implemented it; from here on it belongs to whoever checks it in that environment.
@@ -207,7 +216,7 @@ This creates a `Release #23` iteration, assigns the selected work items to it, a
207
216
  /deploy-release 23 staging
208
217
  /deploy-release 23 prod
209
218
  ```
210
- This finds all work items in Release #23, checks each one against the target environment's gate state, cherry-picks their commits into a release branch (`release/23-to-staging`), creates a PR targeting the environment branch, links all work items, asks who verifies each product group, and — once the merge's CD pipeline comes back green — advances them to the environment's state (`Testing`, `Staging`, `Deployed`) and assigns them to those verifiers.
219
+ This finds all work items in Release #23, checks each one against the target environment's gate state, cherry-picks their commits into a release branch (`release/23-to-staging`), creates a PR targeting the environment branch, links all work items, asks who verifies each product group, merges the PR once Serena approves it (`dev`/`test`/`staging` only — a `prod` PR waits for a person), and — once the merge's CD pipeline comes back green — advances them to the environment's state (`Testing`, `Staging`, `Deployed`) and assigns them to those verifiers.
211
220
 
212
221
  **Selective deployment:** Since releases are deployed via cherry-pick, you can deploy a full release or a subset. If staging has 5 user stories but only 3 are `Ready to Deploy`, create a release with just those 3 and deploy it.
213
222
 
@@ -227,7 +236,7 @@ Cherry-pick specific work items to an environment without a formal release:
227
236
  ```
228
237
  /cherry-pick AB#1234 AB#1235 prod
229
238
  ```
230
- This finds commits for the specified work items, checks them against the target's gate state, cherry-picks them into a branch (`cherry-pick/<date>-to-<environment>`), creates a PR, asks who verifies each product group, and — once the merge's CD pipeline is green — advances and assigns the work items.
239
+ This finds commits for the specified work items, checks them against the target's gate state, cherry-picks them into a branch (`cherry-pick/<date>-to-<environment>`), creates a PR, asks who verifies each product group, merges the PR once Serena approves it (`dev`/`test`/`staging` only — a `prod` PR waits for a person), and — once the merge's CD pipeline is green — advances and assigns the work items.
231
240
 
232
241
  #### Promoting Environments
233
242
 
@@ -237,7 +246,7 @@ Promote all code from one environment to the next:
237
246
  /promote staging prod
238
247
  /promote ← auto-detects source and target from current branch
239
248
  ```
240
- This creates a PR from the source branch to the target branch with a summary of all included commits and their work items, checks the work items against the target's gate state, asks who verifies each product group, and — once the merge's CD pipeline is green — advances and assigns them. `main → dev` is the usual first hop after feature PRs merge.
249
+ This creates a PR from the source branch to the target branch with a summary of all included commits and their work items, checks the work items against the target's gate state, asks who verifies each product group, merges the PR once Serena approves it (`dev`/`test`/`staging` only — a `prod` PR waits for a person), and — once the merge's CD pipeline is green — advances and assigns them. `main → dev` is the usual first hop after feature PRs merge.
241
250
 
242
251
  #### Rollbacks
243
252
 
@@ -302,10 +311,10 @@ All deployment and release operations are available as slash commands:
302
311
  | `/resolve-feedback` | `/resolve-feedback 142` | Address unresolved PR comment threads, push fixes, reply + resolve threads |
303
312
  | `/deploy` | `/deploy "commit message"` | Commit, push, trigger pipeline (only on `dev`/`test`/`staging`/`prod` — never on `main`) |
304
313
  | `/create-release` | `/create-release 23` | Group work items into Release #23 |
305
- | `/deploy-release` | `/deploy-release 23 staging` | Gate-check → cherry-pick release to environment → PR → ask who verifies → advance + assign on a green pipeline |
314
+ | `/deploy-release` | `/deploy-release 23 staging` | Gate-check → list deployment scripts → cherry-pick release to environment → PR → ask who verifies → merge on Serena's approval (below prod) → advance + assign on a green pipeline |
306
315
  | `/add-to-release` | `/add-to-release 24 AB#4599` | Add work items to existing release |
307
- | `/cherry-pick` | `/cherry-pick AB#1234 AB#1235 prod` | Gate-check → cherry-pick specific work items → PR → ask who verifies → advance + assign on a green pipeline |
308
- | `/promote` | `/promote main dev` | Promote all code between environments (`main → dev → test → staging → prod`) → ask who verifies → advance + assign on a green pipeline |
316
+ | `/cherry-pick` | `/cherry-pick AB#1234 AB#1235 prod` | Gate-check → list deployment scripts → cherry-pick specific work items → PR → ask who verifies → merge on Serena's approval (below prod) → advance + assign on a green pipeline |
317
+ | `/promote` | `/promote main dev` | Promote all code between environments (`main → dev → test → staging → prod`) → list deployment scripts → ask who verifies → merge on Serena's approval (below prod) → advance + assign on a green pipeline |
309
318
  | `/rollback` | `/rollback AB#1234 prod` | Revert commits on an environment |
310
319
  | `/track` | `/track release 24` | Check release, pipeline, environment, or work item status; flags work items whose state lags their environment |
311
320
  | `/where` | `/where AB#1234` | Show which environment branches contain a work item's commits |