@skitterbyte/skitterspec-azure-boards 1.2.1 → 1.3.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.
@@ -115,6 +115,31 @@ is an opt-in not taken (fine); `broken` is configured-but-wrong (exit 1).
115
115
  configured state exists on the types, and whether the PAT can search
116
116
  identities (a warn, never broken — only user search degrades without it).
117
117
 
118
+ ## 4b. Optional — see releases on the board
119
+
120
+ The release carrier is a work item per release, so it can have a board of its
121
+ own, and the stories it carries can show where they are. Everything here is a
122
+ process or team setting, and needs **Edit process** on the inherited process
123
+ plus **team administrator** — nothing in this package does it for you.
124
+
125
+ - **A Releases board.** Process → Backlog levels → add a portfolio level
126
+ holding the `Release` type, then Team settings → Backlogs → tick it. The
127
+ board's level picker then offers **Releases**, one column per state. Put
128
+ each env state in the *In Progress* category, or every card stacks in the
129
+ first column.
130
+ - **The release on each story** is a tag (`releases.ticketTag`, on by
131
+ default). Show tags on the card and filter the board by one.
132
+ - **Where each story is deployed.** Add a picklist field to every type
133
+ tickets are minted as (User Story, Bug…) holding exactly the `envs` values
134
+ (`On Test`, `On Demo`, `Released`…), and set its reference name as
135
+ `releases.deployedField` (e.g. `Custom.Deployed`). `release deployed <env>`
136
+ then sets it on each story the release carries, leaving the story's State
137
+ alone. Show it on the card, and add a card style rule per value to colour
138
+ cards by it.
139
+ - **Releases with their stories in one list.** A *Work items and direct
140
+ links* query — top level `Release` in the env states, linked `Related`
141
+ stories — shows each release with its stories under it.
142
+
118
143
  ## 5. Push a spec
119
144
 
120
145
  `/spec-push <spec>` computes the plan, applies it, stamps the returned ids
@@ -19,6 +19,8 @@ env-var NAMES — never a credential. Credentials live in the user-level store
19
19
  | `auth.tokenEnv` | The env-var NAME for the PAT — the official CLI's by default, so a machine set up for `az boards` needs nothing new. Work Items (Read & Write) covers everything but identity search, which wants Identity (Read). | `AZURE_DEVOPS_EXT_PAT` |
20
20
  | `refs.foreignPatterns` | Ref shapes that are KNOWN HISTORY rather than unreferenced commits — a repo migrating off another tracker lists its old key here (e.g. `"ERQ-\\d+"`). | `[]` |
21
21
  | `releases.workItemType` / `releases.series` | The release seam's carrier: one work item of this type per release, found by title, its state moved through each series' `envs` map by `release deployed`. | `"Release"` / `[]` |
22
+ | `releases.ticketTag` | Tag each ticket `release create` attaches with the release tag (`v37.7.0`), so a story card shows which release carried it and the board filters by it. Existing tags are kept. The tag is checked per ticket, separately from the link, so re-running `release create <tag> --apply` backfills a release cut before this existed — without a second comment. `false` opts out. | `true` |
23
+ | `releases.deployedField` | A field reference (e.g. `Custom.Deployed`) that `release deployed <env>` sets on each ticket the release carries, to that env's `envs` value — the same name the release item moves to. Phase Tasks and ticket State are never touched. The value is checked against each ticket type's allowed values before anything is written, so a type without the field or a value its picklist lacks refuses with nothing changed. Empty writes no field. `SETUP.md` → *see releases on the board*. | `""` |
22
24
  | `apply.transport` | `api` \| `mcp`, or empty for "api when credentials resolve, mcp when they don't". | `""` |
23
25
  | `sync.baseDir` | Where last-pushed snapshots live. | `specs/.core/azure-base` |
24
26
  | `sync.fieldOwnership` | Which projection fields push (`description`, `subIssues`, `workflowState`, `assignee`; `"none"` declines one). | all `push` |
@@ -36,7 +36,7 @@ A verdict sentence, a blank line, then a two-column table:
36
36
  | **Branch** | `spec/feat-foo` · 3 commits, clean |
37
37
  | **Built** | POST /orders handler, orders schema |
38
38
  | **Tests** | 128 passed · dotnet test |
