@skitterbyte/skitterspec-azure-boards 1.3.0 → 2.1.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.
Files changed (33) hide show
  1. package/MIGRATION.md +170 -1
  2. package/README.md +8 -7
  3. package/assets/core/SETUP.md +8 -45
  4. package/assets/core/azure-boards.config.json.example +1 -0
  5. package/assets/core/azure-boards.config.md +55 -7
  6. package/assets/core/env.config.md +1 -1
  7. package/assets/rules/spec-planning.md +35 -12
  8. package/assets/rules/spec-reports.md +28 -2
  9. package/assets/skills/no-spec/SKILL.md +2 -2
  10. package/assets/skills/spec/SKILL.md +31 -8
  11. package/assets/skills/spec-azure-setup/SKILL.md +5 -1
  12. package/assets/skills/spec-bug/SKILL.md +2 -2
  13. package/assets/skills/spec-list/SKILL.md +28 -5
  14. package/assets/skills/spec-next/SKILL.md +2 -2
  15. package/assets/skills/spec-status/SKILL.md +28 -26
  16. package/assets/skills/spec-sync/SKILL.md +11 -14
  17. package/package.json +1 -1
  18. package/src/cli.js +108 -3
  19. package/src/env/resolve.js +11 -4
  20. package/src/env/review.js +79 -0
  21. package/src/vendor/azure-boards/api.js +77 -192
  22. package/src/vendor/azure-boards/cli-sync.js +114 -72
  23. package/src/vendor/azure-boards/config.js +60 -67
  24. package/src/vendor/azure-boards/mcp.js +14 -3
  25. package/src/vendor/provider-kit/src/config.js +101 -48
  26. package/src/vendor/provider-kit/src/list-assignee.js +71 -0
  27. package/src/vendor/provider-kit/src/list-rows.js +35 -0
  28. package/src/vendor/provider-kit/src/released.js +27 -77
  29. package/src/vendor/provider-kit/src/specs.js +89 -7
  30. package/src/vendor/sync-core/index.js +3 -4
  31. package/src/vendor/sync-core/src/compare.js +6 -6
  32. package/src/vendor/sync-core/src/normalize.js +60 -59
  33. package/src/vendor/provider-kit/src/releases.js +0 -595
