@skitterbyte/skitterspec-azure-boards 3.1.2 → 3.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.
Files changed (41) hide show
  1. package/assets/claude-md-section.md +4 -0
  2. package/assets/core/azure-boards.config.md +2 -1
  3. package/assets/core/env.config.json.example +5 -0
  4. package/assets/core/env.config.md +20 -1
  5. package/assets/hooks/run-compact.cjs +162 -0
  6. package/assets/review/page.html +122 -2
  7. package/assets/rules/spec-format.md +6 -0
  8. package/assets/rules/spec-planning.md +9 -0
  9. package/assets/rules/spec-reports.md +5 -0
  10. package/assets/skills/spec/SKILL.md +25 -1
  11. package/assets/skills/spec-bug/SKILL.md +14 -0
  12. package/assets/skills/spec-complete/SKILL.md +9 -0
  13. package/assets/skills/spec-diff/SKILL.md +24 -0
  14. package/assets/skills/spec-hotfix/SKILL.md +14 -0
  15. package/assets/skills/spec-idea/SKILL.md +6 -0
  16. package/assets/skills/spec-next/SKILL.md +18 -1
  17. package/assets/skills/spec-next/autonomous.md +126 -0
  18. package/assets/skills/spec-reviewed/SKILL.md +2 -1
  19. package/assets/skills/spec-start/SKILL.md +8 -0
  20. package/assets/skills/spec-start/isolation.md +1 -1
  21. package/bin/skitterspec-azure-boards.js +5 -18
  22. package/package.json +1 -1
  23. package/src/cli.js +267 -2
  24. package/src/env/config.js +18 -0
  25. package/src/env/hooks.js +44 -20
  26. package/src/env/report.js +192 -0
  27. package/src/env/resolve.js +6 -1
  28. package/src/env/review.js +14 -2
  29. package/src/env/run.js +226 -0
  30. package/src/env/runpage.js +229 -0
  31. package/src/env/serve.js +47 -4
  32. package/src/ideacmd.js +5 -2
  33. package/src/provider.js +92 -0
  34. package/src/vendor/azure-boards/api.js +13 -0
  35. package/src/vendor/azure-boards/cli-sync.js +109 -11
  36. package/src/vendor/azure-boards/config.js +47 -2
  37. package/src/vendor/azure-boards/register.js +29 -0
  38. package/src/vendor/provider-kit/src/apply.js +3 -0
  39. package/src/vendor/sync-core/src/compare.js +32 -1
  40. package/src/vendor/sync-core/src/normalize.js +3 -2
  41. package/src/vendor/sync-core/src/push.js +29 -1
@@ -66,6 +66,7 @@ const {
66
66
  specKindOf,
67
67
  mintTypeFor,
68
68
  stateNameFor,
69
+ productArea,
69
70
  } = require('./config.js')