39
- | **Review** | 7 files, +212 −18 · **local** [http://127.0.0.1:7760/…](http://127.0.0.1:7760/…) · **network** [http://192.168.0.136:7760/…](http://192.168.0.136:7760/…) · **remote** off |
39
+ | **Review** | 7 files, +212 −18 · **local** [http://127.0.0.1:7760/…](http://127.0.0.1:7760/…) · **network** [http://192.168.0.136:7760/…](http://192.168.0.136:7760/…) also [http://100.126.111.34:7760/…](http://100.126.111.34:7760/…) (tailnet) · **remote** off |
40
40
  | **Follow-ups** | none |
41
41
  | **Next** | `/spec-next` → phase 3 (Auth) |
42
42
 
@@ -89,6 +89,7 @@ the options may be offered after the table.
89
89
 
90
90
  - **local** — [http://127.0.0.1:7760/7e9e123e7540/feat-orders](http://127.0.0.1:7760/7e9e123e7540/feat-orders)
91
91
  - **network** — [http://192.168.0.136:7760/7e9e123e7540/feat-orders](http://192.168.0.136:7760/7e9e123e7540/feat-orders)
92
+ - also — [http://100.126.111.34:7760/7e9e123e7540/feat-orders](http://100.126.111.34:7760/7e9e123e7540/feat-orders) (tailnet)
92
93
  - **remote** — off · `/spec-remote-review` turns it on
93
94
 
94
95
  live: off — /spec-live to put it live
@@ -156,6 +157,17 @@ on. Dropping the line is what left a reader who had walked out of the house with
156
157
  nothing on screen to tell them a remote page was even possible — they could not
157
158
  ask for what they could not see.
158
159
 
160
+ **The `network` tier may carry alternates, and they are part of it — not a fourth tier.**
161
+ The engine offers the other addresses this machine has (a
162
+ tailnet one, for a reader off the wifi) as `also:` lines under `network`, each
163
+ labelled; `--json` carries them as that tier's `alternates`, labelled the same
164
+ way. Copy them as indented sub-bullets under the network bullet, verbatim,
165
+ labels included. This is not an amendment to the tier rule: the stack is the
166
+ engine's, copied rather than composed, and the engine was already printing
167
+ these — a contract that made the skill edit them out was the composing this
168
+ section forbids. A machine with no alternates renders the banner exactly as
169
+ above, minus the sub-bullet.
170
+
159
171
  **Only promise a wait the transport can deliver.** The wait itself is real in
160
172
  every case; what varies is what carries it back, not whether the run is
161
173
  stopped. Three transports, three true sentences:
@@ -298,8 +310,11 @@ behind, and they cannot.
298
310
  `fetch(location.pathname, …)`, so a page opened at `127.0.0.1:7760/…` and one
299
311
  opened at `192.168.0.136:7760/…` reach the same server process and the same
300
312
  pending store. One wait covers both, and a verdict pressed on either wakes the
301
- same run. Between those two the objection does not apply — which is why both are
302
- offered, and why offering them gives nothing up.
313
+ same run. A `network` alternate — the `also:` tailnet address — is one more
314
+ door into the same room: the same server answers on it, so the wait-coverage
315
+ line stays true with nothing added to it. Between all of those the objection
316
+ does not apply — which is why they are offered, and why offering them gives
317
+ nothing up.
303
318
 
304
319
  **So two things are required, and the second is what the old rule lacked.**
305
320
  Every link is **labelled** with its tier, and one line says
@@ -410,7 +425,7 @@ behind it — say nothing rather than reporting that there was nothing to report
410
425
  | `Landed` | A fast-forward, a tag, a cherry-pick. |
411
426
  | `Worktree` | A worktree provisioned, entered, or torn down. |
412
427
  | `Untouched` | Uncommitted work the run deliberately left alone — whose, and how much. |
413
- | `Review` | The rendered diff page: files, `+`/`−`, and the stack — the same tiers the banner lists, labelled, run together with `·` because a row is one cell, plus `live` where the engine reported one. **No question** — a row cannot be waited on, so a question in one is unanswerable by construction (see *asking implies waiting*). **Omitted entirely when the run is waiting on a verdict**: the banner after the block carries it instead, and a row saying the same thing beside it splits the reader's attention across two places. |
428
+ | `Review` | The rendered diff page: files, `+`/`−`, and the stack — the same tiers the banner lists, labelled, run together with `·` because a row is one cell, with any `network` alternates inline after the network URL (`also <url> (tailnet)`), plus `live` where the engine reported one. **No question** — a row cannot be waited on, so a question in one is unanswerable by construction (see *asking implies waiting*). **Omitted entirely when the run is waiting on a verdict**: the banner after the block carries it instead, and a row saying the same thing beside it splits the reader's attention across two places. |
414
429
  | `Follow-ups` | **Always.** `none`, or one line each. |
415
430
  | `Next` | **Last.** The single next action for this work — runnable from the state the run leaves behind. |
416
431
 
@@ -597,7 +597,9 @@ underneath a reader when detection flipped mid-session.
597
597
 
598
598
  So: **relay all three tier lines, every time.** Any `also:` lines sit under
599
599
  `network` — the other addresses this machine has, offered because the
600
- best-guess one can be wrong — so pass them on rather than editing them out.
600
+ best-guess one can be wrong — so pass them on rather than editing them out: in
601
+ the banner they are indented sub-bullets under **network**, labels
602
+ (`(tailnet)`) included, exactly as `.claude/rules/spec-reports.md` shows.
601
603
 
602
604
  **Never read an environment variable to decide anything about the offer** — not
603
605
  `SSH_CONNECTION`, not `CLAUDE_CODE_*`, not a tty check. There is nothing left
@@ -608,7 +608,9 @@ underneath a reader when detection flipped mid-session.
608
608
 
609
609
  So: **relay all three tier lines, every time.** Any `also:` lines sit under
610
610
  `network` — the other addresses this machine has, offered because the
611
- best-guess one can be wrong — so pass them on rather than editing them out.
611
+ best-guess one can be wrong — so pass them on rather than editing them out: in
612
+ the banner they are indented sub-bullets under **network**, labels
613
+ (`(tailnet)`) included, exactly as `.claude/rules/spec-reports.md` shows.
612
614
 
613
615
  **Never read an environment variable to decide anything about the offer** — not
614
616
  `SSH_CONNECTION`, not `CLAUDE_CODE_*`, not a tty check. There is nothing left
@@ -584,7 +584,9 @@ underneath a reader when detection flipped mid-session.
584
584
 
585
585
  So: **relay all three tier lines, every time.** Any `also:` lines sit under
586
586
  `network` — the other addresses this machine has, offered because the
587
- best-guess one can be wrong — so pass them on rather than editing them out.
587
+ best-guess one can be wrong — so pass them on rather than editing them out: in
588
+ the banner they are indented sub-bullets under **network**, labels
589
+ (`(tailnet)`) included, exactly as `.claude/rules/spec-reports.md` shows.
588
590
 
589
591
  **Never read an environment variable to decide anything about the offer** — not
590
592
  `SSH_CONNECTION`, not `CLAUDE_CODE_*`, not a tty check. There is nothing left
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skitterbyte/skitterspec-azure-boards",
3
- "version": "1.2.1",
3
+ "version": "1.3.0",
4
4
  "description": "Spec-driven development for Claude Code, with one-way Azure Boards sync — a superset of @skitterbyte/skitterspec: the base filesystem workflow plus /spec-status · /spec-push · /spec-claim and the spec-sync CLI, mirroring specs to Azure DevOps work items with parent/child hierarchy, assignment and a release work item per tag. The repo is canonical; Boards is a generated mirror. Install this OR the base OR one other superset — exactly one.",
5
5
  "keywords": [
6
6
  "claude",
package/src/cli.js CHANGED
@@ -88,6 +88,8 @@ const {
88
88
  collectReview,
89
89
  reviewTierStack,
90
90
  reviewTierLine,
91
+ isTailnetAddress,
92
+ tailnetLabel,
91
93
  renderReviewPage,
92
94
  renderReviewBlock,
93
95
  reviewOutPath,
@@ -4258,6 +4260,10 @@ async function specEnvReview(dir, config, specArg, flags, invokedFrom = dir) {
4258
4260
  // use, and the engine cannot know — that guess failed three separate ways
4259
4261
  // in one day. Now every tier is listed, labelled, and either a URL or the
4260
4262
  // one command that turns it on.
4263
+ // The runners-up print as `also:` lines inside the network tier's own
4264
+ // rendering — `reviewTierLine` carries them, which is what puts them
4265
+ // under `network:` rather than dangling after the stack (they used to
4266
+ // print below `remote:`, against the comment that placed them).
4261
4267
  reviewTierStack({
4262
4268
  served,
4263
4269
  fileUrl: reviewFileUrl(out),
@@ -4266,11 +4272,6 @@ async function specEnvReview(dir, config, specArg, flags, invokedFrom = dir) {
4266
4272
  })
4267
4273
  .map((t) => reviewTierLine(t) + '\n')
4268
4274
  .join('') +
4269
- // The runners-up sit UNDER the network tier, because that is what they are
4270
- // alternatives to — and virtual adapters are gone from them entirely.
4271
- (served && !served.loopback && (served.alternates || []).length
4272
- ? served.alternates.map((u) => ` also: ${u}${tailnetLabel(u)}\n`).join('')
4273
- : '') +
4274
4275
  // WHICH TIERS THE WAIT COVERS, once, next to the stack. `local` and
4275
4276
  // `network` are two doors into one room — the page POSTs to
4276
4277
  // `location.pathname`, so both reach this server and this pending store.
@@ -4583,26 +4584,6 @@ function offerableLanAddresses(nets = require('node:os').networkInterfaces()) {
4583
4584
  .map((e) => e.address)
4584
4585
  }
4585
4586
 
4586
- // 100.64.0.0/10 — the CGNAT range Tailscale assigns from.
4587
- //
4588
- // WHAT WOULD FOOL THIS: a carrier-grade NAT or another overlay network using
4589
- // the same range on a utun adapter is offered too. That costs one dud `also:`
4590
- // line, where filtering it hides the only link a reader off the wifi can open.
4591
- function isTailnetAddress(address) {
4592
- const m = /^100\.(\d+)\./.exec(address)
4593
- return !!m && Number(m[1]) >= 64 && Number(m[1]) <= 127
4594
- }
4595
-
4596
- // The suffix on an `also:` line whose host is a tailnet address, so it reads
4597
- // apart from the LAN one — a reader off the wifi needs to know which to tap.
4598
- function tailnetLabel(url) {
4599
- let host = ''
4600
- try {
4601
- host = new URL(url).hostname
4602
- } catch {}
4603
- return isTailnetAddress(host) ? ' (tailnet)' : ''
4604
- }
4605
-
4606
4587
  /**
4607
4588
  * Bring the review server up, or adopt the one already running.
4608
4589
  *
package/src/env/review.js CHANGED
@@ -715,7 +715,21 @@ function reviewTierStack({ served, fileUrl, publishedUrl, config }) {
715
715
  if (!config.review.allowNetwork) {
716
716
  tiers.push({ tier: 'network', off: true, enable: 'skitterspec spec-env review allow network' })
717
717
  } else if (served && !served.loopback && served.url) {
718
- tiers.push({ tier: 'network', url: served.url, alternates: served.alternates || [] })
718
+ // LABELLED HERE, not by the renderer: `--json`'s `tiers` is the stack a
719
+ // skill copies, and an unlabelled alternate made the `(tailnet)` suffix a
720
+ // fact only the text render knew — so the one link a reader off the wifi
721
+ // could open reached the JSON indistinguishable from a second LAN address.
722
+ tiers.push({
723
+ tier: 'network',
724
+ url: served.url,
725
+ alternates: (served.alternates || []).map((u) => {
726
+ let host = ''
727
+ try {
728
+ host = new URL(u).hostname
729
+ } catch {}
730
+ return isTailnetAddress(host) ? { url: u, label: 'tailnet' } : { url: u }
731
+ }),
732
+ })
719
733
  } else {
720
734
  // Permitted, but there is no address to offer — a machine with no network,
721
735
  // or a server that could not take one. Not a problem to report as an error.
@@ -738,13 +752,42 @@ function reviewTierStack({ served, fileUrl, publishedUrl, config }) {
738
752
  }
739
753
 
740
754
  // One tier as a line, padded so the labels form a column the eye can run down.
755
+ // A tier with alternates renders them as indented `also:` lines of its own —
756
+ // they are PART of the tier, which is what puts them under `network:` rather
757
+ // than dangling after the stack (they used to print below `remote:`, against
758
+ // the comment that placed them).
741
759
  function reviewTierLine(t) {
742
760
  const label = ` ${t.tier}:`.padEnd(11)
743
- if (t.url) return `${label}${t.url}${t.note ? ` (${t.note})` : ''}`
761
+ if (t.url) {
762
+ return [
763
+ `${label}${t.url}${t.note ? ` (${t.note})` : ''}`,
764
+ ...(t.alternates || []).map((a) => ` also: ${a.url}${a.label ? ` (${a.label})` : ''}`),
765
+ ].join('\n')
766
+ }
744
767
  if (t.off) return `${label}off — turn on with: ${t.enable}`
745
768
  return `${label}— (${t.note})`
746
769
  }
747
770
 
771
+ // 100.64.0.0/10 — the CGNAT range Tailscale assigns from.
772
+ //
773
+ // WHAT WOULD FOOL THIS: a carrier-grade NAT or another overlay network using
774
+ // the same range on a utun adapter is offered too. That costs one dud `also:`
775
+ // line, where filtering it hides the only link a reader off the wifi can open.
776
+ function isTailnetAddress(address) {
777
+ const m = /^100\.(\d+)\./.exec(address)
778
+ return !!m && Number(m[1]) >= 64 && Number(m[1]) <= 127
779
+ }
780
+
781
+ // The suffix on an `also:` line whose host is a tailnet address, so it reads
782
+ // apart from the LAN one — a reader off the wifi needs to know which to tap.
783
+ function tailnetLabel(url) {
784
+ let host = ''
785
+ try {
786
+ host = new URL(url).hostname
787
+ } catch {}
788
+ return isTailnetAddress(host) ? ' (tailnet)' : ''
789
+ }
790
+
748
791
 
749
792
  // The verdicts that COMMIT, and are therefore blocked by an open comment. One
750
793
  // list, so a fifth verdict cannot become a way around the single refusal this
@@ -2482,6 +2525,8 @@ module.exports = {
2482
2525
  surfacesFor,
2483
2526
  reviewTierStack,
2484
2527
  reviewTierLine,
2528
+ isTailnetAddress,
2529
+ tailnetLabel,
2485
2530
  COMMITTING,
2486
2531
  BUTTON_SETS,
2487
2532
  DEFAULT_BUTTON_SET,
@@ -68,7 +68,7 @@ function vsspsUrlOf(orgUrl) {
68
68
  * Wrap credential + org/project into the typed ops the engine uses. Injected
69
69
  * `fetch` and `sleep` make every op testable offline.
70
70
  */
71
- function makeApiAdapter({ orgUrl, project, token, releaseType, fetch: fetchImpl, sleep, maxRetries = MAX_RETRIES }) {
71
+ function makeApiAdapter({ orgUrl, project, token, releaseType, ticketTag = true, deployedField = '', fetch: fetchImpl, sleep, maxRetries = MAX_RETRIES }) {
72
72
  const doFetch = fetchImpl || globalThis.fetch
73
73
  if (typeof doFetch !== 'function') {
74
74
  throw new Error('no fetch available — Node 18+ is required for the API transport')
@@ -226,6 +226,27 @@ function makeApiAdapter({ orgUrl, project, token, releaseType, fetch: fetchImpl,
226
226
  return ((raw && raw.value) || []).map((item) => normalizeItem(item)).filter(Boolean)
227
227
  }
228
228
 
229
+ /**
230
+ * Add `tag` to each work item that lacks it; returns how many were written.
231
+ * An `add` on System.Tags REPLACES the whole value, so the write is the
232
+ * item's existing tags plus the new one. Azure compares tags
233
+ * case-insensitively, so the presence check does too.
234
+ */
235
+ async function tagTickets(ids, tag) {
236
+ const items = await batchRead(ids, ['System.Tags'])
237
+ const want = String(tag).toLowerCase()
238
+ let tagged = 0
239
+ for (const item of items) {
240
+ if (item.tags.some((t) => t.toLowerCase() === want)) continue
241
+ await request('PATCH', `${projectBase}/wit/workitems/${encodeURIComponent(item.id)}`, {
242
+ body: [{ op: 'add', path: '/fields/System.Tags', value: [...item.tags, tag].join('; ') }],
243
+ patch: true,
244
+ })
245
+ tagged++
246
+ }
247
+ return tagged
248
+ }
249
+
229
250
  return {
230
251
  async readIssue(id) {
231
252
  // $expand=relations cannot be combined with a fields list — Azure
@@ -356,6 +377,20 @@ function makeApiAdapter({ orgUrl, project, token, releaseType, fetch: fetchImpl,
356
377
  * what `states` validation checks the config against, and what an
357
378
  * unknown-state refusal lists.
358
379
  */
380
+ /**
381
+ * The allowed values of `fieldRef` on `workItemType`: `[]` for a field
382
+ * with no picklist (any value goes), null when the type has no such field.
383
+ */
384
+ async fieldAllowedValues(workItemType, fieldRef) {
385
+ const raw = await request(
386
+ 'GET',
387
+ `${projectBase}/wit/workitemtypes/${encodeURIComponent(workItemType)}/fields/${encodeURIComponent(fieldRef)}`,
388
+ { query: { $expand: 'allowedValues' }, allow404: true },
389
+ )
390
+ if (!raw) return null
391
+ return (raw.allowedValues || []).map(String)
392
+ },
393
+
359
394
  async listIssueStates(workItemType) {
360
395
  const raw = await request(
361
396
  'GET',
@@ -507,6 +542,11 @@ function makeApiAdapter({ orgUrl, project, token, releaseType, fetch: fetchImpl,
507
542
  * Attach each ticket to the release item as a Related link, commenting
508
543
  * once on each NEWLY attached ticket. An existing link counts as
509
544
  * `already`, which is what makes a CI retry additive rather than noisy.
545
+ *
546
+ * Then tag each ticket with the release's title (its tag), so the story
547
+ * card shows which release carried it. The tag is checked per ticket,
548
+ * independently of the link, so re-running `create` backfills a release
549
+ * cut before tagging existed — without a second comment.
510
550
  */
511
551
  async releaseAttach(release, tickets) {
512
552
  const raw = await request('GET', `${projectBase}/wit/workitems/${encodeURIComponent(release.id)}`, {
@@ -520,9 +560,11 @@ function makeApiAdapter({ orgUrl, project, token, releaseType, fetch: fetchImpl,
520
560
  )
521
561
  let attached = 0
522
562
  let already = 0
563
+ const ids = []
523
564
  for (const ticket of tickets || []) {
524
565
  const ticketId = String(ticket.ref || '').replace(/^AB#/, '')
525
566
  if (!/^\d+$/.test(ticketId)) continue
567
+ ids.push(ticketId)
526
568
  if (linked.has(ticketId)) {
527
569
  already++
528
570
  continue
@@ -538,17 +580,57 @@ function makeApiAdapter({ orgUrl, project, token, releaseType, fetch: fetchImpl,
538
580
  )
539
581
  attached++
540
582
  }
541
- return { attached, already }
583
+ if (!ticketTag) return { attached, already }
584
+ const tag = raw && raw.fields ? raw.fields['System.Title'] : null
585
+ const tagged = tag ? await tagTickets(ids, tag) : 0
586
+ return { attached, already, tagged }
542
587
  },
543
588
 
544
589
  /**
545
590
  * `deployed <env>`: the RELEASE ITEM's state moves to the env's configured
546
591
  * state — never each ticket's, which is the two-state-machines trap the
547
- * per-ticket mapping exists to avoid. `set` is therefore 1.
592
+ * per-ticket mapping exists to avoid.
593
+ *
594
+ * With `deployedField` set, each attached ticket's field takes the same
595
+ * value, so a story card shows where its release is. The value is checked
596
+ * against every ticket type's allowed values BEFORE anything is written,
597
+ * the release move included: an unknown value or a type without the field
598
+ * refuses with nothing changed. Phase Tasks are never reached — the
599
+ * tickets are the spec items `Refs:` names. `set` is 1 + tickets changed.
548
600
  */
549
- async releaseStage(release, stateName) {
601
+ async releaseStage(release, stateName, tickets) {
602
+ const ids = (tickets || [])
603
+ .map((t) => String(t.ref || '').replace(/^AB#/, ''))
604
+ .filter((id) => /^\d+$/.test(id))
605
+ let pending = []
606
+ if (deployedField && ids.length) {
607
+ const raw = await request('POST', `${projectBase}/wit/workitemsbatch`, {
608
+ body: { ids: ids.map(Number), fields: ['System.WorkItemType', deployedField] },
609
+ })
610
+ const items = (raw && raw.value) || []
611
+ const types = [...new Set(items.map((i) => (i.fields || {})['System.WorkItemType']).filter(Boolean))]
612
+ for (const type of types) {
613
+ const allowed = await this.fieldAllowedValues(type, deployedField)
614
+ if (allowed == null) {
615
+ throw new AzureRefusal(`the "${type}" type has no field "${deployedField}" (releases.deployedField) — nothing written`, { status: null })
616
+ }
617
+ if (allowed.length && !allowed.includes(stateName)) {
618
+ throw new AzureRefusal(
619
+ `"${stateName}" is not an allowed value of ${deployedField} on "${type}" (allows: ${allowed.map((v) => `"${v}"`).join(', ')}) — nothing written`,
620
+ { status: null },
621
+ )
622
+ }
623
+ }
624
+ pending = items.filter((i) => (i.fields || {})[deployedField] !== stateName).map((i) => String(i.id))
625
+ }
550
626
  await this.transitionTo(release.id, stateName)
551
- return { set: 1 }
627
+ for (const id of pending) {
628
+ await request('PATCH', `${projectBase}/wit/workitems/${encodeURIComponent(id)}`, {
629
+ body: [{ op: 'add', path: `/fields/${deployedField}`, value: stateName }],
630
+ patch: true,
631
+ })
632
+ }
633
+ return { set: 1 + pending.length }
552
634
  },
553
635
 
554
636
  /**
@@ -258,6 +258,8 @@ function apiAdapterFor(config, flags) {
258
258
  project: config.azure.project,
259
259
  token: cred.token,
260
260
  releaseType: (config.releases && config.releases.workItemType) || 'Release',
261
+ ticketTag: !config.releases || config.releases.ticketTag !== false,
262
+ deployedField: (config.releases && config.releases.deployedField) || '',
261
263
  fetch: flags.fetch,
262
264
  }),
263
265
  }
@@ -101,8 +101,12 @@ const DEFAULT_CONFIG = Object.freeze({
101
101
  // The release seam's Azure carrier (spec Decision 12): one work item of
102
102
  // `workItemType` per release, found by WIQL title lookup, its state moved
103
103
  // through `series[].envs`. Phase 5 implements the verbs; the config shape
104
- // lives here so setup writes one file.
105
- releases: Object.freeze({ workItemType: 'Release', series: Object.freeze([]) }),
104
+ // lives here so setup writes one file. `ticketTag` tags each attached ticket
105
+ // with the release tag, so a story card shows which release carried it.
106
+ // `deployedField` is a field reference (e.g. `Custom.Deployed`) that
107
+ // `deployed <env>` sets on each attached ticket to the env's value; empty
108
+ // writes none, since the field has to be added to the process first.
109
+ releases: Object.freeze({ workItemType: 'Release', series: Object.freeze([]), ticketTag: true, deployedField: '' }),
106
110
  branch: Object.freeze({ pattern: '{type}/{slug}' }),
107
111
  // An env-var NAME, not a value — the official CLI's, so a machine already
108
112
  // set up for `az boards` needs nothing new.
@@ -158,6 +162,8 @@ function defaults() {
158
162
  releases: {
159
163
  workItemType: DEFAULT_CONFIG.releases.workItemType,
160
164
  series: DEFAULT_CONFIG.releases.series.map((s) => ({ ...s })),
165
+ ticketTag: DEFAULT_CONFIG.releases.ticketTag,
166
+ deployedField: DEFAULT_CONFIG.releases.deployedField,
161
167
  },
162
168
  branch: { ...DEFAULT_CONFIG.branch },
163
169
  auth: { ...DEFAULT_CONFIG.auth },
@@ -267,6 +273,8 @@ function mergeConfig(base, parsed) {
267
273
 
268
274
  if (isObject(parsed.releases)) {
269
275
  assign(base.releases, parsed.releases, 'workItemType', 'string')
276
+ assign(base.releases, parsed.releases, 'ticketTag', 'boolean')
277
+ assign(base.releases, parsed.releases, 'deployedField', 'string?')
270
278
  mergeReleaseSeries(base.releases, parsed.releases)
271
279
  }
272
280
 
@@ -125,6 +125,59 @@ function composeBody({ notes, tickets, links, stage, describe }) {
125
125
  return withStage(parts.join('\n\n'), stage)
126
126
  }
127
127
 
128
+ /**
129
+ * Parse an `x.y.z[-suffix]` version for ordering. A bare version outranks a
130
+ * suffixed one at the same triplet (so `1.0.0` > `1.0.0-stage`), which is all
131
+ * the precedence these tags need: the release workflow validates them to
132
+ * `x.y.z`, and suffixes only appear on registry placeholders.
133
+ */
134
+ function parseVersion(v) {
135
+ const m = /^(\d+)\.(\d+)\.(\d+)(?:[-+].*)?$/.exec(String(v || ''))
136
+ return m ? { n: [Number(m[1]), Number(m[2]), Number(m[3])], bare: !/[-+]/.test(v) } : null
137
+ }
138
+
139
+ /** -1 / 0 / 1 over parseVersion; an unparseable version sorts below everything. */
140
+ function compareVersions(a, b) {
141
+ const pa = parseVersion(a)
142
+ const pb = parseVersion(b)
143
+ if (!pa || !pb) return (pa ? 1 : 0) - (pb ? 1 : 0)
144
+ for (let i = 0; i < 3; i++) {
145
+ if (pa.n[i] !== pb.n[i]) return pa.n[i] < pb.n[i] ? -1 : 1
146
+ }
147
+ if (pa.bare !== pb.bare) return pa.bare ? 1 : -1
148
+ return 0
149
+ }
150
+
151
+ /**
152
+ * The versions of `name` that are live on the npm registry, as a Set.
153
+ *
154
+ * ABSENCE IS NOT FAILURE, in either direction. A version missing from the set
155
+ * means "not published yet" — the registry is eventually consistent, so a
156
+ * just-approved version can be minutes away. A 404 on the whole package means
157
+ * "unpublished, private, or too new", three states this unauthenticated read
158
+ * cannot tell apart — so the caller treats every `ok: false` as a cannot-tell
159
+ * and moves nothing (`.claude/rules/negative-checks.md` rule 4).
160
+ */
161
+ async function npmLiveVersions(name, fetchImpl) {
162
+ const url = `https://registry.npmjs.org/${encodeURIComponent(String(name))}`
163
+ let res
164
+ try {
165
+ res = await fetchImpl(url, { headers: { accept: 'application/json' } })
166
+ } catch (error) {
167
+ return { ok: false, reason: `registry unreachable (${String(error.message).split('\n')[0]})` }
168
+ }
169
+ if (res.status === 404) return { ok: false, reason: 'not on the public registry (unpublished, private, or not settled yet)' }
170
+ if (!res.ok) return { ok: false, reason: `registry answered ${res.status}` }
171
+ let doc
172
+ try {
173
+ doc = await res.json()
174
+ } catch {
175
+ return { ok: false, reason: 'unreadable registry answer' }
176
+ }
177
+ const versions = doc && doc.versions && typeof doc.versions === 'object' ? Object.keys(doc.versions) : []
178
+ return { ok: true, versions: new Set(versions) }
179
+ }
180
+
128
181
  // `--link <url>[=label]`, repeatable. http(s) only: this lands in a body a
129
182
  // tracker renders as a link, and a `javascript:` url there is script.
130
183
  function parseLinks(raw) {
@@ -288,7 +341,10 @@ function makeReleaseCommands(p) {
288
341
  header.push(` unchanged: ${release.url || release.id}`)
289
342
  }
290
343
  const attached = await adapter.releaseAttach(release, t.attach)
291
- header.push(` issues: ${attached.attached} noted, ${attached.already} already noted`)
344
+ header.push(
345
+ ` issues: ${attached.attached} noted, ${attached.already} already noted` +
346
+ (attached.tagged != null ? `, ${attached.tagged} tagged` : ''),
347
+ )
292
348
  return emit(out, flags, header, { tag, range: t.range.range, attach: t.attach.map((x) => x.ref), apply: true, url: release.url || null })
293
349
  }
294
350
 
@@ -337,6 +393,163 @@ function makeReleaseCommands(p) {
337
393
  return emit(out, flags, lines, { tag, apply: true })
338
394
  }
339
395
 
396
+ /**
397
+ * `reconcile` — move every marked release whose version is live on npm (or
398
+ * contained in a newer live version of its series) to the series' final env,
399
+ * then complete it. The self-healing half of the mirror: approvals that
400
+ * happen outside `release deployed` — the npm website, a missed CI run — are
401
+ * caught here on the next run. Dry by default, like every other verb.
402
+ *
403
+ * Only releases carrying the skitterspec stage marker are considered, so a
404
+ * hand-made release is never read or written. A release already at the final
405
+ * env owes nothing and is skipped in silence.
406
+ */
407
+ async function reconcile(dir, config, flags, out) {
408
+ const series = p.series(config)
409
+ if (!series.length) return refuse(out, `no releases.series configured — add one to the ${p.tracker} config`)
410
+ if (p.impossibleOverMcp) {
411
+ const why = p.impossibleOverMcp(config, flags)
412
+ if (why) return refuse(out, why)
413
+ }
414
+ const got = p.adapterFor(config, flags)
415
+ if (!got.ok) return refuse(out, got.error)
416
+ const adapter = got.adapter
417
+ const missing = [...REQUIRED_OPS, 'releaseList'].filter((op) => typeof adapter[op] !== 'function')
418
+ if (missing.length) return refuse(out, `the ${p.tracker} provider has no reconcile support (${missing.join(', ')})`)
419
+
420
+ let all
421
+ try {
422
+ all = await adapter.releaseList()
423
+ } catch (error) {
424
+ // A listing that failed is a cannot-tell about every release at once:
425
+ // refuse loudly (a scheduled run should go red) and write nothing.
426
+ return refuse(out, `could not list releases (${String(error.message).split('\n')[0]}) — nothing reconciled`)
427
+ }
428
+ const marked = all.filter((r) => stageOf(r.body) != null)
429
+
430
+ const git = gitReader(dir)
431
+ // Same refusal as `create`: `describe` in a shallow clone finds no previous
432
+ // tag and a range silently becomes "everything".
433
+ if (git(['rev-parse', '--is-shallow-repository']) === 'true') {
434
+ return refuse(out, 'this clone is shallow, so tag ranges cannot be resolved — check out with fetch-depth: 0')
435
+ }
436
+ const existingTags = new Set(all.map((r) => r.tag))
437
+
438
+ const fetchImpl = flags.fetch || p.fetch || globalThis.fetch
439
+ const lines = [`${prog} reconcile:${flags.apply ? '' : ' (dry run — pass --apply to write)'}`]
440
+ const result = { apply: !!flags.apply, releases: [] }
441
+ const note = (tag, action, reason) => {
442
+ lines.push(` ${tag}: ${action}${reason ? ` — ${reason}` : ''}`)
443
+ result.releases.push({ tag, action, ...(reason ? { reason } : {}) })
444
+ }
445
+
446
+ for (const s of series) {
447
+ const envKeys = Object.keys(s.envs || {})
448
+ const firstEnv = envKeys[0]
449
+ const finalEnv = envKeys[envKeys.length - 1]
450
+ const mine = marked.filter((r) => seriesFor(series, r.tag) === s)
451
+ const tailOf = (tag) => tag.slice(s.tagPrefix.length)
452
+
453
+ // Backfill: pushed tags with NO release at all — the batched-push case,
454
+ // where no workflow ran. Bounded so history never floods the releases
455
+ // page: only tags newer than the series' newest marked release, and the
456
+ // newest tag alone where the series has none — OLDER UNMIRRORED TAGS ARE
457
+ // DELIBERATELY LEFT AS HISTORY. A tag whose release exists but carries
458
+ // no marker is hand-made, so `existingTags` (not `mine`) excludes it.
459
+ const newestKnown = mine.map((r) => tailOf(r.tag)).sort(compareVersions).pop() || null
460
+ let missing = (git(['tag', '--list', `${s.tagPrefix}*`]) || '')
461
+ .split('\n')
462
+ .filter((t) => t && !existingTags.has(t))
463
+ .sort((a, b) => compareVersions(tailOf(a), tailOf(b)))
464
+ missing = newestKnown ? missing.filter((t) => compareVersions(tailOf(t), newestKnown) > 0) : missing.slice(-1)
465
+
466
+ const open = [
467
+ ...mine.filter((r) => stageOf(r.body) !== finalEnv).map((r) => ({ tag: r.tag, release: r })),
468
+ ...missing.map((tag) => ({ tag, release: null })),
469
+ ].sort((a, b) => compareVersions(tailOf(a.tag), tailOf(b.tag)))
470
+ if (!finalEnv || !open.length) continue
471
+ if (!s.npm) {
472
+ note(`${s.tagPrefix}*`, 'skipped', `${open.length} release(s) owe a move or a backfill, but the series has no "npm" name to probe`)
473
+ continue
474
+ }
475
+ const live = await npmLiveVersions(s.npm, fetchImpl)
476
+ if (!live.ok) {
477
+ // Cannot tell is not "not published": keep every release where it is.
478
+ note(`${s.tagPrefix}*`, 'skipped', `npm ${s.npm}: ${live.reason}`)
479
+ continue
480
+ }
481
+ const newestLive = [...live.versions].sort(compareVersions).pop() || null
482
+ // A release already at the final env bounds `make_latest`: a reconciled
483
+ // older version must never steal Latest from it.
484
+ const newestFinal = mine
485
+ .filter((r) => stageOf(r.body) === finalEnv)
486
+ .map((r) => tailOf(r.tag))
487
+ .sort(compareVersions)
488
+ .pop()
489
+ const movable = open.filter((entry) => {
490
+ const v = tailOf(entry.tag)
491
+ // Live itself, or contained: a NEWER live version in the same series
492
+ // carries this tag's commits, so its issues shipped.
493
+ return live.versions.has(v) || (newestLive && compareVersions(newestLive, v) > 0)
494
+ })
495
+ const latestTag = movable.length ? movable[movable.length - 1].tag : null
496
+ for (const entry of open) {
497
+ const v = tailOf(entry.tag)
498
+ const mov = movable.includes(entry)
499
+ const latest = mov && entry.tag === latestTag && (!newestFinal || compareVersions(v, newestFinal) > 0)
500
+ if (!flags.apply) {
501
+ if (!entry.release) note(entry.tag, mov ? `would create, move to ${finalEnv} and complete${latest ? ' (latest)' : ''}` : `would create at ${firstEnv}`, 'no release yet')
502
+ else if (!mov) note(entry.tag, 'kept', `not on npm yet (${s.npm})`)
503
+ else note(entry.tag, `would move to ${finalEnv} and complete${latest ? ' (latest)' : ''}`)
504
+ continue
505
+ }
506
+ if (entry.release && !mov) {
507
+ note(entry.tag, 'kept', `not on npm yet (${s.npm})`)
508
+ continue
509
+ }
510
+ const t = ticketsOf(dir, config, entry.tag, s)
511
+ if (!t.ok) {
512
+ note(entry.tag, 'skipped', t.error)
513
+ continue
514
+ }
515
+ let r = entry.release
516
+ let created = false
517
+ if (!r) {
518
+ // The same guard `create` carries: a tracker handed a tag it lacks
519
+ // CREATES it at the default branch's head. `false` refuses this tag;
520
+ // a throw is a cannot-tell and the create goes ahead.
521
+ if (adapter.releaseTagExists) {
522
+ let exists = null
523
+ try {
524
+ exists = await adapter.releaseTagExists(entry.tag)
525
+ } catch {
526
+ exists = null
527
+ }
528
+ if (exists === false) {
529
+ note(entry.tag, 'skipped', `not on the ${p.tracker} remote yet — push the tag first`)
530
+ continue
531
+ }
532
+ }
533
+ const body = composeBody({ notes: null, tickets: await describeAll(adapter, t.attach), links: [], stage: firstEnv, describe: p.describe })
534
+ r = await adapter.releaseCreate({ tag: entry.tag, name: entry.tag, body, prerelease: true })
535
+ await adapter.releaseAttach(r, t.attach)
536
+ await adapter.releaseStage(r, s.envs[firstEnv], t.attach)
537
+ created = true
538
+ if (!mov) {
539
+ note(entry.tag, `created at ${firstEnv}`, `${t.attach.length} issue(s)`)
540
+ continue
541
+ }
542
+ }
543
+ await adapter.releaseStage(r, s.envs[finalEnv], t.attach)
544
+ await adapter.releaseUpdate(r, { name: entry.tag, body: withStage(r.body, finalEnv) })
545
+ await adapter.releaseComplete(r, { latest })
546
+ note(entry.tag, `${created ? 'created, ' : ''}moved to ${finalEnv} and completed${latest ? ' (latest)' : ''}`, `${t.attach.length} issue(s)`)
547
+ }
548
+ }
549
+ if (lines.length === 1) lines.push(' nothing to reconcile')
550
+ return emit(out, flags, lines, result)
551
+ }
552
+
340
553
  // Titles for the body, best-effort: a ticket the tracker cannot read is
341
554
  // still listed, by ref. The body is information, not a gate.
342
555
  async function describeAll(adapter, tickets) {
@@ -366,15 +579,17 @@ function makeReleaseCommands(p) {
366
579
  if (verb === 'create') return create(dir, config, tag, flags, out)
367
580
  if (verb === 'deployed') return deployed(dir, config, tag, env, flags, out)
368
581
  if (verb === 'complete') return complete(dir, config, tag, flags, out)
582
+ if (verb === 'reconcile') return reconcile(dir, config, flags, out)
369
583
  out.write(
370
584
  `Usage: ${prog} create <tag> [--notes <f>] [--link <url>[=label]] [--stage <env>] [--apply] [--json]\n` +
371
585
  ` ${prog} deployed <tag> <env> [--apply] [--json]\n` +
372
- ` ${prog} complete <tag> [--apply] [--json]\n`,
586
+ ` ${prog} complete <tag> [--apply] [--json]\n` +
587
+ ` ${prog} reconcile [--apply] [--json]\n`,
373
588
  )
374
589
  return verb ? 1 : 0
375
590
  }
376
591
 
377
- return { run, create, deployed, complete }
592
+ return { run, create, deployed, complete, reconcile }
378
593
  }
379
594
 
380
- module.exports = { makeReleaseCommands, resolveRange, seriesFor, composeBody, stageOf, withStage, parseLinks, REQUIRED_OPS }
595
+ module.exports = { makeReleaseCommands, resolveRange, seriesFor, composeBody, stageOf, withStage, parseLinks, parseVersion, compareVersions, npmLiveVersions, REQUIRED_OPS }