@@ -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, ticketTag = true, deployedField = '', fetch: fetchImpl, sleep, maxRetries = MAX_RETRIES }) {
71
+ function makeApiAdapter({ orgUrl, project, token, fetch: fetchImpl, sleep, maxRetries = MAX_RETRIES, bodyFieldByType = {} }) {
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')
@@ -151,6 +151,19 @@ function makeApiAdapter({ orgUrl, project, token, releaseType, ticketTag = true,
151
151
  return m ? m[1] : null
152
152
  }
153
153
 
154
+ // The field a TYPE's body lives in (`azure.bodyFieldByType`), falling back
155
+ // to System.Description. On an Agile/Scrum/CMMI Bug form the Description
156
+ // field is not shown — the body belongs in Repro Steps — so the field is
157
+ // resolved per type and used symmetrically on write AND read: a write-only
158
+ // mapping would make every pushed Bug read back as edited. Type names
159
+ // compare case-insensitively, matching how humans copy them off the form.
160
+ const bodyFields = Object.entries(bodyFieldByType || {}).map(([t, f]) => [String(t).toLowerCase(), f])
161
+ function bodyFieldFor(workItemType) {
162
+ const want = String(workItemType || '').toLowerCase()
163
+ const hit = bodyFields.find(([t]) => t === want)
164
+ return hit ? hit[1] : 'System.Description'
165
+ }
166
+
154
167
  // Text at the boundary: a markdown-format description is entity-DECODED —
155
168
  // Azure encodes stray HTML specials on store (`>` → `>`, `"` → `"`,
156
169
  // observed live), so the decode is the inverse of the store, and what comes
@@ -158,10 +171,21 @@ function makeApiAdapter({ orgUrl, project, token, releaseType, ticketTag = true,
158
171
  // format map is the positive signal that decides — the tag sniff only covers
159
172
  // items too old to carry one.
160
173
  function descriptionText(raw) {
161
- const d = raw.fields && raw.fields['System.Description']
174
+ const field = bodyFieldFor(raw.fields && raw.fields['System.WorkItemType'])
175
+ let d = raw.fields && raw.fields[field]
176
+ let read = field
177
+ // A MAPPED FIELD THAT IS EMPTY FALLS BACK TO System.Description,
178
+ // deliberately: an item minted before the mapping holds its body there,
179
+ // and reading null would accuse it of an edit it never had. The blind
180
+ // spot: a Repro Steps someone deliberately CLEARED in Boards reads as the
181
+ // stale Description until the next push rewrites it.
182
+ if ((d == null || d === '') && field !== 'System.Description') {
183
+ d = raw.fields && raw.fields['System.Description']
184
+ read = 'System.Description'
185
+ }
162
186
  if (d == null) return null
163
187
  const text = String(d)
164
- const fmt = raw.multilineFieldsFormat && raw.multilineFieldsFormat['System.Description']
188
+ const fmt = raw.multilineFieldsFormat && raw.multilineFieldsFormat[read]
165
189
  if (fmt && String(fmt).toLowerCase() === 'markdown') return decodeEntities(text)
166
190
  return looksLikeHtml(text) ? htmlToText(text) : text
167
191
  }
@@ -198,16 +222,16 @@ function makeApiAdapter({ orgUrl, project, token, releaseType, ticketTag = true,
198
222
  * become ops — `undefined` means "say nothing". A null description clears
199
223
  * the field; a null assignee unassigns (Azure clears on empty string).
200
224
  */
201
- function itemPatch(input) {
225
+ function itemPatch(input, bodyField = 'System.Description') {
202
226
  const ops = []
203
227
  const add = (path, value) => ops.push({ op: 'add', path, value })
204
228
  if (input.title !== undefined) add('/fields/System.Title', input.title)
205
229
  if (input.description !== undefined) {
206
- add('/fields/System.Description', input.description == null ? '' : input.description)
230
+ add(`/fields/${bodyField}`, input.description == null ? '' : input.description)
207
231
  // The write format, declared beside the field. One-way by Azure's rule —
208
232
  // a field saved as markdown cannot revert to HTML — which is fine: this
209
233
  // provider never writes HTML.
210
- add('/multilineFieldsFormat/System.Description', 'Markdown')
234
+ add(`/multilineFieldsFormat/${bodyField}`, 'Markdown')
211
235
  }
212
236
  if (input.assigneeId !== undefined) {
213
237
  add('/fields/System.AssignedTo', input.assigneeId == null ? '' : input.assigneeId)
@@ -275,14 +299,14 @@ function makeApiAdapter({ orgUrl, project, token, releaseType, ticketTag = true,
275
299
  const created = await request(
276
300
  'POST',
277
301
  `${projectBase}/wit/workitems/$${encodeURIComponent(workItemType)}`,
278
- { body: itemPatch({ title, description, assigneeId, areaPath }), patch: true },
302
+ { body: itemPatch({ title, description, assigneeId, areaPath }, bodyFieldFor(workItemType)), patch: true },
279
303
  )
280
304
  if (!created || created.id == null) throw new Error('Azure DevOps returned no work item for the create')
281
305
  return { id: String(created.id), identifier: identifierOf(created.id), url: urlOf(created.id) }
282
306
  },
283
307
 
284
308
  async createSubIssue(parentId, { title, description, childType, areaPath }) {
285
- const ops = itemPatch({ title, description, areaPath })
309
+ const ops = itemPatch({ title, description, areaPath }, bodyFieldFor(childType))
286
310
  ops.push({
287
311
  op: 'add',
288
312
  path: '/relations/-',
@@ -298,7 +322,18 @@ function makeApiAdapter({ orgUrl, project, token, releaseType, ticketTag = true,
298
322
  },
299
323
 
300
324
  async updateIssue(id, updates) {
301
- const ops = itemPatch(updates)
325
+ // An update does not know the item's type, and the body field hangs off
326
+ // it — so when a description is being written AND a mapping exists, one
327
+ // field read answers it. With no mapping the read is skipped and the
328
+ // patch is byte-identical to before.
329
+ let bodyField = 'System.Description'
330
+ if (updates.description !== undefined && bodyFields.length) {
331
+ const raw = await request('GET', `${projectBase}/wit/workitems/${encodeURIComponent(numId(id))}`, {
332
+ query: { fields: 'System.WorkItemType' },
333
+ })
334
+ bodyField = bodyFieldFor(raw && raw.fields && raw.fields['System.WorkItemType'])
335
+ }
336
+ const ops = itemPatch(updates, bodyField)
302
337
  if (!ops.length) return {}
303
338
  return request('PATCH', `${projectBase}/wit/workitems/${encodeURIComponent(numId(id))}`, {
304
339
  body: ops,
@@ -350,25 +385,38 @@ function makeApiAdapter({ orgUrl, project, token, releaseType, ticketTag = true,
350
385
  * matches `readIssue`'s essentials (the twin-mint guard needs identifier +
351
386
  * title).
352
387
  */
353
- async searchIssues({ query, workItemType, limit = 50 }) {
388
+ // `assignedTo` is the uniqueName/email `whoami` and `users` return — the
389
+ // value `System.AssignedTo` itself accepts, so WIQL matches it directly.
390
+ //
391
+ // `states` limits to those state names; `orderBy` is a field reference to
392
+ // sort by, ascending — `list --next` passes the backlog's rank field, and
393
+ // WIQL returns ids in that order, which `batchRead` is then made to keep.
394
+ async searchIssues({ query, workItemType, assignedTo = null, states = null, orderBy = null, limit = 50 }) {
395
+ const q = (v) => `'${String(v).replace(/'/g, "''")}'`
354
396
  const quoted = String(query || '').replace(/'/g, "''")
355
397
  const clauses = [
356
398
  '[System.TeamProject] = @project',
357
- workItemType ? `[System.WorkItemType] = '${String(workItemType).replace(/'/g, "''")}'` : null,
399
+ workItemType ? `[System.WorkItemType] = ${q(workItemType)}` : null,
358
400
  quoted ? `[System.Title] CONTAINS '${quoted}'` : null,
401
+ assignedTo ? `[System.AssignedTo] = ${q(assignedTo)}` : null,
402
+ states && states.length ? `[System.State] IN (${states.map(q).join(', ')})` : null,
359
403
  ].filter(Boolean)
404
+ const order = orderBy && /^[A-Za-z0-9_.]+$/.test(orderBy) ? ` ORDER BY [${orderBy}] ASC` : ''
360
405
  const raw = await request('POST', `${projectBase}/wit/wiql`, {
361
406
  query: { $top: limit },
362
- body: { query: `SELECT [System.Id] FROM WorkItems WHERE ${clauses.join(' AND ')}` },
407
+ body: { query: `SELECT [System.Id] FROM WorkItems WHERE ${clauses.join(' AND ')}${order}` },
363
408
  })
364
409
  const ids = ((raw && raw.workItems) || []).map((w) => String(w.id))
365
- const items = await batchRead(ids, ['System.Title', 'System.State', 'System.Parent', 'System.WorkItemType'])
410
+ const read = await batchRead(ids, ['System.Title', 'System.State', 'System.Parent', 'System.WorkItemType', 'System.AssignedTo'])
411
+ const byId = new Map(read.map((i) => [i.id, i]))
412
+ const items = ids.map((id) => byId.get(id)).filter(Boolean)
366
413
  return items.map((i) => ({
367
414
  id: i.id,
368
415
  identifier: i.identifier,
369
416
  title: i.title,
370
417
  state: i.state,
371
418
  parent: i.parent,
419
+ assignee: i.assignee,
372
420
  }))
373
421
  },
374
422
 
@@ -377,20 +425,6 @@ function makeApiAdapter({ orgUrl, project, token, releaseType, ticketTag = true,
377
425
  * what `states` validation checks the config against, and what an
378
426
  * unknown-state refusal lists.
379
427
  */
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
-
394
428
  async listIssueStates(workItemType) {
395
429
  const raw = await request(
396
430
  'GET',
@@ -405,6 +439,22 @@ function makeApiAdapter({ orgUrl, project, token, releaseType, ticketTag = true,
405
439
  }))
406
440
  },
407
441
 
442
+ /**
443
+ * The field reference names a work item type carries — what `doctor
444
+ * --check-remote` validates `azure.bodyFieldByType` against. `null` means
445
+ * the TYPE is not in the project (a 404), kept distinct from a type with
446
+ * an empty field list, which Azure does not produce.
447
+ */
448
+ async listTypeFields(workItemType) {
449
+ const raw = await request(
450
+ 'GET',
451
+ `${projectBase}/wit/workitemtypes/${encodeURIComponent(workItemType)}/fields`,
452
+ { allow404: true },
453
+ )
454
+ if (raw == null) return null
455
+ return ((raw && raw.value) || []).map((f) => f.referenceName).filter(Boolean)
456
+ },
457
+
408
458
  // The authenticated user, from connectionData — the one identity read
409
459
  // that needs no scope beyond the PAT being valid (phase 1 spike).
410
460
  // A PREVIEW resource: plain 7.1 is refused ("the -preview flag must be
@@ -485,171 +535,6 @@ function makeApiAdapter({ orgUrl, project, token, releaseType, ticketTag = true,
485
535
  })
486
536
  return raw && raw.id != null ? { id: String(raw.id) } : null
487
537
  },
488
-
489
- // --- releases (the kit's release seam, `provider-kit/src/releases.js`) ---
490
- // Boards has no Releases object, so the carrier is ONE WORK ITEM of
491
- // `releases.workItemType` per release (spec Decision 12): found by exact
492
- // title, tickets attached as Related links with one comment each,
493
- // `deployed` moving the ITEM's state, `complete` closing it.
494
-
495
- /**
496
- * The release work item for a tag, or null. Found by exact-title WIQL
497
- * under the configured type. TWO hits is a cannot-tell — someone minted a
498
- * twin by hand — and throws rather than picking one (the kit refuses on a
499
- * throw, which is the duplicate-safe branch).
500
- */
501
- async releaseFind(tag) {
502
- const quotedTag = String(tag).replace(/'/g, "''")
503
- const quotedType = String(releaseType || 'Release').replace(/'/g, "''")
504
- const raw = await request('POST', `${projectBase}/wit/wiql`, {
505
- body: {
506
- query:
507
- `SELECT [System.Id] FROM WorkItems WHERE [System.TeamProject] = @project ` +
508
- `AND [System.WorkItemType] = '${quotedType}' AND [System.Title] = '${quotedTag}'`,
509
- },
510
- })
511
- const ids = ((raw && raw.workItems) || []).map((w) => w.id)
512
- if (!ids.length) return null
513
- if (ids.length > 1) {
514
- throw new AzureRefusal(
515
- `${ids.length} "${releaseType || 'Release'}" items are titled "${tag}" (${ids.map(identifierOf).join(', ')}) — cannot tell which is the release`,
516
- { status: null },
517
- )
518
- }
519
- const item = await this.readIssue(ids[0])
520
- return item ? { id: item.id, url: item.url, body: item.description || '', state: item.state, type: item.type } : null
521
- },
522
-
523
- async releaseCreate({ tag, name, body }) {
524
- const created = await this.createIssue({
525
- title: name || tag,
526
- description: body,
527
- workItemType: releaseType || 'Release',
528
- })
529
- return { id: created.id, url: created.url, body: body || '' }
530
- },
531
-
532
- async releaseUpdate(release, { name, body }) {
533
- const updates = {}
534
- if (name != null) updates.title = name
535
- if (body !== undefined) updates.description = body
536
- if (Object.keys(updates).length) await this.updateIssue(release.id, updates)
537
- release.body = body !== undefined ? body : release.body
538
- return release
539
- },
540
-
541
- /**
542
- * Attach each ticket to the release item as a Related link, commenting
543
- * once on each NEWLY attached ticket. An existing link counts as
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.
550
- */
551
- async releaseAttach(release, tickets) {
552
- const raw = await request('GET', `${projectBase}/wit/workitems/${encodeURIComponent(release.id)}`, {
553
- query: { $expand: 'relations' },
554
- })
555
- const linked = new Set(
556
- ((raw && raw.relations) || [])
557
- .filter((r) => r && r.rel === 'System.LinkTypes.Related')
558
- .map((r) => idFromRelationUrl(r.url))
559
- .filter(Boolean),
560
- )
561
- let attached = 0
562
- let already = 0
563
- const ids = []
564
- for (const ticket of tickets || []) {
565
- const ticketId = String(ticket.ref || '').replace(/^AB#/, '')
566
- if (!/^\d+$/.test(ticketId)) continue
567
- ids.push(ticketId)
568
- if (linked.has(ticketId)) {
569
- already++
570
- continue
571
- }
572
- await request('PATCH', `${projectBase}/wit/workitems/${encodeURIComponent(release.id)}`, {
573
- body: [{ op: 'add', path: '/relations/-', value: { rel: 'System.LinkTypes.Related', url: itemApiUrl(ticketId) } }],
574
- patch: true,
575
- })
576
- await this.createComment(
577
- ticketId,
578
- `Included in release **${raw && raw.fields ? raw.fields['System.Title'] : release.id}**` +
579
- (release.url ? ` — ${release.url}` : ''),
580
- )
581
- attached++
582
- }
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 }
587
- },
588
-
589
- /**
590
- * `deployed <env>`: the RELEASE ITEM's state moves to the env's configured
591
- * state — never each ticket's, which is the two-state-machines trap the
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.
600
- */
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
- }
626
- await this.transitionTo(release.id, stateName)
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 }
634
- },
635
-
636
- /**
637
- * Close the release item: the type's own Completed-category state, read at
638
- * run time because a release type's workflow is process-defined like every
639
- * other. No Completed state is a named refusal, never a guess.
640
- */
641
- async releaseComplete(release) {
642
- const states = await this.listIssueStates(release.type || releaseType || 'Release')
643
- const done = states.find((s) => s.category === 'Completed')
644
- if (!done) {
645
- throw new AzureRefusal(
646
- `the "${release.type || releaseType || 'Release'}" type has no Completed-category state (has: ${states.map((s) => `"${s.name}"`).join(', ') || 'none'})`,
647
- { status: null },
648
- )
649
- }
650
- await this.transitionTo(release.id, done.name)
651
- return release
652
- },
653
538
  }
654
539
  }
655
540