70
71
  const {
71
72
  resolveCredential,
@@ -349,7 +350,7 @@ function applyOps({ adapter, config, out, kind = 'feature', snapshotDir = null }
349
350
  description: issue && issue.description != null ? issue.description : undefined,
350
351
  assigneeId: issue && issue.assignee ? issue.assignee : undefined,
351
352
  workItemType: mintType,
352
- areaPath: config.azure.areaPath || undefined,
353
+ areaPath: (issue && issue.placement) || config.azure.areaPath || undefined,
353
354
  severity: severity != null ? severity : undefined,
354
355
  },
355
356
  (input) => skippingRefusedSeverity(input, (i) => adapter.createIssue(i)),
@@ -365,6 +366,7 @@ function applyOps({ adapter, config, out, kind = 'feature', snapshotDir = null }
365
366
  // forwarded whenever the plan carries it, never truthiness-tested.
366
367
  if ('assignee' in issue) updates.assigneeId = issue.assignee ?? null
367
368
  if (severity != null) updates.severity = severity
369
+ if (issue.placement) updates.areaPath = issue.placement
368
370
  if (Object.keys(updates).length) {
369
371
  await skippingRefusedAssignee(updates, (input) =>
370
372
  skippingRefusedSeverity(input, (i) => adapter.updateIssue(apiId(existing.identifier), i)),
@@ -378,7 +380,7 @@ function applyOps({ adapter, config, out, kind = 'feature', snapshotDir = null }
378
380
  title: sub.name,
379
381
  description: sub.goal != null ? sub.goal : undefined,
380
382
  childType: config.azure.childType,
381
- areaPath: config.azure.areaPath || undefined,
383
+ areaPath: sub.placement || config.azure.areaPath || undefined,
382
384
  })
383
385
  await settle(created.id, sub.state, config.azure.childType)
384
386
  return created
@@ -387,15 +389,38 @@ function applyOps({ adapter, config, out, kind = 'feature', snapshotDir = null }
387
389
  const updates = {}
388
390
  if (sub.name != null) updates.title = sub.name
389
391
  if (sub.goal != null) updates.description = sub.goal
392
+ if (sub.placement) updates.areaPath = sub.placement
390
393
  if (Object.keys(updates).length) await adapter.updateIssue(apiId(sub.id), updates)
391
394
  await settle(sub.id, sub.state, config.azure.childType, sub.stateResend)
392
395
  },
393
396
  }
394
397
  }
395
398
 
399
+ // `products` — what a spec's `> **Product:**` may name, read by /spec to know
400
+ // whether to ask, and the area each files into. `default` is where a spec
401
+ // without the header goes once any product is set (null: nothing is placed).
402
+ function specSyncProducts(config, flags, out) {
403
+ const products = Object.entries(config.azure.products || {}).map(([key, p]) => ({ key, areaPath: p.areaPath }))
404
+ const fallback = products.length ? config.azure.areaPath || null : null
405
+ if (flags.json) {
406
+ out.write(JSON.stringify({ products, default: fallback }, null, 2) + '\n')
407
+ return 0
408
+ }
409
+ if (!products.length) {
410
+ out.write(`${PROGRAM} products: none — azure.products is not set, so specs are filed as before\n`)
411
+ return 0
412
+ }
413
+ const lines = [`${PROGRAM} products:`]
414
+ for (const p of products) lines.push(` ${p.key.padEnd(16)} ${p.areaPath}`)
415
+ lines.push(` ${'(no header)'.padEnd(16)} ${fallback || 'the project default area'}`)
416
+ out.write(lines.join('\n') + '\n')
417
+ return 0
418
+ }
419
+
396
420
  // `idea add|list|drop` — the store `skitterspec idea` hands Azure Boards: a
397
421
  // work item of `azure.workItemType` tagged `intake.ideaTag`, created with NO
398
- // area path, so it lands at the project root and out of the spec area. `/spec
422
+ // area path, so it lands at the project root and out of the spec area —
423
+ // unless `--product` names one, which files it in that product's area. `/spec
399
424
  // <id>` adopts one like any other item, which is why an adopted one drops out
400
425
  // of `list`.
401
426
  //
@@ -419,6 +444,17 @@ async function specSyncIdea(dir, config, positional, flags, out) {
419
444
  return verb ? 1 : 0
420
445
  }
421
446
  if (!tag) return refuse('intake.ideaTag is empty — an idea is a work item carrying that tag, so set one')
447
+ // A product files the idea in its area, so each product's stakeholders see
448
+ // their own ideas. Resolved before any call: an unknown product refuses with
449
+ // the text handed back, rather than filing it at the root.
450
+ let area
451
+ if (verb === 'add' && flags.product) {
452
+ try {
453
+ area = productArea(config, flags.product)
454
+ } catch (error) {
455
+ return refuse(`${error.message}; nothing was written`, { text })
456
+ }
457
+ }
422
458
 
423
459
  const cred = apiAdapterFor(config, flags)
424
460
  if (kit.resolveTransport(flags, config, cred.ok) === 'mcp' || !cred.ok) {
@@ -450,9 +486,9 @@ async function specSyncIdea(dir, config, positional, flags, out) {
450
486
  if (at === -1) return refuse('nothing to capture — give the idea some text')
451
487
  const title = lines[at].trim()
452
488
  const description = lines.slice(at + 1).join('\n').trim()
453
- const made = await az.createIssue({ title, description, workItemType: type, tags: [tag] })
454
- say({ ok: true, store: 'azure-boards', action: 'add', identifier: made.identifier, url: made.url, title }, [
455
- `${PROGRAM} idea: filed ${made.identifier} "${title}" (${type}, tagged "${tag}", no area path)`,
489
+ const made = await az.createIssue({ title, description, workItemType: type, tags: [tag], ...(area ? { areaPath: area } : {}) })
490
+ say({ ok: true, store: 'azure-boards', action: 'add', identifier: made.identifier, url: made.url, title, areaPath: area || null }, [
491
+ `${PROGRAM} idea: filed ${made.identifier} "${title}" (${type}, tagged "${tag}", ${area ? `in ${area}` : 'no area path'})`,
456
492
  ` url: ${made.url}`,
457
493
  ` promote: /spec ${made.identifier}`,
458
494
  ])
@@ -686,6 +722,17 @@ function specSyncNormalize(dir, config, specArg, out, err) {
686
722
  return 0
687
723
  }
688
724
 
725
+ // `push`, with a spec whose product the config cannot place returned as a
726
+ // refusal rather than thrown: it names a fix for the reader, not a crash.
727
+ function planOrRefusal(args) {
728
+ try {
729
+ return push(args)
730
+ } catch (error) {
731
+ if (error && error.placementRefused) return { refused: error.message }
732
+ throw error
733
+ }
734
+ }
735
+
689
736
  function specSyncPlan(dir, config, specArg, flags, out, err) {
690
737
  const snapshotDir = resolveOrExit(specArg, dir, out)
691
738
  if (!snapshotDir) return 1
@@ -696,7 +743,11 @@ function specSyncPlan(dir, config, specArg, flags, out, err) {
696
743
  }
697
744
  warnToErr(snapshotDir, config, err)
698
745
  const identifier = specIdentifier(snapshotDir, config)
699
- const r = push({ dir, snapshotDir, identifier, config })
746
+ const r = planOrRefusal({ dir, snapshotDir, identifier, config })
747
+ if (r.refused) {
748
+ out.write(`${PROGRAM} plan: refusing — ${r.refused}\n`)
749
+ return 1
750
+ }
700
751
  if (flags.json || !out.isTTY) {
701
752
  out.write(JSON.stringify(r.plan, null, 2) + '\n')
702
753
  return 0
@@ -817,7 +868,12 @@ async function specSyncApply(dir, config, specArg, flags, out, err) {
817
868
  for (const spec of specs) {
818
869
  const snapshotDir = resolveSnapshotDir(spec.spec, dir)
819
870
  const identifier = specIdentifier(snapshotDir, config)
820
- const r = push({ dir, snapshotDir, identifier, config })
871
+ const r = planOrRefusal({ dir, snapshotDir, identifier, config })
872
+ if (r.refused) {
873
+ failed++
874
+ out.write(`${PROGRAM} apply: ${spec.spec}\n !! ${r.refused}\n`)
875
+ continue
876
+ }
821
877
  if (r.empty) continue
822
878
  out.write(`${PROGRAM} apply: ${spec.spec}\n`)
823
879
  try {
@@ -842,7 +898,12 @@ async function specSyncApply(dir, config, specArg, flags, out, err) {
842
898
  if (!flags.plan) {
843
899
  // --send-held computes its own. After the merge it is normally empty, and
844
900
  // that empty plan is what tells apply that run 1 held the state.
845
- plan = push({ dir, snapshotDir, identifier: specIdentifier(snapshotDir, config), config }).plan
901
+ const r = planOrRefusal({ dir, snapshotDir, identifier: specIdentifier(snapshotDir, config), config })
902
+ if (r.refused) {
903
+ out.write(`${PROGRAM} apply: refusing — ${r.refused}\n`)
904
+ return 1
905
+ }
906
+ plan = r.plan
846
907
  } else {
847
908
  try {
848
909
  plan = JSON.parse(fs.readFileSync(flags.plan, 'utf-8'))
@@ -971,8 +1032,9 @@ function specSyncStatus(dir, config, specArg, flags, out, err) {
971
1032
  lines.push(' states: every configured state exists in the project')
972
1033
  }
973
1034
 
974
- const r = push({ dir, snapshotDir, identifier, config })
975
- if (r.empty) lines.push(' push: in sync — nothing would push')
1035
+ const r = planOrRefusal({ dir, snapshotDir, identifier, config })
1036
+ if (r.refused) lines.push(` push: refused — ${r.refused}`)
1037
+ else if (r.empty) lines.push(' push: in sync — nothing would push')
976
1038
  else {
977
1039
  const c = r.plan.subIssues.create.length
978
1040
  const u = r.plan.subIssues.update.length
@@ -1760,6 +1822,37 @@ async function specSyncDoctor(dir, flags, out) {
1760
1822
  : row('types', 'Mapped types', 'ok', 'every mapped type exists and carries its body field'),
1761
1823
  )
1762
1824
  }
1825
+ // Every product's area path, and the default they fall back to, must
1826
+ // exist — Azure refuses the whole write over an unknown area. NO ROW
1827
+ // when no product is set: a project that places nothing has nothing to
1828
+ // check. An area that could not be asked about is a warning, never a
1829
+ // failure (cannot-tell routes to the harmless branch).
1830
+ const productAreas = Object.values(config.azure.products || {}).map((p) => p.areaPath)
1831
+ if (productAreas.length) {
1832
+ const areas = [...new Set([...productAreas, config.azure.areaPath].filter(Boolean))]
1833
+ const missingAreas = []
1834
+ let unknownArea = null
1835
+ for (const area of areas) {
1836
+ try {
1837
+ if (!(await adapter.areaExists(area))) missingAreas.push(area)
1838
+ } catch (error) {
1839
+ unknownArea = `${area}: ${String((error && error.message) || error).split('\n')[0]}`
1840
+ }
1841
+ }
1842
+ checks.push(
1843
+ missingAreas.length
1844
+ ? row(
1845
+ 'areas',
1846
+ 'Product areas',
1847
+ 'broken',
1848
+ `not in the project: ${missingAreas.join(', ')}`,
1849
+ `create the area under Project settings → Areas, or fix ${CONFIG_FILE} -> azure.products / azure.areaPath`,
1850
+ )
1851
+ : unknownArea
1852
+ ? row('areas', 'Product areas', 'warn', `could not check ${unknownArea}`)
1853
+ : row('areas', 'Product areas', 'ok', `every product's area exists (${areas.length})`),
1854
+ )
1855
+ }
1763
1856
  // The capability probe Decision 8 names: identity search is the op
1764
1857
  // that fails first on a narrow token. A 401 here is a WARN, not
1765
1858
  // broken — work item sync is whole without it; only `users` search
@@ -1922,6 +2015,8 @@ const USAGE = `Usage: skitterspec-azure-boards spec-sync <subcommand>
1922
2015
  list [--all | --state NAME|BUCKET | --next N] [--mine | --by USER] tracker listing
1923
2016
  linked [--json] specs and their linked items (offline)
1924
2017
  idea add|list|drop [--json] ideas: work items tagged intake.ideaTag
2018
+ [--product <key>] add: file the idea in that product's area
2019
+ products [--json] the products a spec can name, and their areas
1925
2020
  ownership [--json] who owns status and assignee (offline)
1926
2021
  board <spec> [--json] is the item finished where the spec is not?
1927
2022
  ref [<spec>] the Refs: trailer value for this branch
@@ -2009,6 +2104,8 @@ async function specSync(rest, io = {}) {
2009
2104
  return specSyncIdea(dir, config, positional, flags, out)
2010
2105
  case 'ownership':
2011
2106
  return kit.specSyncOwnership(config, flags, out, PROGRAM)
2107
+ case 'products':
2108
+ return specSyncProducts(config, flags, out)
2012
2109
  case 'board':
2013
2110
  return specSyncBoard(dir, config, positional[0], flags, out)
2014
2111
  case 'states':
@@ -2086,6 +2183,7 @@ function parseArgs(args, sub) {
2086
2183
  '--release': { kind: 'boolean' },
2087
2184
  '--if-unassigned': { kind: 'boolean', name: 'ifUnassigned' },
2088
2185
  '--reason': { kind: 'value' },
2186
+ '--product': { kind: 'string' },
2089
2187
  '--count': { kind: 'boolean' },
2090
2188
  '--mine': { kind: 'boolean' },
2091
2189
  '--next': { kind: 'number' },
@@ -17,7 +17,7 @@ const { readFileSync } = require('node:fs')
17
17
  const { join, basename } = require('node:path')
18
18
 
19
19
  const kitConfig = require('../provider-kit/src/config.js')
20
- const { effectiveStates } = require('../sync-core')
20
+ const { effectiveStates, specHeaders } = require('../sync-core')
21
21
  const { dialect, htmlToText, looksLikeHtml } = require('./dialect.js')
22
22
 
23
23
  const CONFIG_FILE = 'specs/.core/azure-boards.config.json'
@@ -35,7 +35,10 @@ const DEFAULT_CONFIG = Object.freeze({
35
35
  // `project` is where spec work items land. `workItemType`/`childType` name
36
36
  // the types this project's process uses for a spec and its phases; the
37
37
  // defaults are the Basic template's, and any process overrides them here.
38
- // `areaPath` is optional — empty means the project default.
38
+ // `areaPath` is optional — empty means the project default. `products` maps
39
+ // a spec's `> **Product:**` key to the area path its items are filed in
40
+ // (`{ "tendering": { "areaPath": "LSC\\Tendering" } }`); with any product
41
+ // set, `areaPath` is where a spec without the header goes.
39
42
  azure: Object.freeze({
40
43
  orgUrl: '',
41
44
  project: '',
@@ -62,6 +65,7 @@ const DEFAULT_CONFIG = Object.freeze({
62
65
  // a write-only mapping would make `/spec-status` report every Bug as
63
66
  // edited. Empty means System.Description everywhere, as before.
64
67
  bodyFieldByType: Object.freeze({}),
68
+ products: Object.freeze({}),
65
69
  }),
66
70
  // A spec is a WORK ITEM; each phase a CHILD work item under a hierarchy
67
71
  // link. `tasks` selects how the phase's checkboxes reach that child's
@@ -235,6 +239,17 @@ function mergeConfig(base, parsed) {
235
239
  }
236
240
  base.azure.bodyFieldByType = byType
237
241
  }
242
+ if (isObject(parsed.azure.products)) {
243
+ // A product with no usable area path is dropped, never filed at the
244
+ // project root: a spec naming it is then refused as unknown, which says
245
+ // what is wrong where a silent root filing would not.
246
+ const products = {}
247
+ for (const [key, value] of Object.entries(parsed.azure.products)) {
248
+ const area = isObject(value) && typeof value.areaPath === 'string' ? value.areaPath.trim() : ''
249
+ if (String(key).trim() && area) products[String(key).trim()] = { areaPath: area }
250
+ }
251
+ base.azure.products = products
252
+ }
238
253
  // A trailing slash on the org would double up in every composed URL.
239
254
  if (base.azure.orgUrl) base.azure.orgUrl = base.azure.orgUrl.replace(/\/+$/, '')
240
255
  }
@@ -341,6 +356,30 @@ function stateNameFor(config, bucket, type) {
341
356
  return effectiveStates(config, config.statesByType, type)[bucket]
342
357
  }
343
358
 
359
+ /**
360
+ * The area path a spec's items are filed in, from its `> **Product:**` key.
361
+ * `undefined` when the project places nothing — no `azure.products` and no
362
+ * header — which leaves every push exactly as it was before products existed.
363
+ *
364
+ * Throws (refusing the push) for a key `azure.products` does not have, or a
365
+ * header in a project with no products: filing it in the default area instead
366
+ * would mix one product's work into another's, the thing this exists to stop.
367
+ */
368
+ function productArea(config, product) {
369
+ const products = (config.azure && config.azure.products) || {}
370
+ const keys = Object.keys(products)
371
+ if (product) {
372
+ if (!keys.length) {
373
+ throw new Error(`Product: ${product} — but ${CONFIG_FILE} sets no azure.products, so there is nowhere to file it`)
374
+ }
375
+ const key = keys.find((k) => k.toLowerCase() === String(product).toLowerCase())
376
+ if (!key) throw new Error(`unknown product "${product}" — ${CONFIG_FILE} azure.products has: ${keys.join(', ')}`)
377
+ return products[key].areaPath
378
+ }
379
+ if (!keys.length) return undefined
380
+ return config.azure.areaPath || undefined
381
+ }
382
+
344
383
  // Attach the parts of the provider contract that are code, not JSON: the
345
384
  // markdown dialect, and the `provider` block. Azure identifiers all share the
346
385
  // constant `AB` prefix (`AB#123`), so unlike Jira's project key there is
@@ -359,6 +398,11 @@ function withRuntime(config) {
359
398
  // as markdown or HTML depending on the item's era. Each hook falls back to
360
399
  // the flat Linear-like shape, so a pre-reduced payload keeps working.
361
400
  config.remote = {
401
+ // Where this spec's items are filed: its product's area path (sync-core
402
+ // `placement`), so a header change plans a move like any other edit.
403
+ placement(snapshotDir) {
404
+ return productArea(config, specHeaders(snapshotDir, config).product)
405
+ },
362
406
  // The state name a push writes for this bucket, recorded in the snapshot
363
407
  // so a state-map change is visible to `plan` (sync-core `stateNames`).
364
408
  // Resolved exactly as the apply resolves it: the spec item by its kind's
@@ -453,4 +497,5 @@ module.exports = {
453
497
  DEFAULT_TOKEN_ENV,
454
498
  ENV_CONFIG_DEFAULTS,
455
499
  IDENTIFIER_FIELD,
500
+ productArea,
456
501
  }
@@ -0,0 +1,29 @@
1
+ 'use strict'
2
+
3
+ // What this provider tells the shared engine at start-up. Its own bin calls
4
+ // this, and so does the base `skitterspec` bin when it finds this provider
5
+ // configured in the project (common src/provider.js). A published superset
6
+ // carries its own copy of the engine, so the caller passes in the modules to
7
+ // register ON: registering on this package's copy would leave the base bin's
8
+ // engine as unregistered as before.
9
+
10
+ const { CONFIG_FILE, ENV_CONFIG_DEFAULTS } = require('./config.js')
11
+
12
+ function register({ envConfig, idea }) {
13
+ // The isolation defaults, beneath the project's own env.config.json, so
14
+ // `spec-env stage` claims this provider's snapshot sidecar without a hand
15
+ // edit (see common src/env/config.js, setProviderEnvDefaults).
16
+ envConfig.setProviderEnvDefaults(ENV_CONFIG_DEFAULTS)
17
+ // The config file: present, it is what makes `land.specDocs` default to
18
+ // "branch" (see common src/env/config.js, setProviderConfigFile).
19
+ envConfig.setProviderConfigFile(CONFIG_FILE)
20
+ // Azure Boards holds ideas: a work item tagged `intake.ideaTag`, at the
21
+ // project root, so `skitterspec idea` hands Azure the command instead of
22
+ // writing specs/ideas.md (see common src/idea.js, selectStore).
23
+ idea.setProviderIdeaStore({
24
+ supports: true,
25
+ run: (sub, argv, { cwd, out } = {}) => require('./cli-sync.js').specSync(['idea', sub, ...argv], { cwd, out }),
26
+ })
27
+ }
28
+
29
+ module.exports = { register }
@@ -138,6 +138,9 @@ async function applyInner({
138
138
  // state name for these and only these (`recordPush`). A held state counts:
139
139
  // run 2 sends it, and what run 2 records has to match what run 1 committed.
140
140
  const sent = { issue: !!heldState || !!(plan.issue && plan.issue.state != null), subIssues: new Set() }
141
+ // A place rides the plan's issue: on a create it is always written, on an
142
+ // update only when the plan carries it. Recorded only once written.
143
+ sent.placement = !!(plan.issue && plan.issue.placement !== undefined)
141
144
  // Handed out immediately, so a throw from anywhere below still reports what
142
145
  // had been stamped by the time it happened.
143
146
  if (progress) progress.result = result
@@ -231,6 +231,18 @@ function stateNamesRecord(projection, previous, sent) {
231
231
  return out
232
232
  }
233
233
 
234
+ /**
235
+ * The `placement` record for a snapshot: the place this push SENT, or the one
236
+ * the previous snapshot had when this push sent none, or undefined. The same
237
+ * rule as `stateNamesRecord` — recording a place nobody wrote would claim the
238
+ * tracker holds it.
239
+ */
240
+ function placementRecord(projection, previous, sent) {
241
+ const p = projection || {}
242
+ if (sent && sent.placement && p.placement !== undefined) return p.placement
243
+ return previous && typeof previous.placement === 'string' ? previous.placement : undefined
244
+ }
245
+
234
246
  // Has the state an unchanged item maps to moved under it — a state-map edit in
235
247
  // the config rather than a move of the spec? Only a RECORDED name can say: an
236
248
  // item with none is cannot-tell and plans nothing, so an upgrade or a config
@@ -304,9 +316,27 @@ function planChanges(projection, snapshot, { linked = false, epic = false } = {}
304
316
  // is above, and nothing is retired (spec feat-epic-migration, Decision 2).
305
317
  if (epic && unclaimed.length) subIssues.retire = unclaimed.slice()
306
318
 
319
+ // PLACEMENT: where the items belong (Azure's area path). Sent when the
320
+ // project places specs and the place differs from the one last sent. An
321
+ // unrecorded place on a linked spec is sent too: placement only comes into
322
+ // play when the project configures it, so that first push is the move the
323
+ // project asked for, not a guess about someone else's filing.
324
+ const place = p.placement
325
+ const moved = place !== undefined && snap.placement !== place
326
+ if (place !== undefined) for (const c of subIssues.create) c.placement = place
327
+ if (moved) {
328
+ for (const s of p.subIssues || []) {
329
+ if (s.id == null) continue
330
+ const existing = subIssues.update.find((u) => String(u.id) === String(s.id))
331
+ if (existing) existing.placement = place
332
+ else subIssues.update.push({ ref: s.ref, id: s.id, placement: place })
333
+ }
334
+ }
335
+
307
336
  const plan = { subIssues }
308
337
  if (unstamped.length) plan.unstamped = unstamped
309
- const issue = issueChanges(p, snap, { linked })
338
+ let issue = issueChanges(p, snap, { linked })
339
+ if (moved) issue = { ...(issue || {}), placement: place }
310
340
  if (issue) plan.issue = issue
311
341
  return plan
312
342
  }
@@ -413,6 +443,7 @@ module.exports = {
413
443
  specIssueFieldHashes,
414
444
  snapshotOf,
415
445
  stateNamesRecord,
446
+ placementRecord,
416
447
  isEmptyPlan,
417
448
  hashField,
418
449
  stableStringify,
@@ -436,7 +436,7 @@ function readSnapshot(snapshotDir, config) {
436
436
  }
437
437
 
438
438
  // The spec's own `> **Severity:**`, `> **Incident:**`, `> **Epic:**`,
439
- // `> **Waits on:**` and `> **Lanes:**` headers, off the overview's blockquote
439
+ // `> **Waits on:**`, `> **Lanes:**` and `> **Product:**` headers, off the overview's blockquote
440
440
  // block. They are PUSH-TIME EXTRAS, deliberately not keys on `normalizeLocal`'s
441
441
  // field set: severity lands in a provider-specific home (a field, a label),
442
442
  // the incident and epic links as typed relations, and the waits and lanes are
@@ -448,7 +448,7 @@ function specHeaders(snapshotDir, config) {
448
448
  try {
449
449
  raw = fs.readFileSync(path.join(snapshotDir, overviewFile), 'utf-8')
450
450
  } catch {
451
- return { severity: null, incident: null, epic: null, waitsOn: [], lanes: null }
451
+ return { severity: null, incident: null, epic: null, waitsOn: [], lanes: null, product: null }
452
452
  }
453
453
  const read = (name) => {
454
454
  const m = new RegExp(`^>\\s*\\*\\*${name}:\\*\\*\\s*(.+)$`, 'm').exec(raw)
@@ -460,6 +460,7 @@ function specHeaders(snapshotDir, config) {
460
460
  epic: unquote(read('Epic')) || null,
461
461
  waitsOn: parseWaitsOn(read('Waits on')),
462
462
  lanes: parseLanes(read('Lanes')),
463
+ product: unquote(read('Product')) || null,
463
464
  }
464
465
  }
465
466
 
@@ -20,7 +20,7 @@ const path = require('node:path')
20
20
  const { normalizeLocal, phasesWithheld, phaseModeFor, ownershipOf, readSnapshot } = require('./normalize.js')
21
21
  const { descriptionMode } = require('./summary.js')
22
22
  const { fieldsOf } = require('./fields.js')
23
- const { planChanges, snapshotOf, stateNamesRecord, isEmptyPlan } = require('./compare.js')
23
+ const { planChanges, snapshotOf, stateNamesRecord, placementRecord, isEmptyPlan } = require('./compare.js')
24
24
  const { readBase, writeBase } = require('./base.js')
25
25
  const { detectLegacyMirror } = require('./legacy.js')
26
26
 
@@ -58,9 +58,34 @@ function projectionOf(snapshotDir, config) {
58
58
  // pulled, and read by name, so it can never reach a hash.
59
59
  if (ownershipOf(config, 'workflowState') === 'pull') projection.statePulled = true
60
60
  attachStateNames(projection, snapshotDir, config)
61
+ attachPlacement(projection, snapshotDir, config)
61
62
  return projection
62
63
  }
63
64
 
65
+ // Where on the tracker this spec's items belong — Azure's area path, from the
66
+ // provider's `config.remote.placement(snapshotDir)` hook: a string when the
67
+ // project places specs, `undefined` when it does not (no hook, or the hook
68
+ // says the feature is not in play). Read by name, so it never reaches a hash:
69
+ // recorded beside them as `placement`, it is what lets a plan see a spec move
70
+ // that no field hash covers. A hook that throws REFUSES the plan — a spec
71
+ // naming a place the project does not have must not be filed somewhere else —
72
+ // but only the plan: the error is carried, not raised, so a status or a list
73
+ // over every spec is not taken down by one spec's bad header.
74
+ function attachPlacement(projection, snapshotDir, config) {
75
+ const hook = config && config.remote && config.remote.placement
76
+ if (typeof hook !== 'function') return
77
+ let value
78
+ try {
79
+ value = hook(snapshotDir)
80
+ } catch (error) {
81
+ // Tagged, so a caller can relay it as the refusal it is rather than a crash.
82
+ if (error && typeof error === 'object') error.placementRefused = true
83
+ Object.defineProperty(projection, 'placementError', { value: error, enumerable: false })
84
+ return
85
+ }
86
+ if (typeof value === 'string' && value) projection.placement = value
87
+ }
88
+
64
89
  // The tracker state NAME each bucket resolves to today, from the provider's
65
90
  // `config.remote.writtenStateName(bucket, role, snapshotDir)` hook: a string,
66
91
  // `null` for "this bucket sends no state", or `undefined` for cannot-tell — no
@@ -103,6 +128,7 @@ function isLinked(snapshotDir, config) {
103
128
 
104
129
  function push({ dir, snapshotDir, identifier, config }) {
105
130
  const projection = projectionOf(snapshotDir, config)
131
+ if (projection.placementError) throw projection.placementError
106
132
  const snapshot = readBase(dir, identifier, config)
107
133
  const epic = path.basename(String(snapshotDir || '')).startsWith('epic-')
108
134
  const plan = planChanges(projection, snapshot, { linked: isLinked(snapshotDir, config), epic })
@@ -150,6 +176,8 @@ function recordPush({ dir, snapshotDir, identifier, config, sent = null, keepSub
150
176
  }
151
177
  const names = stateNamesRecord(projection, before, sent)
152
178
  if (names) snapshot.stateNames = names
179
+ const placement = placementRecord(projection, before, sent)
180
+ if (placement !== undefined) snapshot.placement = placement
153
181
  return writeBase(dir, identifier, config, snapshot)
154
182
  }
155
183